public void initializeMods() { progressBar.step("Initializing mods Phase 2"); // Mod controller should be in the initialization state here modController.distributeStateMessage(LoaderState.INITIALIZATION); progressBar.step("Initializing mods Phase 3"); modController.transition(LoaderState.POSTINITIALIZATION, false); modController.distributeStateMessage(FMLInterModComms.IMCEvent.class); ItemStackHolderInjector.INSTANCE.inject(); modController.distributeStateMessage(LoaderState.POSTINITIALIZATION); progressBar.step("Finishing up"); modController.transition(LoaderState.AVAILABLE, false); modController.distributeStateMessage(LoaderState.AVAILABLE); GameData.freezeData(); // Dump the custom registry data map, if necessary GameData.dumpRegistry(minecraftDir); FMLLog.info("Forge Mod Loader has successfully loaded %d mod%s", mods.size(), mods.size() == 1 ? "" : "s"); progressBar.step("Completing Minecraft initialization"); }
@Override protected void nerfStandardRecipes () { for (Item item : (Iterable<Item>) GameData.getItemRegistry()) { if ((item instanceof ItemTool || item instanceof ItemSword) && !isBBTool(item)) { String repairMaterial = BetterBeginningsHandler.getToolRepairMaterial(item); if (!Strings.isNullOrEmpty(repairMaterial) && !OreDictionary.getOres(repairMaterial).isEmpty()) { nerfToolRecipe(new ItemStack(item), repairMaterial); } } } }
protected ItemStack readItemStackFromData(DataInputStream data) throws IOException { ItemStack itemstack = null; String itemName = data.readUTF(); if (!itemName.isEmpty()) { Item item = GameData.getItemRegistry().getRaw(itemName); byte stackSize = data.readByte(); short meta = data.readShort(); itemstack = new ItemStack(item, stackSize, meta); if (item.isDamageable() || item.getShareTag()) { itemstack.stackTagCompound = this.readNBTTagCompound(data); } } return itemstack; }
@TileEvent(TileEventType.WORLD_NBT_WRITE) public void writeNBT(NBTTagCompound cmp){ cmp.setInteger(NBTKeys.storedMana.toString(), currMana); NBTTagCompound inv = new NBTTagCompound(); for (int i = 0; i < inventory.length; i++){ if (inventory[i] == null) continue; NBTTagCompound slot = new NBTTagCompound(); slot.setInteger(NBTKeys.amount.toString(), inventory[i].stackSize); slot.setString(NBTKeys.item.toString(), GameData.getItemRegistry().getNameForObject(inventory[i].getItem())); slot.setInteger(NBTKeys.metadata.toString(), inventory[i].getItemDamage()); if (inventory[i].hasTagCompound()) slot.setString(NBTKeys.nbt.toString(), inventory[i].getTagCompound().toString()); else slot.setString(NBTKeys.nbt.toString(), ""); inv.setTag("#" + i, slot); } cmp.setTag(NBTKeys.inventory.toString(), inv); }
protected String[] blockListToBlockNames(final List<Block> blockList) { if ((blockList == null) || blockList.isEmpty()) { return new String[0]; } else { final String[] result = new String[blockList.size()]; int index = 0; for (final Block block : blockList) { final String blockname = GameData.getBlockRegistry().getNameForObject(block); if (blockname != null) { result[index] = blockname; ++index; } else { DaVincing.log.warn("Ignoring invalid block configuration entry: %s", Utils.blockToString(block)); } } Arrays.sort(result); return result; } }
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; }
@Override public void readCustomNBT(NBTTagCompound compound) { String parentType = compound.getString("parentType"); if(parentType.length() > 0) { Block block = GameData.getBlockRegistry().getObject(parentType); if(block != null && compound.hasKey("parent") && compound.hasKey("parentMetadata")) { NBTTagCompound data = compound.getCompoundTag("parent"); int metadata = compound.getInteger("parentMetadata"); TileEntity tile = block.createTileEntity(getWorldObj(), metadata); if(tile instanceof TileJarFillable) { placedOn = ForgeDirection.getOrientation(compound.getInteger("placedOn")); tile.readFromNBT(data); init((TileJarFillable) tile, block, metadata, placedOn); } } } if(!isValid() && !getWorldObj().isRemote) { getWorldObj().setBlockToAir(xCoord, yCoord, zCoord); } }
public static void preInit() { if(ModConfig.enableAdditionalNodeTypes) { try { ItemBlock item = (ItemBlock) Item.getItemFromBlock(ConfigBlocks.blockAiry); item.field_150939_a = RegisteredBlocks.blockNode; //Hacky way FMLControlledNamespacedRegistry<Block> registry = GameData.getBlockRegistry(); registry.underlyingIntegerMap.field_148749_a.put(RegisteredBlocks.blockNode, Block.getIdFromBlock(ConfigBlocks.blockAiry)); registry.underlyingIntegerMap.field_148748_b.set(Block.getIdFromBlock(ConfigBlocks.blockAiry), RegisteredBlocks.blockNode); ((BiMap)registry.field_148758_b).forcePut(RegisteredBlocks.blockNode, registry.field_148758_b.get(ConfigBlocks.blockAiry)); registry.underlyingIntegerMap.field_148749_a.remove(ConfigBlocks.blockAiry); ConfigBlocks.blockAiry = RegisteredBlocks.blockNode; } catch (Exception e) { e.printStackTrace(); } } }
@Override public void readMovementInfo(IMovingBlock block, NBTTagCompound tag) { block.setBlock(GameData.getBlockRegistry().getObject(tag.getString("block"))); block.setMetadata(tag.getInteger("metadata")); TileEntity te = block.getTileEntity(); if (tag.hasKey("data") && (te != null || block.getBlock() instanceof ITileEntityProvider)) { if (te == null) { te = ((ITileEntityProvider) block.getBlock()).createNewTileEntity(FakeWorld.getFakeWorld((MovingBlock) block), block.getMetadata()); System.out.println("creating!"); } if (te != null) { te.readFromNBT(tag.getCompoundTag("data")); block.setTileEntity(te); } } ((MovingBlock) block).setRenderList(-1); }
/** * Returns the ItemStack with the name specified, or air if nothing is found. * @param name The name of the item to get. * @return The item with the name, or an item that is bound to that name. */ public static ItemStack getItem(String name) { if (GameData.getBlockRegistry().containsKey(name)) { return new ItemStack(GameData.getBlockRegistry().getObject(name)); } else if (GameData.getItemRegistry().containsKey(name)) { return new ItemStack(GameData.getItemRegistry().getObject(name)); } else { if (name.matches("(?i)(class|kit|character).*(icon)*")) return AllKits.getIcon(Vars.get("kit")); else if (name.matches("(?i)sab.*winner")) return InfoSab.getWinnerIcon(); else { for (String s : icons.keySet()) { if (name.matches(s)) return icons.get(s); } return new ItemStack(Blocks.air); } } }
@Override public void postInit() { for (Object o : GameData.getItemRegistry()) { if (o instanceof Item) { // should always be true, but just to be sure Item i = (Item) o; try { Masses.calculateMass(i, 0, 32767); } catch (StackOverflowError error) { continue; } catch (Exception e) { e.printStackTrace(); System.err.println("Dazed and confused, but trying to continue"); continue; } } } Masses.bake(); }
public static void init(){ ConfigHandler.init(DimensionGuard.config); Table<String,String,ItemStack> customStacks = ReflectionHelper.getPrivateValue(GameData.class, null, "customItemStacks"); Map<String,ItemStack> customItemStacks = new LinkedHashMap<String, ItemStack>(); for (Table.Cell<String, String,ItemStack> cell: customStacks.cellSet()) { customItemStacks.put(cell.getRowKey()+":"+cell.getColumnKey(),cell.getValue()); } addDisabledItems(true, customItemStacks); addDisabledItems(false, customItemStacks); addDisabledEntity(true); addDisabledEntity(false); }
@Override public ItemStack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (!json.isJsonObject()) { return null; } JsonObject jsonObject = json.getAsJsonObject(); int stackSize = jsonObject.has(STACK_SIZE) ? jsonObject.get(STACK_SIZE).getAsInt() : DEFAULT_STACK_SIZE; int itemDamage = jsonObject.has(ITEM_DAMAGE) ? jsonObject.get(ITEM_DAMAGE).getAsInt() : DEFAULT_ITEM_DAMAGE; if (jsonObject.has(BLOCK)) { Block block = GameData.getBlockRegistry().getObject(jsonObject.get(BLOCK).getAsString()); return new ItemStack(block, stackSize, itemDamage); } else if (jsonObject.has(ITEM)) { Item item = GameData.getItemRegistry().getObject(jsonObject.get(ITEM).getAsString()); return new ItemStack(item, stackSize, itemDamage); } return null; }
public void callbackIdDifferenceResponse(boolean response) { if (response) { serverShouldBeKilledQuietly = false; GameData.releaseGate(true); client.continueWorldLoading(); } else { serverShouldBeKilledQuietly = true; GameData.releaseGate(false); // Reset and clear the client state client.func_71403_a((WorldClient)null); client.func_71373_a(null); } }
@Override public void execute(INetworkManager network, FMLNetworkHandler handler, NetHandler netHandler, String userName) { byte[] allData = Bytes.concat(partials); GameData.initializeServerGate(1); try { NBTTagCompound serverList = CompressedStreamTools.func_74792_a(allData); NBTTagList list = serverList.func_74761_m("List"); Set<ItemData> itemData = GameData.buildWorldItemData(list); GameData.validateWorldSave(itemData); MapDifference<Integer, ItemData> serverDifference = GameData.gateWorldLoadingForValidation(); if (serverDifference!=null) { FMLCommonHandler.instance().disconnectIDMismatch(serverDifference, netHandler, network); } } catch (IOException e) { } }
@Override public NBTTagCompound getDataForWriting(SaveHandler handler, WorldInfo info) { NBTTagCompound fmlData = new NBTTagCompound(); NBTTagList list = new NBTTagList(); for (ModContainer mc : Loader.instance().getActiveModList()) { NBTTagCompound mod = new NBTTagCompound(); mod.func_74778_a("ModId", mc.getModId()); mod.func_74778_a("ModVersion", mc.getVersion()); list.func_74742_a(mod); } fmlData.func_74782_a("ModList", list); NBTTagList itemList = new NBTTagList(); GameData.writeItemData(itemList); fmlData.func_74782_a("ModItemData", itemList); return fmlData; }
public void callbackIdDifferenceResponse(boolean response) { if (response) { serverShouldBeKilledQuietly = false; GameData.releaseGate(true); client.continueWorldLoading(); } else { serverShouldBeKilledQuietly = true; GameData.releaseGate(false); // Reset and clear the client state client.loadWorld((WorldClient)null); client.displayGuiScreen(null); } }
@Override public void execute(INetworkManager network, FMLNetworkHandler handler, NetHandler netHandler, String userName) { byte[] allData = Bytes.concat(partials); GameData.initializeServerGate(1); try { NBTTagCompound serverList = CompressedStreamTools.decompress(allData); NBTTagList list = serverList.getTagList("List"); Set<ItemData> itemData = GameData.buildWorldItemData(list); GameData.validateWorldSave(itemData); MapDifference<Integer, ItemData> serverDifference = GameData.gateWorldLoadingForValidation(); if (serverDifference!=null) { FMLCommonHandler.instance().disconnectIDMismatch(serverDifference, netHandler, network); } } catch (IOException e) { } }
@Override public NBTTagCompound getDataForWriting(SaveHandler handler, WorldInfo info) { NBTTagCompound fmlData = new NBTTagCompound(); NBTTagList list = new NBTTagList(); for (ModContainer mc : Loader.instance().getActiveModList()) { NBTTagCompound mod = new NBTTagCompound(); mod.setString("ModId", mc.getModId()); mod.setString("ModVersion", mc.getVersion()); list.appendTag(mod); } fmlData.setTag("ModList", list); NBTTagList itemList = new NBTTagList(); GameData.writeItemData(itemList); fmlData.setTag("ModItemData", itemList); return fmlData; }
@Override public ItemStack deserialize(JsonElement element, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject json = element.getAsJsonObject(); boolean isBlock = json.get("isBlock").getAsBoolean(); String name = json.get("name").getAsString(); int meta = json.get("metadata").getAsInt(); ItemStack stack; if (isBlock) { stack = new ItemStack(GameData.getBlockRegistry().getObject(name), 1, meta); } else { stack = new ItemStack(GameData.getItemRegistry().getObject(name), 1, meta); } stack.stackTagCompound = context.deserialize(json.get("nbt"), NBTTagCompound.class); return stack; }
@Override public JsonElement serialize(ItemStack src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("isBlock", src.getItem() instanceof ItemBlock); if (src.getItem() instanceof ItemBlock) { jsonObject.addProperty("name", GameData.getBlockRegistry().getNameForObject(Block.getBlockFromItem(src.getItem()))); } else { jsonObject.addProperty("name", GameData.getItemRegistry().getNameForObject(src.getItem())); } jsonObject.addProperty("metadata", src.getItemDamage()); jsonObject.add("nbt", context.serialize(src.stackTagCompound, NBTTagCompound.class)); return jsonObject; }
/** * Dump ore dictionary */ public static void dumpOreDict() { Map<Integer, ItemData> idMap = ReflectionHelper.getPrivateValue(GameData.class, null, "idMap"); List<String> oreNames = Arrays.asList(OreDictionary.getOreNames()); Collections.sort(oreNames); for (String oreName : oreNames) { StringBuffer sb = new StringBuffer(); sb.append("ore: " + oreName + ": "); ArrayList<ItemStack> oreItems = OreDictionary.getOres(oreName); for (ItemStack oreItem : oreItems) { ItemData itemData = idMap.get(oreItem.itemID); String modID = itemData.getModId(); sb.append(oreItem.itemID + ":" + oreItem.getItemDamage() + "=" + modID + ", "); } System.out.println(sb); } }
@SuppressWarnings("UnusedDeclaration") @EventHandler public void postInit(FMLPostInitializationEvent event) { HashMap<String, Integer> itemsList = new HashMap<String, Integer>(); GameData.getItemRegistry().serializeInto(itemsList); for(String itemName : itemsList.keySet()) { String itemProperName = itemName.startsWith("\u0002") ? itemName.substring(1) : itemName; Item item = GameData.getItemRegistry().getObject(itemProperName); if(item != null && item instanceof ItemHoe) { OreDictionary.registerOre("hoe", new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE)); } } /* * Misc Recipes */ GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(Blocks.farmland), Blocks.dirt, "hoe")); }
public void handleClientWorldClosing(WorldClient world) { NetworkManager client = getClientToServerNetworkManager(); // ONLY revert a non-local connection if (client != null && !client.func_150731_c()) { GameData.revertToFrozen(); } }
public void serverStopped() { GameData.revertToFrozen(); modController.distributeStateMessage(LoaderState.SERVER_STOPPED); modController.transition(LoaderState.SERVER_STOPPED, true); modController.transition(LoaderState.AVAILABLE, true); }
/** * Remap the missing item to the specified Block. * * Use this if you have renamed a Block, don't forget to handle the ItemBlock. * Existing references using the old name will point to the new one. * * @param target Block to remap to. */ public void remap(Block target) { if (type != GameRegistry.Type.BLOCK) throw new IllegalArgumentException("Can't remap an item to a block."); if (target == null) throw new NullPointerException("remap target is null"); if (GameData.getBlockRegistry().getId(target) < 0) throw new IllegalArgumentException(String.format("The specified block %s hasn't been registered at startup.", target)); action = Action.REMAP; this.target = target; }
/** * Remap the missing item to the specified Item. * * Use this if you have renamed an Item. * Existing references using the old name will point to the new one. * * @param target Item to remap to. */ public void remap(Item target) { if (type != GameRegistry.Type.ITEM) throw new IllegalArgumentException("Can't remap a block to an item."); if (target == null) throw new NullPointerException("remap target is null"); if (GameData.getItemRegistry().getId(target) < 0) throw new IllegalArgumentException(String.format("The specified item %s hasn't been registered at startup.", target)); action = Action.REMAP; this.target = target; }
private static void bindHooks() { ChestGenHooks hooks = ChestGenHooks.getInfo("Placemod"); for (Object itemName : GameData.getItemRegistry().getKeys()) { Item item = (Item) Item.itemRegistry.getObject(itemName); int maxMeta = item.getMaxDamage(); for (int meta = 0; meta <= maxMeta; ++meta) { hooks.addItem(new WeightedRandomChestContent(new ItemStack(item, 1, meta), 1, maxChestStackSize, 256 / (maxMeta + 1))); } } hooks.setMin(minChestItems); hooks.setMax(maxChestItems); }
@Override protected void nerfStandardRecipes () { for (Item item : (Iterable<Item>) GameData.getItemRegistry()) { if (item instanceof ItemArmor) { ItemArmor armor = (ItemArmor) item; ItemStack outputStack = new ItemStack(armor); String repairMaterial = BetterBeginningsHandler.getArmorRepairMaterial(armor); if (!Strings.isNullOrEmpty(repairMaterial)) { String ingot = repairMaterial.startsWith("ingot") ? repairMaterial : "ingot" + repairMaterial; String nugget = repairMaterial.startsWith("nugget") ? repairMaterial : "nugget" + repairMaterial; if (!OreDictionary.getOres(ingot).isEmpty() && !OreDictionary.getOres(nugget).isEmpty() && outputStack.getItem() instanceof ItemArmor) { nerfArmorRecipe(outputStack, ingot, nugget); } } } } }
private static int stackToKey(ItemStack itemStack) { int result = GameData.getItemRegistry().getId(itemStack.getItem()); result = 31 * result + itemStack.getItemDamage(); if (itemStack.hasTagCompound()) result = 31 * result + itemStack.getTagCompound().hashCode(); return result; }
protected void writeItemStackToData(ItemStack itemstack, DataOutputStream data) throws IOException { if (itemstack == null) { data.writeUTF(""); } else { data.writeUTF(GameData.getItemRegistry().getNameForObject(itemstack.getItem())); data.writeByte(itemstack.stackSize); data.writeShort(itemstack.getItemDamage()); if (itemstack.getItem().isDamageable() || itemstack.getItem().getShareTag()) { this.writeNBTTagCompound(itemstack.stackTagCompound, data); } } }
public void handleClientWorldClosing(WorldClient world) { NetworkManager client = getClientToServerNetworkManager(); // ONLY revert a non-local connection if (client != null && !client.isLocalChannel()) { GameData.revertToFrozen(); } }
public void initializeMods() { // Mod controller should be in the initialization state here modController.distributeStateMessage(LoaderState.INITIALIZATION); modController.transition(LoaderState.POSTINITIALIZATION, false); modController.distributeStateMessage(FMLInterModComms.IMCEvent.class); modController.distributeStateMessage(LoaderState.POSTINITIALIZATION); modController.transition(LoaderState.AVAILABLE, false); modController.distributeStateMessage(LoaderState.AVAILABLE); GameData.freezeData(); // Dump the custom registry data map, if necessary GameData.dumpRegistry(minecraftDir); FMLLog.info("Forge Mod Loader has successfully loaded %d mod%s", mods.size(), mods.size() == 1 ? "" : "s"); }
private static ItemProfile getProfile(final ItemStack stack) { final Item item = stack.getItem(); ItemProfile profile = registry.get(item); if (profile == null) { ModLog.warn("Item registration is missing: " + ItemStackHelper.resolveInternalName(stack)); if(GameData.getItemRegistry().getId(item) == -1) { ModLog.warn("Item is not registered with Forge!"); } else { ModLog.warn("Looks like a late registration"); } profile = createProfile(stack.getItem()); } return profile; }