Merge pull request #84 in MIN/mineplex from virizion_utils to master

* commit '9d380a0b317b321831688eb7b9b3f4eb21281ad6':
  Added an utility method in UtilBlock to get an ItemStack from a block and also handles correcting Material types and Data Values.
This commit is contained in:
Christopher Jozsa 2015-11-30 17:34:24 -06:00
commit 26b374f4f0

View File

@ -843,4 +843,398 @@ public class UtilBlock
return blocks;
}
public static ItemStack blockToInventoryItemStack(Block block)
{
ItemStack itemStack = new ItemStack(block.getType(), 1, block.getData());
switch (block.getType())
{
case SAPLING:
itemStack.setDurability((short) 0);
break;
case WATER:
itemStack.setType(Material.WATER_BUCKET);
itemStack.setDurability((short) 0);
break;
case STATIONARY_WATER:
itemStack.setType(Material.WATER_BUCKET);
itemStack.setDurability((short) 0);
break;
case LAVA:
itemStack.setType(Material.LAVA_BUCKET);
itemStack.setDurability((short) 0);
break;
case STATIONARY_LAVA:
itemStack.setType(Material.LAVA_BUCKET);
itemStack.setDurability((short) 0);
break;
case LOG:
itemStack.setDurability((short) (itemStack.getDurability() % 4));
break;
case LEAVES:
itemStack.setDurability((short) (itemStack.getDurability() % 4));
break;
case DISPENSER:
itemStack.setDurability((short) 0);
break;
case BED_BLOCK:
itemStack.setType(Material.BED);
itemStack.setDurability((short) 0);
break;
case POWERED_RAIL:
itemStack.setDurability((short) 0);
break;
case DETECTOR_RAIL:
itemStack.setDurability((short) 0);
break;
case PISTON_STICKY_BASE:
itemStack.setDurability((short) 0);
break;
case PISTON_BASE:
itemStack.setDurability((short) 0);
break;
case PISTON_EXTENSION:
itemStack.setType(Material.AIR);
itemStack.setDurability((short) 0);
break;
case PISTON_MOVING_PIECE:
itemStack.setType(Material.AIR);
itemStack.setDurability((short) 0);
break;
case DOUBLE_STEP:
itemStack.setType(Material.STEP);
itemStack.setAmount(2);
break;
case STEP:
itemStack.setDurability((short) (itemStack.getDurability() % 8));
break;
case TORCH:
itemStack.setDurability((short) 0);
break;
case FIRE:
itemStack.setType(Material.FIREBALL);
itemStack.setDurability((short) 0);
break;
case WOOD_STAIRS:
itemStack.setDurability((short) 0);
break;
case CHEST:
itemStack.setDurability((short) 0);
break;
case REDSTONE_WIRE:
itemStack.setType(Material.REDSTONE);
itemStack.setDurability((short) 0);
break;
case CROPS:
itemStack.setType(Material.SEEDS);
itemStack.setDurability((short) 0);
break;
case SOIL:
itemStack.setType(Material.DIRT);
itemStack.setDurability((short) 0);
break;
case FURNACE:
itemStack.setDurability((short) 0);
break;
case BURNING_FURNACE:
itemStack.setType(Material.FURNACE);
itemStack.setDurability((short) 0);
break;
case SIGN_POST:
itemStack.setType(Material.SIGN);
itemStack.setDurability((short) 0);
break;
case WOODEN_DOOR:
itemStack.setType(Material.WOOD_DOOR);
itemStack.setDurability((short) 0);
break;
case LADDER:
itemStack.setDurability((short) 0);
break;
case RAILS:
itemStack.setDurability((short) 0);
break;
case COBBLESTONE_STAIRS:
itemStack.setDurability((short) 0);
break;
case WALL_SIGN:
itemStack.setType(Material.SIGN);
itemStack.setDurability((short) 0);
break;
case LEVER:
itemStack.setDurability((short) 0);
break;
case STONE_PLATE:
itemStack.setDurability((short) 0);
break;
case IRON_DOOR_BLOCK:
itemStack.setType(Material.IRON_DOOR);
itemStack.setDurability((short) 0);
break;
case WOOD_PLATE:
itemStack.setDurability((short) 0);
break;
case GLOWING_REDSTONE_ORE:
itemStack.setType(Material.REDSTONE_ORE);
break;
case REDSTONE_TORCH_OFF:
itemStack.setType(Material.REDSTONE_TORCH_ON);
itemStack.setDurability((short) 0);
break;
case REDSTONE_TORCH_ON:
itemStack.setDurability((short) 0);
break;
case STONE_BUTTON:
itemStack.setDurability((short) 0);
break;
case SNOW:
itemStack.setAmount(1 + itemStack.getDurability());
itemStack.setDurability((short) 0);
break;
case CACTUS:
itemStack.setDurability((short) 0);
break;
case SUGAR_CANE_BLOCK:
itemStack.setType(Material.SUGAR_CANE);
itemStack.setDurability((short) 0);
break;
case JUKEBOX:
itemStack.setDurability((short) 0);
break;
case PORTAL:
itemStack.setType(Material.AIR);
itemStack.setDurability((short) 0);
break;
case CAKE_BLOCK:
itemStack.setType(Material.CAKE);
itemStack.setDurability((short) 0);
break;
case DIODE_BLOCK_OFF:
itemStack.setType(Material.DIODE);
itemStack.setDurability((short) 0);
break;
case DIODE_BLOCK_ON:
itemStack.setType(Material.DIODE);
itemStack.setDurability((short) 0);
break;
case TRAP_DOOR:
itemStack.setDurability((short) 0);
break;
case HUGE_MUSHROOM_1:
itemStack.setDurability((short) 0);
break;
case HUGE_MUSHROOM_2:
itemStack.setDurability((short) 0);
break;
case PUMPKIN_STEM:
itemStack.setType(Material.PUMPKIN_SEEDS);
itemStack.setDurability((short) 0);
break;
case MELON_STEM:
itemStack.setType(Material.MELON_SEEDS);
itemStack.setDurability((short) 0);
break;
case VINE:
itemStack.setDurability((short) 0);
break;
case FENCE_GATE:
itemStack.setDurability((short) 0);
break;
case BRICK_STAIRS:
itemStack.setDurability((short) 0);
break;
case SMOOTH_STAIRS:
itemStack.setDurability((short) 0);
break;
case NETHER_BRICK_STAIRS:
itemStack.setDurability((short) 0);
break;
case NETHER_WARTS:
itemStack.setType(Material.NETHER_STALK);
itemStack.setDurability((short) 0);
break;
case BREWING_STAND:
itemStack.setType(Material.BREWING_STAND_ITEM);
itemStack.setDurability((short) 0);
break;
case CAULDRON:
itemStack.setType(Material.CAULDRON_ITEM);
itemStack.setDurability((short) 0);
break;
case ENDER_PORTAL:
itemStack.setType(Material.AIR);
itemStack.setDurability((short) 0);
break;
case ENDER_PORTAL_FRAME:
itemStack.setDurability((short) 0);
break;
case REDSTONE_LAMP_ON:
itemStack.setType(Material.REDSTONE_LAMP_OFF);
break;
case WOOD_DOUBLE_STEP:
itemStack.setType(Material.WOOD_STEP);
itemStack.setAmount(2);
break;
case WOOD_STEP:
itemStack.setDurability((short) (itemStack.getDurability() % 8));
break;
case COCOA:
itemStack.setType(Material.INK_SACK);
itemStack.setDurability((short) 3);
break;
case SANDSTONE_STAIRS:
itemStack.setDurability((short) 0);
break;
case ENDER_CHEST:
itemStack.setDurability((short) 0);
break;
case TRIPWIRE_HOOK:
itemStack.setDurability((short) 0);
break;
case TRIPWIRE:
itemStack.setType(Material.STRING);
itemStack.setDurability((short) 0);
break;
case SPRUCE_WOOD_STAIRS:
itemStack.setDurability((short) 0);
break;
case BIRCH_WOOD_STAIRS:
itemStack.setDurability((short) 0);
break;
case JUNGLE_WOOD_STAIRS:
itemStack.setDurability((short) 0);
break;
case COMMAND:
itemStack.setDurability((short) 0);
break;
case FLOWER_POT:
itemStack.setType(Material.FLOWER_POT_ITEM);
itemStack.setDurability((short) 0);
break;
case CARROT:
itemStack.setType(Material.CARROT_ITEM);
itemStack.setDurability((short) 0);
break;
case POTATO:
itemStack.setType(Material.POTATO_ITEM);
itemStack.setDurability((short) 0);
break;
case WOOD_BUTTON:
itemStack.setDurability((short) 0);
break;
case SKULL:
itemStack.setType(Material.SKULL_ITEM);
break;
case TRAPPED_CHEST:
itemStack.setDurability((short) 0);
break;
case GOLD_PLATE:
itemStack.setDurability((short) 0);
break;
case IRON_PLATE:
itemStack.setDurability((short) 0);
break;
case REDSTONE_COMPARATOR_OFF:
itemStack.setType(Material.REDSTONE_COMPARATOR);
itemStack.setDurability((short) 0);
break;
case REDSTONE_COMPARATOR_ON:
itemStack.setType(Material.REDSTONE_COMPARATOR);
itemStack.setDurability((short) 0);
break;
case DAYLIGHT_DETECTOR:
itemStack.setDurability((short) 0);
break;
case HOPPER:
itemStack.setDurability((short) 0);
break;
case QUARTZ_STAIRS:
itemStack.setDurability((short) 0);
break;
case ACTIVATOR_RAIL:
itemStack.setDurability((short) 0);
break;
case DROPPER:
itemStack.setDurability((short) 0);
break;
case LEAVES_2:
itemStack.setDurability((short) (itemStack.getDurability() % 4));
break;
case LOG_2:
itemStack.setDurability((short) (itemStack.getDurability() % 4));
break;
case ACACIA_STAIRS:
itemStack.setDurability((short) 0);
break;
case DARK_OAK_STAIRS:
itemStack.setDurability((short) 0);
break;
case IRON_TRAPDOOR:
itemStack.setDurability((short) 0);
break;
case HAY_BLOCK:
itemStack.setDurability((short) 0);
break;
case STANDING_BANNER:
itemStack.setType(Material.BANNER);
itemStack.setDurability((short) 0);
break;
case WALL_BANNER:
itemStack.setType(Material.BANNER);
itemStack.setDurability((short) 0);
break;
case DAYLIGHT_DETECTOR_INVERTED:
itemStack.setType(Material.DAYLIGHT_DETECTOR);
itemStack.setDurability((short) 0);
break;
case RED_SANDSTONE_STAIRS:
itemStack.setDurability((short) 0);
break;
case DOUBLE_STONE_SLAB2:
itemStack.setType(Material.STONE_SLAB2);
itemStack.setAmount(2);
break;
case STONE_SLAB2:
itemStack.setDurability((short) (itemStack.getDurability() % 8));
break;
case SPRUCE_FENCE_GATE:
itemStack.setDurability((short) 0);
break;
case BIRCH_FENCE_GATE:
itemStack.setDurability((short) 0);
break;
case JUNGLE_FENCE_GATE:
itemStack.setDurability((short) 0);
break;
case DARK_OAK_FENCE_GATE:
itemStack.setDurability((short) 0);
break;
case ACACIA_FENCE_GATE:
itemStack.setDurability((short) 0);
break;
case SPRUCE_DOOR:
itemStack.setType(Material.SPRUCE_DOOR_ITEM);
itemStack.setDurability((short) 0);
break;
case BIRCH_DOOR:
itemStack.setType(Material.BIRCH_DOOR_ITEM);
itemStack.setDurability((short) 0);
break;
case JUNGLE_DOOR:
itemStack.setType(Material.JUNGLE_DOOR_ITEM);
itemStack.setDurability((short) 0);
break;
case ACACIA_DOOR:
itemStack.setType(Material.ACACIA_DOOR_ITEM);
itemStack.setDurability((short) 0);
break;
case DARK_OAK_DOOR:
itemStack.setType(Material.DARK_OAK_DOOR_ITEM);
itemStack.setDurability((short) 0);
break;
}
return itemStack;
}
}