public static Material getMaterialFromStatistic(net.minecraft.server.Statistic statistic) { String statisticString = statistic.name; String val = statisticString.substring(statisticString.lastIndexOf(".") + 1); Item item = (Item) Item.REGISTRY.get(new MinecraftKey(val)); if (item != null) { return Material.getMaterial(Item.getId(item)); } Block block = (Block) Block.REGISTRY.get(new MinecraftKey(val)); if (block != null) { return Material.getMaterial(Block.getId(block)); } try { return Material.getMaterial(Integer.parseInt(val)); } catch (NumberFormatException e) { return null; } }
@Override public List<String> tabCompleteInternalMaterialName(String token, List<String> completions) { ArrayList<String> results = Lists.newArrayList(); for (MinecraftKey key : (Set<MinecraftKey>)Item.REGISTRY.keySet()) { results.add(key.toString()); } return StringUtil.copyPartialMatches(token, results, completions); }
public static String getKey(Material material) { MinecraftKey key = Item.REGISTRY.b(CraftMagicNumbers.getItem(material)); return key == null ? null : key.toString(); }
public static @Nullable Material materialByKey(String key) { final Item item = Item.REGISTRY.get(new MinecraftKey(key)); return item == null ? null : CraftMagicNumbers.getMaterial(item); }
@Override public Material getMaterialFromInternalName(String name) { return getMaterial((Item) Item.REGISTRY.get(new MinecraftKey(name))); }
@Test public void testReverse() { for (MinecraftKey effect : SoundEffect.a.keySet()) { assertNotNull(effect + "", Sound.valueOf(effect.a().replace('.', '_').toUpperCase())); } }