mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
Further work on items
This commit is contained in:
parent
001a3544fb
commit
1cc735e359
@ -290,7 +290,7 @@ public class BaseBlock extends Block implements TileEntityBlock {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
Tag idTag = nbtData.getValue().get("id");
|
Tag idTag = nbtData.getValue().get("id");
|
||||||
if (idTag != null && idTag instanceof StringTag) {
|
if (idTag instanceof StringTag) {
|
||||||
return ((StringTag) idTag).getValue();
|
return ((StringTag) idTag).getValue();
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return "";
|
||||||
@ -413,7 +413,7 @@ public class BaseBlock extends Block implements TileEntityBlock {
|
|||||||
* @return true if equal
|
* @return true if equal
|
||||||
*/
|
*/
|
||||||
public boolean equalsFuzzy(BaseBlock o) {
|
public boolean equalsFuzzy(BaseBlock o) {
|
||||||
return (getType() == o.getType()) && (getData() == o.getData() || getData() == -1 || o.getData() == -1);
|
return (getType().equals(o.getType())) && (getData() == o.getData() || getData() == -1 || o.getData() == -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,6 +26,10 @@ public class BlockType {
|
|||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
public BlockType(String id) {
|
public BlockType(String id) {
|
||||||
|
// If it has no namespace, assume minecraft.
|
||||||
|
if (!id.contains(":")) {
|
||||||
|
id = "minecraft:" + id;
|
||||||
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -587,6 +587,10 @@ public class BlockTypes {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static BlockType getBlockType(String id) {
|
public static BlockType getBlockType(String id) {
|
||||||
|
// If it has no namespace, assume minecraft.
|
||||||
|
if (id != null && !id.contains(":")) {
|
||||||
|
id = "minecraft:" + id;
|
||||||
|
}
|
||||||
return blockMapping.get(id);
|
return blockMapping.get(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,10 @@ public class ItemType {
|
|||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
public ItemType(String id) {
|
public ItemType(String id) {
|
||||||
|
// If it has no namespace, assume minecraft.
|
||||||
|
if (!id.contains(":")) {
|
||||||
|
id = "minecraft:" + id;
|
||||||
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -766,6 +766,10 @@ public class ItemTypes {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static ItemType getItemType(String id) {
|
public static ItemType getItemType(String id) {
|
||||||
|
// If it has no namespace, assume minecraft.
|
||||||
|
if (id != null && !id.contains(":")) {
|
||||||
|
id = "minecraft:" + id;
|
||||||
|
}
|
||||||
return itemMapping.get(id);
|
return itemMapping.get(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ import com.sk89q.worldedit.blocks.BaseItem;
|
|||||||
import com.sk89q.worldedit.util.command.composition.SimpleCommand;
|
import com.sk89q.worldedit.util.command.composition.SimpleCommand;
|
||||||
import com.sk89q.worldedit.entity.Entity;
|
import com.sk89q.worldedit.entity.Entity;
|
||||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
|
||||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.extent.Extent;
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
@ -65,8 +64,6 @@ public class ItemParser extends SimpleCommand<BaseItem> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
return WorldEdit.getInstance().getItemFactory().parseFromInput(itemString, parserContext);
|
return WorldEdit.getInstance().getItemFactory().parseFromInput(itemString, parserContext);
|
||||||
} catch (NoMatchException e) {
|
|
||||||
throw new CommandException(e.getMessage(), e);
|
|
||||||
} catch (InputParseException e) {
|
} catch (InputParseException e) {
|
||||||
throw new CommandException(e.getMessage(), e);
|
throw new CommandException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public class DefaultItemParser extends InputParser<BaseItem> {
|
|||||||
public BaseItem parseFromInput(String input, ParserContext context) throws InputParseException {
|
public BaseItem parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||||
String[] tokens = input.split(":", 3);
|
String[] tokens = input.split(":", 3);
|
||||||
BaseItem item;
|
BaseItem item;
|
||||||
short meta = 0;
|
short damage = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int id = Integer.parseInt(tokens[0]);
|
int id = Integer.parseInt(tokens[0]);
|
||||||
@ -43,24 +43,23 @@ public class DefaultItemParser extends InputParser<BaseItem> {
|
|||||||
// Parse metadata
|
// Parse metadata
|
||||||
if (tokens.length == 2) {
|
if (tokens.length == 2) {
|
||||||
try {
|
try {
|
||||||
meta = Short.parseShort(tokens[1]);
|
damage = Short.parseShort(tokens[1]);
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
throw new InputParseException("Expected '" + tokens[1] + "' to be a metadata value but it's not a number");
|
throw new InputParseException("Expected '" + tokens[1] + "' to be a damage value but it's not a number");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
item = context.requireWorld().getWorldData().getItemRegistry().createFromId(id);
|
item = context.requireWorld().getWorldData().getItemRegistry().createFromId(id);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
if (input.length() < 2) {
|
String name = tokens[0];
|
||||||
throw new InputParseException("'" + input + "' isn't a known item name format");
|
if (input.length() >= 2) {
|
||||||
|
name += ":" + tokens[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = tokens[0] + ":" + tokens[1];
|
|
||||||
|
|
||||||
// Parse metadata
|
// Parse metadata
|
||||||
if (tokens.length == 3) {
|
if (tokens.length == 3) {
|
||||||
try {
|
try {
|
||||||
meta = Short.parseShort(tokens[2]);
|
damage = Short.parseShort(tokens[2]);
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
throw new InputParseException("Expected '" + tokens[2] + "' to be a metadata value but it's not a number");
|
throw new InputParseException("Expected '" + tokens[2] + "' to be a metadata value but it's not a number");
|
||||||
}
|
}
|
||||||
@ -72,7 +71,7 @@ public class DefaultItemParser extends InputParser<BaseItem> {
|
|||||||
if (item == null) {
|
if (item == null) {
|
||||||
throw new InputParseException("'" + input + "' did not match any item");
|
throw new InputParseException("'" + input + "' did not match any item");
|
||||||
} else {
|
} else {
|
||||||
item.setData(meta);
|
item.setDamage(damage);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,6 +98,10 @@ public class BundledBlockData {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private BlockEntry findById(String id) {
|
private BlockEntry findById(String id) {
|
||||||
|
// If it has no namespace, assume minecraft.
|
||||||
|
if (!id.contains(":")) {
|
||||||
|
id = "minecraft:" + id;
|
||||||
|
}
|
||||||
return idMap.get(id);
|
return idMap.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,7 +194,7 @@ public class BundledBlockData {
|
|||||||
private String id;
|
private String id;
|
||||||
private String unlocalizedName;
|
private String unlocalizedName;
|
||||||
private List<String> aliases;
|
private List<String> aliases;
|
||||||
private Map<String, SimpleState> states = new HashMap<String, SimpleState>();
|
private Map<String, SimpleState> states = new HashMap<>();
|
||||||
private SimpleBlockMaterial material = new SimpleBlockMaterial();
|
private SimpleBlockMaterial material = new SimpleBlockMaterial();
|
||||||
|
|
||||||
void postDeserialization() {
|
void postDeserialization() {
|
||||||
|
@ -99,6 +99,10 @@ public class BundledItemData {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private ItemEntry findById(String id) {
|
private ItemEntry findById(String id) {
|
||||||
|
// If it has no namespace, assume minecraft.
|
||||||
|
if (!id.contains(":")) {
|
||||||
|
id = "minecraft:" + id;
|
||||||
|
}
|
||||||
return idMap.get(id);
|
return idMap.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,8 +33,7 @@ public class BundledItemRegistry implements ItemRegistry {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public BaseItem createFromId(String id) {
|
public BaseItem createFromId(String id) {
|
||||||
// TODO Fix legacy ID usage
|
return new BaseItem(ItemTypes.getItemType(id));
|
||||||
return new BaseItem(ItemTypes.getItemType(id).getLegacyId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* WorldEdit, a Minecraft world manipulation toolkit
|
|
||||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
||||||
* Copyright (C) WorldEdit team and contributors
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU Lesser General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.sk89q.worldedit.world.registry;
|
|
||||||
|
|
||||||
import com.sk89q.worldedit.blocks.BaseItem;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
public class NullItemRegistry implements ItemRegistry {
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public BaseItem createFromId(String id) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public BaseItem createFromId(int id) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user