public static String getItemName(String s) { // If this name is a number we parse the number then check the item registry for an item with that ID. // If the ID is valid we'll get the name, if not we'll get a null. // If the name isn't a number just return the name again. try { RegistryNamespaced rn = GameData.getItemRegistry(); int id = Integer.parseInt(s); if(rn.containsId(id)) return rn.getNameForObject(rn.getObjectById(id)); else return null; } catch (NumberFormatException e) {} return s; }
@SuppressWarnings({ "rawtypes", "unchecked" }) private static void overwrite_do(RegistryNamespaced registry, String name, Object object, Object oldThing) { int id = registry.getIDForObject(oldThing); BiMap map = (BiMap) ReflectionHelper.getField(registry, "registryObjects"); ObjectIntIdentityMap underlyingIntegerMap = (ObjectIntIdentityMap) ReflectionHelper .getField(registry, "underlyingIntegerMap"); underlyingIntegerMap.func_148746_a(object, id); map.remove(name); map.forcePut(name, object); }
@SuppressWarnings("unchecked") public static void overwriteEntry(RegistryNamespaced registry, String name, Object object) { Object oldThing = registry.getObject(name); Repl.overwrite_do(registry, name, object, oldThing); Multimap<String, Object> reg = Repl.replacements.get(registry); if (reg == null) { Repl.replacements.put(registry, reg = ArrayListMultimap.create()); } if (!reg.containsKey(name)) { reg.put(name, oldThing); } reg.put(name, object); Repl.alterDelegateChain(registry, name, object); }
@Override public Iterable<String[]> dump(int mode) { LinkedList<String[]> list = new LinkedList<String[]>(); RegistryNamespaced registry = registry(); for(T obj : (Iterable<T>)registry) list.add(dump(obj, registry.getIDForObject(obj), registry.getNameForObject(obj))); return list; }
@Override public Iterable<String[]> dump(int mode) { LinkedList<String[]> list = new LinkedList<String[]>(); RegistryNamespaced registry = registry(); for(T obj : (Iterable<T>)registry) list.add(dump(obj, registry.getIDForObject(obj), (String)registry.getNameForObject(obj))); return list; }
private static void alterDelegateChain(RegistryNamespaced registry, String id, Object object) { Multimap<String, Object> map = replacements.get(registry); List<Object> c = (List<Object>) map.get(id); int i = 0, e = c.size() - 1; Object end = c.get(e); for (; i <= e; ++i) { Object t = c.get(i); Repl.alterDelegate(t, end); } }
@SubscribeEvent(priority = EventPriority.HIGHEST) public void _(WorldEvent.Load event) { if (Repl.replacements.size() < 1) { return; } for (Map.Entry<RegistryNamespaced, Multimap<String, Object>> entry : Repl.replacements .entrySet()) { RegistryNamespaced reg = entry.getKey(); Multimap<String, Object> map = entry.getValue(); Iterator<String> v = map.keySet().iterator(); while (v.hasNext()) { String id = v.next(); List<Object> c = (List<Object>) map.get(id); int i = 0, e = c.size() - 1; Object end = c.get(e); if (reg.getIDForObject(c.get(0)) != reg.getIDForObject(end)) { for (; i <= e; ++i) { Object t = c.get(i); Object oldThing = reg.getObject(id); Repl.overwrite_do(reg, id, t, oldThing); Repl.alterDelegate(oldThing, end); } } } } }
@Override public void processCommand(ICommandSender cs, String[] args) { RegistryNamespaced rn = GameData.getItemRegistry(); if(cs instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) cs; try { Item i = null; ItemStack iStack = null; switch(args.length) { case 0: i = (player.getHeldItem() != null) ? player.getHeldItem().getItem() : null; break; case 1: i = (Item) rn.getObjectById(Integer.parseInt(args[0])); break; case 2: i = (Item) rn.getObjectById(Integer.parseInt(args[0])); break; } if(i == null) { Helper.toChatErr(cs, "No held item, or no such item."); return; } iStack = new ItemStack(i); int dmg = 0; switch(args.length) { case 0: iStack.setItemDamage(player.getHeldItem().getItemDamage()); dmg = iStack.getItemDamage(); break; case 1: iStack.setItemDamage(dmg); break; case 2: dmg = Integer.parseInt(args[1]); iStack.setItemDamage(dmg); break; } if(iStack != null) { Helper.toChat(cs, EnumChatFormatting.GRAY + "--"); Helper.toChat(cs, EnumChatFormatting.AQUA + "NNAME: "+ rn.getIDForObject(i) + ":" + dmg); Helper.toChat(cs, EnumChatFormatting.AQUA + "UNAME: "+ rn.getNameForObject(i)); int [] oIDs = OreDictionary.getOreIDs(iStack); for(int j = 0; j < oIDs.length; j++) { Helper.toChat(cs, EnumChatFormatting.AQUA + "ONAME: "+OreDictionary.getOreName(oIDs[j])); } } } catch(NumberFormatException e) { Helper.toChatErr(cs, "Non-number in numeric field."); } } }
public abstract RegistryNamespaced registry();