2011-01-01 07:01:53 +00:00
|
|
|
package org.bukkit;
|
|
|
|
|
2011-01-13 23:33:10 +00:00
|
|
|
import java.lang.reflect.Constructor;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
2011-01-01 07:01:53 +00:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2011-01-13 23:33:10 +00:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
2011-01-15 20:38:41 +00:00
|
|
|
import org.bukkit.material.*;
|
2011-01-01 07:01:53 +00:00
|
|
|
|
|
|
|
/**
|
2011-01-15 20:53:43 +01:00
|
|
|
* An enum of all material ids accepted by the official server + client
|
2011-01-01 07:01:53 +00:00
|
|
|
*/
|
|
|
|
public enum Material {
|
2011-01-13 23:33:10 +00:00
|
|
|
AIR(0),
|
|
|
|
STONE(1),
|
|
|
|
GRASS(2),
|
|
|
|
DIRT(3),
|
|
|
|
COBBLESTONE(4),
|
|
|
|
WOOD(5),
|
2011-04-25 13:26:58 -07:00
|
|
|
SAPLING(6, Tree.class),
|
2011-01-13 23:33:10 +00:00
|
|
|
BEDROCK(7),
|
2011-04-02 16:42:12 -07:00
|
|
|
WATER(8, MaterialData.class),
|
|
|
|
STATIONARY_WATER(9, MaterialData.class),
|
|
|
|
LAVA(10, MaterialData.class),
|
|
|
|
STATIONARY_LAVA(11, MaterialData.class),
|
2011-01-13 23:33:10 +00:00
|
|
|
SAND(12),
|
|
|
|
GRAVEL(13),
|
|
|
|
GOLD_ORE(14),
|
|
|
|
IRON_ORE(15),
|
|
|
|
COAL_ORE(16),
|
2011-03-14 18:08:57 -07:00
|
|
|
LOG(17, Tree.class),
|
|
|
|
LEAVES(18, Tree.class),
|
2011-01-13 23:33:10 +00:00
|
|
|
SPONGE(19),
|
|
|
|
GLASS(20),
|
|
|
|
LAPIS_ORE(21),
|
|
|
|
LAPIS_BLOCK(22),
|
2011-04-02 16:42:12 -07:00
|
|
|
DISPENSER(23, Dispenser.class),
|
2011-01-13 23:33:10 +00:00
|
|
|
SANDSTONE(24),
|
|
|
|
NOTE_BLOCK(25),
|
2011-04-02 16:42:12 -07:00
|
|
|
BED_BLOCK(26, Bed.class),
|
2011-04-25 13:26:58 -07:00
|
|
|
POWERED_RAIL(27, PoweredRail.class),
|
|
|
|
DETECTOR_RAIL(28, DetectorRail.class),
|
2011-06-30 15:18:11 +01:00
|
|
|
PISTON_STICKY_BASE(29, PistonBaseMaterial.class),
|
2011-04-21 15:41:40 +01:00
|
|
|
WEB(30),
|
2011-06-07 02:15:19 -04:00
|
|
|
LONG_GRASS(31, LongGrass.class),
|
2011-05-26 06:28:24 +01:00
|
|
|
DEAD_BUSH(32),
|
2011-06-30 15:18:11 +01:00
|
|
|
PISTON_BASE(33, PistonBaseMaterial.class),
|
|
|
|
PISTON_EXTENSION(34, PistonExtensionMaterial.class),
|
2011-01-14 00:20:00 +00:00
|
|
|
WOOL(35, Wool.class),
|
2011-06-30 15:18:11 +01:00
|
|
|
PISTON_MOVING_PIECE(36),
|
2011-01-13 23:33:10 +00:00
|
|
|
YELLOW_FLOWER(37),
|
|
|
|
RED_ROSE(38),
|
|
|
|
BROWN_MUSHROOM(39),
|
|
|
|
RED_MUSHROOM(40),
|
|
|
|
GOLD_BLOCK(41),
|
|
|
|
IRON_BLOCK(42),
|
2011-03-14 18:08:57 -07:00
|
|
|
DOUBLE_STEP(43, Step.class),
|
|
|
|
STEP(44, Step.class),
|
2011-01-13 23:33:10 +00:00
|
|
|
BRICK(45),
|
2011-01-01 07:01:53 +00:00
|
|
|
TNT(46),
|
2011-01-13 23:33:10 +00:00
|
|
|
BOOKSHELF(47),
|
|
|
|
MOSSY_COBBLESTONE(48),
|
|
|
|
OBSIDIAN(49),
|
2011-01-15 20:38:41 +00:00
|
|
|
TORCH(50, Torch.class),
|
2011-01-13 23:33:10 +00:00
|
|
|
FIRE(51),
|
|
|
|
MOB_SPAWNER(52),
|
2011-04-02 16:42:12 -07:00
|
|
|
WOOD_STAIRS(53, Stairs.class),
|
2011-01-13 23:33:10 +00:00
|
|
|
CHEST(54),
|
2011-01-15 20:38:41 +00:00
|
|
|
REDSTONE_WIRE(55, RedstoneWire.class),
|
2011-01-13 23:33:10 +00:00
|
|
|
DIAMOND_ORE(56),
|
|
|
|
DIAMOND_BLOCK(57),
|
|
|
|
WORKBENCH(58),
|
2011-03-14 18:08:57 -07:00
|
|
|
CROPS(59, Crops.class),
|
2011-04-02 16:42:12 -07:00
|
|
|
SOIL(60, MaterialData.class),
|
|
|
|
FURNACE(61, Furnace.class),
|
|
|
|
BURNING_FURNACE(62, Furnace.class),
|
2011-01-20 02:51:17 +00:00
|
|
|
SIGN_POST(63, 1, Sign.class),
|
2011-03-25 14:54:58 -07:00
|
|
|
WOODEN_DOOR(64, Door.class),
|
2011-01-15 20:45:24 +00:00
|
|
|
LADDER(65, Ladder.class),
|
2011-04-02 16:42:12 -07:00
|
|
|
RAILS(66, Rails.class),
|
|
|
|
COBBLESTONE_STAIRS(67, Stairs.class),
|
2011-01-20 02:51:17 +00:00
|
|
|
WALL_SIGN(68, 1, Sign.class),
|
2011-01-15 20:51:16 +00:00
|
|
|
LEVER(69, Lever.class),
|
2011-04-02 16:42:12 -07:00
|
|
|
STONE_PLATE(70, PressurePlate.class),
|
2011-03-25 14:54:58 -07:00
|
|
|
IRON_DOOR_BLOCK(71, Door.class),
|
2011-04-02 16:42:12 -07:00
|
|
|
WOOD_PLATE(72, PressurePlate.class),
|
2011-01-13 23:33:10 +00:00
|
|
|
REDSTONE_ORE(73),
|
|
|
|
GLOWING_REDSTONE_ORE(74),
|
2011-01-15 20:38:41 +00:00
|
|
|
REDSTONE_TORCH_OFF(75, RedstoneTorch.class),
|
|
|
|
REDSTONE_TORCH_ON(76, RedstoneTorch.class),
|
2011-01-15 20:58:34 +00:00
|
|
|
STONE_BUTTON(77, Button.class),
|
2011-01-13 23:33:10 +00:00
|
|
|
SNOW(78),
|
|
|
|
ICE(79),
|
|
|
|
SNOW_BLOCK(80),
|
2011-04-02 16:42:12 -07:00
|
|
|
CACTUS(81, MaterialData.class),
|
2011-01-13 23:33:10 +00:00
|
|
|
CLAY(82),
|
2011-04-02 16:42:12 -07:00
|
|
|
SUGAR_CANE_BLOCK(83, MaterialData.class),
|
2011-08-22 01:27:48 -04:00
|
|
|
JUKEBOX(84),
|
2011-01-13 23:33:10 +00:00
|
|
|
FENCE(85),
|
2011-04-02 16:42:12 -07:00
|
|
|
PUMPKIN(86, Pumpkin.class),
|
2011-01-13 23:33:10 +00:00
|
|
|
NETHERRACK(87),
|
|
|
|
SOUL_SAND(88),
|
|
|
|
GLOWSTONE(89),
|
|
|
|
PORTAL(90),
|
2011-04-02 16:42:12 -07:00
|
|
|
JACK_O_LANTERN(91, Pumpkin.class),
|
2011-03-26 12:29:52 -04:00
|
|
|
CAKE_BLOCK(92, 1, Cake.class),
|
|
|
|
DIODE_BLOCK_OFF(93, Diode.class),
|
|
|
|
DIODE_BLOCK_ON(94, Diode.class),
|
2011-03-31 21:55:16 +01:00
|
|
|
LOCKED_CHEST(95),
|
2011-05-26 06:28:24 +01:00
|
|
|
TRAP_DOOR(96, TrapDoor.class),
|
2011-09-25 15:27:16 +01:00
|
|
|
MONSTER_EGGS(97, MonsterEggs.class),
|
2011-09-15 16:33:53 -07:00
|
|
|
SMOOTH_BRICK(98, SmoothBrick.class),
|
2011-09-15 02:54:19 +01:00
|
|
|
HUGE_MUSHROOM_1(99),
|
|
|
|
HUGE_MUSHROOM_2(100),
|
|
|
|
IRON_FENCE(101),
|
|
|
|
THIN_GLASS(102),
|
|
|
|
MELON_BLOCK(103),
|
|
|
|
PUMPKIN_STEM(104),
|
|
|
|
MELON_STEM(105),
|
|
|
|
VINE(106),
|
|
|
|
FENCE_GATE(107),
|
|
|
|
BRICK_STAIRS(108),
|
|
|
|
SMOOTH_STAIRS(109),
|
2011-10-29 09:43:19 +01:00
|
|
|
MYCEL(110),
|
|
|
|
WATER_LILY(111),
|
|
|
|
NETHER_BRICK(112),
|
|
|
|
NETHER_FENCE(113),
|
|
|
|
NETHER_BRICK_STAIRS(114),
|
2011-10-29 10:04:11 +01:00
|
|
|
NETHER_WARTS(115),
|
2011-10-29 09:43:19 +01:00
|
|
|
ENCHANTMENT_TABLE(116),
|
|
|
|
BREWING_STAND(117),
|
|
|
|
CAULDRON(118),
|
|
|
|
ENDER_PORTAL(119),
|
2011-11-28 15:52:11 +11:00
|
|
|
ENDER_PORTAL_FRAME(120),
|
2011-11-21 22:38:51 +00:00
|
|
|
ENDER_STONE(121),
|
|
|
|
DRAGON_EGG(122),
|
2011-01-31 01:06:53 +00:00
|
|
|
// ----- Item Separator -----
|
|
|
|
IRON_SPADE(256, 1, 250),
|
|
|
|
IRON_PICKAXE(257, 1, 250),
|
|
|
|
IRON_AXE(258, 1, 250),
|
|
|
|
FLINT_AND_STEEL(259, 1, 64),
|
2011-09-17 16:55:22 -04:00
|
|
|
APPLE(260),
|
2011-11-28 09:49:22 +11:00
|
|
|
BOW(261, 1, 384),
|
2011-01-13 23:33:10 +00:00
|
|
|
ARROW(262),
|
2011-03-14 18:08:57 -07:00
|
|
|
COAL(263, Coal.class),
|
2011-01-13 23:33:10 +00:00
|
|
|
DIAMOND(264),
|
|
|
|
IRON_INGOT(265),
|
|
|
|
GOLD_INGOT(266),
|
2011-06-07 02:23:01 -04:00
|
|
|
IRON_SWORD(267, 1, 250),
|
2011-01-31 01:06:53 +00:00
|
|
|
WOOD_SWORD(268, 1, 59),
|
|
|
|
WOOD_SPADE(269, 1, 59),
|
|
|
|
WOOD_PICKAXE(270, 1, 59),
|
|
|
|
WOOD_AXE(271, 1, 59),
|
|
|
|
STONE_SWORD(272, 1, 131),
|
|
|
|
STONE_SPADE(273, 1, 131),
|
|
|
|
STONE_PICKAXE(274, 1, 131),
|
|
|
|
STONE_AXE(275, 1, 131),
|
|
|
|
DIAMOND_SWORD(276, 1, 1561),
|
|
|
|
DIAMOND_SPADE(277, 1, 1561),
|
|
|
|
DIAMOND_PICKAXE(278, 1, 1561),
|
|
|
|
DIAMOND_AXE(279, 1, 1561),
|
2011-01-13 23:33:10 +00:00
|
|
|
STICK(280),
|
|
|
|
BOWL(281),
|
2011-01-20 02:51:17 +00:00
|
|
|
MUSHROOM_SOUP(282, 1),
|
2011-01-31 01:06:53 +00:00
|
|
|
GOLD_SWORD(283, 1, 32),
|
|
|
|
GOLD_SPADE(284, 1, 32),
|
|
|
|
GOLD_PICKAXE(285, 1, 32),
|
|
|
|
GOLD_AXE(286, 1, 32),
|
2011-01-13 23:33:10 +00:00
|
|
|
STRING(287),
|
|
|
|
FEATHER(288),
|
|
|
|
SULPHUR(289),
|
2011-01-31 01:06:53 +00:00
|
|
|
WOOD_HOE(290, 1, 59),
|
|
|
|
STONE_HOE(291, 1, 131),
|
|
|
|
IRON_HOE(292, 1, 250),
|
|
|
|
DIAMOND_HOE(293, 1, 1561),
|
|
|
|
GOLD_HOE(294, 1, 32),
|
2011-01-13 23:33:10 +00:00
|
|
|
SEEDS(295),
|
|
|
|
WHEAT(296),
|
2011-09-17 16:55:22 -04:00
|
|
|
BREAD(297),
|
2011-01-31 01:06:53 +00:00
|
|
|
LEATHER_HELMET(298, 1, 33),
|
|
|
|
LEATHER_CHESTPLATE(299, 1, 47),
|
|
|
|
LEATHER_LEGGINGS(300, 1, 45),
|
|
|
|
LEATHER_BOOTS(301, 1, 39),
|
|
|
|
CHAINMAIL_HELMET(302, 1, 66),
|
|
|
|
CHAINMAIL_CHESTPLATE(303, 1, 95),
|
|
|
|
CHAINMAIL_LEGGINGS(304, 1, 91),
|
|
|
|
CHAINMAIL_BOOTS(305, 1, 78),
|
|
|
|
IRON_HELMET(306, 1, 135),
|
|
|
|
IRON_CHESTPLATE(307, 1, 191),
|
|
|
|
IRON_LEGGINGS(308, 1, 183),
|
|
|
|
IRON_BOOTS(309, 1, 159),
|
|
|
|
DIAMOND_HELMET(310, 1, 271),
|
|
|
|
DIAMOND_CHESTPLATE(311, 1, 383),
|
|
|
|
DIAMOND_LEGGINGS(312, 1, 367),
|
|
|
|
DIAMOND_BOOTS(313, 1, 319),
|
|
|
|
GOLD_HELMET(314, 1, 67),
|
|
|
|
GOLD_CHESTPLATE(315, 1, 95),
|
|
|
|
GOLD_LEGGINGS(316, 1, 91),
|
|
|
|
GOLD_BOOTS(317, 1, 79),
|
2011-01-13 23:33:10 +00:00
|
|
|
FLINT(318),
|
2011-09-17 16:55:22 -04:00
|
|
|
PORK(319),
|
|
|
|
GRILLED_PORK(320),
|
2011-01-13 23:33:10 +00:00
|
|
|
PAINTING(321),
|
2011-09-17 16:55:22 -04:00
|
|
|
GOLDEN_APPLE(322),
|
2011-03-26 12:29:52 -04:00
|
|
|
SIGN(323, 1),
|
2011-01-20 02:51:17 +00:00
|
|
|
WOOD_DOOR(324, 1),
|
|
|
|
BUCKET(325, 1),
|
|
|
|
WATER_BUCKET(326, 1),
|
|
|
|
LAVA_BUCKET(327, 1),
|
|
|
|
MINECART(328, 1),
|
|
|
|
SADDLE(329, 1),
|
|
|
|
IRON_DOOR(330, 1),
|
2011-03-26 12:29:52 -04:00
|
|
|
REDSTONE(331),
|
2011-01-20 02:51:17 +00:00
|
|
|
SNOW_BALL(332, 16),
|
|
|
|
BOAT(333, 1),
|
2011-01-13 23:33:10 +00:00
|
|
|
LEATHER(334),
|
2011-07-12 02:24:14 -04:00
|
|
|
MILK_BUCKET(335, 1),
|
2011-01-13 23:33:10 +00:00
|
|
|
CLAY_BRICK(336),
|
|
|
|
CLAY_BALL(337),
|
|
|
|
SUGAR_CANE(338),
|
|
|
|
PAPER(339),
|
|
|
|
BOOK(340),
|
|
|
|
SLIME_BALL(341),
|
2011-01-20 02:51:17 +00:00
|
|
|
STORAGE_MINECART(342, 1),
|
|
|
|
POWERED_MINECART(343, 1),
|
|
|
|
EGG(344, 16),
|
2011-01-13 23:33:10 +00:00
|
|
|
COMPASS(345),
|
2011-07-12 02:24:14 -04:00
|
|
|
FISHING_ROD(346, 1, 64),
|
2011-01-13 23:33:10 +00:00
|
|
|
WATCH(347),
|
|
|
|
GLOWSTONE_DUST(348),
|
2011-09-17 16:55:22 -04:00
|
|
|
RAW_FISH(349),
|
|
|
|
COOKED_FISH(350),
|
2011-01-14 00:20:00 +00:00
|
|
|
INK_SACK(351, Dye.class),
|
2011-01-13 23:33:10 +00:00
|
|
|
BONE(352),
|
|
|
|
SUGAR(353),
|
2011-01-20 02:51:17 +00:00
|
|
|
CAKE(354, 1),
|
2011-07-12 02:24:14 -04:00
|
|
|
BED(355, 1),
|
2011-02-23 03:18:08 +00:00
|
|
|
DIODE(356),
|
2011-09-17 16:55:22 -04:00
|
|
|
COOKIE(357),
|
2011-07-12 02:24:14 -04:00
|
|
|
MAP(358, 1, MaterialData.class),
|
|
|
|
SHEARS(359, 1, 238),
|
2011-09-15 02:54:19 +01:00
|
|
|
MELON(360),
|
|
|
|
PUMPKIN_SEEDS(361),
|
|
|
|
MELON_SEEDS(362),
|
|
|
|
RAW_BEEF(363),
|
|
|
|
COOKED_BEEF(364),
|
|
|
|
RAW_CHICKEN(365),
|
|
|
|
COOKED_CHICKEN(366),
|
|
|
|
ROTTEN_FLESH(367),
|
2012-01-04 09:36:43 +01:00
|
|
|
ENDER_PEARL(368, 16),
|
2011-10-29 09:43:19 +01:00
|
|
|
BLAZE_ROD(369),
|
|
|
|
GHAST_TEAR(370),
|
|
|
|
GOLD_NUGGET(371),
|
|
|
|
NETHER_STALK(372),
|
2012-01-05 17:00:57 +01:00
|
|
|
POTION(373, 1),
|
2011-10-29 09:43:19 +01:00
|
|
|
GLASS_BOTTLE(374),
|
|
|
|
SPIDER_EYE(375),
|
|
|
|
FERMENTED_SPIDER_EYE(376),
|
|
|
|
BLAZE_POWDER(377),
|
|
|
|
MAGMA_CREAM(378),
|
|
|
|
BREWING_STAND_ITEM(379),
|
|
|
|
CAULDRON_ITEM(380),
|
|
|
|
EYE_OF_ENDER(381),
|
|
|
|
SPECKLED_MELON(382),
|
2011-01-20 02:51:17 +00:00
|
|
|
GOLD_RECORD(2256, 1),
|
2011-10-29 09:43:19 +01:00
|
|
|
GREEN_RECORD(2257, 1),
|
|
|
|
RECORD_3(2258, 1),
|
|
|
|
RECORD_4(2259, 1),
|
|
|
|
RECORD_5(2260, 1),
|
|
|
|
RECORD_6(2261, 1),
|
|
|
|
RECORD_7(2262, 1),
|
|
|
|
RECORD_8(2263, 1),
|
|
|
|
RECORD_9(2264, 1),
|
|
|
|
RECORD_10(2265, 1),
|
|
|
|
RECORD_11(2266, 1);
|
2011-01-01 08:01:07 -05:00
|
|
|
|
2011-01-01 07:01:53 +00:00
|
|
|
private final int id;
|
2011-01-14 00:20:00 +00:00
|
|
|
private final Class<? extends MaterialData> data;
|
2011-01-10 17:24:35 -05:00
|
|
|
private static final Map<Integer, Material> lookupId = new HashMap<Integer, Material>();
|
|
|
|
private static final Map<String, Material> lookupName = new HashMap<String, Material>();
|
2011-01-20 02:51:17 +00:00
|
|
|
private final int maxStack;
|
2011-01-31 01:06:53 +00:00
|
|
|
private final short durability;
|
2011-01-01 07:01:53 +00:00
|
|
|
|
|
|
|
private Material(final int id) {
|
2011-01-20 02:51:17 +00:00
|
|
|
this(id, 64);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Material(final int id, final int stack) {
|
|
|
|
this(id, stack, null);
|
2011-01-13 23:33:10 +00:00
|
|
|
}
|
|
|
|
|
2011-01-31 01:06:53 +00:00
|
|
|
private Material(final int id, final int stack, final int durability) {
|
|
|
|
this(id, stack, durability, null);
|
|
|
|
}
|
|
|
|
|
2011-01-14 00:20:00 +00:00
|
|
|
private Material(final int id, final Class<? extends MaterialData> data) {
|
2011-01-20 02:51:17 +00:00
|
|
|
this(id, 64, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Material(final int id, final int stack, final Class<? extends MaterialData> data) {
|
2011-03-02 00:23:48 -08:00
|
|
|
this(id, stack, -1, data);
|
2011-01-31 01:06:53 +00:00
|
|
|
}
|
|
|
|
|
2011-02-04 22:45:52 +01:00
|
|
|
private Material(final int id, final int stack, final int durability, final Class<? extends MaterialData> data) {
|
2011-01-01 07:01:53 +00:00
|
|
|
this.id = id;
|
2011-05-14 23:22:54 +02:00
|
|
|
this.durability = (short) durability;
|
2011-01-20 02:51:17 +00:00
|
|
|
this.maxStack = stack;
|
2011-01-31 01:06:53 +00:00
|
|
|
this.data = data;
|
2011-01-01 07:01:53 +00:00
|
|
|
}
|
|
|
|
|
2011-01-20 02:51:17 +00:00
|
|
|
/**
|
|
|
|
* Gets the item ID or block ID of this Material
|
|
|
|
*
|
|
|
|
* @return ID of this material
|
|
|
|
*/
|
2011-01-15 20:53:43 +01:00
|
|
|
public int getId() {
|
2011-01-01 07:01:53 +00:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2011-01-20 02:51:17 +00:00
|
|
|
/**
|
|
|
|
* Gets the maximum amount of this material that can be held in a stack
|
|
|
|
*
|
|
|
|
* @return Maximum stack size for this material
|
|
|
|
*/
|
|
|
|
public int getMaxStackSize() {
|
|
|
|
return maxStack;
|
|
|
|
}
|
|
|
|
|
2011-01-31 01:06:53 +00:00
|
|
|
/**
|
|
|
|
* Gets the maximum durability of this material
|
|
|
|
*
|
|
|
|
* @return Maximum durability for this material
|
|
|
|
*/
|
|
|
|
public short getMaxDurability() {
|
|
|
|
return durability;
|
|
|
|
}
|
|
|
|
|
2011-01-20 02:51:17 +00:00
|
|
|
/**
|
|
|
|
* Gets the MaterialData class associated with this Material
|
|
|
|
*
|
|
|
|
* @return MaterialData associated with this Material
|
|
|
|
*/
|
2011-01-14 00:20:00 +00:00
|
|
|
public Class<? extends MaterialData> getData() {
|
2011-09-25 03:05:07 +01:00
|
|
|
return (data == null) ? MaterialData.class : data;
|
2011-01-13 23:33:10 +00:00
|
|
|
}
|
|
|
|
|
2011-01-20 02:51:17 +00:00
|
|
|
/**
|
|
|
|
* Constructs a new MaterialData relevant for this Material, with the given
|
|
|
|
* initial data
|
|
|
|
*
|
|
|
|
* @param raw Initial data to construct the MaterialData with
|
|
|
|
* @return New MaterialData with the given data
|
|
|
|
*/
|
2011-01-13 23:33:10 +00:00
|
|
|
public MaterialData getNewData(final byte raw) {
|
|
|
|
if (data == null) {
|
2011-09-25 03:05:07 +01:00
|
|
|
return new MaterialData(id, raw);
|
2011-01-13 23:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2011-01-14 00:20:00 +00:00
|
|
|
Constructor<? extends MaterialData> ctor = data.getConstructor(int.class, byte.class);
|
2011-05-14 23:22:54 +02:00
|
|
|
|
2011-01-13 23:33:10 +00:00
|
|
|
return ctor.newInstance(id, raw);
|
|
|
|
} catch (InstantiationException ex) {
|
|
|
|
Logger.getLogger(Material.class.getName()).log(Level.SEVERE, null, ex);
|
|
|
|
} catch (IllegalAccessException ex) {
|
|
|
|
Logger.getLogger(Material.class.getName()).log(Level.SEVERE, null, ex);
|
|
|
|
} catch (IllegalArgumentException ex) {
|
|
|
|
Logger.getLogger(Material.class.getName()).log(Level.SEVERE, null, ex);
|
|
|
|
} catch (InvocationTargetException ex) {
|
|
|
|
Logger.getLogger(Material.class.getName()).log(Level.SEVERE, null, ex);
|
|
|
|
} catch (NoSuchMethodException ex) {
|
|
|
|
Logger.getLogger(Material.class.getName()).log(Level.SEVERE, null, ex);
|
|
|
|
} catch (SecurityException ex) {
|
|
|
|
Logger.getLogger(Material.class.getName()).log(Level.SEVERE, null, ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-01-20 02:51:17 +00:00
|
|
|
/**
|
|
|
|
* Checks if this Material is a placable block
|
|
|
|
*
|
|
|
|
* @return true if this material is a block
|
|
|
|
*/
|
2011-01-07 04:40:46 -05:00
|
|
|
public boolean isBlock() {
|
2011-02-02 00:02:08 +01:00
|
|
|
return id < 256;
|
2011-01-07 04:40:46 -05:00
|
|
|
}
|
2011-02-01 12:55:29 +00:00
|
|
|
|
2011-12-06 09:44:16 +00:00
|
|
|
/**
|
|
|
|
* Checks if this Material is edible.
|
|
|
|
*
|
|
|
|
* @return true if this Material is edible.
|
|
|
|
*/
|
|
|
|
public boolean isEdible() {
|
|
|
|
return equals(Material.BREAD)
|
|
|
|
|| equals(Material.COOKIE)
|
|
|
|
|| equals(Material.MELON)
|
|
|
|
|| equals(Material.MUSHROOM_SOUP)
|
|
|
|
|| equals(Material.RAW_CHICKEN)
|
|
|
|
|| equals(Material.COOKED_CHICKEN)
|
|
|
|
|| equals(Material.RAW_BEEF)
|
|
|
|
|| equals(Material.COOKED_BEEF)
|
|
|
|
|| equals(Material.RAW_FISH)
|
|
|
|
|| equals(Material.COOKED_FISH)
|
|
|
|
|| equals(Material.PORK)
|
|
|
|
|| equals(Material.GRILLED_PORK)
|
|
|
|
|| equals(Material.APPLE)
|
|
|
|
|| equals(Material.GOLDEN_APPLE)
|
|
|
|
|| equals(Material.ROTTEN_FLESH)
|
|
|
|
|| equals(Material.SPIDER_EYE);
|
|
|
|
}
|
|
|
|
|
2011-02-01 12:55:29 +00:00
|
|
|
/**
|
|
|
|
* Attempts to get the Material with the given ID
|
|
|
|
*
|
|
|
|
* @param id ID of the material to get
|
|
|
|
* @return Material if found, or null
|
|
|
|
*/
|
2011-01-01 07:01:53 +00:00
|
|
|
public static Material getMaterial(final int id) {
|
2011-01-10 17:24:35 -05:00
|
|
|
return lookupId.get(id);
|
|
|
|
}
|
|
|
|
|
2011-02-01 12:55:29 +00:00
|
|
|
/**
|
|
|
|
* Attempts to get the Material with the given name.
|
|
|
|
* This is a normal lookup, names must be the precise name they are given
|
|
|
|
* in the enum.
|
|
|
|
*
|
|
|
|
* @param name Name of the material to get
|
|
|
|
* @return Material if found, or null
|
|
|
|
*/
|
2011-01-10 17:24:35 -05:00
|
|
|
public static Material getMaterial(final String name) {
|
|
|
|
return lookupName.get(name);
|
2011-01-01 07:01:53 +00:00
|
|
|
}
|
2011-02-01 12:55:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempts to match the Material with the given name.
|
|
|
|
* This is a match lookup; names will be converted to uppercase, then stripped
|
|
|
|
* of special characters in an attempt to format it like the enum
|
|
|
|
*
|
|
|
|
* @param name Name of the material to get
|
|
|
|
* @return Material if found, or null
|
|
|
|
*/
|
|
|
|
public static Material matchMaterial(final String name) {
|
|
|
|
Material result = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
result = getMaterial(Integer.parseInt(name));
|
2011-05-14 23:22:54 +02:00
|
|
|
} catch (NumberFormatException ex) {}
|
2011-02-01 12:55:29 +00:00
|
|
|
|
|
|
|
if (result == null) {
|
|
|
|
String filtered = name.toUpperCase();
|
2011-05-14 23:22:54 +02:00
|
|
|
|
2011-02-01 12:55:29 +00:00
|
|
|
filtered = filtered.replaceAll("\\s+", "_").replaceAll("\\W", "");
|
|
|
|
result = lookupName.get(filtered);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2011-02-02 00:02:08 +01:00
|
|
|
|
2011-01-01 07:01:53 +00:00
|
|
|
static {
|
|
|
|
for (Material material : values()) {
|
2011-01-15 20:53:43 +01:00
|
|
|
lookupId.put(material.getId(), material);
|
2011-01-10 17:24:35 -05:00
|
|
|
lookupName.put(material.name(), material);
|
2011-01-01 07:01:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|