private int registerItem(Item item, String name, int idHint) { if (item instanceof ItemBlock) // ItemBlock, adjust id and clear the slot already occupied by the corresponding // block { Block block = ((ItemBlock) item).field_150939_a; int id = iBlockRegistry.getId(block); if (id == -1) // ItemBlock before its Block { if (idHint < 0 || availabilityMap.get(idHint) || idHint > MAX_BLOCK_ID) // non-suitable id, allocate one in the block id range, add would // use the item id range otherwise { id = availabilityMap.nextClearBit( MIN_BLOCK_ID); // find suitable id here, iItemRegistry would search from // MIN_ITEM_ID if (id > MAX_BLOCK_ID) throw new RuntimeException( String.format("Invalid id %d - maximum id range exceeded.", id)); FMLLog.fine( "Allocated id %d for ItemBlock %s in the block id range, original id requested: %d.", id, name, idHint); } else // idHint is suitable without changes { id = idHint; } } else // ItemBlock after its Block { FMLLog.fine( "Found matching Block %s for ItemBlock %s at id %d, original id requested: %d", block, item, id, idHint); freeSlot( id, item); // temporarily free the slot occupied by the Block for the item registration } idHint = id; } int itemId = iItemRegistry.add(idHint, name, item, availabilityMap); if (item instanceof ItemBlock) // verify { if (itemId != idHint) throw new IllegalStateException( String.format("ItemBlock at block id %d insertion failed, got id %d.", idHint, itemId)); verifyItemBlockName((ItemBlock) item); } // block the Block Registry slot with the same id useSlot(itemId); return itemId; }
private void doModEntityRegistration(Class<? extends Entity> entityClass, String entityName, int id, Object mod, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates) { ModContainer mc = FMLCommonHandler.instance().findContainerFor(mod); EntityRegistration er = new EntityRegistration(mc, entityClass, entityName, id, trackingRange, updateFrequency, sendsVelocityUpdates); try { entityClassRegistrations.put(entityClass, er); entityNames.put(entityName, mc); if (!EntityList.classToStringMapping.containsKey(entityClass)) { String entityModName = String.format("%s.%s", mc.getModId(), entityName); EntityList.classToStringMapping.put(entityClass, entityModName); EntityList.stringToClassMapping.put(entityModName, entityClass); FMLLog.finest("Automatically registered mod %s entity %s as %s", mc.getModId(), entityName, entityModName); } else { FMLLog.fine("Skipping automatic mod %s entity registration for already registered class %s", mc.getModId(), entityClass.getName()); } } catch (IllegalArgumentException e) { FMLLog.log(Level.WARNING, e, "The mod %s tried to register the entity (name,class) (%s,%s) one or both of which are already registered", mc.getModId(), entityName, entityClass.getName()); return; } entityRegistrations.put(mc, er); }
public static void freezeData() { FMLLog.fine("Freezing block and item id maps"); getMain().testConsistency(); frozen = new GameData(getMain()); frozen.testConsistency(); }
private void testConsistency() { // test if there's an entry for every set bit in availabilityMap for (int i = availabilityMap.nextSetBit(0); i >= 0; i = availabilityMap.nextSetBit(i + 1)) { if (iBlockRegistry.getRaw(i) == null && iItemRegistry.getRaw(i) == null && !blockedIds.contains(i)) { throw new IllegalStateException( String.format("availabilityMap references empty entries for id %d.", i)); } } for (int pass = 0; pass < 2; pass++) { boolean isBlock = pass == 0; String type = isBlock ? "block" : "item"; FMLControlledNamespacedRegistry<?> registry = isBlock ? iBlockRegistry : iItemRegistry; registry.validateContent( (isBlock ? MAX_BLOCK_ID : MAX_ITEM_ID), type, availabilityMap, blockedIds, iBlockRegistry); } FMLLog.fine("Registry consistency check successful"); }
public static void revertToFrozen() { if (frozen == null) { FMLLog.warning("Can't revert to frozen GameData state without freezing first."); } else { FMLLog.fine("Reverting to frozen data state."); getMain().set(frozen); } // the id mapping has reverted, ensure we sync up the object holders ObjectHolderRegistry.INSTANCE.applyObjectHolders(); }
public static void sendPacketToAllPlayers(Packet var0) { MinecraftServer var1 = FMLCommonHandler.instance().getMinecraftServerInstance(); if (var1 != null) { var1.getServerConfigurationManager().sendAll(var0); } else { FMLLog.fine( "Attempt to send packet to all in dimension without a server instance available", new Object[0]); } }
public static void sendPacketToAllAround( double var0, double var2, double var4, double var6, int var8, Packet var9) { MinecraftServer var10 = FMLCommonHandler.instance().getMinecraftServerInstance(); if (var10 != null) { var10.getServerConfigurationManager().sendPacketNearby(var0, var2, var4, var6, var8, var9); } else { FMLLog.fine( "Attempt to send packet to all around without a server instance available", new Object[0]); } }
private void adjustEntity(EntityAdjustMessage msg) { Entity ent = FMLClientHandler.instance().getWorldClient().getEntityByID(msg.entityId); if (ent != null) { ent.serverPosX = msg.serverX; ent.serverPosY = msg.serverY; ent.serverPosZ = msg.serverZ; } else { FMLLog.fine( "Attempted to adjust the position of entity %d which is not present on the client", msg.entityId); } }
@Override public void adjustEntityLocationOnClient(EntitySpawnAdjustmentPacket packet) { Entity ent = client.field_71441_e.func_73045_a(packet.entityId); if (ent != null) { ent.field_70118_ct = packet.serverX; ent.field_70117_cu = packet.serverY; ent.field_70116_cv = packet.serverZ; } else { FMLLog.fine( "Attempted to adjust the position of entity %d which is not present on the client", packet.entityId); } }
public static Integer[] getIDs(boolean check) { if (check) { List<World> allWorlds = Lists.newArrayList(weakWorldMap.keySet()); allWorlds.removeAll(worlds.values()); for (ListIterator<World> li = allWorlds.listIterator(); li.hasNext(); ) { World w = li.next(); leakedWorlds.add(System.identityHashCode(w)); } for (World w : allWorlds) { int leakCount = leakedWorlds.count(System.identityHashCode(w)); if (leakCount == 5) { FMLLog.fine( "The world %x (%s) may have leaked: first encounter (5 occurences).\n", System.identityHashCode(w), w.getWorldInfo().getWorldName()); } else if (leakCount % 5 == 0) { FMLLog.fine( "The world %x (%s) may have leaked: seen %d times.\n", System.identityHashCode(w), w.getWorldInfo().getWorldName(), leakCount); } } } return getIDs(); }
public void addNewTextureOverride( String textureToOverride, String overridingTexturePath, int location) { OverrideInfo info = new OverrideInfo(); info.index = location; info.override = overridingTexturePath; info.texture = textureToOverride; overrideInfo.put(textureToOverride, info); FMLLog.fine( "Overriding %s @ %d with %s. %d slots remaining", textureToOverride, location, overridingTexturePath, SpriteHelper.freeSlotCount(textureToOverride)); }
@Override public FMLPacket consumePacket(byte[] data) { sentModList = Lists.newArrayList(); ByteArrayDataInput in = ByteStreams.newDataInput(data); int listSize = in.readInt(); for (int i = 0; i < listSize; i++) { sentModList.add(in.readUTF()); } try { compatibilityLevel = in.readByte(); } catch (IllegalStateException e) { FMLLog.fine("No compatibility byte found - the server is too old"); } return this; }
/** * This packet is executed on the client to evaluate the server's mod list against the client * * @see cpw.mods.fml.common.network.FMLPacket#execute(INetworkManager, FMLNetworkHandler, * NetHandler, String) */ @Override public void execute( INetworkManager mgr, FMLNetworkHandler handler, NetHandler netHandler, String userName) { List<String> missingMods = Lists.newArrayList(); Map<String, String> modVersions = Maps.newHashMap(); Map<String, ModContainer> indexedModList = Maps.newHashMap(Loader.instance().getIndexedModList()); for (String m : sentModList) { ModContainer mc = indexedModList.get(m); if (mc == null) { missingMods.add(m); continue; } indexedModList.remove(m); modVersions.put(m, mc.getVersion()); } if (indexedModList.size() > 0) { for (Entry<String, ModContainer> e : indexedModList.entrySet()) { if (e.getValue().isNetworkMod()) { NetworkModHandler missingHandler = FMLNetworkHandler.instance().findNetworkModHandler(e.getValue()); if (missingHandler.requiresServerSide()) { // TODO : what should we do if a mod is marked "serverSideRequired"? Stop the // connection? FMLLog.warning( "The mod %s was not found on the server you connected to, but requested that the server side be present", e.getKey()); } } } } FMLLog.fine("The server has compatibility level %d", compatibilityLevel); FMLCommonHandler.instance().getSidedDelegate().setClientCompatibilityLevel(compatibilityLevel); mgr.func_74429_a( PacketDispatcher.getPacket( "FML", FMLPacket.makePacket(MOD_LIST_RESPONSE, modVersions, missingMods))); }
private int registerBlock(Block block, String name, int idHint) { // handle ItemBlock-before-Block registrations ItemBlock itemBlock = null; for (Item item : iItemRegistry.typeSafeIterable()) // find matching ItemBlock { if (item instanceof ItemBlock && ((ItemBlock) item).field_150939_a == block) { itemBlock = (ItemBlock) item; break; } } if (itemBlock != null) // has ItemBlock, adjust id and clear the slot already occupied by the // corresponding item { idHint = iItemRegistry.getId(itemBlock); FMLLog.fine("Found matching ItemBlock %s for Block %s at id %d", itemBlock, block, idHint); freeSlot( idHint, block); // temporarily free the slot occupied by the Item for the block registration } // add int blockId = iBlockRegistry.add(idHint, name, block, availabilityMap); if (itemBlock != null) // verify { if (blockId != idHint) throw new IllegalStateException( String.format( "Block at itemblock id %d insertion failed, got id %d.", idHint, blockId)); verifyItemBlockName(itemBlock); } useSlot(blockId); return blockId; }
@Override public ItemStack getStackInSlot(int i) { int j = 0; if (inventory[i] != null) { for (int k = 0; k < inventory[i].stackSize; k++) { Item item = inventory[i].getItem(); String s = item.getItemName(); FMLLog.fine(s); j = goldvalues.PriceItem(s); if (FMLCommonHandler.instance().getEffectiveSide().isServer()) gold.addGold(setPlayerName(player), j); this.par1player = (Player) player; PacketDispatcher.sendPacketToPlayer( PacketType.populatePacket(new PacketGold(player.username, gold.getGoldTotal(player))), par1player); } if (j != 0) { inventory[i] = null; } } return inventory[i]; }
@Override protected void parseEx(Node node) { NodeList childNodes = node.getChildNodes(); for (int i = 0; i < childNodes.getLength(); ++i) { Node child = childNodes.item(i); if (child.getNodeName().equals("meta")) { meta = Integer.parseInt(child.getTextContent()); } else if (child.getNodeName().equals("modifiedBy") && !child.getTextContent().isEmpty()) { String[] modifierTypes = child.getTextContent().split(","); ArrayList<SpellModifiers> list = new ArrayList<SpellModifiers>(); for (String s : modifierTypes) { try { SpellModifiers modifier = Enum.valueOf(SpellModifiers.class, s); list.add(modifier); } catch (Throwable t) { FMLLog.fine( "Ars Magica 2 >> Compendium Parsing Error - No modifiable constant exists with the name '%s'", s); } } this.modifiedBy = list.toArray(new SpellModifiers[list.size()]); } } }
public static List<String> processIdRematches( Iterable<MissingMapping> missedMappings, boolean isLocalWorld, GameData gameData, Map<String, Integer[]> remaps) { List<String> failed = Lists.newArrayList(); List<String> ignored = Lists.newArrayList(); List<String> warned = Lists.newArrayList(); List<String> defaulted = Lists.newArrayList(); for (MissingMapping remap : missedMappings) { FMLMissingMappingsEvent.Action action = remap.getAction(); if (action == FMLMissingMappingsEvent.Action.REMAP) { // block/item re-mapped, finish the registration with the new name/object, but the old id int currId, newId; String newName; if (remap.type == Type.BLOCK) { currId = getMain().iBlockRegistry.getId((Block) remap.getTarget()); newName = getMain().iBlockRegistry.getNameForObject(remap.getTarget()); FMLLog.fine("The Block %s is being remapped to %s.", remap.name, newName); newId = gameData.registerBlock((Block) remap.getTarget(), newName, remap.id); gameData.iBlockRegistry.addAlias(remap.name, newName); } else { currId = getMain().iItemRegistry.getId((Item) remap.getTarget()); newName = getMain().iItemRegistry.getNameForObject(remap.getTarget()); FMLLog.fine("The Item %s is being remapped to %s.", remap.name, newName); newId = gameData.registerItem((Item) remap.getTarget(), newName, remap.id); gameData.iItemRegistry.addAlias(remap.name, newName); } if (newId != remap.id) throw new IllegalStateException(); if (currId != newId) { FMLLog.info( "Fixed %s id mismatch %s: %d (init) -> %d (map).", remap.type == Type.BLOCK ? "block" : "item", newName, currId, newId); remaps.put(newName, new Integer[] {currId, newId}); } } else { // block item missing, warn as requested and block the id if (action == FMLMissingMappingsEvent.Action.DEFAULT) { defaulted.add(remap.name); } else if (action == FMLMissingMappingsEvent.Action.IGNORE) { ignored.add(remap.name); } else if (action == FMLMissingMappingsEvent.Action.FAIL) { failed.add(remap.name); } else if (action == FMLMissingMappingsEvent.Action.WARN) { warned.add(remap.name); } gameData.block(remap.id); // prevent the id from being reused later } } if (!defaulted.isEmpty()) { String text = "Forge Mod Loader detected missing blocks/items.\n\n" + "There are " + defaulted.size() + " missing blocks and items in this save.\n" + "If you continue the missing blocks/items will get removed.\n" + "A world backup will be automatically created in your saves directory.\n\n" + "Missing Blocks/Items:\n"; for (String s : defaulted) text += s + "\n"; boolean confirmed = StartupQuery.confirm(text); if (!confirmed) StartupQuery.abort(); try { ZipperUtil.backupWorld(); } catch (IOException e) { StartupQuery.notify("The world backup couldn't be created.\n\n" + e); StartupQuery.abort(); } warned.addAll(defaulted); } if (!failed.isEmpty()) { FMLLog.severe( "This world contains blocks and items that refuse to be remapped. The world will not be loaded"); return failed; } if (!warned.isEmpty()) { FMLLog.severe("This world contains block and item mappings that may cause world breakage"); return failed; } else if (!ignored.isEmpty()) { FMLLog.fine("There were %d missing mappings that have been ignored", ignored.size()); } return failed; }
public static List<String> injectWorldIDMap( Map<String, Integer> dataList, Set<Integer> blockedIds, Map<String, String> blockAliases, Map<String, String> itemAliases, boolean injectFrozenData, boolean isLocalWorld) { FMLLog.info( "Injecting existing block and item data into this %s instance", FMLCommonHandler.instance().getEffectiveSide().isServer() ? "server" : "client"); Map<String, Integer[]> remaps = Maps.newHashMap(); LinkedHashMap<String, Integer> missingMappings = new LinkedHashMap<String, Integer>(); getMain().testConsistency(); getMain().iBlockRegistry.dump(); getMain().iItemRegistry.dump(); GameData newData = new GameData(); for (int id : blockedIds) { newData.block(id); } for (Map.Entry<String, String> entry : blockAliases.entrySet()) { newData.iBlockRegistry.addAlias(entry.getKey(), entry.getValue()); } for (Map.Entry<String, String> entry : itemAliases.entrySet()) { newData.iItemRegistry.addAlias(entry.getKey(), entry.getValue()); } // process blocks and items in the world, blocks in the first pass, items in the second // blocks need to be added first for proper ItemBlock handling for (int pass = 0; pass < 2; pass++) { boolean isBlock = (pass == 0); for (Entry<String, Integer> entry : dataList.entrySet()) { String itemName = entry.getKey(); int newId = entry.getValue(); // names starting with 0x1 are blocks, skip if the type isn't handled by this pass if ((itemName.charAt(0) == '\u0001') != isBlock) continue; itemName = itemName.substring(1); int currId = isBlock ? getMain().iBlockRegistry.getId(itemName) : getMain().iItemRegistry.getId(itemName); if (currId == -1) { FMLLog.info("Found a missing id from the world %s", itemName); missingMappings.put(entry.getKey(), newId); continue; // no block/item -> nothing to add } else if (currId != newId) { FMLLog.fine( "Fixed %s id mismatch %s: %d (init) -> %d (map).", isBlock ? "block" : "item", itemName, currId, newId); remaps.put(itemName, new Integer[] {currId, newId}); } // register if (isBlock) { currId = newData.registerBlock(getMain().iBlockRegistry.getRaw(itemName), itemName, newId); } else { currId = newData.registerItem(getMain().iItemRegistry.getRaw(itemName), itemName, newId); } if (currId != newId) { throw new IllegalStateException( String.format( "Can't map %s %s to id %d, already occupied by %s, blocked %b, ItemBlock %b", isBlock ? "block" : "item", itemName, newId, isBlock ? newData.iBlockRegistry.getRaw(newId) : newData.iItemRegistry.getRaw(newId), newData.blockedIds.contains(newId), isBlock ? false : (getMain().iItemRegistry.getRaw(currId) instanceof ItemBlock))); } } } List<String> missedMappings = Loader.instance().fireMissingMappingEvent(missingMappings, isLocalWorld, newData, remaps); if (!missedMappings.isEmpty()) return missedMappings; if (injectFrozenData) // add blocks + items missing from the map { Map<String, Integer> missingBlocks = frozen.iBlockRegistry.getEntriesNotIn(newData.iBlockRegistry); Map<String, Integer> missingItems = frozen.iItemRegistry.getEntriesNotIn(newData.iItemRegistry); if (!missingBlocks.isEmpty() || !missingItems.isEmpty()) { FMLLog.info("Injecting new block and item data into this server instance."); for (int pass = 0; pass < 2; pass++) { boolean isBlock = pass == 0; Map<String, Integer> missing = (pass == 0) ? missingBlocks : missingItems; for (Entry<String, Integer> entry : missing.entrySet()) { String itemName = entry.getKey(); int currId = entry.getValue(); int newId; if (isBlock) { newId = newData.registerBlock(frozen.iBlockRegistry.getRaw(itemName), itemName, currId); } else { newId = newData.registerItem(frozen.iItemRegistry.getRaw(itemName), itemName, currId); } FMLLog.info( "Injected new block/item %s: %d (init) -> %d (map).", itemName, currId, newId); if (newId != currId) // a new id was assigned { remaps.put(itemName, new Integer[] {entry.getValue(), newId}); } } } } } newData.testConsistency(); getMain().set(newData); getMain().iBlockRegistry.dump(); getMain().iItemRegistry.dump(); Loader.instance().fireRemapEvent(remaps); // The id map changed, ensure we apply object holders ObjectHolderRegistry.INSTANCE.applyObjectHolders(); return ImmutableList.of(); }