From 72c021d99d67cd98b22bff856deee3e15b9c6d34 Mon Sep 17 00:00:00 2001 From: Player Date: Thu, 14 Aug 2014 15:50:13 +0200 Subject: [PATCH] Work around LaunchClassLoader tripping over missing IC2 classes. --- src/main/java/forestry/plugins/PluginIC2.java | 229 +++++++++--------- 1 file changed, 118 insertions(+), 111 deletions(-) diff --git a/src/main/java/forestry/plugins/PluginIC2.java b/src/main/java/forestry/plugins/PluginIC2.java index d79be6a5b..251c8b33e 100755 --- a/src/main/java/forestry/plugins/PluginIC2.java +++ b/src/main/java/forestry/plugins/PluginIC2.java @@ -18,6 +18,8 @@ import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.registry.GameData; import ic2.api.item.IC2Items; +import ic2.api.recipe.RecipeInputItemStack; +import ic2.api.recipe.Recipes; import forestry.api.core.IPlugin; import forestry.api.core.PluginInfo; @@ -33,8 +35,6 @@ import forestry.core.proxy.Proxies; import forestry.core.utils.LiquidHelper; import forestry.core.utils.RecipeUtil; import forestry.core.utils.StackUtils; -import ic2.api.recipe.RecipeInputItemStack; -import ic2.api.recipe.Recipes; @PluginInfo(pluginID = "IC2", name = "IndustrialCraft2", author = "SirSengir", url = Defaults.URL, description = "Compatibility plugin for IC2.") public class PluginIC2 implements IPlugin { @@ -77,116 +77,9 @@ public class PluginIC2 implements IPlugin { if (!isAvailable()) return; - initLiquidContainers(); - initRubberChain(); - initFermentation(); - initCrates(); - - Recipes.recyclerBlacklist.add(new RecipeInputItemStack(ForestryItem.beeQueenGE.getItemStack())); - Recipes.recyclerBlacklist.add(new RecipeInputItemStack(ForestryItem.beePrincessGE.getItemStack())); - - // Remove some items from the recycler - registerBackpackItems(); - - if (rubbersapling != null && resin != null) { - String imc = String.format("farmArboreal@%s.%s.%s.%s", - GameData.getBlockRegistry().getNameForObject(StackUtils.getBlock(rubbersapling)), - rubbersapling.getItemDamage(), - GameData.getItemRegistry().getNameForObject(resin.getItem()), - resin.getItemDamage()); - Proxies.log.finest("Sending IMC '%s'.", imc); - FMLInterModComms.sendMessage(Defaults.MOD, "add-farmable-sapling", imc); - } - } - - private void initFermentation() { - plantBall = IC2Items.getItem("plantBall"); - compressedPlantBall = IC2Items.getItem("compressedPlantBall"); - if (plantBall == null || compressedPlantBall == null) { - Proxies.log.fine("No IC2 plantballs found."); - return; - } - - // Add extra recipes - RecipeUtil.injectLeveledRecipe(plantBall, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat") * 4, Defaults.LIQUID_BIOMASS); - RecipeUtil.injectLeveledRecipe(compressedPlantBall, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat") * 5, Defaults.LIQUID_BIOMASS); - } - - private void initLiquidContainers() { - emptyCell = IC2Items.getItem("cell"); - lavaCell = IC2Items.getItem("lavaCell"); - waterCell = IC2Items.getItem("waterCell"); - if (emptyCell == null || lavaCell == null || waterCell == null) { - Proxies.log.fine("Any of the following IC2 items could not be found: empty cell, water cell, lava cell. Skipped adding IC2 liquid containers."); - return; - } - - LiquidHelper.injectTinContainer(Defaults.LIQUID_LAVA, Defaults.BUCKET_VOLUME, lavaCell, emptyCell); - LiquidHelper.injectTinContainer(Defaults.LIQUID_WATER, Defaults.BUCKET_VOLUME, waterCell, emptyCell); - if (GameMode.getGameMode().getStackSetting("recipe.output.bogearth.can").stackSize > 0) - Proxies.common - .addRecipe(GameMode.getGameMode().getStackSetting("recipe.output.bogearth.can"), "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', waterCell, 'Y', Blocks.sand); - } - - private void initRubberChain() { - treetap = IC2Items.getItem("treetap"); - resin = IC2Items.getItem("resin"); - rubberwood = IC2Items.getItem("rubberWood"); - rubbersapling = IC2Items.getItem("rubberSapling"); - rubberleaves = IC2Items.getItem("rubberLeaves"); - fuelcanFilled = IC2Items.getItem("filledFuelCan"); - fuelcanEmpty = IC2Items.getItem("fuelCan"); - if (treetap == null || resin == null || rubberwood == null || rubbersapling == null || rubberleaves == null || fuelcanFilled == null - || fuelcanEmpty == null) { - Proxies.log - .fine("Any of the following IC2 blocks and items could not be found: resin, rubber wood, saplings or leaves, filled fuel cans, empty fuel cans. Skipped adding rubber chain."); - return; - } - - // Add extra recipes - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.propolis.getItemStack(), resin); - ItemStack fuelcanStack = new ItemStack(fuelcanFilled.getItem(), 1, 0); - NBTTagCompound compound = new NBTTagCompound(); - compound.setInteger("value", 15288); - fuelcanStack.setTagCompound(compound); - RecipeManagers.bottlerManager.addRecipe(20, LiquidHelper.getLiquid(Defaults.LIQUID_ETHANOL, Defaults.BOTTLER_FUELCAN_VOLUME), fuelcanEmpty, fuelcanStack); - - RecipeUtil.injectLeveledRecipe(rubbersapling, GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Defaults.LIQUID_BIOMASS); - - // Add backpack items - BackpackManager.backpackItems[2].add(rubbersapling); - BackpackManager.backpackItems[2].add(rubberleaves); - // Rubber wood is added via ore dictionary. - } - - private void initCrates() { - resin = IC2Items.getItem("resin"); - rubber = IC2Items.getItem("rubber"); - scrap = IC2Items.getItem("scrap"); - - // Add crates for the IC2 items that exist. - if (resin != null) { - ((ItemCrated) ForestryItem.cratedResin.item()).setContained(ForestryItem.cratedResin.getItemStack(), resin); - } - - if (rubber != null) { - ((ItemCrated) ForestryItem.cratedRubber.item()).setContained(ForestryItem.cratedRubber.getItemStack(), rubber); - } - - if (scrap != null) { - ((ItemCrated) ForestryItem.cratedScrap.item()).setContained(ForestryItem.cratedScrap.getItemStack(), scrap); - } - } - - private void registerBackpackItems() { - if (BackpackManager.backpackItems == null) - return; - - if (resin != null) - BackpackManager.definitions.get("forester").addValidItem(resin); - if (rubber != null) - BackpackManager.definitions.get("forester").addValidItem(rubber); + new Impl().init(); } + @Override public void preInit() { @@ -195,4 +88,118 @@ public class PluginIC2 implements IPlugin { @Override public void postInit() { } + + private static class Impl { + private void init() { + initLiquidContainers(); + initRubberChain(); + initFermentation(); + initCrates(); + + Recipes.recyclerBlacklist.add(new RecipeInputItemStack(ForestryItem.beeQueenGE.getItemStack())); + Recipes.recyclerBlacklist.add(new RecipeInputItemStack(ForestryItem.beePrincessGE.getItemStack())); + + // Remove some items from the recycler + registerBackpackItems(); + + if (rubbersapling != null && resin != null) { + String imc = String.format("farmArboreal@%s.%s.%s.%s", + GameData.getBlockRegistry().getNameForObject(StackUtils.getBlock(rubbersapling)), + rubbersapling.getItemDamage(), + GameData.getItemRegistry().getNameForObject(resin.getItem()), + resin.getItemDamage()); + Proxies.log.finest("Sending IMC '%s'.", imc); + FMLInterModComms.sendMessage(Defaults.MOD, "add-farmable-sapling", imc); + } + } + + private void initFermentation() { + plantBall = IC2Items.getItem("plantBall"); + compressedPlantBall = IC2Items.getItem("compressedPlantBall"); + if (plantBall == null || compressedPlantBall == null) { + Proxies.log.fine("No IC2 plantballs found."); + return; + } + + // Add extra recipes + RecipeUtil.injectLeveledRecipe(plantBall, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat") * 4, Defaults.LIQUID_BIOMASS); + RecipeUtil.injectLeveledRecipe(compressedPlantBall, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat") * 5, Defaults.LIQUID_BIOMASS); + } + + private void initLiquidContainers() { + emptyCell = IC2Items.getItem("cell"); + lavaCell = IC2Items.getItem("lavaCell"); + waterCell = IC2Items.getItem("waterCell"); + if (emptyCell == null || lavaCell == null || waterCell == null) { + Proxies.log.fine("Any of the following IC2 items could not be found: empty cell, water cell, lava cell. Skipped adding IC2 liquid containers."); + return; + } + + LiquidHelper.injectTinContainer(Defaults.LIQUID_LAVA, Defaults.BUCKET_VOLUME, lavaCell, emptyCell); + LiquidHelper.injectTinContainer(Defaults.LIQUID_WATER, Defaults.BUCKET_VOLUME, waterCell, emptyCell); + if (GameMode.getGameMode().getStackSetting("recipe.output.bogearth.can").stackSize > 0) + Proxies.common + .addRecipe(GameMode.getGameMode().getStackSetting("recipe.output.bogearth.can"), "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', waterCell, 'Y', Blocks.sand); + } + + private void initRubberChain() { + treetap = IC2Items.getItem("treetap"); + resin = IC2Items.getItem("resin"); + rubberwood = IC2Items.getItem("rubberWood"); + rubbersapling = IC2Items.getItem("rubberSapling"); + rubberleaves = IC2Items.getItem("rubberLeaves"); + fuelcanFilled = IC2Items.getItem("filledFuelCan"); + fuelcanEmpty = IC2Items.getItem("fuelCan"); + if (treetap == null || resin == null || rubberwood == null || rubbersapling == null || rubberleaves == null || fuelcanFilled == null + || fuelcanEmpty == null) { + Proxies.log + .fine("Any of the following IC2 blocks and items could not be found: resin, rubber wood, saplings or leaves, filled fuel cans, empty fuel cans. Skipped adding rubber chain."); + return; + } + + // Add extra recipes + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.propolis.getItemStack(), resin); + ItemStack fuelcanStack = new ItemStack(fuelcanFilled.getItem(), 1, 0); + NBTTagCompound compound = new NBTTagCompound(); + compound.setInteger("value", 15288); + fuelcanStack.setTagCompound(compound); + RecipeManagers.bottlerManager.addRecipe(20, LiquidHelper.getLiquid(Defaults.LIQUID_ETHANOL, Defaults.BOTTLER_FUELCAN_VOLUME), fuelcanEmpty, fuelcanStack); + + RecipeUtil.injectLeveledRecipe(rubbersapling, GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Defaults.LIQUID_BIOMASS); + + // Add backpack items + BackpackManager.backpackItems[2].add(rubbersapling); + BackpackManager.backpackItems[2].add(rubberleaves); + // Rubber wood is added via ore dictionary. + } + + private void initCrates() { + resin = IC2Items.getItem("resin"); + rubber = IC2Items.getItem("rubber"); + scrap = IC2Items.getItem("scrap"); + + // Add crates for the IC2 items that exist. + if (resin != null) { + ((ItemCrated) ForestryItem.cratedResin.item()).setContained(ForestryItem.cratedResin.getItemStack(), resin); + } + + if (rubber != null) { + ((ItemCrated) ForestryItem.cratedRubber.item()).setContained(ForestryItem.cratedRubber.getItemStack(), rubber); + } + + if (scrap != null) { + ((ItemCrated) ForestryItem.cratedScrap.item()).setContained(ForestryItem.cratedScrap.getItemStack(), scrap); + } + } + + private void registerBackpackItems() { + if (BackpackManager.backpackItems == null) + return; + + if (resin != null) + BackpackManager.definitions.get("forester").addValidItem(resin); + if (rubber != null) + BackpackManager.definitions.get("forester").addValidItem(rubber); + } + } }