From 08d543b2efb540a42ba3ac7745b5c59633f540ee Mon Sep 17 00:00:00 2001 From: mezz Date: Thu, 28 Apr 2016 19:41:03 -0700 Subject: [PATCH] Close #1144 add IC2 compatibility back --- build.gradle | 6 + gradle.properties | 1 + lang | 2 +- .../java/forestry/core/gui/GuiIdRegistry.java | 4 + .../energy/blocks/BlockTypeEngine.java | 26 +- .../energy/circuits/CircuitElectricBoost.java | 21 ++ .../circuits/CircuitElectricChange.java | 63 ++++ .../energy/circuits/CircuitElectricChoke.java | 20 ++ .../circuits/CircuitElectricEfficiency.java | 21 ++ .../energy/gui/ContainerEngineElectric.java | 46 +++ .../energy/gui/ContainerGenerator.java | 45 +++ .../energy/gui/GuiEngineElectric.java | 46 +++ .../forestry/energy/gui/GuiGenerator.java | 37 ++ .../inventory/InventoryEngineElectric.java | 34 ++ .../energy/inventory/InventoryGenerator.java | 37 ++ .../energy/tiles/TileEngineElectric.java | 326 ++++++++++++++++++ .../energy/tiles/TileEuGenerator.java | 242 +++++++++++++ .../java/forestry/factory/PluginFactory.java | 11 +- .../farming/logic/CropBasicIC2Crop.java | 81 +++++ .../forestry/farming/logic/CropRubber.java | 40 +++ .../farming/logic/FarmLogicRubber.java | 190 ++++++++++ .../farming/logic/FarmableBasicIC2Crop.java | 82 +++++ .../forestry/plugins/compat/PluginIC2.java | 317 +++++++++++++++++ .../models/item/engine_electrical.json | 3 + 24 files changed, 1694 insertions(+), 7 deletions(-) create mode 100644 src/main/java/forestry/energy/circuits/CircuitElectricBoost.java create mode 100755 src/main/java/forestry/energy/circuits/CircuitElectricChange.java create mode 100644 src/main/java/forestry/energy/circuits/CircuitElectricChoke.java create mode 100644 src/main/java/forestry/energy/circuits/CircuitElectricEfficiency.java create mode 100644 src/main/java/forestry/energy/gui/ContainerEngineElectric.java create mode 100755 src/main/java/forestry/energy/gui/ContainerGenerator.java create mode 100644 src/main/java/forestry/energy/gui/GuiEngineElectric.java create mode 100755 src/main/java/forestry/energy/gui/GuiGenerator.java create mode 100644 src/main/java/forestry/energy/inventory/InventoryEngineElectric.java create mode 100644 src/main/java/forestry/energy/inventory/InventoryGenerator.java create mode 100644 src/main/java/forestry/energy/tiles/TileEngineElectric.java create mode 100644 src/main/java/forestry/energy/tiles/TileEuGenerator.java create mode 100644 src/main/java/forestry/farming/logic/CropBasicIC2Crop.java create mode 100755 src/main/java/forestry/farming/logic/CropRubber.java create mode 100755 src/main/java/forestry/farming/logic/FarmLogicRubber.java create mode 100644 src/main/java/forestry/farming/logic/FarmableBasicIC2Crop.java create mode 100644 src/main/java/forestry/plugins/compat/PluginIC2.java create mode 100644 src/main/resources/assets/forestry/models/item/engine_electrical.json diff --git a/build.gradle b/build.gradle index 7b2189646..918e44427 100755 --- a/build.gradle +++ b/build.gradle @@ -63,10 +63,16 @@ repositories { maven { url "http://dvs1.progwml6.com/files/maven" } + maven { + name = "ic2" + url = "http://maven.ic2.player.to/" + } } dependencies { deobfCompile "mezz.jei:jei_${mcversion}:${jei_version}" + deobfCompile "net.industrial-craft:industrialcraft-2:${ic2_version}:api" + runtime "net.industrial-craft:industrialcraft-2:${ic2_version}:dev" } configurations { diff --git a/gradle.properties b/gradle.properties index 518bd7ccc..45a5be0f6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,6 +3,7 @@ forgeversion=11.15.1.1855 mcp_mappings=snapshot_20160223 jei_version=2.28.+ +ic2_version=2.3.235-ex18 version_major=5 version_minor=0 diff --git a/lang b/lang index c30cd88ed..e9fdd790d 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit c30cd88ed65424042908da81e288daa9b55c0f86 +Subproject commit e9fdd790dcba503656f2a9cdb6b4a4cb8e8421c9 diff --git a/src/main/java/forestry/core/gui/GuiIdRegistry.java b/src/main/java/forestry/core/gui/GuiIdRegistry.java index 26e693390..fcfb259f2 100644 --- a/src/main/java/forestry/core/gui/GuiIdRegistry.java +++ b/src/main/java/forestry/core/gui/GuiIdRegistry.java @@ -31,7 +31,9 @@ import forestry.core.tiles.TileAnalyzer; import forestry.core.tiles.TileEscritoire; import forestry.core.tiles.TileNaturalistChest; import forestry.energy.tiles.TileEngineBiogas; +import forestry.energy.tiles.TileEngineElectric; import forestry.energy.tiles.TileEnginePeat; +import forestry.energy.tiles.TileEuGenerator; import forestry.factory.tiles.TileBottler; import forestry.factory.tiles.TileCarpenter; import forestry.factory.tiles.TileCentrifuge; @@ -87,7 +89,9 @@ public class GuiIdRegistry { TileGreenhouse.class, TileEngineBiogas.class, + TileEngineElectric.class, TileEnginePeat.class, + TileEuGenerator.class, TileMailbox.class, TileStampCollector.class, diff --git a/src/main/java/forestry/energy/blocks/BlockTypeEngine.java b/src/main/java/forestry/energy/blocks/BlockTypeEngine.java index e9ecfdfd3..7e5c97f4a 100644 --- a/src/main/java/forestry/energy/blocks/BlockTypeEngine.java +++ b/src/main/java/forestry/energy/blocks/BlockTypeEngine.java @@ -16,26 +16,42 @@ import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import forestry.core.blocks.IBlockTypeTesr; import forestry.core.blocks.IMachinePropertiesTesr; +import forestry.core.blocks.MachinePropertiesTesr; import forestry.core.config.Constants; +import forestry.core.proxy.Proxies; +import forestry.core.tiles.TileBase; import forestry.core.tiles.TileEngine; import forestry.energy.PluginEnergy; import forestry.energy.tiles.TileEngineBiogas; import forestry.energy.tiles.TileEngineClockwork; +import forestry.energy.tiles.TileEngineElectric; import forestry.energy.tiles.TileEnginePeat; +import forestry.energy.tiles.TileEuGenerator; public enum BlockTypeEngine implements IBlockTypeTesr { - PEAT(0, TileEnginePeat.class, "peat", "/engine_copper_"), - BIOGAS(1, TileEngineBiogas.class, "biogas", "/engine_bronze_"), - CLOCKWORK(2, TileEngineClockwork.class, "clockwork", "/engine_clock_"); + PEAT(createEngineProperties(0, TileEnginePeat.class, "peat", "/engine_copper_")), + BIOGAS(createEngineProperties(1, TileEngineBiogas.class, "biogas", "/engine_bronze_")), + CLOCKWORK(createEngineProperties(2, TileEngineClockwork.class, "clockwork", "/engine_clock_")), + ELECTRICAL(createEngineProperties(3, TileEngineElectric.class, "electrical", "/engine_tin_")), + GENERATOR(createMachineProperties(4, TileEuGenerator.class, "generator", "/generator_")); public static final BlockTypeEngine[] VALUES = values(); @Nonnull private final IMachinePropertiesTesr machineProperties; - BlockTypeEngine(int meta, @Nonnull Class teClass, @Nonnull String name, @Nonnull String textureName) { + BlockTypeEngine(@Nonnull IMachinePropertiesTesr machineProperties) { + this.machineProperties = machineProperties; + } + + protected static IMachinePropertiesTesr createEngineProperties(int meta, @Nonnull Class teClass, @Nonnull String name, @Nonnull String textureName) { TileEntitySpecialRenderer renderer = PluginEnergy.proxy.getRenderDefaultEngine(Constants.TEXTURE_PATH_BLOCKS + textureName); - this.machineProperties = new MachinePropertiesEngine<>(meta, teClass, name, renderer); + return new MachinePropertiesEngine<>(meta, teClass, name, renderer); + } + + protected static IMachinePropertiesTesr createMachineProperties(int meta, @Nonnull Class teClass, @Nonnull String name, @Nonnull String textureName) { + TileEntitySpecialRenderer renderer = Proxies.render.getRenderDefaultMachine(Constants.TEXTURE_PATH_BLOCKS + textureName); + return new MachinePropertiesTesr<>(meta, teClass, name, renderer); } @Nonnull diff --git a/src/main/java/forestry/energy/circuits/CircuitElectricBoost.java b/src/main/java/forestry/energy/circuits/CircuitElectricBoost.java new file mode 100644 index 000000000..5cca5bf28 --- /dev/null +++ b/src/main/java/forestry/energy/circuits/CircuitElectricBoost.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.energy.circuits; + +public class CircuitElectricBoost extends CircuitElectricChange { + + public CircuitElectricBoost(String uid, int limit, int eu, int rf) { + super(uid, false); + this.setLimit(limit); + this.configureChange(eu, rf); + } + +} diff --git a/src/main/java/forestry/energy/circuits/CircuitElectricChange.java b/src/main/java/forestry/energy/circuits/CircuitElectricChange.java new file mode 100755 index 000000000..cecb6f416 --- /dev/null +++ b/src/main/java/forestry/energy/circuits/CircuitElectricChange.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.energy.circuits; + +import forestry.core.circuits.Circuit; +import forestry.energy.tiles.TileEngineElectric; + +public abstract class CircuitElectricChange extends Circuit { + + private int euChange = 7; + private int rfChange = 20; + + protected CircuitElectricChange(String uid, boolean requiresDiscovery) { + super(uid, requiresDiscovery); + } + + protected void configureChange(int euChange, int rfChange) { + this.euChange = euChange; + this.rfChange = rfChange; + } + + @Override + public boolean isCircuitable(Object tile) { + return tile instanceof TileEngineElectric; + } + + @Override + public void onInsertion(int slot, Object tile) { + if (!isCircuitable(tile)) { + return; + } + + TileEngineElectric engine = (TileEngineElectric) tile; + engine.changeEnergyConfig(euChange, rfChange, 2 * euChange); + } + + @Override + public void onLoad(int slot, Object tile) { + onInsertion(slot, tile); + } + + @Override + public void onRemoval(int slot, Object tile) { + if (!isCircuitable(tile)) { + return; + } + + TileEngineElectric engine = (TileEngineElectric) tile; + engine.changeEnergyConfig(-euChange, -rfChange, -(2 * euChange)); + } + + @Override + public void onTick(int slot, Object tile) { + } +} diff --git a/src/main/java/forestry/energy/circuits/CircuitElectricChoke.java b/src/main/java/forestry/energy/circuits/CircuitElectricChoke.java new file mode 100644 index 000000000..859aae6bc --- /dev/null +++ b/src/main/java/forestry/energy/circuits/CircuitElectricChoke.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.energy.circuits; + +public class CircuitElectricChoke extends CircuitElectricChange { + + public CircuitElectricChoke(String uid) { + super(uid, false); + this.configureChange(-2, -10); + this.setLimit(1); + } +} diff --git a/src/main/java/forestry/energy/circuits/CircuitElectricEfficiency.java b/src/main/java/forestry/energy/circuits/CircuitElectricEfficiency.java new file mode 100644 index 000000000..d44ebd816 --- /dev/null +++ b/src/main/java/forestry/energy/circuits/CircuitElectricEfficiency.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.energy.circuits; + +public class CircuitElectricEfficiency extends CircuitElectricChange { + + public CircuitElectricEfficiency(String uid) { + super(uid, false); + this.setLimit(1); + this.configureChange(-1, 0); + } + +} diff --git a/src/main/java/forestry/energy/gui/ContainerEngineElectric.java b/src/main/java/forestry/energy/gui/ContainerEngineElectric.java new file mode 100644 index 000000000..7b457448a --- /dev/null +++ b/src/main/java/forestry/energy/gui/ContainerEngineElectric.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.energy.gui; + +import net.minecraft.entity.player.InventoryPlayer; + +import forestry.core.gui.ContainerSocketed; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.network.packets.PacketGuiUpdate; +import forestry.energy.inventory.InventoryEngineElectric; +import forestry.energy.tiles.TileEngineElectric; + +public class ContainerEngineElectric extends ContainerSocketed { + + public ContainerEngineElectric(InventoryPlayer player, TileEngineElectric tile) { + super(tile, player, 8, 84); + + this.addSlotToContainer(new SlotFiltered(tile, InventoryEngineElectric.SLOT_BATTERY, 84, 53)); + } + + @Override + public void updateProgressBar(int i, int j) { + if (tile != null) { + tile.getGUINetworkData(i, j); + } + } + + @Override + public void detectAndSendChanges() { + super.detectAndSendChanges(); + + if (tile != null) { + PacketGuiUpdate packet = new PacketGuiUpdate(tile); + sendPacketToCrafters(packet); + } + } + +} diff --git a/src/main/java/forestry/energy/gui/ContainerGenerator.java b/src/main/java/forestry/energy/gui/ContainerGenerator.java new file mode 100755 index 000000000..980b2b7dc --- /dev/null +++ b/src/main/java/forestry/energy/gui/ContainerGenerator.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.energy.gui; + +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ICrafting; + +import forestry.core.gui.ContainerLiquidTanks; +import forestry.core.gui.slots.SlotFiltered; +import forestry.energy.inventory.InventoryGenerator; +import forestry.energy.tiles.TileEuGenerator; + +public class ContainerGenerator extends ContainerLiquidTanks { + + public ContainerGenerator(InventoryPlayer player, TileEuGenerator tile) { + super(tile, player, 8, 84); + + this.addSlotToContainer(new SlotFiltered(tile, InventoryGenerator.SLOT_CAN, 22, 38)); + } + + @Override + public void updateProgressBar(int messageId, int data) { + super.updateProgressBar(messageId, data); + + tile.getGUINetworkData(messageId, data); + } + + @Override + @SuppressWarnings("unchecked") + public void detectAndSendChanges() { + super.detectAndSendChanges(); + + for (Object crafter : crafters) { + tile.sendGUINetworkData(this, (ICrafting) crafter); + } + } +} diff --git a/src/main/java/forestry/energy/gui/GuiEngineElectric.java b/src/main/java/forestry/energy/gui/GuiEngineElectric.java new file mode 100644 index 000000000..9e5cdaef8 --- /dev/null +++ b/src/main/java/forestry/energy/gui/GuiEngineElectric.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.energy.gui; + +import net.minecraft.entity.player.InventoryPlayer; + +import forestry.core.config.Constants; +import forestry.core.gui.widgets.SocketWidget; +import forestry.core.render.EnumTankLevel; +import forestry.energy.tiles.TileEngineElectric; + +public class GuiEngineElectric extends GuiEngine { + + public GuiEngineElectric(InventoryPlayer inventory, TileEngineElectric tile) { + super(Constants.TEXTURE_PATH_GUI + "/electricalengine.png", new ContainerEngineElectric(inventory, tile), tile); + widgetManager.add(new SocketWidget(this.widgetManager, 30, 40, tile, 0)); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { + super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); + + TileEngineElectric engine = inventory; + int storageHeight = engine.getStorageScaled(46); + int storageMaxHeight = engine.getStorageScaled(100); + EnumTankLevel rated = EnumTankLevel.rateTankLevel(storageMaxHeight); + + drawHealthMeter(guiLeft + 74, guiTop + 25, storageHeight, rated); + } + + private void drawHealthMeter(int x, int y, int height, EnumTankLevel rated) { + int i = 176 + rated.getLevelScaled(16); + int k = 0; + + this.drawTexturedModalRect(x, y + 46 - height, i, k + 46 - height, 4, height); + } + +} diff --git a/src/main/java/forestry/energy/gui/GuiGenerator.java b/src/main/java/forestry/energy/gui/GuiGenerator.java new file mode 100755 index 000000000..fba17b2b1 --- /dev/null +++ b/src/main/java/forestry/energy/gui/GuiGenerator.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.energy.gui; + +import net.minecraft.entity.player.InventoryPlayer; + +import forestry.core.config.Constants; +import forestry.core.gui.GuiForestryTitled; +import forestry.core.gui.widgets.TankWidget; +import forestry.energy.tiles.TileEuGenerator; + +public class GuiGenerator extends GuiForestryTitled { + + public GuiGenerator(InventoryPlayer inventory, TileEuGenerator tile) { + super(Constants.TEXTURE_PATH_GUI + "/generator.png", new ContainerGenerator(inventory, tile), tile); + widgetManager.add(new TankWidget(this.widgetManager, 49, 17, 0)); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { + super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); + + int progress = inventory.getStoredScaled(49); + if (progress > 0) { + drawTexturedModalRect(guiLeft + 108, guiTop + 38, 176, 91, progress, 18); + } + } + +} diff --git a/src/main/java/forestry/energy/inventory/InventoryEngineElectric.java b/src/main/java/forestry/energy/inventory/InventoryEngineElectric.java new file mode 100644 index 000000000..8af78b513 --- /dev/null +++ b/src/main/java/forestry/energy/inventory/InventoryEngineElectric.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.energy.inventory; + +import net.minecraft.item.ItemStack; + +import forestry.core.inventory.InventoryAdapterTile; +import forestry.energy.tiles.TileEngineElectric; + +import ic2.api.item.ElectricItem; + +public class InventoryEngineElectric extends InventoryAdapterTile { + public static final short SLOT_BATTERY = 0; + + public InventoryEngineElectric(TileEngineElectric engineTin) { + super(engineTin, 1, "electrical"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_BATTERY) { + return ElectricItem.manager.getCharge(itemStack) > 0; + } + return false; + } +} diff --git a/src/main/java/forestry/energy/inventory/InventoryGenerator.java b/src/main/java/forestry/energy/inventory/InventoryGenerator.java new file mode 100644 index 000000000..cbc88c01b --- /dev/null +++ b/src/main/java/forestry/energy/inventory/InventoryGenerator.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.energy.inventory; + +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.Fluid; + +import forestry.core.fluids.FluidHelper; +import forestry.core.inventory.InventoryAdapterTile; +import forestry.energy.tiles.TileEuGenerator; + +public class InventoryGenerator extends InventoryAdapterTile { + public static final short SLOT_CAN = 0; + + public InventoryGenerator(TileEuGenerator generator) { + super(generator, 1, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_CAN) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return tile.getTankManager().accepts(fluid); + } + + return false; + } +} diff --git a/src/main/java/forestry/energy/tiles/TileEngineElectric.java b/src/main/java/forestry/energy/tiles/TileEngineElectric.java new file mode 100644 index 000000000..51d221c39 --- /dev/null +++ b/src/main/java/forestry/energy/tiles/TileEngineElectric.java @@ -0,0 +1,326 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.energy.tiles; + +import java.io.IOException; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.ICrafting; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import forestry.api.circuits.ChipsetManager; +import forestry.api.circuits.CircuitSocketType; +import forestry.api.circuits.ICircuitBoard; +import forestry.api.circuits.ICircuitSocketType; +import forestry.api.core.IErrorLogic; +import forestry.core.circuits.ISocketable; +import forestry.core.config.Constants; +import forestry.core.errors.EnumErrorCode; +import forestry.core.inventory.InventoryAdapter; +import forestry.core.network.DataInputStreamForestry; +import forestry.core.network.DataOutputStreamForestry; +import forestry.core.network.IStreamableGui; +import forestry.core.tiles.TemperatureState; +import forestry.core.tiles.TileEngine; +import forestry.energy.gui.ContainerEngineElectric; +import forestry.energy.gui.GuiEngineElectric; +import forestry.energy.inventory.InventoryEngineElectric; +import forestry.plugins.compat.PluginIC2; + +import ic2.api.energy.prefab.BasicSink; + +public class TileEngineElectric extends TileEngine implements ISocketable, IInventory, IStreamableGui { + protected static class EuConfig { + + public int euForCycle; + public int rfPerCycle; + public int euStorage; + + public EuConfig() { + this.euForCycle = Constants.ENGINE_TIN_EU_FOR_CYCLE; + this.rfPerCycle = Constants.ENGINE_TIN_ENERGY_PER_CYCLE; + this.euStorage = Constants.ENGINE_TIN_MAX_EU_STORED; + } + } + + private final InventoryAdapter sockets = new InventoryAdapter(1, "sockets"); + private final EuConfig euConfig = new EuConfig(); + + private BasicSink ic2EnergySink; + + public TileEngineElectric() { + super("engine.tin", Constants.ENGINE_ELECTRIC_HEAT_MAX, 100000); + + setInternalInventory(new InventoryEngineElectric(this)); + + if (PluginIC2.instance.isAvailable()) { + ic2EnergySink = new BasicSink(this, euConfig.euStorage, 3); + } + } + + // / SAVING / LOADING + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) { + super.readFromNBT(nbttagcompound); + + if (ic2EnergySink != null) { + ic2EnergySink.readFromNBT(nbttagcompound); + } + sockets.readFromNBT(nbttagcompound); + + ItemStack chip = sockets.getStackInSlot(0); + if (chip != null) { + ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(chip); + if (chipset != null) { + chipset.onLoad(this); + } + } + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) { + super.writeToNBT(nbttagcompound); + + if (ic2EnergySink != null) { + ic2EnergySink.writeToNBT(nbttagcompound); + } + sockets.writeToNBT(nbttagcompound); + } + + @Override + public void onChunkUnload() { + if (ic2EnergySink != null) { + ic2EnergySink.onChunkUnload(); + } + + super.onChunkUnload(); + } + + @Override + public void invalidate() { + if (ic2EnergySink != null) { + ic2EnergySink.invalidate(); + } + + super.invalidate(); + } + + // / HEAT MANAGEMENT + @Override + public int dissipateHeat() { + if (heat <= 0) { + return 0; + } + + int loss = 0; + + if (!isBurning() || !isRedstoneActivated()) { + loss += 1; + } + + TemperatureState tempState = getTemperatureState(); + if (tempState == TemperatureState.OVERHEATING || tempState == TemperatureState.OPERATING_TEMPERATURE) { + loss += 1; + } + + heat -= loss; + return loss; + } + + @Override + public int generateHeat() { + + int gain = 0; + if (isRedstoneActivated() && isBurning()) { + gain++; + if (((double) energyManager.getTotalEnergyStored() / (double) energyManager.getMaxEnergyStored()) > 0.5) { + gain++; + } + } + + addHeat(gain); + return gain; + } + + // / WORK + @Override + public void updateServerSide() { + IErrorLogic errorLogic = getErrorLogic(); + + // No work to be done if IC2 is unavailable. + if (errorLogic.setCondition(ic2EnergySink == null, EnumErrorCode.NO_ENERGY_NET)) { + return; + } + + ic2EnergySink.update(); + + super.updateServerSide(); + + if (forceCooldown) { + return; + } + + if (getStackInSlot(InventoryEngineElectric.SLOT_BATTERY) != null) { + replenishFromBattery(InventoryEngineElectric.SLOT_BATTERY); + } + + // Updating of gui delayed to prevent it from going crazy + if (!updateOnInterval(80)) { + return; + } + + boolean canUseEnergy = ic2EnergySink.canUseEnergy(euConfig.euForCycle); + errorLogic.setCondition(!canUseEnergy, EnumErrorCode.NO_FUEL); + } + + @Override + public void burn() { + + currentOutput = 0; + + if (!isRedstoneActivated()) { + return; + } + + if (ic2EnergySink.useEnergy(euConfig.euForCycle)) { + currentOutput = euConfig.rfPerCycle; + energyManager.generateEnergy(euConfig.rfPerCycle); + } + + } + + private void replenishFromBattery(int slot) { + if (!isRedstoneActivated()) { + return; + } + + ic2EnergySink.discharge(getStackInSlot(slot), euConfig.euForCycle * 3); + } + + // / STATE INFORMATION + @Override + protected boolean isBurning() { + return mayBurn() && ic2EnergySink != null && ic2EnergySink.canUseEnergy(euConfig.euForCycle); + } + + public int getStorageScaled(int i) { + if (ic2EnergySink == null) { + return 0; + } + + return Math.min(i, (int) (ic2EnergySink.getEnergyStored() * i) / ic2EnergySink.getCapacity()); + } + + // / SMP GUI + @Override + public void writeGuiData(DataOutputStreamForestry data) throws IOException { + data.writeVarInt(currentOutput); + data.writeVarInt(heat); + sockets.writeData(data); + energyManager.writeData(data); + final boolean hasIc2EnergySink = (ic2EnergySink != null); + data.writeBoolean(hasIc2EnergySink); + if (hasIc2EnergySink) { + data.writeVarInt((int) ic2EnergySink.getEnergyStored()); + } + } + + @Override + public void readGuiData(DataInputStreamForestry data) throws IOException { + currentOutput = data.readVarInt(); + heat = data.readVarInt(); + sockets.readData(data); + energyManager.readData(data); + final boolean hasIc2EnergySink = data.readBoolean(); + if (hasIc2EnergySink) { + final int energyStored = data.readVarInt(); + ic2EnergySink.setEnergyStored(energyStored); + } + } + + @Override + public void getGUINetworkData(int i, int j) { + // handled by IStreamableGui + } + + @Override + public void sendGUINetworkData(Container containerEngine, ICrafting iCrafting) { + // handled by IStreamableGui + } + + // / ENERGY CONFIG CHANGE + public void changeEnergyConfig(int euChange, int rfChange, int storageChange) { + euConfig.euForCycle += euChange; + euConfig.rfPerCycle += rfChange; + euConfig.euStorage += storageChange; + + if (ic2EnergySink != null) { + ic2EnergySink.setCapacity(euConfig.euStorage); + } + } + + /* ISocketable */ + @Override + public int getSocketCount() { + return sockets.getSizeInventory(); + } + + @Override + public ItemStack getSocket(int slot) { + return sockets.getStackInSlot(slot); + } + + @Override + public void setSocket(int slot, ItemStack stack) { + + if (stack != null && !ChipsetManager.circuitRegistry.isChipset(stack)) { + return; + } + + // Dispose correctly of old chipsets + if (sockets.getStackInSlot(slot) != null) { + if (ChipsetManager.circuitRegistry.isChipset(sockets.getStackInSlot(slot))) { + ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(sockets.getStackInSlot(slot)); + if (chipset != null) { + chipset.onRemoval(this); + } + } + } + + sockets.setInventorySlotContents(slot, stack); + if (stack == null) { + return; + } + + ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(stack); + if (chipset != null) { + chipset.onInsertion(this); + } + } + + @Override + public ICircuitSocketType getSocketType() { + return CircuitSocketType.ELECTRIC_ENGINE; + } + + @Override + public Object getGui(EntityPlayer player, int data) { + return new GuiEngineElectric(player.inventory, this); + } + + @Override + public Object getContainer(EntityPlayer player, int data) { + return new ContainerEngineElectric(player.inventory, this); + } +} diff --git a/src/main/java/forestry/energy/tiles/TileEuGenerator.java b/src/main/java/forestry/energy/tiles/TileEuGenerator.java new file mode 100644 index 000000000..e20c9d77f --- /dev/null +++ b/src/main/java/forestry/energy/tiles/TileEuGenerator.java @@ -0,0 +1,242 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.energy.tiles; + +import java.io.IOException; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.ICrafting; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; + +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; + +import forestry.api.core.IErrorLogic; +import forestry.api.fuels.FuelManager; +import forestry.api.fuels.GeneratorFuel; +import forestry.core.config.Constants; +import forestry.core.errors.EnumErrorCode; +import forestry.core.fluids.FluidHelper; +import forestry.core.fluids.TankManager; +import forestry.core.fluids.tanks.FilteredTank; +import forestry.core.network.DataInputStreamForestry; +import forestry.core.network.DataOutputStreamForestry; +import forestry.core.render.TankRenderInfo; +import forestry.core.tiles.ILiquidTankTile; +import forestry.core.tiles.IRenderableTile; +import forestry.core.tiles.TileBase; +import forestry.energy.gui.ContainerGenerator; +import forestry.energy.gui.GuiGenerator; +import forestry.energy.inventory.InventoryGenerator; +import forestry.plugins.compat.PluginIC2; + +import ic2.api.energy.prefab.BasicSource; + +public class TileEuGenerator extends TileBase implements ISidedInventory, ILiquidTankTile, IFluidHandler, IRenderableTile { + private static final int maxEnergy = 30000; + + private final TankManager tankManager; + private final FilteredTank resourceTank; + + private int tickCount = 0; + + private BasicSource ic2EnergySource; + + public TileEuGenerator() { + super("generator"); + + setInternalInventory(new InventoryGenerator(this)); + + resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, FuelManager.generatorFuel.keySet()); + tankManager = new TankManager(this, resourceTank); + + if (PluginIC2.instance.isAvailable()) { + ic2EnergySource = new BasicSource(this, maxEnergy, 1); + } + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) { + super.writeToNBT(nbttagcompound); + + if (ic2EnergySource != null) { + ic2EnergySource.writeToNBT(nbttagcompound); + } + + tankManager.writeToNBT(nbttagcompound); + } + + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) { + super.readFromNBT(nbttagcompound); + + if (ic2EnergySource != null) { + ic2EnergySource.readFromNBT(nbttagcompound); + } + + tankManager.readFromNBT(nbttagcompound); + } + + @Override + public void writeData(DataOutputStreamForestry data) throws IOException { + super.writeData(data); + tankManager.writeData(data); + } + + @Override + public void readData(DataInputStreamForestry data) throws IOException { + super.readData(data); + tankManager.readData(data); + } + + @Override + public void onChunkUnload() { + if (ic2EnergySource != null) { + ic2EnergySource.onChunkUnload(); + } + + super.onChunkUnload(); + } + + @Override + public void invalidate() { + if (ic2EnergySource != null) { + ic2EnergySource.invalidate(); + } + + super.invalidate(); + } + + @Override + public void updateServerSide() { + if (updateOnInterval(20)) { + FluidHelper.drainContainers(tankManager, this, InventoryGenerator.SLOT_CAN); + } + + IErrorLogic errorLogic = getErrorLogic(); + + // No work to be done if IC2 is unavailable. + if (errorLogic.setCondition(ic2EnergySource == null, EnumErrorCode.NO_ENERGY_NET)) { + return; + } + + ic2EnergySource.update(); + + if (resourceTank.getFluidAmount() > 0) { + GeneratorFuel fuel = FuelManager.generatorFuel.get(resourceTank.getFluid().getFluid()); + if (resourceTank.canDrain(fuel.fuelConsumed) && ic2EnergySource.getFreeCapacity() >= fuel.eu) { + ic2EnergySource.addEnergy(fuel.eu); + this.tickCount++; + + if (tickCount >= fuel.rate) { + tickCount = 0; + resourceTank.drain(fuel.fuelConsumed.amount, true); + } + } + + } + + boolean hasFuel = resourceTank.getFluidAmount() > 0; + errorLogic.setCondition(!hasFuel, EnumErrorCode.NO_FUEL); + } + + public boolean isWorking() { + return resourceTank.getFluidAmount() > 0; + } + + public int getResourceScaled(int i) { + return (resourceTank.getFluidAmount() * i) / Constants.PROCESSOR_TANK_CAPACITY; + } + + public int getStoredScaled(int i) { + if (ic2EnergySource == null) { + return 0; + } + + return (int) (ic2EnergySource.getEnergyStored() * i) / maxEnergy; + } + + @Override + public TankRenderInfo getResourceTankInfo() { + return new TankRenderInfo(resourceTank); + } + + @Override + public TankRenderInfo getProductTankInfo() { + return TankRenderInfo.EMPTY; + } + + /* SMP GUI */ + public void getGUINetworkData(int i, int j) { + if (i == 0) { + if (ic2EnergySource != null) { + ic2EnergySource.setEnergyStored(j); + } + } + } + + public void sendGUINetworkData(Container container, ICrafting iCrafting) { + if (ic2EnergySource != null) { + iCrafting.sendProgressBarUpdate(container, 0, (short) ic2EnergySource.getEnergyStored()); + } + } + + /* ILiquidTankTile */ + @Override + public int fill(EnumFacing from, FluidStack resource, boolean doFill) { + return tankManager.fill(from, resource, doFill); + } + + @Override + public TankManager getTankManager() { + return tankManager; + } + + @Override + public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain) { + return tankManager.drain(from, resource, doDrain); + } + + @Override + public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain) { + return tankManager.drain(from, maxDrain, doDrain); + } + + @Override + public boolean canFill(EnumFacing from, Fluid fluid) { + return tankManager.canFill(from, fluid); + } + + @Override + public boolean canDrain(EnumFacing from, Fluid fluid) { + return tankManager.canDrain(from, fluid); + } + + @Override + public FluidTankInfo[] getTankInfo(EnumFacing from) { + return tankManager.getTankInfo(from); + } + + @Override + public Object getGui(EntityPlayer player, int data) { + return new GuiGenerator(player.inventory, this); + } + + @Override + public Object getContainer(EntityPlayer player, int data) { + return new ContainerGenerator(player.inventory, this); + } +} diff --git a/src/main/java/forestry/factory/PluginFactory.java b/src/main/java/forestry/factory/PluginFactory.java index 2b08f61cf..9c4d84567 100644 --- a/src/main/java/forestry/factory/PluginFactory.java +++ b/src/main/java/forestry/factory/PluginFactory.java @@ -168,7 +168,16 @@ public class PluginFactory extends BlankForestryPlugin { FuelManager.rainSubstrate.put(iodineCharge, new RainSubstrate(iodineCharge, Constants.RAINMAKER_RAIN_DURATION_IODINE, 0.01f)); FuelManager.rainSubstrate.put(dissipationCharge, new RainSubstrate(dissipationCharge, 0.075f)); - blocks.factoryTESR.addDefinitions(BlockTypeFactoryTesr.VALUES); + blocks.factoryTESR.addDefinitions( + BlockTypeFactoryTesr.BOTTLER, + BlockTypeFactoryTesr.CARPENTER, + BlockTypeFactoryTesr.CENTRIFUGE, + BlockTypeFactoryTesr.FERMENTER, + BlockTypeFactoryTesr.MOISTENER, + BlockTypeFactoryTesr.SQUEEZER, + BlockTypeFactoryTesr.STILL, + BlockTypeFactoryTesr.RAINMAKER + ); blocks.factoryPlain.addDefinitions(BlockTypeFactoryPlain.VALUES); ICircuitLayout layoutMachineUpgrade = new CircuitLayout("machine.upgrade", CircuitSocketType.MACHINE); diff --git a/src/main/java/forestry/farming/logic/CropBasicIC2Crop.java b/src/main/java/forestry/farming/logic/CropBasicIC2Crop.java new file mode 100644 index 000000000..07f6c3582 --- /dev/null +++ b/src/main/java/forestry/farming/logic/CropBasicIC2Crop.java @@ -0,0 +1,81 @@ +package forestry.farming.logic; + +import java.util.Collection; +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import net.minecraftforge.fml.common.Optional; + +import forestry.core.utils.vect.Vect; +import forestry.plugins.compat.PluginIC2; + +import ic2.api.crops.ICropTile; + +public class CropBasicIC2Crop extends Crop { + private final TileEntity tileEntity; + + public CropBasicIC2Crop(World world, TileEntity tileEntity, Vect position) { + super(world, position); + this.tileEntity = tileEntity; + } + + @Override + protected boolean isCrop(Vect pos) { + return canHarvestCrop(this.tileEntity); + } + + @Override + protected Collection harvestBlock(Vect pos) { + return getCropDrops(this.tileEntity); + } + + /** + * Check if there is an instance of ICropTile. + * @param tileEntity tile entity to be checked. + * @return true if there is an IC2 crop and false otherwise. + */ + @Optional.Method(modid = PluginIC2.modId) + public static boolean isIC2Crop(TileEntity tileEntity) { + if (tileEntity instanceof ICropTile) { + return true; + } + return false; + } + + /** + * Check if an IC2 crop is ready to be harvested. + * @param tileEntity tile entity to be checked. + * @return true if crop size is optimal for harvest and false otherwise. + */ + @Optional.Method(modid = PluginIC2.modId) + public static boolean canHarvestCrop(TileEntity tileEntity) { + if (isIC2Crop(tileEntity)) { + ICropTile crop = (ICropTile) tileEntity; + if (crop.getCrop() == null) { + return false; + } + if (crop.getCurrentSize() == crop.getCrop().getOptimalHarvestSize(crop)) { + return true; + } + } + return false; + } + + /** + * This function takes care of everything related to the harvesting of the + * crop meaning it will calculate the drops and also do setSizeAfterHarvest(). + * @param tileEntity tile entity to be checked. + * @return list containing the drops. + */ + @Optional.Method(modid = PluginIC2.modId) + private static List getCropDrops(TileEntity tileEntity) { + if (isIC2Crop(tileEntity)) { + ICropTile crop = (ICropTile) tileEntity; + return crop.performHarvest(); + } + return null; + } +} diff --git a/src/main/java/forestry/farming/logic/CropRubber.java b/src/main/java/forestry/farming/logic/CropRubber.java new file mode 100755 index 000000000..345ae1078 --- /dev/null +++ b/src/main/java/forestry/farming/logic/CropRubber.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.farming.logic; + +import java.util.ArrayList; +import java.util.Collection; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import forestry.core.config.Constants; +import forestry.core.proxy.Proxies; +import forestry.core.utils.vect.Vect; +import forestry.plugins.compat.PluginIC2; + +public class CropRubber extends CropBlock { + + public CropRubber(World world, Block block, int meta, Vect position) { + super(world, block, meta, position); + } + + @Override + protected Collection harvestBlock(Vect pos) { + Collection harvested = new ArrayList<>(); + harvested.add(PluginIC2.resin.copy()); + Proxies.common.addBlockDestroyEffects(world, pos, block.getStateFromMeta(0)); + world.setBlockState(pos, block.getStateFromMeta(meta + 6), Constants.FLAG_BLOCK_SYNCH); + return harvested; + } + +} diff --git a/src/main/java/forestry/farming/logic/FarmLogicRubber.java b/src/main/java/forestry/farming/logic/FarmLogicRubber.java new file mode 100755 index 000000000..f8dbf3ea3 --- /dev/null +++ b/src/main/java/forestry/farming/logic/FarmLogicRubber.java @@ -0,0 +1,190 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.farming.logic; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; +import java.util.Stack; + +import net.minecraft.block.Block; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; +import net.minecraft.world.World; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.farming.FarmDirection; +import forestry.api.farming.ICrop; +import forestry.api.farming.IFarmHousing; +import forestry.core.utils.ItemStackUtil; +import forestry.core.utils.Log; +import forestry.core.utils.vect.Vect; +import forestry.core.utils.vect.VectUtil; +import forestry.plugins.compat.PluginIC2; + +public class FarmLogicRubber extends FarmLogic { + + private boolean inActive; + + public FarmLogicRubber(IFarmHousing housing) { + super(housing); + if (PluginIC2.rubberWood == null || PluginIC2.resin == null) { + Log.warning("Failed to init a farm logic %s since IC2 was not found", getClass().getName()); + inActive = true; + } + } + + @Override + @SideOnly(Side.CLIENT) + public Item getItem() { + if (!inActive) { + return PluginIC2.resin.getItem(); + } else { + return Items.gunpowder; + } + } + + @Override + public String getName() { + return "Rubber Plantation"; + } + + @Override + public int getFertilizerConsumption() { + return 40; + } + + @Override + public int getWaterConsumption(float hydrationModifier) { + return (int) (5 * hydrationModifier); + } + + @Override + public boolean isAcceptedResource(ItemStack itemstack) { + return false; + } + + @Override + public boolean isAcceptedGermling(ItemStack itemstack) { + return false; + } + + @Override + public boolean isAcceptedWindfall(ItemStack stack) { + return false; + } + + @Override + public Collection collect() { + return null; + } + + @Override + public boolean cultivate(BlockPos pos, FarmDirection direction, int extent) { + return false; + } + + private final HashMap lastExtents = new HashMap<>(); + + @Override + public Collection harvest(BlockPos pos, FarmDirection direction, int extent) { + if (inActive) { + return null; + } + + Vect start = new Vect(pos); + if (!lastExtents.containsKey(start)) { + lastExtents.put(start, 0); + } + + int lastExtent = lastExtents.get(start); + if (lastExtent > extent) { + lastExtent = 0; + } + + Vect position = translateWithOffset(pos.add(0, 1, 0), direction, lastExtent); + Collection crops = getHarvestBlocks(position); + lastExtent++; + lastExtents.put(start, lastExtent); + + return crops; + } + + private Collection getHarvestBlocks(Vect position) { + + Set seen = new HashSet<>(); + Stack crops = new Stack<>(); + + World world = getWorld(); + + // Determine what type we want to harvest. + Block block = VectUtil.getBlock(world, position); + if (!ItemStackUtil.equals(block, PluginIC2.rubberWood)) { + return crops; + } + + int meta = VectUtil.getBlockMeta(world, position); + if (meta >= 2 && meta <= 5) { + crops.push(new CropRubber(getWorld(), block, meta, position)); + } + + ArrayList candidates = processHarvestBlock(crops, seen, position); + ArrayList temp = new ArrayList<>(); + while (!candidates.isEmpty() && crops.size() < 100) { + for (Vect candidate : candidates) { + temp.addAll(processHarvestBlock(crops, seen, candidate)); + } + candidates.clear(); + candidates.addAll(temp); + temp.clear(); + } + + return crops; + } + + private ArrayList processHarvestBlock(Stack crops, Set seen, Vect position) { + World world = getWorld(); + + ArrayList candidates = new ArrayList<>(); + + // Get additional candidates to return + for (int j = 0; j < 2; j++) { + Vect candidate = new Vect(position.getX(), position.getY() + j, position.getZ()); + if (candidate.equals(position)) { + continue; + } + + // See whether the given position has already been processed + if (seen.contains(candidate)) { + continue; + } + + Block block = VectUtil.getBlock(world, candidate); + if (ItemStackUtil.equals(block, PluginIC2.rubberWood)) { + int meta = VectUtil.getBlockMeta(world, candidate); + if (meta >= 2 && meta <= 5) { + crops.push(new CropRubber(world, block, meta, candidate)); + } + candidates.add(candidate); + seen.add(candidate); + } + } + + return candidates; + } + +} diff --git a/src/main/java/forestry/farming/logic/FarmableBasicIC2Crop.java b/src/main/java/forestry/farming/logic/FarmableBasicIC2Crop.java new file mode 100644 index 000000000..ef304f6de --- /dev/null +++ b/src/main/java/forestry/farming/logic/FarmableBasicIC2Crop.java @@ -0,0 +1,82 @@ +package forestry.farming.logic; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockPos; +import net.minecraft.world.World; + +import net.minecraftforge.fml.common.Optional; + +import forestry.api.farming.ICrop; +import forestry.api.farming.IFarmable; +import forestry.core.utils.vect.Vect; +import forestry.plugins.compat.PluginIC2; + +import ic2.api.crops.ICropTile; + +public class FarmableBasicIC2Crop implements IFarmable { + + /** + * Perform some of the actions of the crop-matron. + */ + @Optional.Method(modid = PluginIC2.modId) + public static void babysitCrop(TileEntity tileEntity) { + if (CropBasicIC2Crop.isIC2Crop(tileEntity)) { + ICropTile crop = (ICropTile) tileEntity; + /* + This part might be unbalanced until a custom farm logic is added and makes use of weed-ex. + if (crop.getCrop() != null) { + if (crop.getCrop().isWeed(crop)) { + crop.reset(); + } + }*/ + if (crop.getStorageWater() <= 200) { + crop.setStorageWater(200); + } + if (crop.getStorageNutrient() <= 100) { + crop.setStorageNutrient(crop.getStorageNutrient() + 100); + } + } + } + + @Override + public boolean isSaplingAt(World world, BlockPos pos) { + TileEntity crop = world.getTileEntity(pos); + if (CropBasicIC2Crop.isIC2Crop(crop)) { + babysitCrop(crop); + return true; + } + return false; + } + + @Override + public ICrop getCropAt(World world, BlockPos pos) { + TileEntity crop = world.getTileEntity(pos); + if (crop == null) { + return null; + } + if (!CropBasicIC2Crop.isIC2Crop(crop)) { + return null; + } + if (!CropBasicIC2Crop.canHarvestCrop(crop)) { + return null; + } + return new CropBasicIC2Crop(world, crop, new Vect(pos)); + } + + @Override + public boolean isGermling(ItemStack itemstack) { + return false; + } + + @Override + public boolean isWindfall(ItemStack itemstack) { + return false; + } + + @Override + public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) { + return false; + } +} diff --git a/src/main/java/forestry/plugins/compat/PluginIC2.java b/src/main/java/forestry/plugins/compat/PluginIC2.java new file mode 100644 index 000000000..6d09a2382 --- /dev/null +++ b/src/main/java/forestry/plugins/compat/PluginIC2.java @@ -0,0 +1,317 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.plugins.compat; + +import com.google.common.collect.ImmutableMap; + +import javax.annotation.Nonnull; +import java.util.Set; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fml.common.Optional; +import net.minecraftforge.fml.common.event.FMLInterModComms; +import net.minecraftforge.fml.common.registry.GameRegistry; + +import forestry.api.circuits.ChipsetManager; +import forestry.api.circuits.CircuitSocketType; +import forestry.api.circuits.ICircuitLayout; +import forestry.api.core.ForestryAPI; +import forestry.api.farming.Farmables; +import forestry.api.fuels.EngineBronzeFuel; +import forestry.api.fuels.FuelManager; +import forestry.api.recipes.RecipeManagers; +import forestry.api.storage.BackpackManager; +import forestry.api.storage.IBackpackDefinition; +import forestry.api.storage.ICrateRegistry; +import forestry.api.storage.StorageManager; +import forestry.apiculture.PluginApiculture; +import forestry.apiculture.items.EnumPropolis; +import forestry.apiculture.items.ItemRegistryApiculture; +import forestry.core.PluginCore; +import forestry.core.blocks.BlockSoil; +import forestry.core.circuits.Circuit; +import forestry.core.circuits.CircuitLayout; +import forestry.core.config.Constants; +import forestry.core.fluids.Fluids; +import forestry.core.items.EnumElectronTube; +import forestry.core.items.ItemRegistryCore; +import forestry.core.recipes.RecipeUtil; +import forestry.core.utils.ItemStackUtil; +import forestry.core.utils.Log; +import forestry.core.utils.ModUtil; +import forestry.energy.PluginEnergy; +import forestry.energy.blocks.BlockRegistryEnergy; +import forestry.energy.blocks.BlockTypeEngine; +import forestry.energy.circuits.CircuitElectricBoost; +import forestry.energy.circuits.CircuitElectricChoke; +import forestry.energy.circuits.CircuitElectricEfficiency; +import forestry.farming.circuits.CircuitFarmLogic; +import forestry.farming.logic.FarmLogicRubber; +import forestry.farming.logic.FarmableBasicIC2Crop; +import forestry.plugins.BlankForestryPlugin; +import forestry.plugins.ForestryPlugin; +import forestry.plugins.ForestryPluginUids; + +import ic2.api.item.IC2Items; +import ic2.api.recipe.RecipeInputItemStack; +import ic2.api.recipe.Recipes; + +@ForestryPlugin(pluginID = "IC2", name = "IndustrialCraft2", author = "SirSengir", url = Constants.URL, unlocalizedDescription = "for.plugin.ic2.description") +public class PluginIC2 extends BlankForestryPlugin { + public static final String modId = "IC2"; + public static PluginIC2 instance; + + private static ItemStack rubberSapling; + private static ItemStack rubber; + public static ItemStack rubberWood; + public static ItemStack resin; + + public PluginIC2() { + if (PluginIC2.instance == null) { + PluginIC2.instance = this; + } + } + + @Override + public boolean isAvailable() { + return ModUtil.isModLoaded(PluginIC2.modId); + } + + @Override + public String getFailMessage() { + return "IndustrialCraft2 not found"; + } + + @Nonnull + @Override + public Set getDependencyUids() { + Set dependencyUids = super.getDependencyUids(); + dependencyUids.add(ForestryPluginUids.FARMING); + dependencyUids.add(ForestryPluginUids.FACTORY); + return dependencyUids; + } + + @Override + @Optional.Method(modid = PluginIC2.modId) + public void preInit() { + super.preInit(); + + BlockRegistryEnergy energyBlocks = PluginEnergy.blocks; + if (energyBlocks != null) { + energyBlocks.engine.addDefinitions(BlockTypeEngine.ELECTRICAL); + energyBlocks.engine.addDefinitions(BlockTypeEngine.GENERATOR); + } + + // rubber chain + rubberWood = IC2Items.getItem("rubber_wood"); + resin = IC2Items.getItem("misc_resource", "resin"); + rubberSapling = IC2Items.getItem("sapling"); + rubber = IC2Items.getItem("crafting", "rubber"); + + Circuit.farmRubberManual = new CircuitFarmLogic("manualRubber", FarmLogicRubber.class); + + ICircuitLayout layoutEngineTin = new CircuitLayout("engine.tin", CircuitSocketType.ELECTRIC_ENGINE); + ChipsetManager.circuitRegistry.registerLayout(layoutEngineTin); + } + + @Override + @Optional.Method(modid = PluginIC2.modId) + public void doInit() { + super.doInit(); + + // Remove some items from the recycler + if (Recipes.recyclerBlacklist != null) { + ItemRegistryApiculture beeItems = PluginApiculture.items; + if (beeItems != null) { + Recipes.recyclerBlacklist.add(new RecipeInputItemStack(new ItemStack(beeItems.beeQueenGE))); + Recipes.recyclerBlacklist.add(new RecipeInputItemStack(new ItemStack(beeItems.beePrincessGE))); + } + } else { + Log.error("IC2 Recipes.recyclerBlacklist not found."); + } + + Circuit.energyElectricChoke1 = new CircuitElectricChoke("electric.choke.1"); + Circuit.energyElectricEfficiency1 = new CircuitElectricEfficiency("electric.efficiency.1"); + Circuit.energyElectricBoost1 = new CircuitElectricBoost("electric.boost.1", 2, 7, 20); + Circuit.energyElectricBoost2 = new CircuitElectricBoost("electric.boost.2", 2, 15, 40); + } + + @Override + public void postInit() { + super.postInit(); + + if (BackpackManager.backpackInterface == null) { + return; + } + + IBackpackDefinition forester = BackpackManager.backpackInterface.getBackpack(BackpackManager.FORESTER_UID); + + if (resin != null) { + forester.addValidItem(resin); + } + if (rubber != null) { + forester.addValidItem(rubber); + } + if (rubberSapling != null) { + forester.addValidItem(rubberSapling); + } + ItemStack rubberLeaves = IC2Items.getItem("leaves"); + if (rubberLeaves != null) { + forester.addValidItem(rubberLeaves); + } + } + + @Override + public void registerCrates() { + ICrateRegistry crateRegistry = StorageManager.crateRegistry; + if (crateRegistry == null) { + return; + } + + if (resin != null) { + crateRegistry.registerCrate(resin, "cratedResin"); + } + + if (rubber != null) { + crateRegistry.registerCrate(rubber, "cratedRubber"); + } + + ItemStack scrap = IC2Items.getItem("crafting", "scrap"); + if (scrap != null) { + crateRegistry.registerCrate(scrap, "cratedScrap"); + } + + ItemStack uuMatter = IC2Items.getItem("misc_resource", "matter"); + if (uuMatter != null) { + crateRegistry.registerCrate(uuMatter, "cratedUUM"); + } + + ItemStack silver = IC2Items.getItem("ingot", "silver"); + if (silver != null) { + crateRegistry.registerCrateUsingOreDict(silver, "cratedSilver"); + } + + ItemStack brass = IC2Items.getItem("ingot", "bronze"); + if (brass != null) { + crateRegistry.registerCrateUsingOreDict(brass, "cratedBrass"); + } + } + + @Override + @Optional.Method(modid = PluginIC2.modId) + public void registerRecipes() { + ItemRegistryCore coreItems = PluginCore.items; + + if (rubber != null) { + for (Object rubberOreDict : RecipeUtil.getOreDictRecipeEquivalents(rubber)) { + RecipeManagers.fabricatorManager.addRecipe(null, Fluids.GLASS.getFluid(500), coreItems.tubes.get(EnumElectronTube.RUBBER, 4), + new Object[]{" X ", "#X#", "XXX", '#', "dustRedstone", 'X', rubberOreDict}); + } + } + + ItemStack plantBall = IC2Items.getItem("crafting", "plant_ball"); + if (plantBall != null) { + RecipeUtil.addFermenterRecipes(plantBall, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat") * 9, Fluids.BIOMASS); + } + + ItemStack bioChaff = IC2Items.getItem("crafting", "bio_chaff"); + if (bioChaff != null) { + RecipeUtil.addFermenterRecipes(bioChaff, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat") * 9, Fluids.BIOMASS); + } + + ItemRegistryApiculture beeItems = PluginApiculture.items; + if (beeItems != null) { + if (resin != null) { + RecipeManagers.centrifugeManager.addRecipe(20, beeItems.propolis.get(EnumPropolis.NORMAL, 1), ImmutableMap.of(resin, 1.0f)); + } else { + Log.info("Missing IC2 resin, skipping centrifuge recipe for propolis to resin."); + } + } + + if (rubberSapling != null) { + RecipeUtil.addFermenterRecipes(rubberSapling, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS); + } else { + Log.info("Missing IC2 rubber sapling, skipping fermenter recipe for converting rubber sapling to biomass."); + } + + if (rubberSapling != null && resin != null) { + String saplingName = ItemStackUtil.getBlockNameFromRegistryAsSting(ItemStackUtil.getBlock(rubberSapling)); + String resinName = ItemStackUtil.getItemNameFromRegistryAsSting(resin.getItem()); + String imc = String.format("farmArboreal@%s.%s.%s.%s", + saplingName, rubberSapling.getItemDamage(), + resinName, resin.getItemDamage()); + Log.trace("Sending IMC '%s'.", imc); + FMLInterModComms.sendMessage(Constants.MOD_ID, "add-farmable-sapling", imc); + } + + + if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.ENERGY)) { + FluidStack biogas = FluidRegistry.getFluidStack("ic2biogas", 1000); + if (biogas != null) { + int burnDuration = Math.round(Constants.ENGINE_CYCLE_DURATION_BIOMASS * ForestryAPI.activeMode.getFloatSetting("fuel.biomass.biogas")); + EngineBronzeFuel bronzeFuel = new EngineBronzeFuel(Fluids.BIOMASS.getFluid(), Constants.ENGINE_FUEL_VALUE_BIOMASS, burnDuration, 1); + FuelManager.bronzeEngineFuel.put(biogas.getFluid(), bronzeFuel); + } + } + + ItemStack waterCell = IC2Items.getItem("fluid_cell", "water"); + if (waterCell != null) { + int bogEarthOutputCan = ForestryAPI.activeMode.getIntegerSetting("recipe.output.bogearth.can"); + if (bogEarthOutputCan > 0) { + ItemStack bogEarthCan = PluginCore.blocks.soil.get(BlockSoil.SoilType.BOG_EARTH, bogEarthOutputCan); + RecipeUtil.addRecipe(bogEarthCan, "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', waterCell, 'Y', "sand"); + } + } + + ICircuitLayout layout = ChipsetManager.circuitRegistry.getLayout("forestry.engine.tin"); + + // / Solder Manager + ChipsetManager.solderManager.addRecipe(layout, coreItems.tubes.get(EnumElectronTube.COPPER, 1), Circuit.energyElectricChoke1); + ChipsetManager.solderManager.addRecipe(layout, coreItems.tubes.get(EnumElectronTube.TIN, 1), Circuit.energyElectricBoost1); + ChipsetManager.solderManager.addRecipe(layout, coreItems.tubes.get(EnumElectronTube.BRONZE, 1), Circuit.energyElectricBoost2); + ChipsetManager.solderManager.addRecipe(layout, coreItems.tubes.get(EnumElectronTube.IRON, 1), Circuit.energyElectricEfficiency1); + + if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING)) { + if (resin != null && rubberWood != null) { + ICircuitLayout layoutManual = ChipsetManager.circuitRegistry.getLayout("forestry.farms.manual"); + ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.RUBBER, 1), Circuit.farmRubberManual); + } + + Farmables.farmables.get("farmOrchard").add(new FarmableBasicIC2Crop()); + } + + + BlockRegistryEnergy energyBlocks = PluginEnergy.blocks; + if (energyBlocks != null) { + RecipeUtil.addRecipe(energyBlocks.engine.get(BlockTypeEngine.GENERATOR), + "X#X", + "XYX", + "X#X", + '#', "blockGlass", + 'X', "ingotGold", + 'Y', coreItems.sturdyCasing); + + RecipeUtil.addRecipe(energyBlocks.engine.get(BlockTypeEngine.ELECTRICAL), + "###", + " X ", + "YVY", + '#', "ingotTin", + 'X', "blockGlass", + 'Y', "gearTin", + 'V', Blocks.piston); + } + } +} diff --git a/src/main/resources/assets/forestry/models/item/engine_electrical.json b/src/main/resources/assets/forestry/models/item/engine_electrical.json new file mode 100644 index 000000000..43a272a60 --- /dev/null +++ b/src/main/resources/assets/forestry/models/item/engine_electrical.json @@ -0,0 +1,3 @@ +{ + "parent": "builtin/entity" +}