Added a "hand" pseudo block type that uses the currently selected block.

This commit is contained in:
TomyLobo 2013-11-03 19:34:46 +01:00
parent 8319eb6d91
commit 768adee389

View File

@ -397,44 +397,55 @@ public class WorldEdit {
int data = -1; int data = -1;
boolean parseDataValue = true; boolean parseDataValue = true;
if ("hand".equalsIgnoreCase(testID)) {
// Get the block type from the item in the user's hand.
final BaseBlock blockInHand = player.getBlockInHand();
if (blockInHand.getClass() != BaseBlock.class) {
return blockInHand;
}
// Attempt to parse the item ID or otherwise resolve an item/block blockId = blockInHand.getId();
// name to its numeric ID
try {
blockId = Integer.parseInt(testID);
blockType = BlockType.fromID(blockId); blockType = BlockType.fromID(blockId);
} catch (NumberFormatException e) { data = blockInHand.getData();
blockType = BlockType.lookup(testID); } else {
if (blockType == null) { // Attempt to parse the item ID or otherwise resolve an item/block
int t = server.resolveItem(testID); // name to its numeric ID
if (t > 0) { try {
blockType = BlockType.fromID(t); // Could be null blockId = Integer.parseInt(testID);
blockId = t; blockType = BlockType.fromID(blockId);
} catch (NumberFormatException e) {
blockType = BlockType.lookup(testID);
if (blockType == null) {
int t = server.resolveItem(testID);
if (t > 0) {
blockType = BlockType.fromID(t); // Could be null
blockId = t;
}
} }
} }
}
if (blockId == -1 && blockType == null) { if (blockId == -1 && blockType == null) {
// Maybe it's a cloth // Maybe it's a cloth
ClothColor col = ClothColor.lookup(testID); ClothColor col = ClothColor.lookup(testID);
if (col == null) { if (col == null) {
throw new UnknownItemException(arg); throw new UnknownItemException(arg);
}
blockType = BlockType.CLOTH;
data = col.getID();
// Prevent overriding the data value
parseDataValue = false;
} }
blockType = BlockType.CLOTH; // Read block ID
data = col.getID(); if (blockId == -1) {
blockId = blockType.getID();
}
// Prevent overriding the data value if (!player.getWorld().isValidBlockType(blockId)) {
parseDataValue = false; throw new UnknownItemException(arg);
} }
// Read block ID
if (blockId == -1) {
blockId = blockType.getID();
}
if (!player.getWorld().isValidBlockType(blockId)) {
throw new UnknownItemException(arg);
} }
if (!allowNoData && data == -1) { if (!allowNoData && data == -1) {