Added data value mappings for certain blocks and made all other block types wildcard matches.

This commit is contained in:
TomyLobo 2013-12-01 23:57:09 +01:00
parent ef43e141ee
commit d467bf1386
2 changed files with 31 additions and 6 deletions

View File

@ -284,7 +284,25 @@ public enum BlockType {
} }
private static Map<Integer, BaseBlock> itemBlockMapping = new HashMap<Integer, BaseBlock>(); private static Map<Integer, BaseBlock> itemBlockMapping = new HashMap<Integer, BaseBlock>();
private static Map<Integer, BaseBlock> dataItemBlockMapping = new HashMap<Integer, BaseBlock>();
static { static {
for (int data = 0; data < 16; ++data) {
//dataItemBlockMapping.put(typeDataKey(BlockID.DIRT, data), new BaseBlock(BlockID.DIRT, data));
dataItemBlockMapping.put(typeDataKey(BlockID.WOOD, data), new BaseBlock(BlockID.WOOD, data));
dataItemBlockMapping.put(typeDataKey(BlockID.SAND, data), new BaseBlock(BlockID.SAND, data));
dataItemBlockMapping.put(typeDataKey(BlockID.SANDSTONE, data), new BaseBlock(BlockID.SANDSTONE, data));
dataItemBlockMapping.put(typeDataKey(BlockID.LONG_GRASS, data), new BaseBlock(BlockID.LONG_GRASS, data));
dataItemBlockMapping.put(typeDataKey(BlockID.CLOTH, data), new BaseBlock(BlockID.CLOTH, data));
dataItemBlockMapping.put(typeDataKey(BlockID.SILVERFISH_BLOCK, data), new BaseBlock(BlockID.SILVERFISH_BLOCK, data));
dataItemBlockMapping.put(typeDataKey(BlockID.STONE_BRICK, data), new BaseBlock(BlockID.STONE_BRICK, data));
dataItemBlockMapping.put(typeDataKey(BlockID.COBBLESTONE_WALL, data), new BaseBlock(BlockID.COBBLESTONE_WALL, data));
dataItemBlockMapping.put(typeDataKey(BlockID.STAINED_CLAY, data), new BaseBlock(BlockID.STAINED_CLAY, data));
dataItemBlockMapping.put(typeDataKey(BlockID.CARPET, data), new BaseBlock(BlockID.CARPET, data));
//dataItemBlockMapping.put(typeDataKey(BlockID.FLOWER, data), new BaseBlock(BlockID.FLOWER, data));
//dataItemBlockMapping.put(typeDataKey(BlockID.LARGE_FLOWER, data), new BaseBlock(BlockID.LARGE_FLOWER, data));
//dataItemBlockMapping.put(typeDataKey(BlockID.STAINED_GLASS, data), new BaseBlock(BlockID.STAINED_GLASS, data));
}
itemBlockMapping.put(ItemID.FLINT_AND_TINDER, new BaseBlock(BlockID.FIRE, -1)); itemBlockMapping.put(ItemID.FLINT_AND_TINDER, new BaseBlock(BlockID.FIRE, -1));
itemBlockMapping.put(ItemID.STRING, new BaseBlock(BlockID.TRIPWIRE, -1)); itemBlockMapping.put(ItemID.STRING, new BaseBlock(BlockID.TRIPWIRE, -1));
itemBlockMapping.put(ItemID.SEEDS, new BaseBlock(BlockID.CROPS, -1)); itemBlockMapping.put(ItemID.SEEDS, new BaseBlock(BlockID.CROPS, -1));
@ -312,8 +330,14 @@ public enum BlockType {
itemBlockMapping.put(ItemID.MILK_BUCKET, new BaseBlock(BlockID.SNOW, -1)); // Whoops, spilled the milk itemBlockMapping.put(ItemID.MILK_BUCKET, new BaseBlock(BlockID.SNOW, -1)); // Whoops, spilled the milk
} }
public static BaseBlock getBlockForItem(int typeId) { public static BaseBlock getBlockForItem(int typeId, int data) {
return itemBlockMapping.get(typeId); final BaseBlock block = itemBlockMapping.get(typeId);
if (block != null) {
return block;
}
return dataItemBlockMapping.get(typeDataKey(typeId, data));
} }
/** /**

View File

@ -166,9 +166,6 @@ public class BukkitUtil {
public static BaseBlock toBlock(LocalWorld world, ItemStack itemStack) throws WorldEditException { public static BaseBlock toBlock(LocalWorld world, ItemStack itemStack) throws WorldEditException {
final int typeId = itemStack.getTypeId(); final int typeId = itemStack.getTypeId();
if (world.isValidBlockType(typeId)) {
return new BaseBlock(typeId, itemStack.getDurability());
}
switch (typeId) { switch (typeId) {
case ItemID.INK_SACK: case ItemID.INK_SACK:
@ -182,13 +179,17 @@ public class BukkitUtil {
return new SkullBlock(0, (byte) itemStack.getDurability()); return new SkullBlock(0, (byte) itemStack.getDurability());
default: default:
final BaseBlock baseBlock = BlockType.getBlockForItem(typeId); final BaseBlock baseBlock = BlockType.getBlockForItem(typeId, itemStack.getDurability());
if (baseBlock != null) { if (baseBlock != null) {
return baseBlock; return baseBlock;
} }
break; break;
} }
if (world.isValidBlockType(typeId)) {
return new BaseBlock(typeId, -1);
}
throw new NotABlockException(typeId); throw new NotABlockException(typeId);
} }
} }