diff --git a/lang b/lang index c7d8010d7..6e0c7799e 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit c7d8010d75ba787d643e4c783748925a7dba7f99 +Subproject commit 6e0c7799eb9b5a73455e5c7199f15b208b63771c diff --git a/src/main/java/forestry/apiculture/gui/GuiAlveary.java b/src/main/java/forestry/apiculture/gui/GuiAlveary.java index 7f0dd8cf6..ff5eb757b 100755 --- a/src/main/java/forestry/apiculture/gui/GuiAlveary.java +++ b/src/main/java/forestry/apiculture/gui/GuiAlveary.java @@ -16,7 +16,7 @@ import forestry.apiculture.multiblock.IAlvearyController; import forestry.apiculture.multiblock.TileAlvearyPlain; import forestry.core.config.Defaults; import forestry.core.gui.GuiForestryTitled; -import forestry.core.gui.OwnerLedger; +import forestry.core.gui.ledgers.OwnerLedger; import forestry.core.utils.EnumTankLevel; import forestry.core.utils.Utils; diff --git a/src/main/java/forestry/apiculture/multiblock/IAlvearyController.java b/src/main/java/forestry/apiculture/multiblock/IAlvearyController.java index eeb37a2f6..91cc94dd5 100644 --- a/src/main/java/forestry/apiculture/multiblock/IAlvearyController.java +++ b/src/main/java/forestry/apiculture/multiblock/IAlvearyController.java @@ -15,10 +15,8 @@ import forestry.api.apiculture.IBeeHousing; import forestry.core.interfaces.IClimatised; import forestry.core.interfaces.IRestrictedAccessTile; import forestry.core.inventory.IInventoryAdapter; -import forestry.core.network.IStreamableGui; - -public interface IAlvearyController extends IBeeHousing, IClimatised, IRestrictedAccessTile, IStreamableGui { +public interface IAlvearyController extends IBeeHousing, IClimatised, IRestrictedAccessTile { IInventoryAdapter getInternalInventory(); Iterable getComponents(); diff --git a/src/main/java/forestry/apiculture/multiblock/TileAlvearyClimatiser.java b/src/main/java/forestry/apiculture/multiblock/TileAlvearyClimatiser.java index ca090b4c4..e2a0d9376 100644 --- a/src/main/java/forestry/apiculture/multiblock/TileAlvearyClimatiser.java +++ b/src/main/java/forestry/apiculture/multiblock/TileAlvearyClimatiser.java @@ -26,6 +26,9 @@ import cofh.api.energy.IEnergyHandler; public abstract class TileAlvearyClimatiser extends TileAlveary implements IEnergyHandler, IActivatable, IAlvearyComponent.Climatiser { + private static final int WORK_CYCLES = 1; + private static final int ENERGY_PER_OPERATION = 50; + protected interface IClimitiserDefinition { float getChangePerTransfer(); @@ -49,16 +52,16 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner protected TileAlvearyClimatiser(IClimitiserDefinition definition) { this.definition = definition; - this.energyManager = new EnergyManager(1000, 50, 2000); + this.energyManager = new EnergyManager(1000, 2000); this.energyManager.setReceiveOnly(); } /* UPDATING */ @Override public void changeClimate(int tick, IClimateControlled climateControlled) { - if (workingTime < 20 && energyManager.consumeEnergyToDoWork()) { - // consume 10 RF per tick of work - workingTime += energyManager.getEnergyPerWork() / 10; + if (workingTime < 20 && energyManager.consumeEnergyToDoWork(WORK_CYCLES, ENERGY_PER_OPERATION)) { + // one tick of work for every 10 RF + workingTime += ENERGY_PER_OPERATION / 10; } if (workingTime > 0) { diff --git a/src/main/java/forestry/apiculture/multiblock/TileAlvearyWithGui.java b/src/main/java/forestry/apiculture/multiblock/TileAlvearyWithGui.java index 9826c4e12..a528dcd11 100644 --- a/src/main/java/forestry/apiculture/multiblock/TileAlvearyWithGui.java +++ b/src/main/java/forestry/apiculture/multiblock/TileAlvearyWithGui.java @@ -24,10 +24,9 @@ import forestry.core.interfaces.ITitled; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.GuiId; -import forestry.core.network.IStreamableGui; import forestry.core.utils.EnumAccess; -public abstract class TileAlvearyWithGui extends TileAlveary implements IStreamableGui, ITitled, IRestrictedAccessTile { +public abstract class TileAlvearyWithGui extends TileAlveary implements ITitled, IRestrictedAccessTile { private final AccessHandler accessHandler; private final String unlocalizedTitle; diff --git a/src/main/java/forestry/core/circuits/Circuit.java b/src/main/java/forestry/core/circuits/Circuit.java index 44ce176c1..724e54d09 100755 --- a/src/main/java/forestry/core/circuits/Circuit.java +++ b/src/main/java/forestry/core/circuits/Circuit.java @@ -98,4 +98,8 @@ public abstract class Circuit implements ICircuit { public static ICircuit farmOrchardManual; public static ICircuit farmRubberManual; public static ICircuit farmEnderManaged; + + public static ICircuit machineSpeedUpgrade1; + public static ICircuit machineSpeedUpgrade2; + public static ICircuit machineEfficiencyUpgrade1; } diff --git a/src/main/java/forestry/core/interfaces/ISocketable.java b/src/main/java/forestry/core/circuits/ISocketable.java old mode 100755 new mode 100644 similarity index 95% rename from src/main/java/forestry/core/interfaces/ISocketable.java rename to src/main/java/forestry/core/circuits/ISocketable.java index 4a1207d50..b2e42f960 --- a/src/main/java/forestry/core/interfaces/ISocketable.java +++ b/src/main/java/forestry/core/circuits/ISocketable.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.interfaces; +package forestry.core.circuits; import net.minecraft.item.ItemStack; diff --git a/src/main/java/forestry/core/circuits/ISpeedUpgradable.java b/src/main/java/forestry/core/circuits/ISpeedUpgradable.java new file mode 100644 index 000000000..b6afc836e --- /dev/null +++ b/src/main/java/forestry/core/circuits/ISpeedUpgradable.java @@ -0,0 +1,15 @@ +/******************************************************************************* + * 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.core.circuits; + +public interface ISpeedUpgradable { + void applySpeedUpgrade(double speedChange, double powerChange); +} diff --git a/src/main/java/forestry/core/config/Defaults.java b/src/main/java/forestry/core/config/Defaults.java index 09fd85df1..9fe41f80f 100755 --- a/src/main/java/forestry/core/config/Defaults.java +++ b/src/main/java/forestry/core/config/Defaults.java @@ -145,10 +145,6 @@ public class Defaults { // Factory public static final int PROCESSOR_TANK_CAPACITY = 10 * BUCKET_VOLUME; - public static final int MACHINE_LATENCY = 1000; - public static final int MACHINE_MIN_ENERGY_RECEIVED = 50; - public static final int MACHINE_MAX_ENERGY_RECEIVED = 400; - public static final int MACHINE_MIN_ACTIVATION_ENERGY = 150; public static final int MACHINE_MAX_ENERGY = 5000; public static final int RAINMAKER_RAIN_DURATION_IODINE = 10000; diff --git a/src/main/java/forestry/core/fluids/tanks/StandardTank.java b/src/main/java/forestry/core/fluids/tanks/StandardTank.java index a624ff62a..344c62f56 100644 --- a/src/main/java/forestry/core/fluids/tanks/StandardTank.java +++ b/src/main/java/forestry/core/fluids/tanks/StandardTank.java @@ -131,6 +131,11 @@ public class StandardTank extends FluidTank { return false; } + public boolean canDrain(int amount) { + FluidStack drained = drain(amount, false); + return (drained != null) && (drained.amount == amount); + } + @Override public FluidStack drain(int maxDrain, boolean doDrain) { if (maxDrain <= 0) { diff --git a/src/main/java/forestry/core/gadgets/BlockBase.java b/src/main/java/forestry/core/gadgets/BlockBase.java index 378d5b3ef..8e5c47f6d 100755 --- a/src/main/java/forestry/core/gadgets/BlockBase.java +++ b/src/main/java/forestry/core/gadgets/BlockBase.java @@ -35,10 +35,9 @@ import net.minecraftforge.fluids.IFluidHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import forestry.core.circuits.ISocketable; import forestry.core.fluids.FluidHelper; import forestry.core.interfaces.IAccessHandler; -import forestry.core.interfaces.IRestrictedAccessTile; -import forestry.core.interfaces.ISocketable; import forestry.core.items.ItemNBTTile; import forestry.core.proxy.Proxies; import forestry.core.utils.PlayerUtil; diff --git a/src/main/java/forestry/core/gadgets/BlockStructure.java b/src/main/java/forestry/core/gadgets/BlockStructure.java index a34d0ce9e..a84eb87f6 100755 --- a/src/main/java/forestry/core/gadgets/BlockStructure.java +++ b/src/main/java/forestry/core/gadgets/BlockStructure.java @@ -18,7 +18,7 @@ import net.minecraft.util.ChatComponentText; import net.minecraft.util.StatCollector; import net.minecraft.world.World; -import forestry.core.interfaces.ISocketable; +import forestry.core.circuits.ISocketable; import forestry.core.multiblock.MultiblockControllerBase; import forestry.core.multiblock.MultiblockTileEntityBase; import forestry.core.proxy.Proxies; diff --git a/src/main/java/forestry/core/gadgets/Engine.java b/src/main/java/forestry/core/gadgets/Engine.java index 4c7ceb66e..38994a40a 100755 --- a/src/main/java/forestry/core/gadgets/Engine.java +++ b/src/main/java/forestry/core/gadgets/Engine.java @@ -56,7 +56,7 @@ public abstract class Engine extends TileBase implements IEnergyConnection, IAct protected Engine(int maxHeat, int maxEnergy) { this.maxHeat = maxHeat; - energyManager = new EnergyManager(2000, 100, maxEnergy); + energyManager = new EnergyManager(2000, maxEnergy); // allow engines to chain, but not have energy sucked out of them energyManager.setReceiveOnly(); diff --git a/src/main/java/forestry/core/gadgets/TileAnalyzer.java b/src/main/java/forestry/core/gadgets/TileAnalyzer.java index d9c8cb70f..06062014b 100755 --- a/src/main/java/forestry/core/gadgets/TileAnalyzer.java +++ b/src/main/java/forestry/core/gadgets/TileAnalyzer.java @@ -69,15 +69,15 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui private int analyzeTime; private final FilteredTank resourceTank; - private final TankManager tankManager; - private final IInventory invInput; private final IInventory invOutput; + private ItemStack individualOnDisplayClient; + /* CONSTRUCTOR */ public TileAnalyzer() { - super(800, 40, Defaults.MACHINE_MAX_ENERGY); + super(800, Defaults.MACHINE_MAX_ENERGY, 160); setInternalInventory(new AnalyzerInventoryAdapter(this)); resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, Fluids.HONEY.getFluid()); tankManager = new TankManager(resourceTank); @@ -225,14 +225,17 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui } /* STATE INFORMATION */ - // @Override - @Override - public boolean isWorking() { - return analyzeTime > 0; - } - @Override public boolean hasWork() { + ItemStack stackToAnalyze = getStackInSlot(SLOT_ANALYZE); + if (stackToAnalyze != null) { + return true; + } + + if (getInputSlot() != null) { + return true; + } + Set errors = new HashSet(getErrorLogic().getErrorStates()); errors.remove(EnumErrorCode.NOPOWER); return errors.size() == 0; @@ -242,8 +245,6 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui return (analyzeTime * i) / TIME_TO_ANALYZE; } - private ItemStack individualOnDisplayClient; - public ItemStack getIndividualOnDisplay() { if (worldObj.isRemote) { return individualOnDisplayClient; diff --git a/src/main/java/forestry/core/gadgets/TileForestry.java b/src/main/java/forestry/core/gadgets/TileForestry.java index fa08fa863..2f05658f5 100755 --- a/src/main/java/forestry/core/gadgets/TileForestry.java +++ b/src/main/java/forestry/core/gadgets/TileForestry.java @@ -42,7 +42,6 @@ import forestry.core.inventory.IInventoryAdapter; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.IStreamable; -import forestry.core.network.IStreamableGui; import forestry.core.network.PacketTileStream; import forestry.core.proxy.Proxies; import forestry.core.utils.AdjacentTileCache; @@ -54,7 +53,7 @@ import buildcraft.api.statements.ITriggerInternal; import buildcraft.api.statements.ITriggerProvider; @Optional.Interface(iface = "buildcraft.api.statements.ITriggerProvider", modid = "BuildCraftAPI|statements") -public abstract class TileForestry extends TileEntity implements IStreamable, IErrorLogicSource, ITriggerProvider, ISidedInventory, IFilterSlotDelegate, IRestrictedAccessTile, IStreamableGui, ITitled { +public abstract class TileForestry extends TileEntity implements IStreamable, IErrorLogicSource, ITriggerProvider, ISidedInventory, IFilterSlotDelegate, IRestrictedAccessTile, ITitled { private static final Random rand = new Random(); diff --git a/src/main/java/forestry/core/gadgets/TilePowered.java b/src/main/java/forestry/core/gadgets/TilePowered.java index 9ae0a1d7d..e52af16ca 100644 --- a/src/main/java/forestry/core/gadgets/TilePowered.java +++ b/src/main/java/forestry/core/gadgets/TilePowered.java @@ -20,6 +20,7 @@ import cpw.mods.fml.common.Optional; import forestry.api.core.IErrorLogic; import forestry.core.EnumErrorCode; +import forestry.core.circuits.ISpeedUpgradable; import forestry.core.interfaces.IPowerHandler; import forestry.core.interfaces.IRenderableMachine; import forestry.core.network.DataInputStreamForestry; @@ -30,20 +31,53 @@ import forestry.energy.EnergyManager; import buildcraft.api.tiles.IHasWork; @Optional.Interface(iface = "buildcraft.api.tiles.IHasWork", modid = "BuildCraftAPI|tiles") -public abstract class TilePowered extends TileBase implements IRenderableMachine, IPowerHandler, IHasWork { - - private static final int WORK_CYCLES = 4; +public abstract class TilePowered extends TileBase implements IRenderableMachine, IPowerHandler, IHasWork, ISpeedUpgradable { private final EnergyManager energyManager; - protected TilePowered(int maxTransfer, int energyPerWork, int capacity) { - this.energyManager = new EnergyManager(maxTransfer, energyPerWork, capacity); + private int workCounter; + private int ticksPerWorkCycle; + private int energyPerWorkCycle; + + protected float speedMultiplier = 1.0f; + protected float powerMultiplier = 1.0f; + + // the number of work ticks that this machine has had no power + private int noPowerTime = 0; + + protected TilePowered(int maxTransfer, int capacity, int energyPerWorkCycle) { + this.energyManager = new EnergyManager(maxTransfer, capacity); this.energyManager.setReceiveOnly(); + + setEnergyPerWorkCycle(energyPerWorkCycle); + this.ticksPerWorkCycle = 4; + } + + public int getWorkCounter() { + return workCounter; + } + + public void setTicksPerWorkCycle(int ticksPerWorkCycle) { + this.ticksPerWorkCycle = ticksPerWorkCycle; + this.workCounter = 0; + } + + public int getTicksPerWorkCycle() { + if (worldObj.isRemote) { + return ticksPerWorkCycle; + } + return Math.round(ticksPerWorkCycle / speedMultiplier); + } + + public void setEnergyPerWorkCycle(int energyPerWorkCycle) { + this.energyPerWorkCycle = EnergyManager.scaleForDifficulty(energyPerWorkCycle); + } + + public int getEnergyPerWorkCycle() { + return Math.round(energyPerWorkCycle * powerMultiplier); } /* STATE INFORMATION */ - public abstract boolean isWorking(); - public boolean hasResourcesMin(float percentage) { return false; } @@ -54,12 +88,15 @@ public abstract class TilePowered extends TileBase implements IRenderableMachine public abstract boolean hasWork(); - private int workCounter; - @Override protected void updateServerSide() { super.updateServerSide(); + // one Forestry work tick happens every 5 game ticks + if (!updateOnInterval(5)) { + return; + } + IErrorLogic errorLogic = getErrorLogic(); boolean disabled = isRedstoneActivated(); @@ -68,17 +105,27 @@ public abstract class TilePowered extends TileBase implements IRenderableMachine return; } - if (updateOnInterval(20)) { - boolean hasEnergy = energyManager.hasEnergyToDoWork(); - errorLogic.setCondition(!hasEnergy, EnumErrorCode.NOPOWER); + if (!hasWork()) { + return; } - if (workCounter < WORK_CYCLES) { - if (energyManager.consumeEnergyToDoWork()) { + int ticksPerWorkCycle = getTicksPerWorkCycle(); + + if (workCounter < ticksPerWorkCycle) { + int energyPerWorkCycle = getEnergyPerWorkCycle(); + boolean consumedEnergy = energyManager.consumeEnergyToDoWork(ticksPerWorkCycle, energyPerWorkCycle); + if (consumedEnergy) { + errorLogic.setCondition(false, EnumErrorCode.NOPOWER); workCounter++; + noPowerTime = 0; + } else { + noPowerTime++; + if (noPowerTime > 4) { + errorLogic.setCondition(true, EnumErrorCode.NOPOWER); + } } } else { - if (updateOnInterval(5) && workCycle()) { + if (workCycle()) { workCounter = 0; } } @@ -86,6 +133,15 @@ public abstract class TilePowered extends TileBase implements IRenderableMachine protected abstract boolean workCycle(); + public int getProgressScaled(int i) { + int ticksPerWorkCycle = getTicksPerWorkCycle(); + if (ticksPerWorkCycle == 0) { + return i; + } + + return ((ticksPerWorkCycle - workCounter) * i) / ticksPerWorkCycle; + } + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); @@ -102,12 +158,24 @@ public abstract class TilePowered extends TileBase implements IRenderableMachine public void writeGuiData(DataOutputStreamForestry data) throws IOException { super.writeGuiData(data); energyManager.writeData(data); + data.writeVarInt(workCounter); + data.writeVarInt(getTicksPerWorkCycle()); } @Override public void readGuiData(DataInputStreamForestry data) throws IOException { super.readGuiData(data); energyManager.readData(data); + workCounter = data.readVarInt(); + ticksPerWorkCycle = data.readVarInt(); + } + + /* ISpeedUpgradable */ + @Override + public void applySpeedUpgrade(double speedChange, double powerChange) { + speedMultiplier += speedChange; + powerMultiplier += powerChange; + workCounter = 0; } // / ADDITIONAL LIQUID HANDLING diff --git a/src/main/java/forestry/core/gui/ContainerLiquidTanks.java b/src/main/java/forestry/core/gui/ContainerLiquidTanks.java index 2487d2828..f10da2e64 100755 --- a/src/main/java/forestry/core/gui/ContainerLiquidTanks.java +++ b/src/main/java/forestry/core/gui/ContainerLiquidTanks.java @@ -14,69 +14,29 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidTank; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import forestry.api.core.IToolPipette; import forestry.core.interfaces.ILiquidTankContainer; -import forestry.core.network.IStreamableGui; -import forestry.core.network.PacketId; -import forestry.core.network.PacketSlotClick; -import forestry.core.proxy.Proxies; -public abstract class ContainerLiquidTanks extends ContainerTile { +public abstract class ContainerLiquidTanks extends ContainerTile implements IContainerLiquidTanks { + + private final ContainerLiquidTanksHelper helper; protected ContainerLiquidTanks(T tile, InventoryPlayer playerInventory, int xInv, int yInv) { super(tile, playerInventory, xInv, yInv); + this.helper = new ContainerLiquidTanksHelper(tile); } - @SideOnly(Side.CLIENT) + @Override public void handlePipetteClickClient(int slot, EntityPlayer player) { - ItemStack itemstack = player.inventory.getItemStack(); - if (itemstack == null || !(itemstack.getItem() instanceof IToolPipette)) { - return; - } - - Proxies.net.sendToServer(new PacketSlotClick(PacketId.PIPETTE_CLICK, tile, slot)); + helper.handlePipetteClickClient(slot, player); } + @Override public void handlePipetteClick(int slot, EntityPlayerMP player) { - - ItemStack itemstack = player.inventory.getItemStack(); - if (itemstack == null) { - return; - } - - Item held = itemstack.getItem(); - if (!(held instanceof IToolPipette)) { - return; - } - - IToolPipette pipette = (IToolPipette) held; - IFluidTank tank = tile.getTankManager().getTank(slot); - int liquidAmount = tank.getFluidAmount(); - - if (pipette.canPipette(itemstack) && liquidAmount > 0) { - if (liquidAmount > 0) { - FluidStack fillAmount = tank.drain(1000, false); - int filled = pipette.fill(itemstack, fillAmount, true); - tank.drain(filled, true); - player.updateHeldItem(); - } - } else { - FluidStack potential = pipette.drain(itemstack, pipette.getCapacity(itemstack), false); - if (potential != null) { - pipette.drain(itemstack, tank.fill(potential, true), true); - player.updateHeldItem(); - } - } + helper.handlePipetteClick(slot, player); } @Override diff --git a/src/main/java/forestry/core/gui/ContainerLiquidTanksHelper.java b/src/main/java/forestry/core/gui/ContainerLiquidTanksHelper.java new file mode 100644 index 000000000..3b04eafae --- /dev/null +++ b/src/main/java/forestry/core/gui/ContainerLiquidTanksHelper.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * 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.core.gui; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; + +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidTank; + +import forestry.api.core.IToolPipette; +import forestry.core.interfaces.ILiquidTankContainer; +import forestry.core.network.PacketId; +import forestry.core.network.PacketSlotClick; +import forestry.core.proxy.Proxies; + +public class ContainerLiquidTanksHelper implements IContainerLiquidTanks { + + private final T tile; + + public ContainerLiquidTanksHelper(T tile) { + this.tile = tile; + } + + @Override + public void handlePipetteClickClient(int slot, EntityPlayer player) { + ItemStack itemstack = player.inventory.getItemStack(); + if (itemstack == null || !(itemstack.getItem() instanceof IToolPipette)) { + return; + } + + Proxies.net.sendToServer(new PacketSlotClick(PacketId.PIPETTE_CLICK, tile, slot)); + } + + @Override + public void handlePipetteClick(int slot, EntityPlayerMP player) { + ItemStack itemstack = player.inventory.getItemStack(); + if (itemstack == null) { + return; + } + + Item held = itemstack.getItem(); + if (!(held instanceof IToolPipette)) { + return; + } + + IToolPipette pipette = (IToolPipette) held; + IFluidTank tank = tile.getTankManager().getTank(slot); + int liquidAmount = tank.getFluidAmount(); + + if (pipette.canPipette(itemstack) && liquidAmount > 0) { + if (liquidAmount > 0) { + FluidStack fillAmount = tank.drain(1000, false); + int filled = pipette.fill(itemstack, fillAmount, true); + tank.drain(filled, true); + player.updateHeldItem(); + } + } else { + FluidStack potential = pipette.drain(itemstack, pipette.getCapacity(itemstack), false); + if (potential != null) { + pipette.drain(itemstack, tank.fill(potential, true), true); + player.updateHeldItem(); + } + } + } + + @Override + public IFluidTank getTank(int slot) { + return tile.getTankManager().getTank(slot); + } +} diff --git a/src/main/java/forestry/core/gui/ContainerLiquidTanksSocketed.java b/src/main/java/forestry/core/gui/ContainerLiquidTanksSocketed.java new file mode 100644 index 000000000..aa13df26a --- /dev/null +++ b/src/main/java/forestry/core/gui/ContainerLiquidTanksSocketed.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * 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.core.gui; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ICrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; + +import net.minecraftforge.fluids.IFluidTank; + +import forestry.core.circuits.ISocketable; +import forestry.core.interfaces.ILiquidTankContainer; + +public abstract class ContainerLiquidTanksSocketed extends ContainerTile implements IContainerSocketed, IContainerLiquidTanks { + + private final ContainerSocketedHelper socketedHelper; + private final ContainerLiquidTanksHelper tanksHelper; + + protected ContainerLiquidTanksSocketed(T tile, InventoryPlayer playerInventory, int xInv, int yInv) { + super(tile, playerInventory, xInv, yInv); + this.socketedHelper = new ContainerSocketedHelper(tile); + this.tanksHelper = new ContainerLiquidTanksHelper(tile); + } + + /* IContainerLiquidTanks */ + @Override + public void handlePipetteClickClient(int slot, EntityPlayer player) { + tanksHelper.handlePipetteClickClient(slot, player); + } + + @Override + public void handlePipetteClick(int slot, EntityPlayerMP player) { + tanksHelper.handlePipetteClick(slot, player); + } + + @Override + public void updateProgressBar(int messageId, int data) { + super.updateProgressBar(messageId, data); + + tile.getTankManager().processGuiUpdate(messageId, data); + tile.getGUINetworkData(messageId, data); + } + + @Override + @SuppressWarnings("unchecked") + public void detectAndSendChanges() { + super.detectAndSendChanges(); + tile.getTankManager().updateGuiData(this, crafters); + for (Object crafter : crafters) { + tile.sendGUINetworkData(this, (ICrafting) crafter); + } + } + + @Override + public void addCraftingToCrafters(ICrafting icrafting) { + super.addCraftingToCrafters(icrafting); + tile.getTankManager().initGuiData(this, icrafting); + } + + public IFluidTank getTank(int slot) { + return tile.getTankManager().getTank(slot); + } + + /* IContainerSocketed */ + @Override + public void handleChipsetClick(int slot) { + socketedHelper.handleChipsetClick(slot); + } + + @Override + public void handleChipsetClickServer(int slot, EntityPlayerMP player, ItemStack itemstack) { + socketedHelper.handleChipsetClickServer(slot, player, itemstack); + } + + @Override + public void handleSolderingIronClick(int slot) { + socketedHelper.handleSolderingIronClick(slot); + } + + @Override + public void handleSolderingIronClickServer(int slot, EntityPlayerMP player, ItemStack itemstack) { + socketedHelper.handleSolderingIronClickServer(slot, player, itemstack); + } + +} diff --git a/src/main/java/forestry/core/gui/ContainerSocketed.java b/src/main/java/forestry/core/gui/ContainerSocketed.java index 3bf908ea2..a21db5f0c 100755 --- a/src/main/java/forestry/core/gui/ContainerSocketed.java +++ b/src/main/java/forestry/core/gui/ContainerSocketed.java @@ -15,67 +15,34 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import forestry.core.interfaces.ISocketable; -import forestry.core.network.IStreamableGui; -import forestry.core.network.PacketId; -import forestry.core.network.PacketSlotClick; -import forestry.core.network.PacketSocketUpdate; -import forestry.core.proxy.Proxies; -import forestry.core.utils.StackUtils; +import forestry.core.circuits.ISocketable; -public abstract class ContainerSocketed extends ContainerTile { +public abstract class ContainerSocketed extends ContainerTile implements IContainerSocketed { + + private final ContainerSocketedHelper helper; protected ContainerSocketed(T tile, InventoryPlayer playerInventory, int xInv, int yInv) { super(tile, playerInventory, xInv, yInv); + this.helper = new ContainerSocketedHelper(tile); } + @Override public void handleChipsetClick(int slot) { - PacketSlotClick packet = new PacketSlotClick(PacketId.CHIPSET_CLICK, tile, slot); - Proxies.net.sendToServer(packet); + helper.handleChipsetClick(slot); } + @Override public void handleChipsetClickServer(int slot, EntityPlayerMP player, ItemStack itemstack) { - ItemStack toSocket = itemstack.copy(); - toSocket.stackSize = 1; - tile.setSocket(slot, toSocket); - - ItemStack stack = player.inventory.getItemStack(); - stack.stackSize--; - if (stack.stackSize <= 0) { - player.inventory.setItemStack(null); - } - player.updateHeldItem(); - - PacketSocketUpdate packet = new PacketSocketUpdate(tile); - Proxies.net.sendToPlayer(packet, player); + helper.handleChipsetClickServer(slot, player, itemstack); } + @Override public void handleSolderingIronClick(int slot) { - PacketSlotClick packet = new PacketSlotClick(PacketId.SOLDERING_IRON_CLICK, tile, slot); - Proxies.net.sendToServer(packet); + helper.handleSolderingIronClick(slot); } + @Override public void handleSolderingIronClickServer(int slot, EntityPlayerMP player, ItemStack itemstack) { - ItemStack socket = tile.getSocket(slot); - if (socket == null) { - return; - } - - StackUtils.stowInInventory(socket, player.inventory, true); - // Not sufficient space in player's inventory. failed to stow. - if (socket.stackSize > 0) { - return; - } - - tile.setSocket(slot, null); - itemstack.damageItem(1, player); - if (itemstack.stackSize <= 0) { - player.inventory.setItemStack(null); - } - player.updateHeldItem(); - - - PacketSocketUpdate packet = new PacketSocketUpdate(tile); - Proxies.net.sendToPlayer(packet, player); + helper.handleSolderingIronClickServer(slot, player, itemstack); } } diff --git a/src/main/java/forestry/core/gui/ContainerSocketedHelper.java b/src/main/java/forestry/core/gui/ContainerSocketedHelper.java new file mode 100644 index 000000000..4981211d2 --- /dev/null +++ b/src/main/java/forestry/core/gui/ContainerSocketedHelper.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * 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.core.gui; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; + +import forestry.core.circuits.ISocketable; +import forestry.core.network.PacketId; +import forestry.core.network.PacketSlotClick; +import forestry.core.network.PacketSocketUpdate; +import forestry.core.proxy.Proxies; +import forestry.core.utils.StackUtils; + +public class ContainerSocketedHelper implements IContainerSocketed { + + private final T tile; + + public ContainerSocketedHelper(T tile) { + this.tile = tile; + } + + @Override + public void handleChipsetClick(int slot) { + PacketSlotClick packet = new PacketSlotClick(PacketId.CHIPSET_CLICK, tile, slot); + Proxies.net.sendToServer(packet); + } + + @Override + public void handleChipsetClickServer(int slot, EntityPlayerMP player, ItemStack itemstack) { + if (tile.getSocket(slot) != null) { + return; + } + + ItemStack toSocket = itemstack.copy(); + toSocket.stackSize = 1; + tile.setSocket(slot, toSocket); + + ItemStack stack = player.inventory.getItemStack(); + stack.stackSize--; + if (stack.stackSize <= 0) { + player.inventory.setItemStack(null); + } + player.updateHeldItem(); + + PacketSocketUpdate packet = new PacketSocketUpdate(tile); + Proxies.net.sendToPlayer(packet, player); + } + + @Override + public void handleSolderingIronClick(int slot) { + PacketSlotClick packet = new PacketSlotClick(PacketId.SOLDERING_IRON_CLICK, tile, slot); + Proxies.net.sendToServer(packet); + } + + @Override + public void handleSolderingIronClickServer(int slot, EntityPlayerMP player, ItemStack itemstack) { + ItemStack socket = tile.getSocket(slot); + if (socket == null) { + return; + } + + StackUtils.stowInInventory(socket, player.inventory, true); + // Not sufficient space in player's inventory. failed to stow. + if (socket.stackSize > 0) { + return; + } + + tile.setSocket(slot, null); + itemstack.damageItem(1, player); + if (itemstack.stackSize <= 0) { + player.inventory.setItemStack(null); + } + player.updateHeldItem(); + + + PacketSocketUpdate packet = new PacketSocketUpdate(tile); + Proxies.net.sendToPlayer(packet, player); + } +} diff --git a/src/main/java/forestry/core/gui/ContainerTile.java b/src/main/java/forestry/core/gui/ContainerTile.java index 2f78c1838..a402aa6b5 100644 --- a/src/main/java/forestry/core/gui/ContainerTile.java +++ b/src/main/java/forestry/core/gui/ContainerTile.java @@ -19,10 +19,10 @@ import net.minecraft.tileentity.TileEntity; import forestry.api.core.IErrorLogicSource; import forestry.api.core.IErrorState; import forestry.core.delegates.FakeAccessHandler; +import forestry.core.gadgets.TilePowered; import forestry.core.interfaces.IAccessHandler; import forestry.core.interfaces.IPowerHandler; import forestry.core.interfaces.IRestrictedAccessTile; -import forestry.core.network.IStreamableGui; import forestry.core.network.PacketErrorUpdate; import forestry.core.network.PacketGuiEnergy; import forestry.core.network.PacketGuiUpdate; @@ -30,7 +30,7 @@ import forestry.core.utils.EnumAccess; import forestry.core.utils.Utils; import forestry.energy.EnergyManager; -public abstract class ContainerTile extends ContainerForestry { +public abstract class ContainerTile extends ContainerForestry { protected final T tile; private final IAccessHandler accessHandler; @@ -64,6 +64,8 @@ public abstract class ContainerTile exten private ImmutableSet previousErrorStates; private int previousEnergyManagerData = 0; private EnumAccess previousAccess; + private int previousWorkCounter = 0; + private int previousTicksPerWorkCycle = 0; @Override public void detectAndSendChanges() { @@ -92,15 +94,42 @@ public abstract class ContainerTile exten } } - if (tile instanceof IRestrictedAccessTile) { + boolean guiUpdated = false; + + if (!guiUpdated && tile instanceof IRestrictedAccessTile) { IRestrictedAccessTile restrictedAccessTile = (IRestrictedAccessTile) tile; IAccessHandler accessHandler = restrictedAccessTile.getAccessHandler(); EnumAccess access = accessHandler.getAccessType(); if (access != previousAccess) { - PacketGuiUpdate packet = new PacketGuiUpdate(tile); + PacketGuiUpdate packet = new PacketGuiUpdate(restrictedAccessTile); sendPacketToCrafters(packet); previousAccess = access; + guiUpdated = true; + } + } + + if (!guiUpdated && tile instanceof TilePowered) { + TilePowered tilePowered = (TilePowered) tile; + + boolean changed = false; + + int workCounter = tilePowered.getWorkCounter(); + if (workCounter != previousWorkCounter) { + changed = true; + previousWorkCounter = workCounter; + } + + int ticksPerWorkCycle = tilePowered.getTicksPerWorkCycle(); + if (ticksPerWorkCycle != previousTicksPerWorkCycle) { + changed = true; + previousTicksPerWorkCycle = ticksPerWorkCycle; + } + + if (changed) { + PacketGuiUpdate packet = new PacketGuiUpdate(tilePowered); + sendPacketToCrafters(packet); + guiUpdated = true; } } } diff --git a/src/main/java/forestry/core/gui/GuiEscritoire.java b/src/main/java/forestry/core/gui/GuiEscritoire.java index c20dc432f..b417ab6c1 100755 --- a/src/main/java/forestry/core/gui/GuiEscritoire.java +++ b/src/main/java/forestry/core/gui/GuiEscritoire.java @@ -28,6 +28,7 @@ import forestry.core.gadgets.NaturalistGame; import forestry.core.gadgets.NaturalistGame.GameToken; import forestry.core.gadgets.TileEscritoire; import forestry.core.gui.widgets.Widget; +import forestry.core.gui.widgets.WidgetManager; import forestry.core.network.PacketGuiSelect; import forestry.core.network.PacketId; import forestry.core.proxy.Proxies; diff --git a/src/main/java/forestry/core/gui/GuiForestry.java b/src/main/java/forestry/core/gui/GuiForestry.java index 57f901a6a..140054e7c 100755 --- a/src/main/java/forestry/core/gui/GuiForestry.java +++ b/src/main/java/forestry/core/gui/GuiForestry.java @@ -38,10 +38,16 @@ import forestry.api.core.IErrorLogicSource; import forestry.api.core.IErrorSource; import forestry.core.config.Config; import forestry.core.gadgets.TileForestry; +import forestry.core.gui.ledgers.ClimateLedger; +import forestry.core.gui.ledgers.HintLedger; +import forestry.core.gui.ledgers.LedgerManager; +import forestry.core.gui.ledgers.OwnerLedger; +import forestry.core.gui.ledgers.PowerLedger; import forestry.core.gui.tooltips.IToolTipProvider; import forestry.core.gui.tooltips.ToolTip; import forestry.core.gui.tooltips.ToolTipLine; import forestry.core.gui.widgets.Widget; +import forestry.core.gui.widgets.WidgetManager; import forestry.core.interfaces.IClimatised; import forestry.core.interfaces.IHintSource; import forestry.core.interfaces.IPowerHandler; @@ -313,7 +319,7 @@ public abstract class GuiForestry ext InventoryPlayer playerInv = mc.thePlayer.inventory; if (playerInv.getItemStack() == null) { - drawToolTips(widgetManager.widgets, mouseX, mouseY); + drawToolTips(widgetManager.getWidgets(), mouseX, mouseY); drawToolTips(buttonList, mouseX, mouseY); drawToolTips(inventorySlots.inventorySlots, mouseX, mouseY); } @@ -409,6 +415,10 @@ public abstract class GuiForestry ext return guiTop; } + public FontColour getFontColor() { + return fontColor; + } + @Override public void drawGradientRect(int par1, int par2, int par3, int par4, int par5, int par6) { super.drawGradientRect(par1, par2, par3, par4, par5, par6); diff --git a/src/main/java/forestry/core/gui/IContainerLiquidTanks.java b/src/main/java/forestry/core/gui/IContainerLiquidTanks.java new file mode 100644 index 000000000..87e6749cc --- /dev/null +++ b/src/main/java/forestry/core/gui/IContainerLiquidTanks.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * 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.core.gui; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; + +import net.minecraftforge.fluids.IFluidTank; + +public interface IContainerLiquidTanks { + void handlePipetteClickClient(int slot, EntityPlayer player); + + void handlePipetteClick(int slot, EntityPlayerMP player); + + IFluidTank getTank(int slot); +} diff --git a/src/main/java/forestry/core/gui/IContainerSocketed.java b/src/main/java/forestry/core/gui/IContainerSocketed.java new file mode 100644 index 000000000..46cb6ae5b --- /dev/null +++ b/src/main/java/forestry/core/gui/IContainerSocketed.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * 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.core.gui; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; + +public interface IContainerSocketed { + void handleChipsetClick(int slot); + + void handleChipsetClickServer(int slot, EntityPlayerMP player, ItemStack itemstack); + + void handleSolderingIronClick(int slot); + + void handleSolderingIronClickServer(int slot, EntityPlayerMP player, ItemStack itemstack); +} diff --git a/src/main/java/forestry/core/gui/ClimateLedger.java b/src/main/java/forestry/core/gui/ledgers/ClimateLedger.java old mode 100755 new mode 100644 similarity index 98% rename from src/main/java/forestry/core/gui/ClimateLedger.java rename to src/main/java/forestry/core/gui/ledgers/ClimateLedger.java index b52e0b29b..61ca00082 --- a/src/main/java/forestry/core/gui/ClimateLedger.java +++ b/src/main/java/forestry/core/gui/ledgers/ClimateLedger.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.gui; +package forestry.core.gui.ledgers; import forestry.api.core.EnumTemperature; import forestry.api.genetics.AlleleManager; diff --git a/src/main/java/forestry/core/gui/ErrorLedger.java b/src/main/java/forestry/core/gui/ledgers/ErrorLedger.java old mode 100755 new mode 100644 similarity index 98% rename from src/main/java/forestry/core/gui/ErrorLedger.java rename to src/main/java/forestry/core/gui/ledgers/ErrorLedger.java index 7fe92a5d4..a8e579ddc --- a/src/main/java/forestry/core/gui/ErrorLedger.java +++ b/src/main/java/forestry/core/gui/ledgers/ErrorLedger.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.gui; +package forestry.core.gui.ledgers; import javax.annotation.Nullable; diff --git a/src/main/java/forestry/core/gui/HintLedger.java b/src/main/java/forestry/core/gui/ledgers/HintLedger.java old mode 100755 new mode 100644 similarity index 98% rename from src/main/java/forestry/core/gui/HintLedger.java rename to src/main/java/forestry/core/gui/ledgers/HintLedger.java index 8960ce64d..04d59d7dc --- a/src/main/java/forestry/core/gui/HintLedger.java +++ b/src/main/java/forestry/core/gui/ledgers/HintLedger.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.gui; +package forestry.core.gui.ledgers; import java.util.Random; diff --git a/src/main/java/forestry/core/gui/Ledger.java b/src/main/java/forestry/core/gui/ledgers/Ledger.java old mode 100755 new mode 100644 similarity index 94% rename from src/main/java/forestry/core/gui/Ledger.java rename to src/main/java/forestry/core/gui/ledgers/Ledger.java index 75c08709d..1e20ec533 --- a/src/main/java/forestry/core/gui/Ledger.java +++ b/src/main/java/forestry/core/gui/ledgers/Ledger.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.gui; +package forestry.core.gui.ledgers; import net.minecraft.client.Minecraft; import net.minecraft.util.IIcon; @@ -65,10 +65,10 @@ public abstract class Ledger { texture = ledgerTextureLeft; } - fontColorHeader = manager.gui.fontColor.get("ledger." + name + ".header"); - fontColorSubheader = manager.gui.fontColor.get("ledger." + name + ".subheader"); - fontColorText = manager.gui.fontColor.get("ledger." + name + ".text"); - overlayColor = manager.gui.fontColor.get("ledger." + name + ".background"); + fontColorHeader = manager.gui.getFontColor().get("ledger." + name + ".header"); + fontColorSubheader = manager.gui.getFontColor().get("ledger." + name + ".subheader"); + fontColorText = manager.gui.getFontColor().get("ledger." + name + ".text"); + overlayColor = manager.gui.getFontColor().get("ledger." + name + ".background"); } // adjust the update's move amount to match the look of 60 fps (16.67 ms per update) diff --git a/src/main/java/forestry/core/gui/LedgerManager.java b/src/main/java/forestry/core/gui/ledgers/LedgerManager.java old mode 100755 new mode 100644 similarity index 97% rename from src/main/java/forestry/core/gui/LedgerManager.java rename to src/main/java/forestry/core/gui/ledgers/LedgerManager.java index a4d4fd766..0184f3bc5 --- a/src/main/java/forestry/core/gui/LedgerManager.java +++ b/src/main/java/forestry/core/gui/ledgers/LedgerManager.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.gui; +package forestry.core.gui.ledgers; import com.google.common.collect.ImmutableSet; @@ -23,6 +23,7 @@ import forestry.api.core.IErrorSource; import forestry.api.core.IErrorState; import forestry.core.config.SessionVars; import forestry.core.delegates.FakeErrorSource; +import forestry.core.gui.GuiForestry; import forestry.core.proxy.Proxies; public class LedgerManager { @@ -106,7 +107,7 @@ public class LedgerManager { return null; } - protected void drawLedgers() { + public void drawLedgers() { int yPos = 8; for (Ledger ledger : ledgers) { @@ -143,7 +144,7 @@ public class LedgerManager { } } - protected void drawTooltips(int mouseX, int mouseY) { + public void drawTooltips(int mouseX, int mouseY) { Ledger ledger = getAtPosition(mouseX, mouseY); if (ledger != null) { diff --git a/src/main/java/forestry/core/gui/OwnerLedger.java b/src/main/java/forestry/core/gui/ledgers/OwnerLedger.java old mode 100755 new mode 100644 similarity index 98% rename from src/main/java/forestry/core/gui/OwnerLedger.java rename to src/main/java/forestry/core/gui/ledgers/OwnerLedger.java index 52b4343f7..06651a405 --- a/src/main/java/forestry/core/gui/OwnerLedger.java +++ b/src/main/java/forestry/core/gui/ledgers/OwnerLedger.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.gui; +package forestry.core.gui.ledgers; import java.util.Locale; diff --git a/src/main/java/forestry/core/gui/PowerLedger.java b/src/main/java/forestry/core/gui/ledgers/PowerLedger.java old mode 100755 new mode 100644 similarity index 98% rename from src/main/java/forestry/core/gui/PowerLedger.java rename to src/main/java/forestry/core/gui/ledgers/PowerLedger.java index c0c9ec575..055a02a18 --- a/src/main/java/forestry/core/gui/PowerLedger.java +++ b/src/main/java/forestry/core/gui/ledgers/PowerLedger.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.gui; +package forestry.core.gui.ledgers; import forestry.core.interfaces.IPowerHandler; import forestry.core.render.TextureManager; diff --git a/src/main/java/forestry/core/gui/widgets/ReservoirWidget.java b/src/main/java/forestry/core/gui/widgets/ReservoirWidget.java index cbee04828..a179f114a 100755 --- a/src/main/java/forestry/core/gui/widgets/ReservoirWidget.java +++ b/src/main/java/forestry/core/gui/widgets/ReservoirWidget.java @@ -16,7 +16,6 @@ import net.minecraftforge.fluids.FluidStack; import org.lwjgl.opengl.GL11; -import forestry.core.gui.WidgetManager; import forestry.core.proxy.Proxies; import forestry.core.render.SpriteSheet; diff --git a/src/main/java/forestry/core/gui/widgets/SocketWidget.java b/src/main/java/forestry/core/gui/widgets/SocketWidget.java index 28319cc18..a698df983 100755 --- a/src/main/java/forestry/core/gui/widgets/SocketWidget.java +++ b/src/main/java/forestry/core/gui/widgets/SocketWidget.java @@ -17,13 +17,12 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; +import forestry.core.circuits.ISocketable; import forestry.core.circuits.ISolderingIron; import forestry.core.circuits.ItemCircuitBoard; -import forestry.core.gui.ContainerSocketed; import forestry.core.gui.GuiForestry; -import forestry.core.gui.WidgetManager; +import forestry.core.gui.IContainerSocketed; import forestry.core.gui.tooltips.ToolTip; -import forestry.core.interfaces.ISocketable; import forestry.core.proxy.Proxies; import forestry.core.utils.StringUtil; @@ -79,11 +78,11 @@ public class SocketWidget extends Widget { Item held = itemstack.getItem(); Container container = manager.gui.inventorySlots; - if (!(container instanceof ContainerSocketed)) { + if (!(container instanceof IContainerSocketed)) { return; } - ContainerSocketed containerSocketed = (ContainerSocketed) container; + IContainerSocketed containerSocketed = (IContainerSocketed) container; // Insert chipsets if (held instanceof ItemCircuitBoard) { diff --git a/src/main/java/forestry/core/gui/widgets/TankWidget.java b/src/main/java/forestry/core/gui/widgets/TankWidget.java index c7d2c8547..2a78dc0f5 100755 --- a/src/main/java/forestry/core/gui/widgets/TankWidget.java +++ b/src/main/java/forestry/core/gui/widgets/TankWidget.java @@ -22,8 +22,7 @@ import org.lwjgl.opengl.GL11; import forestry.api.core.IToolPipette; import forestry.core.fluids.tanks.StandardTank; -import forestry.core.gui.ContainerLiquidTanks; -import forestry.core.gui.WidgetManager; +import forestry.core.gui.IContainerLiquidTanks; import forestry.core.gui.tooltips.ToolTip; import forestry.core.proxy.Proxies; import forestry.core.render.SpriteSheet; @@ -52,8 +51,8 @@ public class TankWidget extends Widget { public IFluidTank getTank() { Container container = manager.gui.inventorySlots; - if (container instanceof ContainerLiquidTanks) { - return ((ContainerLiquidTanks) container).getTank(slot); + if (container instanceof IContainerLiquidTanks) { + return ((IContainerLiquidTanks) container).getTank(slot); } else if (container instanceof ContainerFarm) { return ((ContainerFarm) container).getTank(slot); } @@ -124,9 +123,8 @@ public class TankWidget extends Widget { } Item held = itemstack.getItem(); - if (held instanceof IToolPipette && manager.gui.inventorySlots instanceof ContainerLiquidTanks) { - ((ContainerLiquidTanks) manager.gui.inventorySlots).handlePipetteClickClient(slot, manager.minecraft.thePlayer); + if (held instanceof IToolPipette && manager.gui.inventorySlots instanceof IContainerLiquidTanks) { + ((IContainerLiquidTanks) manager.gui.inventorySlots).handlePipetteClickClient(slot, manager.minecraft.thePlayer); } - } } diff --git a/src/main/java/forestry/core/gui/widgets/Widget.java b/src/main/java/forestry/core/gui/widgets/Widget.java index 1e4bbabdc..909c82283 100755 --- a/src/main/java/forestry/core/gui/widgets/Widget.java +++ b/src/main/java/forestry/core/gui/widgets/Widget.java @@ -12,7 +12,6 @@ package forestry.core.gui.widgets; import net.minecraft.entity.player.EntityPlayer; -import forestry.core.gui.WidgetManager; import forestry.core.gui.tooltips.IToolTipProvider; import forestry.core.gui.tooltips.ToolTip; import forestry.core.proxy.Proxies; diff --git a/src/main/java/forestry/core/gui/WidgetManager.java b/src/main/java/forestry/core/gui/widgets/WidgetManager.java old mode 100755 new mode 100644 similarity index 88% rename from src/main/java/forestry/core/gui/WidgetManager.java rename to src/main/java/forestry/core/gui/widgets/WidgetManager.java index 2fe6c06db..ff52cc894 --- a/src/main/java/forestry/core/gui/WidgetManager.java +++ b/src/main/java/forestry/core/gui/widgets/WidgetManager.java @@ -8,22 +8,23 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.gui; +package forestry.core.gui.widgets; import java.util.ArrayList; +import java.util.List; import net.minecraft.client.Minecraft; import org.lwjgl.opengl.GL11; -import forestry.core.gui.widgets.Widget; +import forestry.core.gui.GuiForestry; import forestry.core.proxy.Proxies; public class WidgetManager { public final GuiForestry gui; public final Minecraft minecraft; - protected final ArrayList widgets = new ArrayList(); + protected final List widgets = new ArrayList(); public WidgetManager(GuiForestry gui) { this.gui = gui; @@ -42,7 +43,11 @@ public class WidgetManager { this.widgets.clear(); } - protected Widget getAtPosition(int mX, int mY) { + public List getWidgets() { + return widgets; + } + + public Widget getAtPosition(int mX, int mY) { for (Widget slot : widgets) { if (slot.isMouseOver(mX, mY)) { return slot; diff --git a/src/main/java/forestry/core/interfaces/IRestrictedAccessTile.java b/src/main/java/forestry/core/interfaces/IRestrictedAccessTile.java index ef0678342..6395cfb61 100644 --- a/src/main/java/forestry/core/interfaces/IRestrictedAccessTile.java +++ b/src/main/java/forestry/core/interfaces/IRestrictedAccessTile.java @@ -12,9 +12,10 @@ package forestry.core.interfaces; import net.minecraft.util.ChunkCoordinates; +import forestry.core.network.IStreamableGui; import forestry.core.utils.EnumAccess; -public interface IRestrictedAccessTile { +public interface IRestrictedAccessTile extends IStreamableGui { IAccessHandler getAccessHandler(); ChunkCoordinates getCoordinates(); diff --git a/src/main/java/forestry/core/inventory/InvTools.java b/src/main/java/forestry/core/inventory/InvTools.java index 3150f00ce..da2d450ab 100755 --- a/src/main/java/forestry/core/inventory/InvTools.java +++ b/src/main/java/forestry/core/inventory/InvTools.java @@ -413,6 +413,15 @@ public abstract class InvTools { return ((float) amount / (float) stackMax) >= percent; } + public static boolean isEmpty(IInventory inventory, int slotStart, int slotCount) { + for (int i = slotStart; i < slotStart + slotCount; i++) { + if (inventory.getStackInSlot(i) != null) { + return false; + } + } + return true; + } + public static ItemStack[] getStacks(IInventory inventory) { ItemStack[] stacks = new ItemStack[inventory.getSizeInventory()]; for (int i = 0; i < inventory.getSizeInventory(); i++) { diff --git a/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java b/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java index e4a0495ea..4d732e4f5 100644 --- a/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java +++ b/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java @@ -32,7 +32,6 @@ import forestry.core.inventory.FakeInventoryAdapter; import forestry.core.inventory.IInventoryAdapter; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; -import forestry.core.network.IStreamableGui; import forestry.core.proxy.Proxies; import forestry.core.utils.StringUtil; @@ -42,7 +41,7 @@ import forestry.core.utils.StringUtil; * * Subordinate TileEntities implement the IMultiblockPart class and, generally, should not have an update() loop. */ -public abstract class MultiblockControllerBase implements ISidedInventory, IRestrictedAccessTile, IStreamableGui, IErrorLogicSource { +public abstract class MultiblockControllerBase implements ISidedInventory, IRestrictedAccessTile, IErrorLogicSource { public static final short DIMENSION_UNBOUNDED = -1; // Multiblock stuff - do not mess with diff --git a/src/main/java/forestry/core/network/PacketHandler.java b/src/main/java/forestry/core/network/PacketHandler.java index 57b9bd660..8c4b821bd 100644 --- a/src/main/java/forestry/core/network/PacketHandler.java +++ b/src/main/java/forestry/core/network/PacketHandler.java @@ -37,13 +37,13 @@ import forestry.apiculture.multiblock.IAlvearyController; import forestry.apiculture.multiblock.TileAlveary; import forestry.apiculture.network.PacketActiveUpdate; import forestry.core.circuits.ContainerSolderingIron; +import forestry.core.circuits.ISocketable; import forestry.core.circuits.ItemCircuitBoard; import forestry.core.genetics.BreedingTracker; -import forestry.core.gui.ContainerLiquidTanks; -import forestry.core.gui.ContainerSocketed; +import forestry.core.gui.IContainerLiquidTanks; +import forestry.core.gui.IContainerSocketed; import forestry.core.gui.IGuiSelectable; import forestry.core.interfaces.IRestrictedAccessTile; -import forestry.core.interfaces.ISocketable; import forestry.core.proxy.Proxies; import forestry.farming.multiblock.IFarmController; import forestry.farming.multiblock.TileFarm; @@ -251,7 +251,7 @@ public class PacketHandler { private static void onChipsetClick(PacketSlotClick packet, EntityPlayerMP player) { assert FMLCommonHandler.instance().getEffectiveSide().isServer(); - if (!(player.openContainer instanceof ContainerSocketed)) { + if (!(player.openContainer instanceof IContainerSocketed)) { return; } ItemStack itemstack = player.inventory.getItemStack(); @@ -259,18 +259,18 @@ public class PacketHandler { return; } - ((ContainerSocketed) player.openContainer).handleChipsetClickServer(packet.getSlot(), player, itemstack); + ((IContainerSocketed) player.openContainer).handleChipsetClickServer(packet.getSlot(), player, itemstack); } private static void onSolderingIronClick(PacketSlotClick packet, EntityPlayerMP player) { assert FMLCommonHandler.instance().getEffectiveSide().isServer(); - if (!(player.openContainer instanceof ContainerSocketed)) { + if (!(player.openContainer instanceof IContainerSocketed)) { return; } ItemStack itemstack = player.inventory.getItemStack(); - ((ContainerSocketed) player.openContainer).handleSolderingIronClickServer(packet.getSlot(), player, itemstack); + ((IContainerSocketed) player.openContainer).handleSolderingIronClickServer(packet.getSlot(), player, itemstack); } private static void onAccessSwitch(PacketCoordinates packet, EntityPlayer playerEntity) { @@ -296,10 +296,8 @@ public class PacketHandler { private static void onPipetteClick(PacketSlotClick packet, EntityPlayerMP player) { assert FMLCommonHandler.instance().getEffectiveSide().isServer(); - if (!(player.openContainer instanceof ContainerLiquidTanks)) { - return; + if ((player.openContainer instanceof IContainerLiquidTanks)) { + ((IContainerLiquidTanks) player.openContainer).handlePipetteClick(packet.getSlot(), player); } - - ((ContainerLiquidTanks) player.openContainer).handlePipetteClick(packet.getSlot(), player); } } diff --git a/src/main/java/forestry/core/network/PacketSocketUpdate.java b/src/main/java/forestry/core/network/PacketSocketUpdate.java index 12287b347..183c73475 100755 --- a/src/main/java/forestry/core/network/PacketSocketUpdate.java +++ b/src/main/java/forestry/core/network/PacketSocketUpdate.java @@ -15,7 +15,7 @@ import java.io.IOException; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import forestry.core.interfaces.ISocketable; +import forestry.core.circuits.ISocketable; public class PacketSocketUpdate extends PacketCoordinates { diff --git a/src/main/java/forestry/core/utils/Utils.java b/src/main/java/forestry/core/utils/Utils.java index bda1a526f..b4756bb23 100755 --- a/src/main/java/forestry/core/utils/Utils.java +++ b/src/main/java/forestry/core/utils/Utils.java @@ -31,7 +31,7 @@ import net.minecraftforge.oredict.OreDictionary; import cpw.mods.fml.common.registry.EntityRegistry; import forestry.api.core.ForestryAPI; -import forestry.core.interfaces.ISocketable; +import forestry.core.circuits.ISocketable; import forestry.core.proxy.Proxies; import buildcraft.api.tools.IToolWrench; diff --git a/src/main/java/forestry/energy/EnergyManager.java b/src/main/java/forestry/energy/EnergyManager.java index 80f955cd6..01ce948d6 100644 --- a/src/main/java/forestry/energy/EnergyManager.java +++ b/src/main/java/forestry/energy/EnergyManager.java @@ -23,16 +23,14 @@ public class EnergyManager implements IEnergyHandler, IStreamable { EXTRACT, RECEIVE, BOTH } - private final int energyPerWork; private final EnergyStorage energyStorage; private EnergyTransferMode mode = EnergyTransferMode.BOTH; - public EnergyManager(int maxTransfer, int energyPerWork, int capacity) { - this.energyPerWork = scaleForDifficulty(energyPerWork); + public EnergyManager(int maxTransfer, int capacity) { this.energyStorage = new EnergyStorage(scaleForDifficulty(capacity), scaleForDifficulty(maxTransfer), scaleForDifficulty(maxTransfer)); } - private static int scaleForDifficulty(int energyPerUse) { + public static int scaleForDifficulty(int energyPerUse) { return Math.round(energyPerUse * GameMode.getGameMode().getFloatSetting("energy.demand.modifier")); } @@ -149,25 +147,19 @@ public class EnergyManager implements IEnergyHandler, IStreamable { return true; } - public int getEnergyPerWork() { - return energyPerWork; - } - /** * Consumes one work cycle's worth of energy. * * @return true if the energy to do work was consumed */ - public boolean consumeEnergyToDoWork() { - if (!hasEnergyToDoWork()) { + public boolean consumeEnergyToDoWork(int ticksPerWorkCycle, int energyPerWorkCycle) { + int energyPerCycle = (int) Math.ceil(energyPerWorkCycle / (float) ticksPerWorkCycle); + if (energyStorage.getEnergyStored() < energyPerCycle) { return false; } - energyStorage.modifyEnergyStored(-energyPerWork); - return true; - } - public boolean hasEnergyToDoWork() { - return energyStorage.getEnergyStored() >= energyPerWork; + energyStorage.modifyEnergyStored(-energyPerCycle); + return true; } /** diff --git a/src/main/java/forestry/energy/gadgets/EngineTin.java b/src/main/java/forestry/energy/gadgets/EngineTin.java index 0bacae972..a4421a7e1 100755 --- a/src/main/java/forestry/energy/gadgets/EngineTin.java +++ b/src/main/java/forestry/energy/gadgets/EngineTin.java @@ -23,10 +23,10 @@ import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorLogic; import forestry.core.EnumErrorCode; import forestry.core.TemperatureState; +import forestry.core.circuits.ISocketable; import forestry.core.config.Config; import forestry.core.config.Defaults; import forestry.core.gadgets.Engine; -import forestry.core.interfaces.ISocketable; import forestry.core.inventory.InventoryAdapter; import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.GuiId; diff --git a/src/main/java/forestry/energy/gui/GuiEngine.java b/src/main/java/forestry/energy/gui/GuiEngine.java index 3372a9b0f..c07b6356a 100755 --- a/src/main/java/forestry/energy/gui/GuiEngine.java +++ b/src/main/java/forestry/energy/gui/GuiEngine.java @@ -14,7 +14,7 @@ import net.minecraft.inventory.Container; import forestry.core.gadgets.Engine; import forestry.core.gui.GuiForestryTitled; -import forestry.core.gui.Ledger; +import forestry.core.gui.ledgers.Ledger; import forestry.core.render.TextureManager; import forestry.core.utils.StringUtil; diff --git a/src/main/java/forestry/energy/gui/GuiEngineBronze.java b/src/main/java/forestry/energy/gui/GuiEngineBronze.java index aa512aca1..0a7da89a8 100755 --- a/src/main/java/forestry/energy/gui/GuiEngineBronze.java +++ b/src/main/java/forestry/energy/gui/GuiEngineBronze.java @@ -21,9 +21,9 @@ import net.minecraftforge.fluids.FluidStack; import org.lwjgl.opengl.GL11; import forestry.core.config.Defaults; -import forestry.core.gui.WidgetManager; import forestry.core.gui.widgets.TankWidget; import forestry.core.gui.widgets.Widget; +import forestry.core.gui.widgets.WidgetManager; import forestry.core.proxy.Proxies; import forestry.core.render.SpriteSheet; import forestry.core.utils.StringUtil; diff --git a/src/main/java/forestry/factory/GuiHandlerFactory.java b/src/main/java/forestry/factory/GuiHandlerFactory.java index a3b74cca2..932da645d 100755 --- a/src/main/java/forestry/factory/GuiHandlerFactory.java +++ b/src/main/java/forestry/factory/GuiHandlerFactory.java @@ -15,6 +15,8 @@ import net.minecraft.world.World; import forestry.core.GuiHandlerBase; import forestry.core.network.GuiId; +import forestry.core.network.PacketSocketUpdate; +import forestry.core.proxy.Proxies; import forestry.factory.gadgets.MachineBottler; import forestry.factory.gadgets.MachineCarpenter; import forestry.factory.gadgets.MachineCentrifuge; diff --git a/src/main/java/forestry/factory/circuits/CircuitSpeedUpgrade.java b/src/main/java/forestry/factory/circuits/CircuitSpeedUpgrade.java new file mode 100644 index 000000000..f142632f4 --- /dev/null +++ b/src/main/java/forestry/factory/circuits/CircuitSpeedUpgrade.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.factory.circuits; + +import forestry.core.circuits.Circuit; +import forestry.core.circuits.ISpeedUpgradable; + +public class CircuitSpeedUpgrade extends Circuit { + + private final double speedBoost; + private final float powerDraw; + + public CircuitSpeedUpgrade(String uid, double speedBoost, float powerDraw, int limit) { + super(uid, false); + this.setLimit(limit); + this.speedBoost = speedBoost; + this.powerDraw = powerDraw; + } + + @Override + public boolean isCircuitable(Object tile) { + return tile instanceof ISpeedUpgradable; + } + + @Override + public void onInsertion(int slot, Object tile) { + if (!isCircuitable(tile)) { + return; + } + if (tile instanceof ISpeedUpgradable) { + ISpeedUpgradable machine = (ISpeedUpgradable) tile; + machine.applySpeedUpgrade(speedBoost, powerDraw); + } + } + + @Override + public void onLoad(int slot, Object tile) { + onInsertion(slot, tile); + } + + @Override + public void onRemoval(int slot, Object tile) { + if (!isCircuitable(tile)) { + return; + } + if (tile instanceof ISpeedUpgradable) { + ISpeedUpgradable machine = (ISpeedUpgradable) tile; + machine.applySpeedUpgrade(-speedBoost, -powerDraw); + } + } + + @Override + public void onTick(int slot, Object tile) { + } +} diff --git a/src/main/java/forestry/factory/gadgets/MachineBottler.java b/src/main/java/forestry/factory/gadgets/MachineBottler.java index 89b7525f2..a05379a10 100755 --- a/src/main/java/forestry/factory/gadgets/MachineBottler.java +++ b/src/main/java/forestry/factory/gadgets/MachineBottler.java @@ -145,7 +145,7 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq private int fillingTotalTime; public MachineBottler() { - super(1100, 50, 4000); + super(1100, 4000, 200); setInternalInventory(new BottlerInventoryAdapter(this)); @@ -265,10 +265,6 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq } // / STATE INFORMATION - @Override - public boolean isWorking() { - return fillingTime > 0; - } @Override public boolean hasResourcesMin(float percentage) { @@ -290,7 +286,7 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq return 0; } - return (fillingTime * i) / fillingTotalTime; + return ((fillingTotalTime - fillingTime) * i) / fillingTotalTime; } diff --git a/src/main/java/forestry/factory/gadgets/MachineCarpenter.java b/src/main/java/forestry/factory/gadgets/MachineCarpenter.java index 1478bb0d1..e340da613 100755 --- a/src/main/java/forestry/factory/gadgets/MachineCarpenter.java +++ b/src/main/java/forestry/factory/gadgets/MachineCarpenter.java @@ -91,7 +91,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL } public MachineCarpenter() { - super(1100, 50, 4000); + super(1100, 4000, 200); setHints(Config.hints.get("carpenter")); resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluids); @@ -327,22 +327,15 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL } /* STATE INFORMATION */ - @Override - public boolean isWorking() { - return packageTime > 0 || pendingProduct != null || currentRecipe != null && validateResources(); - } - @Override public boolean hasWork() { if (currentRecipe == null) { return false; } - IInventoryAdapter accessibleInventory = getInternalInventory(); // Stop working if the output slot cannot take more - if (accessibleInventory.getStackInSlot(SLOT_PRODUCT) != null - && accessibleInventory.getStackInSlot(SLOT_PRODUCT).getMaxStackSize() - accessibleInventory.getStackInSlot(SLOT_PRODUCT).stackSize < currentRecipe - .getCraftingResult().stackSize) { + ItemStack product = getStackInSlot(SLOT_PRODUCT); + if (product != null && product.getMaxStackSize() - product.stackSize < currentRecipe.getCraftingResult().stackSize) { return false; } @@ -499,10 +492,6 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL return internal.matches(inventorycrafting, world); } - public boolean isIngredient(ItemStack resource) { - return internal.isIngredient(resource); - } - public ItemStack getBox() { return box; } diff --git a/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java b/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java index 4941c1492..806e9c992 100755 --- a/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java +++ b/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java @@ -12,6 +12,7 @@ package forestry.factory.gadgets; import com.google.common.collect.ImmutableMap; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -23,8 +24,6 @@ import java.util.Set; import java.util.Stack; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -35,16 +34,23 @@ import net.minecraftforge.common.util.ForgeDirection; import cpw.mods.fml.common.Optional; +import forestry.api.circuits.ChipsetManager; +import forestry.api.circuits.ICircuitBoard; import forestry.api.core.ForestryAPI; +import forestry.api.core.IErrorLogic; import forestry.api.recipes.ICentrifugeManager; import forestry.api.recipes.ICentrifugeRecipe; import forestry.core.EnumErrorCode; +import forestry.core.circuits.ISocketable; import forestry.core.config.Config; import forestry.core.config.Defaults; import forestry.core.gadgets.TilePowered; import forestry.core.inventory.IInventoryAdapter; import forestry.core.inventory.InvTools; +import forestry.core.inventory.InventoryAdapter; import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.network.DataInputStreamForestry; +import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.GuiId; import forestry.core.utils.StackUtils; import forestry.core.utils.Utils; @@ -52,7 +58,12 @@ import forestry.factory.triggers.FactoryTriggers; import buildcraft.api.statements.ITriggerExternal; -public class MachineCentrifuge extends TilePowered implements ISidedInventory { +public class MachineCentrifuge extends TilePowered implements ISocketable, ISidedInventory { + + private static final int TICKS_PER_RECIPE_TIME = 4; + private static final int ENERGY_PER_RECIPE_TIME = 210; + + private final InventoryAdapter sockets = new InventoryAdapter(1, "sockets"); /* CONSTANTS */ public static final int SLOT_RESOURCE = 0; @@ -63,11 +74,9 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory { private ICentrifugeRecipe currentRecipe; private final Stack pendingProducts = new Stack(); - private int productionTime; - private int timePerItem; public MachineCentrifuge() { - super(800, 40, Defaults.MACHINE_MAX_ENERGY); + super(800, Defaults.MACHINE_MAX_ENERGY, 4200); setInternalInventory(new CentrifugeInventoryAdapter(this)); setHints(Config.hints.get("centrifuge")); } @@ -82,8 +91,7 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory { public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); - nbttagcompound.setInteger("ProductionTime", productionTime); - nbttagcompound.setInteger("TimePerItem", timePerItem); + sockets.writeToNBT(nbttagcompound); NBTTagList nbttaglist = new NBTTagList(); ItemStack[] offspring = pendingProducts.toArray(new ItemStack[pendingProducts.size()]); @@ -102,35 +110,37 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory { public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); - productionTime = nbttagcompound.getInteger("ProductionTime"); - timePerItem = nbttagcompound.getInteger("TimePerItem"); - NBTTagList nbttaglist = nbttagcompound.getTagList("PendingProducts", 10); for (int i = 0; i < nbttaglist.tagCount(); i++) { NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); pendingProducts.add(ItemStack.loadItemStackFromNBT(nbttagcompound1)); } + sockets.readFromNBT(nbttagcompound); - checkRecipe(); + ItemStack chip = sockets.getStackInSlot(0); + if (chip != null) { + ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitboard(chip); + if (chipset != null) { + chipset.onLoad(this); + } + } } @Override - public void updateServerSide() { - super.updateServerSide(); + public void writeGuiData(DataOutputStreamForestry data) throws IOException { + super.writeGuiData(data); + sockets.writeData(data); + } - if (!updateOnInterval(20)) { - return; - } - - // Check and reset recipe if necessary - checkRecipe(); + @Override + public void readGuiData(DataInputStreamForestry data) throws IOException { + super.readGuiData(data); + sockets.readData(data); } @Override public boolean workCycle() { - checkRecipe(); - // If we add pending products, we skip to the next work cycle. if (tryAddPending()) { return false; @@ -140,53 +150,32 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory { return false; } - // Continue work if nothing needs to be added - if (productionTime <= 0) { - return false; - } - if (currentRecipe == null) { return false; } - productionTime--; - // Still not done, return - if (productionTime > 0) { - return true; - } - // We are done, add products to queue Collection products = currentRecipe.getProducts(worldObj.rand); pendingProducts.addAll(products); getInternalInventory().decrStackSize(SLOT_RESOURCE, 1); - checkRecipe(); - resetRecipeTimes(); tryAddPending(); return true; } private void checkRecipe() { - ICentrifugeRecipe machingRecipe = RecipeManager.findMatchingRecipe(getInternalInventory().getStackInSlot(SLOT_RESOURCE)); + ItemStack resource = getStackInSlot(SLOT_RESOURCE); + ICentrifugeRecipe matchingRecipe = RecipeManager.findMatchingRecipe(resource); - if (currentRecipe != machingRecipe) { - currentRecipe = machingRecipe; - resetRecipeTimes(); + if (currentRecipe != matchingRecipe) { + currentRecipe = matchingRecipe; + if (currentRecipe != null) { + int recipeTime = currentRecipe.getProcessingTime(); + setTicksPerWorkCycle(recipeTime * TICKS_PER_RECIPE_TIME); + setEnergyPerWorkCycle(recipeTime * ENERGY_PER_RECIPE_TIME); + } } - - getErrorLogic().setCondition(currentRecipe == null, EnumErrorCode.NORECIPE); - } - - private void resetRecipeTimes() { - if (currentRecipe == null) { - productionTime = 0; - timePerItem = 0; - return; - } - - productionTime = currentRecipe.getProcessingTime(); - timePerItem = currentRecipe.getProcessingTime(); } private boolean tryAddPending() { @@ -206,11 +195,6 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory { return added; } - @Override - public boolean isWorking() { - return currentRecipe != null; - } - @Override public boolean hasResourcesMin(float percentage) { IInventoryAdapter inventory = getInternalInventory(); @@ -223,32 +207,14 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory { @Override public boolean hasWork() { - return currentRecipe != null; - } + checkRecipe(); - public int getProgressScaled(int i) { - if (timePerItem == 0) { - return i; - } + boolean hasResource = getStackInSlot(SLOT_RESOURCE) != null; - return ((timePerItem - productionTime) * i) / timePerItem; - } + IErrorLogic errorLogic = getErrorLogic(); + errorLogic.setCondition(!hasResource, EnumErrorCode.NORESOURCE); - /* GUI */ - public void getGUINetworkData(int i, int j) { - switch (i) { - case 0: - productionTime = j; - break; - case 1: - timePerItem = j; - break; - } - } - - public void sendGUINetworkData(Container container, ICrafting iCrafting) { - iCrafting.sendProgressBarUpdate(container, 0, productionTime); - iCrafting.sendProgressBarUpdate(container, 1, timePerItem); + return hasResource; } /* ITRIGGERPROVIDER */ @@ -277,6 +243,45 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory { } } + /* 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); + } + } + /* RECIPE MANAGEMENT */ public static class CentrifugeRecipe implements ICentrifugeRecipe { @@ -344,10 +349,14 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory { addRecipe(recipe); } - public static ICentrifugeRecipe findMatchingRecipe(ItemStack item) { + public static ICentrifugeRecipe findMatchingRecipe(ItemStack itemStack) { + if (itemStack == null) { + return null; + } + for (ICentrifugeRecipe recipe : recipes) { ItemStack recipeInput = recipe.getInput(); - if (StackUtils.isCraftingEquivalent(recipeInput, item)) { + if (StackUtils.isCraftingEquivalent(recipeInput, itemStack)) { return recipe; } } diff --git a/src/main/java/forestry/factory/gadgets/MachineFabricator.java b/src/main/java/forestry/factory/gadgets/MachineFabricator.java index 45b644525..9f8f13aa5 100755 --- a/src/main/java/forestry/factory/gadgets/MachineFabricator.java +++ b/src/main/java/forestry/factory/gadgets/MachineFabricator.java @@ -81,7 +81,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ILiquidT private int guiMeltingPoint = 0; public MachineFabricator() { - super(1100, 50, 3300); + super(1100, 3300, 200); craftingInventory = new TileInventoryAdapter(this, SLOT_CRAFTING_COUNT, "CraftItems"); setInternalInventory(new FabricatorInventoryAdapter(this)); moltenTank = new FilteredTank(2 * Defaults.BUCKET_VOLUME, Fluids.GLASS.getFluid()); @@ -298,11 +298,6 @@ public class MachineFabricator extends TilePowered implements ICrafter, ILiquidT } } - @Override - public boolean isWorking() { - return this.heat <= MAX_HEAT; - } - @Override public boolean hasWork() { IInventoryAdapter inventory = getInternalInventory(); diff --git a/src/main/java/forestry/factory/gadgets/MachineFermenter.java b/src/main/java/forestry/factory/gadgets/MachineFermenter.java index abb3ca1a7..7269d695d 100755 --- a/src/main/java/forestry/factory/gadgets/MachineFermenter.java +++ b/src/main/java/forestry/factory/gadgets/MachineFermenter.java @@ -177,7 +177,7 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL private int fuelCurrentFerment = 0; public MachineFermenter() { - super(2000, 150, 8000); + super(2000, 8000, 600); setInternalInventory(new FermenterInventoryAdapter(this)); setHints(Config.hints.get("fermenter")); resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluidInputs); @@ -394,19 +394,7 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL return ((IVariableFermentable) itemstack.getItem()).getFermentationModifier(itemstack); } - @Override - public boolean isWorking() { - IInventoryAdapter inventory = getInternalInventory(); - if (currentRecipe == null - && RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid()) == null) { - return false; - } - if (fuelBurnTime > 0) { - return resourceTank.getFluidAmount() > 0 && productTank.getFluidAmount() < Defaults.PROCESSOR_TANK_CAPACITY; - } else { - return determineFuelValue(getFuelStack()) > 0; - } - } + @Override public boolean hasResourcesMin(float percentage) { @@ -428,32 +416,23 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL @Override public boolean hasWork() { - IInventoryAdapter inventory = getInternalInventory(); - if (this.getFuelStack() == null && fuelBurnTime <= 0) { + if (currentRecipe == null && RecipeManager.findMatchingRecipe(getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid()) == null) { return false; - } else if (fuelBurnTime <= 0) { - if (RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid()) == null) { - return false; - } } - if (this.getFermentationStack() == null && fermentationTime <= 0) { + if (fuelBurnTime <= 0 && determineFuelValue(getFuelStack()) <= 0) { + return false; + } + + if (fermentationTime <= 0 && this.getFermentationStack() == null) { return false; - } else if (fermentationTime <= 0) { - if (RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid()) == null) { - return false; - } } if (resourceTank.getFluidAmount() <= fuelCurrentFerment) { return false; } - if (productTank.getFluidAmount() >= productTank.getCapacity()) { - return false; - } - - return true; + return productTank.getFluidAmount() < productTank.getCapacity(); } public int getBurnTimeRemainingScaled(int i) { diff --git a/src/main/java/forestry/factory/gadgets/MachineSqueezer.java b/src/main/java/forestry/factory/gadgets/MachineSqueezer.java index a7935444c..8e4429f12 100755 --- a/src/main/java/forestry/factory/gadgets/MachineSqueezer.java +++ b/src/main/java/forestry/factory/gadgets/MachineSqueezer.java @@ -29,10 +29,14 @@ import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; +import forestry.api.circuits.ChipsetManager; +import forestry.api.circuits.ICircuitBoard; import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorLogic; import forestry.api.recipes.ISqueezerManager; import forestry.core.EnumErrorCode; +import forestry.core.circuits.ISocketable; +import forestry.core.circuits.ISpeedUpgradable; import forestry.core.config.Config; import forestry.core.config.Defaults; import forestry.core.fluids.FluidHelper; @@ -41,8 +45,8 @@ import forestry.core.fluids.tanks.FilteredTank; import forestry.core.fluids.tanks.StandardTank; import forestry.core.gadgets.TilePowered; import forestry.core.interfaces.ILiquidTankContainer; -import forestry.core.inventory.IInventoryAdapter; import forestry.core.inventory.InvTools; +import forestry.core.inventory.InventoryAdapter; import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; @@ -52,15 +56,310 @@ import forestry.core.utils.EnumTankLevel; import forestry.core.utils.StackUtils; import forestry.core.utils.Utils; -public class MachineSqueezer extends TilePowered implements ISidedInventory, ILiquidTankContainer { +public class MachineSqueezer extends TilePowered implements ISocketable, ISidedInventory, ILiquidTankContainer, ISpeedUpgradable { - /* CONSTANTS */ - public static final short SLOT_RESOURCE_1 = 0; - public static final short SLOTS_RESOURCE_COUNT = 9; - public static final short SLOT_REMNANT = 9; - public static final short SLOT_REMNANT_COUNT = 1; - public static final short SLOT_CAN_INPUT = 10; - public static final short SLOT_CAN_OUTPUT = 11; + private static final int TICKS_PER_RECIPE_TIME = 4; + private static final int ENERGY_PER_RECIPE_TIME = 200; + + private final InventoryAdapter sockets = new InventoryAdapter(1, "sockets"); + + /* MEMBER */ + private final TankManager tankManager; + private final FilteredTank productTank; + private final SqueezerInventory inventory; + + private Recipe currentRecipe; + + public MachineSqueezer() { + super(1100, 4000, 2000); + this.inventory = new SqueezerInventory(this); + setInternalInventory(this.inventory); + setHints(Config.hints.get("squeezer")); + this.productTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluids); + this.productTank.tankMode = StandardTank.TankMode.OUTPUT; + this.tankManager = new TankManager(productTank); + } + + @Override + public void openGui(EntityPlayer player) { + player.openGui(ForestryAPI.instance, GuiId.SqueezerGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); + } + + /* LOADING & SAVING */ + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) { + super.writeToNBT(nbttagcompound); + tankManager.writeTanksToNBT(nbttagcompound); + sockets.writeToNBT(nbttagcompound); + } + + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) { + super.readFromNBT(nbttagcompound); + tankManager.readTanksFromNBT(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 writeData(DataOutputStreamForestry data) throws IOException { + super.writeData(data); + tankManager.writePacketData(data); + } + + @Override + public void readData(DataInputStreamForestry data) throws IOException { + super.readData(data); + tankManager.readPacketData(data); + } + + @Override + public void writeGuiData(DataOutputStreamForestry data) throws IOException { + super.writeGuiData(data); + sockets.writeData(data); + } + + @Override + public void readGuiData(DataInputStreamForestry data) throws IOException { + super.readGuiData(data); + sockets.readData(data); + } + + // / WORKING + @Override + public void updateServerSide() { + super.updateServerSide(); + + if (updateOnInterval(20)) { + inventory.fillContainers(productTank.getFluid(), tankManager); + } + } + + @Override + public boolean workCycle() { + EntityPlayer player = Proxies.common.getPlayer(worldObj, getAccessHandler().getOwner()); + if (!inventory.removeResources(currentRecipe.resources, player)) { + return false; + } + + FluidStack resultFluid = currentRecipe.liquid; + productTank.fill(resultFluid, true); + + if (currentRecipe.remnants != null && worldObj.rand.nextInt(100) < currentRecipe.chance) { + ItemStack remnant = currentRecipe.remnants.copy(); + inventory.addRemnant(remnant, true); + } + + return true; + } + + private boolean checkRecipe() { + ItemStack[] resources = inventory.getResources(); + Recipe matchingRecipe = RecipeManager.findMatchingRecipe(resources); + + if (currentRecipe != matchingRecipe) { + currentRecipe = matchingRecipe; + if (currentRecipe != null) { + int recipeTime = currentRecipe.timePerItem; + setTicksPerWorkCycle(recipeTime * TICKS_PER_RECIPE_TIME); + setEnergyPerWorkCycle(recipeTime * ENERGY_PER_RECIPE_TIME); + } + } + + getErrorLogic().setCondition(currentRecipe == null, EnumErrorCode.NORECIPE); + return currentRecipe != null; + } + + @Override + public boolean hasWork() { + checkRecipe(); + + boolean hasResources = inventory.hasResources(); + boolean hasRecipe = true; + boolean canFill = true; + boolean canAdd = true; + + if (hasResources) { + hasRecipe = (currentRecipe != null); + if (hasRecipe) { + FluidStack resultFluid = currentRecipe.liquid; + canFill = (productTank.fill(resultFluid, false) == resultFluid.amount); + + if (currentRecipe.remnants != null) { + canAdd = inventory.addRemnant(currentRecipe.remnants, false); + } + } + } + + IErrorLogic errorLogic = getErrorLogic(); + errorLogic.setCondition(!hasResources, EnumErrorCode.NORESOURCE); + errorLogic.setCondition(!hasRecipe, EnumErrorCode.NORECIPE); + errorLogic.setCondition(!canFill, EnumErrorCode.NOSPACETANK); + errorLogic.setCondition(!canAdd, EnumErrorCode.NOSPACE); + + return hasResources && hasRecipe && canFill && canAdd; + } + + public int getResourceScaled(int i) { + return (productTank.getFluidAmount() * i) / Defaults.PROCESSOR_TANK_CAPACITY; + } + + @Override + public EnumTankLevel getSecondaryLevel() { + return Utils.rateTankLevel(getResourceScaled(100)); + } + + /* ILIQUIDCONTAINER IMPLEMENTATION */ + @Override + public TankManager getTankManager() { + return tankManager; + } + + @Override + public void getGUINetworkData(int messageId, int data) { + + } + + @Override + public void sendGUINetworkData(Container container, ICrafting iCrafting) { + + } + + @Override + public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { + return tankManager.fill(from, resource, doFill); + } + + @Override + public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { + return tankManager.drain(from, resource, doDrain); + } + + @Override + public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { + return tankManager.drain(from, maxDrain, doDrain); + } + + @Override + public boolean canFill(ForgeDirection from, Fluid fluid) { + return tankManager.canFill(from, fluid); + } + + @Override + public boolean canDrain(ForgeDirection from, Fluid fluid) { + return tankManager.canDrain(from, fluid); + } + + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection from) { + return tankManager.getTankInfo(from); + } + + /* 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); + } + } + + public static class SqueezerInventory extends TileInventoryAdapter { + public static final short SLOT_RESOURCE_1 = 0; + public static final short SLOTS_RESOURCE_COUNT = 9; + public static final short SLOT_REMNANT = 9; + public static final short SLOT_REMNANT_COUNT = 1; + public static final short SLOT_CAN_INPUT = 10; + public static final short SLOT_CAN_OUTPUT = 11; + + public SqueezerInventory(MachineSqueezer squeezer) { + super(squeezer, 12, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_CAN_INPUT) { + return FluidHelper.isEmptyContainer(itemStack); + } + + if (slotIndex >= SLOT_RESOURCE_1 && slotIndex < SLOT_RESOURCE_1 + SLOTS_RESOURCE_COUNT) { + if (FluidHelper.isEmptyContainer(itemStack)) { + return false; + } + + if (RecipeManager.canUse(itemStack)) { + return true; + } + } + + return false; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return slotIndex == SLOT_REMNANT || slotIndex == SLOT_CAN_OUTPUT; + } + + public boolean hasResources() { + return !InvTools.isEmpty(this, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT); + } + + public ItemStack[] getResources() { + return InvTools.getStacks(this, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT); + } + + public boolean removeResources(ItemStack[] stacks, EntityPlayer player) { + return InvTools.removeSets(this, 1, stacks, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT, player, false, true); + } + + public boolean addRemnant(ItemStack remnant, boolean doAdd) { + return InvTools.tryAddStack(this, remnant, SLOT_REMNANT, SLOT_REMNANT_COUNT, true, doAdd); + } + + public void fillContainers(FluidStack fluidStack, TankManager tankManager) { + if (getStackInSlot(SLOT_CAN_INPUT) == null || fluidStack == null) { + return; + } + FluidHelper.fillContainers(tankManager, this, SLOT_CAN_INPUT, SLOT_CAN_OUTPUT, fluidStack.getFluid()); + } + } /* RECIPE MANAGMENT */ public static class Recipe { @@ -140,280 +439,4 @@ public class MachineSqueezer extends TilePowered implements ISidedInventory, ILi } } - /* MEMBER */ - private final TankManager tankManager; - private final FilteredTank productTank; - - private Recipe currentRecipe; - - private int productionTime; - private int timePerItem; - - public MachineSqueezer() { - super(1100, 50, 4000); - setInternalInventory(new SqueezerInventoryAdapter(this)); - setHints(Config.hints.get("squeezer")); - productTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluids); - productTank.tankMode = StandardTank.TankMode.OUTPUT; - tankManager = new TankManager(productTank); - } - - @Override - public void openGui(EntityPlayer player) { - player.openGui(ForestryAPI.instance, GuiId.SqueezerGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); - } - - /* LOADING & SAVING */ - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - super.writeToNBT(nbttagcompound); - - nbttagcompound.setInteger("ProductionTime", productionTime); - nbttagcompound.setInteger("TimePerItem", timePerItem); - - tankManager.writeTanksToNBT(nbttagcompound); - } - - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - super.readFromNBT(nbttagcompound); - - productionTime = nbttagcompound.getInteger("ProductionTime"); - timePerItem = nbttagcompound.getInteger("TimePerItem"); - tankManager.readTanksFromNBT(nbttagcompound); - - checkRecipe(); - } - - @Override - public void writeData(DataOutputStreamForestry data) throws IOException { - super.writeData(data); - tankManager.writePacketData(data); - } - - @Override - public void readData(DataInputStreamForestry data) throws IOException { - super.readData(data); - tankManager.readPacketData(data); - } - - // / WORKING - @Override - public void updateServerSide() { - super.updateServerSide(); - - if (!updateOnInterval(20)) { - return; - } - - IInventoryAdapter inventory = getInternalInventory(); - // Can/capsule input/output needs to be handled here. - if (inventory.getStackInSlot(SLOT_CAN_INPUT) != null) { - FluidStack fluidStack = productTank.getFluid(); - if (fluidStack != null) { - FluidHelper.fillContainers(tankManager, inventory, SLOT_CAN_INPUT, SLOT_CAN_OUTPUT, fluidStack.getFluid()); - } - } - - checkRecipe(); - } - - @Override - public boolean workCycle() { - - if (!checkRecipe()) { - return false; - } - - IErrorLogic errorLogic = getErrorLogic(); - - FluidStack resultFluid = currentRecipe.liquid; - boolean canFill = productTank.fill(resultFluid, false) == resultFluid.amount; - errorLogic.setCondition(!canFill, EnumErrorCode.NOSPACETANK); - - if (!canFill) { - return false; - } - - ItemStack remnant = null; - if (currentRecipe.remnants != null) { - remnant = currentRecipe.remnants.copy(); - boolean canAdd = InvTools.tryAddStack(getInternalInventory(), remnant, SLOT_REMNANT, SLOT_REMNANT_COUNT, true, false); - errorLogic.setCondition(!canAdd, EnumErrorCode.NOSPACE); - if (!canAdd) { - return false; - } - } - - if (productionTime <= 0) { - return false; - } - - if (currentRecipe == null) { - return false; - } - - productionTime--; - // Still not done, return - if (productionTime > 0) { - return true; - } - - if (!removeResources(currentRecipe.resources)) { - return false; - } - - productTank.fill(resultFluid, true); - if (remnant != null && worldObj.rand.nextInt(100) < currentRecipe.chance) { - InvTools.tryAddStack(getInternalInventory(), remnant, SLOT_REMNANT, SLOT_REMNANT_COUNT, true); - } - - checkRecipe(); - resetRecipeTimes(); - - return true; - } - - private boolean checkRecipe() { - ItemStack[] resources = InvTools.getStacks(getInternalInventory(), SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT); - Recipe matchingRecipe = RecipeManager.findMatchingRecipe(resources); - - if (currentRecipe != matchingRecipe) { - currentRecipe = matchingRecipe; - resetRecipeTimes(); - } - - getErrorLogic().setCondition(currentRecipe == null, EnumErrorCode.NORECIPE); - return currentRecipe != null; - } - - private void resetRecipeTimes() { - if (currentRecipe == null) { - productionTime = 0; - timePerItem = 0; - return; - } - - productionTime = currentRecipe.timePerItem; - timePerItem = currentRecipe.timePerItem; - } - - private boolean removeResources(ItemStack[] stacks) { - EntityPlayer player = Proxies.common.getPlayer(worldObj, getAccessHandler().getOwner()); - return InvTools.removeSets(getInternalInventory(), 1, stacks, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT, player, false, true); - } - - @Override - public boolean isWorking() { - return currentRecipe != null && productTank.getFluidAmount() < productTank.getCapacity(); - } - - @Override - public boolean hasWork() { - return currentRecipe != null && productTank.getFluidAmount() < productTank.getCapacity(); - } - - public int getProgressScaled(int i) { - if (timePerItem == 0) { - return i; - } - - return (productionTime * i) / timePerItem; - } - - public int getResourceScaled(int i) { - return (productTank.getFluidAmount() * i) / Defaults.PROCESSOR_TANK_CAPACITY; - } - - @Override - public EnumTankLevel getSecondaryLevel() { - return Utils.rateTankLevel(getResourceScaled(100)); - } - - /* SMP GUI */ - @Override - public void getGUINetworkData(int i, int j) { - i -= tankManager.maxMessageId() + 1; - switch (i) { - case 0: - productionTime = j; - break; - case 1: - timePerItem = j; - break; - } - } - - @Override - public void sendGUINetworkData(Container container, ICrafting iCrafting) { - int i = tankManager.maxMessageId() + 1; - iCrafting.sendProgressBarUpdate(container, i, productionTime); - iCrafting.sendProgressBarUpdate(container, i + 1, timePerItem); - } - - /* ILIQUIDCONTAINER IMPLEMENTATION */ - @Override - public TankManager getTankManager() { - return tankManager; - } - - @Override - public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { - return tankManager.fill(from, resource, doFill); - } - - @Override - public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { - return tankManager.drain(from, resource, doDrain); - } - - @Override - public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { - return tankManager.drain(from, maxDrain, doDrain); - } - - @Override - public boolean canFill(ForgeDirection from, Fluid fluid) { - return tankManager.canFill(from, fluid); - } - - @Override - public boolean canDrain(ForgeDirection from, Fluid fluid) { - return tankManager.canDrain(from, fluid); - } - - @Override - public FluidTankInfo[] getTankInfo(ForgeDirection from) { - return tankManager.getTankInfo(from); - } - - private static class SqueezerInventoryAdapter extends TileInventoryAdapter { - public SqueezerInventoryAdapter(MachineSqueezer squeezer) { - super(squeezer, 12, "Items"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - if (slotIndex == SLOT_CAN_INPUT) { - return FluidHelper.isEmptyContainer(itemStack); - } - - if (slotIndex >= SLOT_RESOURCE_1 && slotIndex < SLOT_RESOURCE_1 + SLOTS_RESOURCE_COUNT) { - if (FluidHelper.isEmptyContainer(itemStack)) { - return false; - } - - if (RecipeManager.canUse(itemStack)) { - return true; - } - } - - return false; - } - - @Override - public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { - return slotIndex == SLOT_REMNANT || slotIndex == SLOT_CAN_OUTPUT; - } - } } diff --git a/src/main/java/forestry/factory/gadgets/MachineStill.java b/src/main/java/forestry/factory/gadgets/MachineStill.java index e937044a7..9a046004f 100755 --- a/src/main/java/forestry/factory/gadgets/MachineStill.java +++ b/src/main/java/forestry/factory/gadgets/MachineStill.java @@ -131,7 +131,7 @@ public class MachineStill extends TilePowered implements ISidedInventory, ILiqui private int distillationTotalTime = 0; public MachineStill() { - super(1100, 50, 8000); + super(1100, 8000, 200); setInternalInventory(new StillInventoryAdapter(this)); setHints(Config.hints.get("still")); resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluidInputs); @@ -258,11 +258,6 @@ public class MachineStill extends TilePowered implements ISidedInventory, ILiqui getErrorLogic().setCondition(currentRecipe == null, EnumErrorCode.NORECIPE); } - @Override - public boolean isWorking() { - return distillationTime > 0 || currentRecipe != null && productTank.getFluidAmount() + currentRecipe.output.amount <= Defaults.PROCESSOR_TANK_CAPACITY; - } - @Override public boolean hasWork() { if (currentRecipe == null) { diff --git a/src/main/java/forestry/factory/gui/ContainerCentrifuge.java b/src/main/java/forestry/factory/gui/ContainerCentrifuge.java index bcab72064..3a4a4e5bf 100755 --- a/src/main/java/forestry/factory/gui/ContainerCentrifuge.java +++ b/src/main/java/forestry/factory/gui/ContainerCentrifuge.java @@ -11,20 +11,19 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; -import forestry.core.gui.ContainerTile; +import forestry.core.gui.ContainerSocketed; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; import forestry.factory.gadgets.MachineCentrifuge; -public class ContainerCentrifuge extends ContainerTile { +public class ContainerCentrifuge extends ContainerSocketed { public ContainerCentrifuge(InventoryPlayer player, MachineCentrifuge tile) { super(tile, player, 8, 84); // Resource - this.addSlotToContainer(new SlotFiltered(tile, 0, 34, 37)); + this.addSlotToContainer(new SlotFiltered(tile, 0, 30, 37)); // Product Inventory for (int l = 0; l < 3; l++) { @@ -34,18 +33,4 @@ public class ContainerCentrifuge extends ContainerTile { } } - @Override - public void updateProgressBar(int i, int j) { - tile.getGUINetworkData(i, j); - } - - @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - - for (Object crafter : crafters) { - tile.sendGUINetworkData(this, (ICrafting) crafter); - } - } - } diff --git a/src/main/java/forestry/factory/gui/ContainerSqueezer.java b/src/main/java/forestry/factory/gui/ContainerSqueezer.java index 68c7f5a23..4f0248099 100755 --- a/src/main/java/forestry/factory/gui/ContainerSqueezer.java +++ b/src/main/java/forestry/factory/gui/ContainerSqueezer.java @@ -12,29 +12,29 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; -import forestry.core.gui.ContainerLiquidTanks; +import forestry.core.gui.ContainerLiquidTanksSocketed; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; import forestry.factory.gadgets.MachineSqueezer; -public class ContainerSqueezer extends ContainerLiquidTanks { +public class ContainerSqueezer extends ContainerLiquidTanksSocketed { public ContainerSqueezer(InventoryPlayer player, MachineSqueezer tile) { super(tile, player, 8, 84); // Resource inventory - for (int l = 0; l < 3; l++) { - for (int k = 0; k < 3; k++) { - addSlotToContainer(new SlotFiltered(tile, k + l * 3, 19 + k * 18, 18 + l * 18)); + for (int row = 0; row < 3; row++) { + for (int column = 0; column < 3; column++) { + addSlotToContainer(new SlotFiltered(tile, column + row * 3, 17 + column * 18, 21 + row * 18)); } } // Remnants slot - this.addSlotToContainer(new SlotOutput(tile, MachineSqueezer.SLOT_REMNANT, 123, 19)); + this.addSlotToContainer(new SlotOutput(tile, MachineSqueezer.SqueezerInventory.SLOT_REMNANT, 97, 60)); // Can slot - this.addSlotToContainer(new SlotFiltered(tile, MachineSqueezer.SLOT_CAN_INPUT, 106, 55)); + this.addSlotToContainer(new SlotFiltered(tile, MachineSqueezer.SqueezerInventory.SLOT_CAN_INPUT, 147, 24)); // Output slot - this.addSlotToContainer(new SlotOutput(tile, MachineSqueezer.SLOT_CAN_OUTPUT, 140, 55)); + this.addSlotToContainer(new SlotOutput(tile, MachineSqueezer.SqueezerInventory.SLOT_CAN_OUTPUT, 147, 60)); } } diff --git a/src/main/java/forestry/factory/gui/GuiBottler.java b/src/main/java/forestry/factory/gui/GuiBottler.java index 756a49f24..25a1b8c64 100755 --- a/src/main/java/forestry/factory/gui/GuiBottler.java +++ b/src/main/java/forestry/factory/gui/GuiBottler.java @@ -29,9 +29,7 @@ public class GuiBottler extends GuiForestryTitled { public GuiCentrifuge(InventoryPlayer inventory, MachineCentrifuge tile) { - super(Defaults.TEXTURE_PATH_GUI + "/centrifuge.png", new ContainerCentrifuge(inventory, tile), tile); + super(Defaults.TEXTURE_PATH_GUI + "/centrifugesocket.png", new ContainerCentrifuge(inventory, tile), tile); + widgetManager.add(new SocketWidget(this.widgetManager, 71, 37, tile, 0)); } @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); - MachineCentrifuge machine = inventory; - int progress = machine.getProgressScaled(16); - drawTexturedModalRect(guiLeft + 62, guiTop + 36 + 17 - progress, 176, 17 - progress, 4, progress); + int progress = 16 - inventory.getProgressScaled(16); + drawTexturedModalRect(guiLeft + 58, guiTop + 36 + 17 - progress, 176, 17 - progress, 4, progress); } } diff --git a/src/main/java/forestry/factory/gui/GuiSqueezer.java b/src/main/java/forestry/factory/gui/GuiSqueezer.java index 801dea4c9..d3794d067 100755 --- a/src/main/java/forestry/factory/gui/GuiSqueezer.java +++ b/src/main/java/forestry/factory/gui/GuiSqueezer.java @@ -14,20 +14,22 @@ import net.minecraft.entity.player.InventoryPlayer; import forestry.core.config.Defaults; import forestry.core.gui.GuiForestryTitled; +import forestry.core.gui.widgets.SocketWidget; import forestry.core.gui.widgets.TankWidget; import forestry.factory.gadgets.MachineSqueezer; public class GuiSqueezer extends GuiForestryTitled { public GuiSqueezer(InventoryPlayer inventory, MachineSqueezer tile) { - super(Defaults.TEXTURE_PATH_GUI + "/squeezer.png", new ContainerSqueezer(inventory, tile), tile); - widgetManager.add(new TankWidget(this.widgetManager, 85, 15, 0)); + super(Defaults.TEXTURE_PATH_GUI + "/squeezersocket.png", new ContainerSqueezer(inventory, tile), tile); + widgetManager.add(new TankWidget(this.widgetManager, 122, 18, 0)); + widgetManager.add(new SocketWidget(this.widgetManager, 75, 20, tile, 0)); } @Override protected void drawWidgets() { int progress = inventory.getProgressScaled(43); - drawTexturedModalRect(75, 20, 176, 60, 43 - progress, 18); + drawTexturedModalRect(75, 41, 176, 60, 43 - progress, 18); super.drawWidgets(); } diff --git a/src/main/java/forestry/factory/gui/GuiStill.java b/src/main/java/forestry/factory/gui/GuiStill.java index 4fec7a547..df8bd7da3 100755 --- a/src/main/java/forestry/factory/gui/GuiStill.java +++ b/src/main/java/forestry/factory/gui/GuiStill.java @@ -30,9 +30,7 @@ public class GuiStill extends GuiForestryTitled { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); MachineStill still = inventory; - if (still.isWorking()) { - drawTexturedModalRect(guiLeft + 81, guiTop + 57, 176, 60, 14, 14); - } + drawTexturedModalRect(guiLeft + 81, guiTop + 57, 176, 60, 14, 14); int massRemaining = still.getDistillationProgressScaled(16); if (massRemaining > 0) { diff --git a/src/main/java/forestry/factory/gui/GuiWorktable.java b/src/main/java/forestry/factory/gui/GuiWorktable.java index 52e9300df..df3f10587 100755 --- a/src/main/java/forestry/factory/gui/GuiWorktable.java +++ b/src/main/java/forestry/factory/gui/GuiWorktable.java @@ -18,8 +18,8 @@ import org.lwjgl.opengl.GL11; import forestry.core.config.Defaults; import forestry.core.gui.GuiForestryTitled; -import forestry.core.gui.WidgetManager; import forestry.core.gui.widgets.Widget; +import forestry.core.gui.widgets.WidgetManager; import forestry.core.proxy.Proxies; import forestry.core.render.SpriteSheet; import forestry.core.render.TextureManager; diff --git a/src/main/java/forestry/farming/gui/FarmLedger.java b/src/main/java/forestry/farming/gui/FarmLedger.java index b95f02708..85ba98f0d 100644 --- a/src/main/java/forestry/farming/gui/FarmLedger.java +++ b/src/main/java/forestry/farming/gui/FarmLedger.java @@ -12,8 +12,8 @@ package forestry.farming.gui; import net.minecraft.init.Items; -import forestry.core.gui.Ledger; -import forestry.core.gui.LedgerManager; +import forestry.core.gui.ledgers.Ledger; +import forestry.core.gui.ledgers.LedgerManager; import forestry.core.utils.StringUtil; public class FarmLedger extends Ledger { diff --git a/src/main/java/forestry/farming/gui/GuiFarm.java b/src/main/java/forestry/farming/gui/GuiFarm.java index 38c326b65..2a8d28557 100755 --- a/src/main/java/forestry/farming/gui/GuiFarm.java +++ b/src/main/java/forestry/farming/gui/GuiFarm.java @@ -18,14 +18,14 @@ import org.lwjgl.opengl.GL11; import forestry.api.farming.FarmDirection; import forestry.api.farming.IFarmLogic; import forestry.core.config.Defaults; -import forestry.core.gui.ClimateLedger; import forestry.core.gui.GuiForestry; -import forestry.core.gui.OwnerLedger; -import forestry.core.gui.WidgetManager; +import forestry.core.gui.ledgers.ClimateLedger; +import forestry.core.gui.ledgers.OwnerLedger; import forestry.core.gui.tooltips.ToolTip; import forestry.core.gui.widgets.SocketWidget; import forestry.core.gui.widgets.TankWidget; import forestry.core.gui.widgets.Widget; +import forestry.core.gui.widgets.WidgetManager; import forestry.core.proxy.Proxies; import forestry.core.utils.StringUtil; import forestry.farming.multiblock.IFarmController; diff --git a/src/main/java/forestry/farming/multiblock/IFarmController.java b/src/main/java/forestry/farming/multiblock/IFarmController.java index e963b392b..b4a192795 100644 --- a/src/main/java/forestry/farming/multiblock/IFarmController.java +++ b/src/main/java/forestry/farming/multiblock/IFarmController.java @@ -12,15 +12,14 @@ package forestry.farming.multiblock; import forestry.api.core.IErrorLogicSource; import forestry.api.farming.IFarmHousing; +import forestry.core.circuits.ISocketable; import forestry.core.fluids.ITankManager; import forestry.core.interfaces.IClimatised; import forestry.core.interfaces.IRestrictedAccessTile; -import forestry.core.interfaces.ISocketable; import forestry.core.inventory.IInventoryAdapter; -import forestry.core.network.IStreamableGui; import forestry.farming.gui.IFarmLedgerDelegate; -public interface IFarmController extends IFarmHousing, ISocketable, IClimatised, IRestrictedAccessTile, IErrorLogicSource, IStreamableGui { +public interface IFarmController extends IFarmHousing, ISocketable, IClimatised, IRestrictedAccessTile, IErrorLogicSource { IFarmLedgerDelegate getFarmLedgerDelegate(); IInventoryAdapter getInternalInventory(); diff --git a/src/main/java/forestry/farming/multiblock/TileFarm.java b/src/main/java/forestry/farming/multiblock/TileFarm.java index 45531526a..4827fa0aa 100644 --- a/src/main/java/forestry/farming/multiblock/TileFarm.java +++ b/src/main/java/forestry/farming/multiblock/TileFarm.java @@ -22,9 +22,9 @@ import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorLogic; import forestry.api.core.IErrorLogicSource; import forestry.api.farming.IFarmComponent; +import forestry.core.circuits.ISocketable; import forestry.core.config.Config; import forestry.core.interfaces.IHintSource; -import forestry.core.interfaces.ISocketable; import forestry.core.inventory.IInventoryAdapter; import forestry.core.multiblock.MultiblockControllerBase; import forestry.core.multiblock.MultiblockValidationException; diff --git a/src/main/java/forestry/farming/multiblock/TileGearbox.java b/src/main/java/forestry/farming/multiblock/TileGearbox.java index 5f9593d36..2745d6d62 100644 --- a/src/main/java/forestry/farming/multiblock/TileGearbox.java +++ b/src/main/java/forestry/farming/multiblock/TileGearbox.java @@ -23,6 +23,7 @@ import forestry.energy.EnergyManager; public class TileGearbox extends TileFarm implements IPowerHandler, IFarmComponent.Active { private static final int WORK_CYCLES = 4; + private static final int ENERGY_PER_OPERATION = WORK_CYCLES * 50; private final EnergyManager energyManager; @@ -31,7 +32,7 @@ public class TileGearbox extends TileFarm implements IPowerHandler, IFarmCompone private int workCounter; public TileGearbox() { - energyManager = new EnergyManager(200, 50, 10000); + energyManager = new EnergyManager(200, 10000); } /* SAVING & LOADING */ @@ -71,7 +72,7 @@ public class TileGearbox extends TileFarm implements IPowerHandler, IFarmCompone } // Hard limit to 4 cycles / second. - if (workCounter < WORK_CYCLES && energyManager.consumeEnergyToDoWork()) { + if (workCounter < WORK_CYCLES && energyManager.consumeEnergyToDoWork(WORK_CYCLES, ENERGY_PER_OPERATION)) { workCounter++; } diff --git a/src/main/java/forestry/plugins/PluginFactory.java b/src/main/java/forestry/plugins/PluginFactory.java index d975cdbf3..bbb00d0fd 100644 --- a/src/main/java/forestry/plugins/PluginFactory.java +++ b/src/main/java/forestry/plugins/PluginFactory.java @@ -21,8 +21,12 @@ import net.minecraftforge.fluids.FluidStack; import cpw.mods.fml.common.network.IGuiHandler; +import forestry.api.circuits.ChipsetManager; +import forestry.api.circuits.ICircuitLayout; import forestry.api.recipes.RecipeManagers; import forestry.core.GameMode; +import forestry.core.circuits.Circuit; +import forestry.core.circuits.CircuitLayout; import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; @@ -37,6 +41,7 @@ import forestry.core.utils.RecipeUtil; import forestry.core.utils.ShapedRecipeCustom; import forestry.factory.DummyManagers; import forestry.factory.GuiHandlerFactory; +import forestry.factory.circuits.CircuitSpeedUpgrade; import forestry.factory.gadgets.MachineBottler; import forestry.factory.gadgets.MachineCarpenter; import forestry.factory.gadgets.MachineCentrifuge; @@ -226,6 +231,10 @@ public class PluginFactory extends ForestryPlugin { 'W', Blocks.crafting_table, 'C', Blocks.chest)) .setFaces(0, 1, 2, 3, 4, 4)); + + ICircuitLayout layoutMachineUpgrade = new CircuitLayout("machine.upgrade"); + ChipsetManager.circuitRegistry.registerLayout(layoutMachineUpgrade); + } @Override @@ -249,6 +258,9 @@ public class PluginFactory extends ForestryPlugin { definitionRainmaker.register(); definitionWorktable.register(); + Circuit.machineSpeedUpgrade1 = new CircuitSpeedUpgrade("machine.speed.boost.1", 0.125f, 0.05f, 4); + Circuit.machineSpeedUpgrade2 = new CircuitSpeedUpgrade("machine.speed.boost.2", 0.250f, 0.10f, 4); + Circuit.machineEfficiencyUpgrade1 = new CircuitSpeedUpgrade("machine.efficiency.1", 0, -0.10f, 2); } @Override @@ -462,6 +474,12 @@ public class PluginFactory extends ForestryPlugin { if (PluginManager.Module.STORAGE.isEnabled()) { PluginStorage.createCrateRecipes(); } + ICircuitLayout layout = ChipsetManager.circuitRegistry.getLayout("forestry.machine.upgrade"); + + // / Solder Manager + ChipsetManager.solderManager.addRecipe(layout, ForestryItem.tubes.getItemStack(1, 9), Circuit.machineSpeedUpgrade1); + ChipsetManager.solderManager.addRecipe(layout, ForestryItem.tubes.getItemStack(1, 7), Circuit.machineSpeedUpgrade2); + ChipsetManager.solderManager.addRecipe(layout, ForestryItem.tubes.getItemStack(1, 4), Circuit.machineEfficiencyUpgrade1); } @Override diff --git a/src/main/resources/assets/forestry/textures/gui/centrifuge.png b/src/main/resources/assets/forestry/textures/gui/centrifuge.png deleted file mode 100755 index 9a3290c88..000000000 Binary files a/src/main/resources/assets/forestry/textures/gui/centrifuge.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/gui/centrifugesocket.png b/src/main/resources/assets/forestry/textures/gui/centrifugesocket.png new file mode 100644 index 000000000..f84945838 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/gui/centrifugesocket.png differ diff --git a/src/main/resources/assets/forestry/textures/gui/squeezer.png b/src/main/resources/assets/forestry/textures/gui/squeezer.png deleted file mode 100755 index 7b32856c7..000000000 Binary files a/src/main/resources/assets/forestry/textures/gui/squeezer.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/gui/squeezersocket.png b/src/main/resources/assets/forestry/textures/gui/squeezersocket.png new file mode 100644 index 000000000..e42ca7db4 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/gui/squeezersocket.png differ