diff --git a/src/main/java/forestry/core/config/Defaults.java b/src/main/java/forestry/core/config/Defaults.java index d4c77cf3e..bdca13f1f 100755 --- a/src/main/java/forestry/core/config/Defaults.java +++ b/src/main/java/forestry/core/config/Defaults.java @@ -125,6 +125,7 @@ public class Defaults { public static final int ID_PACKAGE_MACHINE_STILL = 1; public static final int ID_PACKAGE_MACHINE_BOTTLER = 2; public static final int ID_PACKAGE_MACHINE_RAINTANK = 3; + public static final int ID_PACKAGE_MACHINE_GENERATOR = 4; public static final int ID_PACKAGE_MACHINE_CARPENTER = 5; public static final int ID_PACKAGE_MACHINE_MOISTENER = 6; public static final int ID_PACKAGE_MACHINE_APIARY = 7; diff --git a/src/main/java/forestry/core/gadgets/BlockBase.java b/src/main/java/forestry/core/gadgets/BlockBase.java index dfc1dcd99..404db46d6 100755 --- a/src/main/java/forestry/core/gadgets/BlockBase.java +++ b/src/main/java/forestry/core/gadgets/BlockBase.java @@ -110,7 +110,10 @@ public class BlockBase extends BlockForestry { if (metadata >= definitions.size() || definitions.get(metadata) == null) metadata = 0; - return definitions.get(metadata).createMachine(); + MachineDefinition definition = definitions.get(metadata); + if (definition == null) + return null; + return definition.createMachine(); } @Override @@ -207,6 +210,9 @@ public class BlockBase extends BlockForestry { public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) { IOwnable tile = (IOwnable) world.getTileEntity(x, y, z); + if (tile == null) + return world.setBlockToAir(x, y, z); + if (tile.isOwnable() && !tile.allowsRemoval(player)) return false; @@ -234,6 +240,8 @@ public class BlockBase extends BlockForestry { @Override public void registerBlockIcons(IIconRegister register) { for (MachineDefinition def : definitions) { + if (def == null) + continue; def.registerIcons(register); } } diff --git a/src/main/java/forestry/core/gadgets/TileMachine.java b/src/main/java/forestry/core/gadgets/TileMachine.java index 2cb47a929..8ba815885 100755 --- a/src/main/java/forestry/core/gadgets/TileMachine.java +++ b/src/main/java/forestry/core/gadgets/TileMachine.java @@ -41,6 +41,7 @@ import forestry.plugins.PluginCore; import forestry.plugins.PluginEnergy; import forestry.plugins.PluginFactory; import forestry.plugins.PluginMail; +import forestry.plugins.PluginIC2; public abstract class TileMachine extends TileForestry implements ISpecialInventory, IClimatised, IHintSource { @@ -153,7 +154,8 @@ public abstract class TileMachine extends TileForestry implements ISpecialInvent machineMap.put(Defaults.ID_PACKAGE_MACHINE_SQUEEZER, PluginFactory.definitionSqueezer); machineMap.put(Defaults.ID_PACKAGE_MACHINE_STILL, PluginFactory.definitionStill); machineMap.put(Defaults.ID_PACKAGE_MACHINE_APIARY, PluginApiculture.definitionApiary); - machineMap.put(4, PluginEnergy.definitionGenerator); + if (PluginIC2.instance.isAvailable()) + machineMap.put(Defaults.ID_PACKAGE_MACHINE_GENERATOR, PluginIC2.definitionGenerator); definitionMap.put(ForestryBlock.factoryTESR.block(), machineMap); HashMap millMap = new HashMap(); @@ -168,7 +170,8 @@ public abstract class TileMachine extends TileForestry implements ISpecialInvent HashMap engineMap = new HashMap(); engineMap.put(0, PluginEnergy.definitionEngineBronze); engineMap.put(1, PluginEnergy.definitionEngineCopper); - engineMap.put(2, PluginEnergy.definitionEngineTin); + if (PluginIC2.instance.isAvailable()) + engineMap.put(2, PluginIC2.definitionEngineTin); definitionMap.put(ForestryBlock.engine.block(), engineMap); } diff --git a/src/main/java/forestry/plugins/PluginEnergy.java b/src/main/java/forestry/plugins/PluginEnergy.java index 95f98caf4..e2632fed7 100755 --- a/src/main/java/forestry/plugins/PluginEnergy.java +++ b/src/main/java/forestry/plugins/PluginEnergy.java @@ -56,11 +56,9 @@ public class PluginEnergy extends ForestryPlugin { @SidedProxy(clientSide = "forestry.energy.proxy.ClientProxyEnergy", serverSide = "forestry.energy.proxy.ProxyEnergy") public static ProxyEnergy proxy; - public static MachineDefinition definitionEngineTin; public static MachineDefinition definitionEngineCopper; public static MachineDefinition definitionEngineBronze; public static MachineDefinition definitionEngineClockwork; - public static MachineDefinition definitionGenerator; @Override public void preInit() { @@ -68,16 +66,6 @@ public class PluginEnergy extends ForestryPlugin { ForestryBlock.engine.registerBlock(new BlockBase(Material.iron, true), ItemForestryBlock.class, "engine"); - definitionEngineTin = ((BlockBase) ForestryBlock.engine.block()).addDefinition(new EngineDefinition(Defaults.DEFINITION_ENGINETIN_META, "forestry.EngineTin", EngineTin.class, - PluginEnergy.proxy.getRenderDefaultEngine(Defaults.TEXTURE_PATH_BLOCKS + "/engine_tin_"), ShapedRecipeCustom.createShapedRecipe( - ForestryBlock.engine.getItemStack(1, Defaults.DEFINITION_ENGINETIN_META), - "###", - " X ", - "YVY", - '#', "ingotTin", - 'X', Blocks.glass, - 'Y', "gearTin", - 'V', Blocks.piston))); definitionEngineCopper = ((BlockBase) ForestryBlock.engine.block()).addDefinition(new EngineDefinition(Defaults.DEFINITION_ENGINECOPPER_META, "forestry.EngineCopper", EngineCopper.class, PluginEnergy.proxy.getRenderDefaultEngine(Defaults.TEXTURE_PATH_BLOCKS + "/engine_copper_"), ShapedRecipeCustom.createShapedRecipe( ForestryBlock.engine.getItemStack(1, Defaults.DEFINITION_ENGINECOPPER_META), @@ -99,16 +87,6 @@ public class PluginEnergy extends ForestryPlugin { 'Y', "gearBronze", 'V', Blocks.piston))); - definitionGenerator = ((BlockBase) ForestryBlock.engine.block()).addDefinition(new MachineDefinition(Defaults.DEFINITION_GENERATOR_META, "forestry.Generator", MachineGenerator.class, - Proxies.render.getRenderDefaultMachine(Defaults.TEXTURE_PATH_BLOCKS + "/generator_"), ShapedRecipeCustom.createShapedRecipe( - ForestryBlock.engine.getItemStack(1, Defaults.DEFINITION_GENERATOR_META), - "X#X", - "XYX", - "X#X", - '#', Blocks.glass, - 'X', Items.gold_ingot, - 'Y', ForestryItem.sturdyCasing))); - ShapedRecipeCustom clockworkRecipe = null; if (GameMode.getGameMode().getBooleanSetting("energy.engine.clockwork")) clockworkRecipe = ShapedRecipeCustom.createShapedRecipe( @@ -136,10 +114,8 @@ public class PluginEnergy extends ForestryPlugin { public void doInit() { super.doInit(); - definitionEngineTin.register(); definitionEngineCopper.register(); definitionEngineBronze.register(); - definitionGenerator.register(); definitionEngineClockwork.register(); FluidStack ethanol = LiquidHelper.getLiquid(Defaults.LIQUID_ETHANOL, 1); diff --git a/src/main/java/forestry/plugins/PluginFactory.java b/src/main/java/forestry/plugins/PluginFactory.java index 099f50696..164da1094 100755 --- a/src/main/java/forestry/plugins/PluginFactory.java +++ b/src/main/java/forestry/plugins/PluginFactory.java @@ -264,9 +264,6 @@ public class PluginFactory extends ForestryPlugin { " X ", "#X#", "XXX", '#', Items.redstone, 'X', Blocks.obsidian}); RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), ForestryItem.tubes.getItemStack(4, 7), new Object[]{ " X ", "#X#", "XXX", '#', Items.redstone, 'X', Items.blaze_powder}); - if (PluginIC2.rubber != null) - RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), ForestryItem.tubes.getItemStack(4, 8), - new Object[]{" X ", "#X#", "XXX", '#', Items.redstone, 'X', PluginIC2.rubber}); RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), ForestryItem.tubes.getItemStack(4, 9), new Object[]{ " X ", "#X#", "XXX", '#', Items.redstone, 'X', Items.emerald}); RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), ForestryItem.tubes.getItemStack(4, 10), diff --git a/src/main/java/forestry/plugins/PluginFarming.java b/src/main/java/forestry/plugins/PluginFarming.java index 7c22cd04c..fa363cd19 100755 --- a/src/main/java/forestry/plugins/PluginFarming.java +++ b/src/main/java/forestry/plugins/PluginFarming.java @@ -182,7 +182,6 @@ public class PluginFarming extends ForestryPlugin { Circuit.farmCocoaManual = new CircuitFarmLogic("manualCocoa", FarmLogicCocoa.class).setManual(); Circuit.farmOrchardManual = new CircuitFarmLogic("manualOrchard", FarmLogicOrchard.class); - Circuit.farmRubberManual = new CircuitFarmLogic("manualRubber", FarmLogicRubber.class); MinecraftForge.EVENT_BUS.register(new EventHandlerFarming()); } diff --git a/src/main/java/forestry/plugins/PluginIC2.java b/src/main/java/forestry/plugins/PluginIC2.java index 5b7c67ebb..377b77624 100644 --- a/src/main/java/forestry/plugins/PluginIC2.java +++ b/src/main/java/forestry/plugins/PluginIC2.java @@ -10,37 +10,53 @@ ******************************************************************************/ package forestry.plugins; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - +import cpw.mods.fml.common.Optional; 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.recipes.RecipeManagers; import forestry.api.storage.BackpackManager; import forestry.core.GameMode; +import forestry.core.circuits.Circuit; import forestry.core.config.Config; import forestry.core.config.Configuration; import forestry.core.config.Defaults; +import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; +import forestry.core.gadgets.BlockBase; +import forestry.core.gadgets.MachineDefinition; import forestry.core.items.ItemCrated; import forestry.core.proxy.Proxies; import forestry.core.utils.LiquidHelper; import forestry.core.utils.RecipeUtil; +import forestry.core.utils.ShapedRecipeCustom; import forestry.core.utils.StackUtils; +import forestry.energy.gadgets.EngineDefinition; +import forestry.energy.gadgets.EngineTin; +import forestry.energy.gadgets.MachineGenerator; +import forestry.farming.circuits.CircuitFarmLogic; +import forestry.farming.logic.FarmLogicRubber; +import ic2.api.item.IC2Items; +import ic2.api.recipe.RecipeInputItemStack; +import ic2.api.recipe.Recipes; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; + +import java.util.EnumSet; @Plugin(pluginID = "IC2", name = "IndustrialCraft2", author = "SirSengir", url = Defaults.URL, description = "Compatibility plugin for IC2.") public class PluginIC2 extends ForestryPlugin { public static PluginIC2 instance; public static Configuration config; + // Ignore IC2? public static boolean ignore; + + // Forestry stuff + public static MachineDefinition definitionGenerator; + public static MachineDefinition definitionEngineTin; + // IC2 stuff public static ItemStack plantBall; public static ItemStack compressedPlantBall; @@ -75,12 +91,68 @@ public class PluginIC2 extends ForestryPlugin { } @Override - public void doInit() { - config = Config.config; + public EnumSet getDependancies() { + EnumSet deps = super.getDependancies(); + deps.add(PluginManager.Module.FARMING); + deps.add(PluginManager.Module.FACTORY); + deps.add(PluginManager.Module.ENERGY); + return deps; + } - initLiquidContainers(); - initRubberChain(); - initFermentation(); + @Override + @Optional.Method(modid = "IC2") + public void preInit() { + super.preInit(); + + definitionEngineTin = ((BlockBase) ForestryBlock.engine.block()).addDefinition(new EngineDefinition(Defaults.DEFINITION_ENGINETIN_META, "forestry.EngineTin", EngineTin.class, + PluginEnergy.proxy.getRenderDefaultEngine(Defaults.TEXTURE_PATH_BLOCKS + "/engine_tin_"), ShapedRecipeCustom.createShapedRecipe( + ForestryBlock.engine.getItemStack(1, Defaults.DEFINITION_ENGINETIN_META), + "###", + " X ", + "YVY", + '#', "ingotTin", + 'X', Blocks.glass, + 'Y', "gearTin", + 'V', Blocks.piston))); + + definitionGenerator = ((BlockBase) ForestryBlock.engine.block()).addDefinition(new MachineDefinition(Defaults.DEFINITION_GENERATOR_META, "forestry.Generator", MachineGenerator.class, + Proxies.render.getRenderDefaultMachine(Defaults.TEXTURE_PATH_BLOCKS + "/generator_"), ShapedRecipeCustom.createShapedRecipe( + ForestryBlock.engine.getItemStack(1, Defaults.DEFINITION_GENERATOR_META), + "X#X", + "XYX", + "X#X", + '#', Blocks.glass, + 'X', Items.gold_ingot, + 'Y', ForestryItem.sturdyCasing))); + + emptyCell = IC2Items.getItem("cell"); + if (emptyCell != null) { + lavaCell = IC2Items.getItem("lavaCell"); + waterCell = IC2Items.getItem("waterCell"); + } else { + Proxies.log.fine("IC2 empty cell could not be found. Skipped adding IC2 liquid containers."); + } + + // rubber chain + treetap = IC2Items.getItem("treetap"); + rubberwood = IC2Items.getItem("rubberWood"); + resin = IC2Items.getItem("resin"); + rubbersapling = IC2Items.getItem("rubberSapling"); + rubberleaves = IC2Items.getItem("rubberLeaves"); + + // fermentation + plantBall = IC2Items.getItem("plantBall"); + compressedPlantBall = IC2Items.getItem("compressedPlantBall"); + + // crated + resin = IC2Items.getItem("resin"); + rubber = IC2Items.getItem("rubber"); + scrap = IC2Items.getItem("scrap"); + uuMatter = IC2Items.getItem("matter"); + silver = IC2Items.getItem("silverIngot"); + brass = IC2Items.getItem("bronzeIngot"); + + Circuit.farmRubberManual = new CircuitFarmLogic("manualRubber", FarmLogicRubber.class); // Remove some items from the recycler Recipes.recyclerBlacklist.add(new RecipeInputItemStack(ForestryItem.beeQueenGE.getItemStack())); @@ -88,6 +160,18 @@ public class PluginIC2 extends ForestryPlugin { } @Override + @Optional.Method(modid = "IC2") + public void doInit() { + super.doInit(); + + config = Config.config; + + definitionEngineTin.register(); + definitionGenerator.register(); + } + + @Override + @Optional.Method(modid = "IC2") protected void registerBackpackItems() { if (BackpackManager.backpackItems == null) return; @@ -96,97 +180,67 @@ public class PluginIC2 extends ForestryPlugin { BackpackManager.definitions.get("forester").addValidItem(resin); if (rubber != null) BackpackManager.definitions.get("forester").addValidItem(rubber); + if (rubbersapling != null) + BackpackManager.definitions.get("forester").addValidItem(rubbersapling); + if (rubberleaves != null) + BackpackManager.definitions.get("forester").addValidItem(rubberleaves); } @Override + @Optional.Method(modid = "IC2") protected void registerCrates() { - - // Add crates for the IC2 items that exist. - resin = IC2Items.getItem("resin"); if (resin != null) { ForestryItem.cratedResin.registerItem(new ItemCrated(), "cratedResin"); ((ItemCrated) ForestryItem.cratedResin.item()).setContained(ForestryItem.cratedResin.getItemStack(), resin); } - rubber = IC2Items.getItem("rubber"); if (rubber != null) { ForestryItem.cratedRubber.registerItem(new ItemCrated(), "cratedRubber"); ((ItemCrated) ForestryItem.cratedRubber.item()).setContained(ForestryItem.cratedRubber.getItemStack(), rubber); } - scrap = IC2Items.getItem("scrap"); if (scrap != null) { ForestryItem.cratedScrap.registerItem(new ItemCrated(), "cratedScrap"); ((ItemCrated) ForestryItem.cratedScrap.item()).setContained(ForestryItem.cratedScrap.getItemStack(), scrap); } - uuMatter = IC2Items.getItem("matter"); if (uuMatter != null) { ForestryItem.cratedUUM.registerItem(new ItemCrated(), "cratedUUM"); ((ItemCrated) ForestryItem.cratedUUM.item()).setContained(ForestryItem.cratedUUM.getItemStack(), uuMatter); } - silver = IC2Items.getItem("silverIngot"); if (silver != null) { ForestryItem.cratedSilver.registerItem(new ItemCrated(), "cratedSilver"); ((ItemCrated) ForestryItem.cratedSilver.item()).setContained(ForestryItem.cratedSilver.getItemStack(), silver); } - brass = IC2Items.getItem("bronzeIngot"); if (brass != null) { ForestryItem.cratedBrass.registerItem(new ItemCrated(), "cratedBrass"); ((ItemCrated) ForestryItem.cratedBrass.item()).setContained(ForestryItem.cratedBrass.getItemStack(), brass); } } - private void initFermentation() { - plantBall = IC2Items.getItem("plantBall"); - compressedPlantBall = IC2Items.getItem("compressedPlantBall"); - if (plantBall == null || compressedPlantBall == null) { + @Optional.Method(modid = "IC2") + protected void registerRecipes() { + + if (rubber != null) + RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), ForestryItem.tubes.getItemStack(4, 8), + new Object[]{" X ", "#X#", "XXX", '#', Items.redstone, 'X', PluginIC2.rubber}); + + if (plantBall != null && compressedPlantBall != null) { + 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); + } else { 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"); - if (emptyCell == null) { - Proxies.log.fine("IC2 empty cell could not be found. Skipped adding IC2 liquid containers."); - return; - } - - lavaCell = IC2Items.getItem("lavaCell"); - if (lavaCell != null) - LiquidHelper.injectTinContainer(Defaults.LIQUID_LAVA, Defaults.BUCKET_VOLUME, lavaCell, emptyCell); - - waterCell = IC2Items.getItem("waterCell"); - if (waterCell != null) { - LiquidHelper.injectTinContainer(Defaults.LIQUID_WATER, Defaults.BUCKET_VOLUME, waterCell, emptyCell); - - ItemStack bogEarthCan = GameMode.getGameMode().getStackSetting("recipe.output.bogearth.can"); - if (bogEarthCan.stackSize > 0) - Proxies.common.addRecipe(bogEarthCan, "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', waterCell, 'Y', Blocks.sand); - } - } - - private void initRubberChain() { - treetap = IC2Items.getItem("treetap"); - rubberwood = IC2Items.getItem("rubberWood"); - - resin = IC2Items.getItem("resin"); if (resin != null) RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.propolis.getItemStack(), resin); else Proxies.log.fine("Missing IC2 resin, skipping centrifuge recipe for propolis to resin."); - rubbersapling = IC2Items.getItem("rubberSapling"); if (rubbersapling != null) { RecipeUtil.injectLeveledRecipe(rubbersapling, GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Defaults.LIQUID_BIOMASS); - BackpackManager.backpackItems[2].add(rubbersapling); } else Proxies.log.fine("Missing IC2 rubber sapling, skipping fermenter recipe for converting rubber sapling to biomass."); @@ -200,13 +254,16 @@ public class PluginIC2 extends ForestryPlugin { FMLInterModComms.sendMessage(Defaults.MOD, "add-farmable-sapling", imc); } - rubberleaves = IC2Items.getItem("rubberLeaves"); - if (rubberleaves != null) - BackpackManager.backpackItems[2].add(rubberleaves); - else - Proxies.log.fine("Missing IC2 rubber leaves"); + if (lavaCell != null) + LiquidHelper.injectTinContainer(Defaults.LIQUID_LAVA, Defaults.BUCKET_VOLUME, lavaCell, emptyCell); - // Rubber wood is added via ore dictionary. + if (waterCell != null) { + LiquidHelper.injectTinContainer(Defaults.LIQUID_WATER, Defaults.BUCKET_VOLUME, waterCell, emptyCell); + + ItemStack bogEarthCan = GameMode.getGameMode().getStackSetting("recipe.output.bogearth.can"); + if (bogEarthCan.stackSize > 0) + Proxies.common.addRecipe(bogEarthCan, "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', waterCell, 'Y', Blocks.sand); + } } }