mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-19 19:49:54 +00:00
Updated all tanks to use TankManager.
This commit is contained in:
1 parent
4b7619355d
commit
6a41a055d1
42 files changed
+914
-822
No files matched your search
@@ -18,14 +18,17 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
import forestry.api.apiculture.IAlvearyComponent;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
@@ -57,7 +60,8 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory
|
||||
|
||||
/* MEMBERS */
|
||||
InventoryAdapter canInventory = new InventoryAdapter(1, "CanInv");
|
||||
private StandardTank liquidTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
private final TankManager tankManager;
|
||||
private FilteredTank liquidTank;
|
||||
|
||||
private HygroregulatorRecipe currentRecipe;
|
||||
private int transferTime;
|
||||
@@ -65,9 +69,16 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory
|
||||
public TileAlvearyHygroregulator() {
|
||||
super(BLOCK_META);
|
||||
|
||||
recipes = new HygroregulatorRecipe[] { new HygroregulatorRecipe(new FluidStack(LiquidHelper.getFluid(Defaults.LIQUID_WATER), 1), 1, 0.01f, -0.005f),
|
||||
new HygroregulatorRecipe(new FluidStack(LiquidHelper.getFluid(Defaults.LIQUID_LAVA), 1), 10, -0.01f, +0.005f),
|
||||
new HygroregulatorRecipe(new FluidStack(LiquidHelper.getFluid(Defaults.LIQUID_ICE), 1), 10, 0.02f, -0.01f) };
|
||||
Fluid water = LiquidHelper.getFluid(Defaults.LIQUID_WATER);
|
||||
Fluid lava = LiquidHelper.getFluid(Defaults.LIQUID_LAVA);
|
||||
Fluid liquidIce = LiquidHelper.getFluid(Defaults.LIQUID_ICE);
|
||||
|
||||
liquidTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, water, lava, liquidIce);
|
||||
tankManager = new TankManager(liquidTank);
|
||||
|
||||
recipes = new HygroregulatorRecipe[] { new HygroregulatorRecipe(new FluidStack(water, 1), 1, 0.01f, -0.005f),
|
||||
new HygroregulatorRecipe(new FluidStack(lava, 1), 10, -0.01f, +0.005f),
|
||||
new HygroregulatorRecipe(new FluidStack(liquidIce, 1), 10, 0.02f, -0.01f) };
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,9 +157,7 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory
|
||||
|
||||
canInventory.readFromNBT(nbttagcompound);
|
||||
|
||||
liquidTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
if (nbttagcompound.hasKey("LiquidTank"))
|
||||
liquidTank.readFromNBT(nbttagcompound.getCompoundTag("LiquidTank"));
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
|
||||
transferTime = nbttagcompound.getInteger("TransferTime");
|
||||
|
||||
@@ -164,9 +173,7 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory
|
||||
|
||||
canInventory.writeToNBT(nbttagcompound);
|
||||
|
||||
NBTTagCompound NBTresourceSlot = new NBTTagCompound();
|
||||
liquidTank.writeToNBT(NBTresourceSlot);
|
||||
nbttagcompound.setTag("LiquidTank", NBTresourceSlot);
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
|
||||
nbttagcompound.setInteger("TransferTime", transferTime);
|
||||
if (currentRecipe != null) {
|
||||
@@ -268,30 +275,54 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory
|
||||
*/
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
|
||||
if (slotIndex == 0) {
|
||||
FluidStack fluid = LiquidHelper.getFluidStackInContainer(itemstack);
|
||||
if (fluid == null || fluid.amount <= 0)
|
||||
return false;
|
||||
return liquidTank.accepts(fluid.getFluid());
|
||||
}
|
||||
|
||||
return super.isItemValidForSlot(slotIndex, itemstack);
|
||||
}
|
||||
|
||||
/* ILIQUIDTANKCONTAINER */
|
||||
@Override
|
||||
public TankManager getTankManager() {
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
return liquidTank.fill(resource, doFill);
|
||||
return tankManager.fill(from, resource, doFill);
|
||||
}
|
||||
|
||||
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 liquidTank.drain(maxDrain, doDrain);
|
||||
return tankManager.drain(from, maxDrain, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardTank[] getTanks() {
|
||||
return new StandardTank[] { liquidTank };
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid) {
|
||||
return tankManager.canFill(from, fluid);
|
||||
}
|
||||
|
||||
/* SMP GUI */
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid) {
|
||||
return tankManager.canDrain(from, fluid);
|
||||
}
|
||||
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
return tankManager.getTankInfo(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getGUINetworkData(int messageId, int data) {}
|
||||
|
||||
@Override
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {}
|
||||
}
|
||||
@@ -37,17 +37,4 @@ public class ContainerAlvearyHygroregulator extends ContainerLiquidTanks {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressBar(int i, int j) {
|
||||
tile.getGUINetworkData(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
|
||||
for (int i = 0; i < crafters.size(); i++)
|
||||
tile.sendGUINetworkData(this, (ICrafting) crafters.get(i));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.core.fluids;
|
||||
|
||||
import com.google.common.collect.ForwardingList;
|
||||
import forestry.core.fluids.tanks.FakeTank;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.inventory.ITileFilter;
|
||||
import forestry.core.network.PacketGuiInteger;
|
||||
@@ -22,6 +23,7 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
@@ -66,6 +68,15 @@ public class TankManager extends ForwardingList<StandardTank> implements IFluidH
|
||||
return tanks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends StandardTank> collection) {
|
||||
boolean changed = false;
|
||||
for (StandardTank tank : collection)
|
||||
changed |= add(tank);
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(StandardTank tank) {
|
||||
boolean added = tanks.add(tank);
|
||||
@@ -76,6 +87,10 @@ public class TankManager extends ForwardingList<StandardTank> implements IFluidH
|
||||
return added;
|
||||
}
|
||||
|
||||
public int maxMessageId() {
|
||||
return NETWORK_DATA * tanks.size();
|
||||
}
|
||||
|
||||
public void writeTanksToNBT(NBTTagCompound data) {
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
for (byte slot = 0; slot < tanks.size(); slot++) {
|
||||
@@ -134,6 +149,11 @@ public class TankManager extends ForwardingList<StandardTank> implements IFluidH
|
||||
tank.setFluid(null);
|
||||
}
|
||||
|
||||
public void initGuiData(Container container, ICrafting player) {
|
||||
for (StandardTank tank : tanks)
|
||||
initGuiData(container, player, tank.getTankIndex());
|
||||
}
|
||||
|
||||
public void initGuiData(Container container, ICrafting player, int tankIndex) {
|
||||
if (tankIndex >= tanks.size())
|
||||
return;
|
||||
@@ -150,6 +170,11 @@ public class TankManager extends ForwardingList<StandardTank> implements IFluidH
|
||||
Proxies.net.sendToPlayer(packet, (EntityPlayerMP)player);
|
||||
}
|
||||
|
||||
public void updateGuiData(Container container, List crafters) {
|
||||
for (StandardTank tank : tanks)
|
||||
updateGuiData(container, crafters, tank.getTankIndex());
|
||||
}
|
||||
|
||||
public void updateGuiData(Container container, List crafters, int tankIndex) {
|
||||
StandardTank tank = tanks.get(tankIndex);
|
||||
FluidStack fluidStack = tank.getFluid();
|
||||
@@ -225,26 +250,41 @@ public class TankManager extends ForwardingList<StandardTank> implements IFluidH
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
return fill(0, resource, doFill);
|
||||
for (StandardTank tank : tanks)
|
||||
if (tankAcceptsFluid(tank, resource))
|
||||
return fill(tank.getTankIndex(), resource, doFill);
|
||||
|
||||
return FakeTank.INSTANCE.fill(resource, doFill);
|
||||
}
|
||||
|
||||
public int fill(int tankIndex, FluidStack resource, boolean doFill) {
|
||||
if (tankIndex < 0 || tankIndex >= tanks.size() || resource == null)
|
||||
return 0;
|
||||
|
||||
return tanks.get(tankIndex).fill(resource, doFill);
|
||||
StandardTank tank = tanks.get(tankIndex);
|
||||
if (!tank.canBeFilledExternally())
|
||||
return 0;
|
||||
|
||||
return tank.fill(resource, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
|
||||
return drain(0, maxDrain, doDrain);
|
||||
for (StandardTank tank : tanks)
|
||||
if (tankCanDrain(tank))
|
||||
return drain(tank.getTankIndex(), maxDrain, doDrain);
|
||||
return FakeTank.INSTANCE.drain(maxDrain, doDrain);
|
||||
}
|
||||
|
||||
public FluidStack drain(int tankIndex, int maxDrain, boolean doDrain) {
|
||||
if (tankIndex < 0 || tankIndex >= tanks.size())
|
||||
return null;
|
||||
|
||||
return tanks.get(tankIndex).drain(maxDrain, doDrain);
|
||||
StandardTank tank = tanks.get(tankIndex);
|
||||
if (!tank.canBeDrainedExternally())
|
||||
return null;
|
||||
|
||||
return tank.drain(maxDrain, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -281,6 +321,10 @@ public class TankManager extends ForwardingList<StandardTank> implements IFluidH
|
||||
return get(tankIndex).getInfo();
|
||||
}
|
||||
|
||||
public FluidStack getFluid(int tankIndex) {
|
||||
return get(tankIndex).getFluid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardTank get(int tankIndex) {
|
||||
return tanks.get(tankIndex);
|
||||
@@ -294,24 +338,6 @@ public class TankManager extends ForwardingList<StandardTank> implements IFluidH
|
||||
fluidStack.amount = capacity;
|
||||
}
|
||||
|
||||
// Used to push fluids to surrounding blocks, missing code from Railcraft, if needed contact CovertJaguar
|
||||
// public void outputLiquid(AdjacentTileCache cache, ITileFilter filter, ForgeDirection[] sides, int tankIndex, int amount) {
|
||||
// for (ForgeDirection side : sides) {
|
||||
// TileEntity tile = cache.getTileOnSide(side);
|
||||
// if (!filter.matches(tile)) continue;
|
||||
// IFluidHandler tank = getTankFromTile(tile);
|
||||
// if (tank == null) continue;
|
||||
// outputLiquid((IFluidHandler) tile, side, tankIndex, amount);
|
||||
// }
|
||||
// }
|
||||
public void outputLiquid(IFluidHandler[] outputs, int tankIndex, int amount) {
|
||||
for (int side = 0; side < 6; side++) {
|
||||
IFluidHandler nearbyTank = outputs[side];
|
||||
if (nearbyTank != null)
|
||||
outputLiquid(nearbyTank, ForgeDirection.getOrientation(side), tankIndex, amount);
|
||||
}
|
||||
}
|
||||
|
||||
public static IFluidHandler getTankFromTile(TileEntity tile) {
|
||||
IFluidHandler tank = null;
|
||||
if (tile instanceof IFluidHandler)
|
||||
@@ -319,25 +345,18 @@ public class TankManager extends ForwardingList<StandardTank> implements IFluidH
|
||||
return tank;
|
||||
}
|
||||
|
||||
private void outputLiquid(IFluidHandler tank, ForgeDirection side, int tankIndex, int amount) {
|
||||
FluidStack available = drain(tankIndex, amount, false);
|
||||
if (available != null) {
|
||||
int used = tank.fill(side.getOpposite(), available, true);
|
||||
if (used > 0)
|
||||
drain(tankIndex, used, true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean tankAcceptsFluid(IFluidTank tank, FluidStack fluidStack) {
|
||||
private boolean tankAcceptsFluid(StandardTank tank, FluidStack fluidStack) {
|
||||
if (fluidStack == null)
|
||||
return false;
|
||||
if (!tank.canBeFilledExternally())
|
||||
return false;
|
||||
if (tank.fill(fluidStack, false) > 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean tankCanDrainFluid(IFluidTank tank, FluidStack fluidStack) {
|
||||
if (fluidStack == null)
|
||||
private boolean tankCanDrain(StandardTank tank) {
|
||||
if (!tank.canBeDrainedExternally())
|
||||
return false;
|
||||
FluidStack drained = tank.drain(1, false);
|
||||
if (drained != null && drained.amount > 0)
|
||||
@@ -345,4 +364,8 @@ public class TankManager extends ForwardingList<StandardTank> implements IFluidH
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean tankCanDrainFluid(StandardTank tank, FluidStack fluidStack) {
|
||||
return fluidStack != null && tankCanDrain(tank);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -25,7 +26,7 @@ import java.util.Collection;
|
||||
*/
|
||||
public class FilteredTank extends StandardTank {
|
||||
|
||||
private Collection<Fluid> filters;
|
||||
private HashSet<Fluid> filters;
|
||||
|
||||
public FilteredTank(int capacity, Fluid... filters) {
|
||||
this(capacity, Arrays.asList(filters), null);
|
||||
@@ -37,9 +38,14 @@ public class FilteredTank extends StandardTank {
|
||||
|
||||
public FilteredTank(int capacity, Collection<Fluid> filters, TileEntity tile) {
|
||||
super(capacity, tile);
|
||||
this.filters = filters;
|
||||
this.filters = new HashSet<Fluid>(filters);
|
||||
}
|
||||
|
||||
public void addFilter(Fluid filter) {
|
||||
if (!accepts(filter))
|
||||
filters.add(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, boolean doFill) {
|
||||
if (liquidMatchesFilter(resource))
|
||||
@@ -47,6 +53,7 @@ public class FilteredTank extends StandardTank {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accepts(Fluid fluid) {
|
||||
return filters.contains(fluid);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,12 @@ import net.minecraftforge.fluids.FluidTank;
|
||||
*/
|
||||
public class StandardTank extends FluidTank {
|
||||
|
||||
// defines how the tank responds to IFluidHandler requests
|
||||
public enum TankMode {
|
||||
DEFAULT, OUTPUT, INPUT, INTERNAL
|
||||
}
|
||||
|
||||
public TankMode tankMode = TankMode.DEFAULT;
|
||||
public static final int DEFAULT_COLOR = 0xFFFFFF;
|
||||
public int colorCache = DEFAULT_COLOR;
|
||||
private int tankIndex;
|
||||
@@ -92,9 +98,33 @@ public class StandardTank extends FluidTank {
|
||||
return 0;
|
||||
if (resource.amount <= 0)
|
||||
return 0;
|
||||
if (!accepts(resource.getFluid()))
|
||||
return 0;
|
||||
return super.fill(resource, doFill);
|
||||
}
|
||||
|
||||
public boolean accepts(Fluid fluid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canBeFilledExternally() {
|
||||
switch (tankMode) {
|
||||
case DEFAULT:
|
||||
case INPUT:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canBeDrainedExternally() {
|
||||
switch (tankMode) {
|
||||
case DEFAULT:
|
||||
case OUTPUT:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(int maxDrain, boolean doDrain) {
|
||||
if (maxDrain <= 0)
|
||||
|
||||
@@ -19,7 +19,6 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
|
||||
|
||||
import buildcraft.api.core.Position;
|
||||
import buildcraft.api.power.IPowerEmitter;
|
||||
@@ -31,7 +30,6 @@ import buildcraft.api.transport.IPipeTile.PipeType;
|
||||
|
||||
import forestry.core.TemperatureState;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.interfaces.IPowerHandler;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.proxy.Proxies;
|
||||
@@ -52,7 +50,6 @@ public abstract class Engine extends TileBase implements IPowerHandler, IPipeCon
|
||||
payload.intPayload[2] = heat;
|
||||
|
||||
payload.floatPayload[0] = pistonSpeedServer;
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
@@ -96,20 +93,7 @@ public abstract class Engine extends TileBase implements IPowerHandler, IPipeCon
|
||||
powerProvider.configure(10, 200, 10, 100000);
|
||||
}
|
||||
|
||||
protected ItemStack replenishByContainer(ItemStack inventoryStack, FluidContainerData container, StandardTank tank) {
|
||||
if (container == null)
|
||||
return inventoryStack;
|
||||
|
||||
if (tank.fill(container.fluid, false) >= container.fluid.amount) {
|
||||
tank.fill(container.fluid, true);
|
||||
if (container.filledContainer != null && container.filledContainer.getItem().hasContainerItem(container.filledContainer))
|
||||
inventoryStack = container.emptyContainer.copy();
|
||||
else
|
||||
inventoryStack.stackSize--;
|
||||
}
|
||||
|
||||
return inventoryStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotateAfterPlacement(World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack itemstack) {
|
||||
|
||||
@@ -22,15 +22,18 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.network.Packet;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.ISpecialInventory;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.core.EnumErrorCode;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.network.EntityNetData;
|
||||
@@ -38,11 +41,10 @@ import forestry.core.network.GuiId;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketInventoryStack;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.LiquidHelper;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.StringUtil;
|
||||
|
||||
public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedInventory, ILiquidTankContainer {
|
||||
|
||||
@@ -65,13 +67,17 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
|
||||
private final short inputSlot1 = 2;
|
||||
private final short outputSlot1 = 8;
|
||||
|
||||
public FluidStack resource = FluidRegistry.getFluidStack(Defaults.LIQUID_HONEY, HONEY_REQUIRED);
|
||||
@EntityNetData
|
||||
public StandardTank resourceTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
public FilteredTank resourceTank;
|
||||
|
||||
private final TankManager tankManager;
|
||||
|
||||
private final Stack<ItemStack> pendingProducts = new Stack<ItemStack>();
|
||||
|
||||
/* CONSTRUCTOR */
|
||||
public TileAnalyzer() {
|
||||
resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, FluidRegistry.getFluid(Defaults.LIQUID_HONEY));
|
||||
tankManager = new TankManager(resourceTank);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -92,8 +98,7 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
|
||||
|
||||
nbttagcompound.setInteger("AnalyzeTime", analyzeTime);
|
||||
|
||||
// / Resource tank
|
||||
resourceTank.writeToNBT(nbttagcompound);
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
|
||||
// / Pending Products
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
@@ -117,8 +122,7 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
|
||||
|
||||
analyzeTime = nbttagcompound.getInteger("AnalyzeTime");
|
||||
|
||||
// / Resource tank
|
||||
resourceTank.readFromNBT(nbttagcompound);
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
|
||||
// / Pending Products
|
||||
NBTTagList nbttaglist = nbttagcompound.getTagList("PendingProducts", 10);
|
||||
@@ -146,7 +150,7 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
|
||||
// Check if we have suitable items waiting in the can slot
|
||||
if (getStackInSlot(canSlot) != null) {
|
||||
FluidContainerData container = LiquidHelper.getLiquidContainer(getStackInSlot(canSlot));
|
||||
if (container != null && resource.isFluidEqual(container.fluid)) {
|
||||
if (container != null && resourceTank.accepts(container.fluid.getFluid())) {
|
||||
|
||||
setInventorySlotContents(canSlot, StackUtils.replenishByContainer(this, getStackInSlot(canSlot), container, resourceTank));
|
||||
if (getStackInSlot(canSlot).stackSize <= 0)
|
||||
@@ -187,7 +191,7 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
|
||||
return;
|
||||
|
||||
// We need our liquid honey
|
||||
if (resourceTank.getFluidAmount() < resource.amount) {
|
||||
if (resourceTank.getFluidAmount() < HONEY_REQUIRED) {
|
||||
setErrorState(EnumErrorCode.NORESOURCE);
|
||||
return;
|
||||
}
|
||||
@@ -208,7 +212,7 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
|
||||
|
||||
setInventorySlotContents(analyzeSlot, getStackInSlot(i));
|
||||
setInventorySlotContents(i, null);
|
||||
resourceTank.drain(resource.amount, true);
|
||||
resourceTank.drain(HONEY_REQUIRED, true);
|
||||
analyzeTime = TIME_TO_ANALYZE;
|
||||
sendNetworkUpdate();
|
||||
return;
|
||||
@@ -251,6 +255,7 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
|
||||
|
||||
/* SMP */
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
i -= tankManager.maxMessageId() + 1;
|
||||
switch (i) {
|
||||
case 0:
|
||||
analyzeTime = j;
|
||||
@@ -259,7 +264,8 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
|
||||
}
|
||||
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
||||
iCrafting.sendProgressBarUpdate(container, 0, analyzeTime);
|
||||
int i = tankManager.maxMessageId() + 1;
|
||||
iCrafting.sendProgressBarUpdate(container, i, analyzeTime);
|
||||
|
||||
}
|
||||
|
||||
@@ -388,7 +394,7 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
|
||||
if (!AlleleManager.alleleRegistry.isIndividual(stack)) {
|
||||
|
||||
FluidContainerData container = LiquidHelper.getLiquidContainer(stack);
|
||||
if (container == null || !container.fluid.isFluidEqual(resource))
|
||||
if (container == null || !resourceTank.accepts(container.fluid.getFluid()))
|
||||
return 0;
|
||||
|
||||
if (getStackInSlot(canSlot) == null) {
|
||||
@@ -423,33 +429,39 @@ public class TileAnalyzer extends TileBase implements ISpecialInventory, ISidedI
|
||||
}
|
||||
|
||||
/* ILIQUIDCONTAINER */
|
||||
@Override
|
||||
public TankManager getTankManager() {
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
|
||||
// We only accept what is already in the tank or valid ingredients
|
||||
if (resourceTank.getFluidAmount() > 0 && !resourceTank.getFluid().isFluidEqual(resource))
|
||||
return 0;
|
||||
else if (!LiquidHelper.isLiquid(Defaults.LIQUID_HONEY, resource))
|
||||
return 0;
|
||||
|
||||
int used = resourceTank.fill(resource, doFill);
|
||||
|
||||
if (doFill && used > 0)
|
||||
sendNetworkUpdate();
|
||||
|
||||
return used;
|
||||
return tankManager.fill(from, resource, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardTank[] getTanks() {
|
||||
return new StandardTank[] { resourceTank };
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
||||
return tankManager.drain(from, resource, doDrain);
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) {
|
||||
return resourceTank;
|
||||
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);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -352,37 +352,4 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
|
||||
return getInternalInventory().getSizeInventorySide(side);
|
||||
|
||||
}
|
||||
|
||||
/* IFLUIDHANDLER BASICS */
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
if (this instanceof ILiquidTankContainer) {
|
||||
StandardTank[] tanks = ((ILiquidTankContainer) this).getTanks();
|
||||
FluidTankInfo[] info = new FluidTankInfo[tanks.length];
|
||||
for (int i = 0; i < info.length; i++) {
|
||||
info[i] = tanks[i].getInfo();
|
||||
}
|
||||
return info;
|
||||
}
|
||||
return FakeTank.INFO;
|
||||
}
|
||||
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
||||
return resource != null ? drain(from, resource.amount, doDrain) : null;
|
||||
}
|
||||
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -54,17 +54,4 @@ public class ContainerAnalyzer extends ContainerLiquidTanks {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressBar(int i, int j) {
|
||||
tile.getGUINetworkData(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
|
||||
for (int i = 0; i < crafters.size(); i++)
|
||||
tile.sendGUINetworkData(this, (ICrafting) crafters.get(i));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -206,11 +206,4 @@ public class ContainerForestry extends Container {
|
||||
public boolean canInteractWith(EntityPlayer entityplayer) {
|
||||
return inventory.isUseableByPlayer(entityplayer);
|
||||
}
|
||||
|
||||
public void onTankUpdate(NBTTagCompound nbt) {
|
||||
}
|
||||
|
||||
public StandardTank getTank(int slot) {
|
||||
return FakeTank.INSTANCE;
|
||||
}
|
||||
}
|
||||
@@ -10,36 +10,29 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gui;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
|
||||
import forestry.api.core.IToolPipette;
|
||||
import forestry.core.fluids.tanks.FakeTank;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.PacketTankUpdate;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class ContainerLiquidTanks extends ContainerForestry {
|
||||
|
||||
private ILiquidTankContainer tanks;
|
||||
private ILiquidTankContainer tile;
|
||||
|
||||
public ContainerLiquidTanks(IInventory inventory, ILiquidTankContainer tanks) {
|
||||
public ContainerLiquidTanks(IInventory inventory, ILiquidTankContainer tile) {
|
||||
super(inventory);
|
||||
this.tanks = tanks;
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
public void handlePipetteClick(int slot, EntityPlayer player) {
|
||||
@@ -53,74 +46,52 @@ public class ContainerLiquidTanks extends ContainerForestry {
|
||||
return;
|
||||
|
||||
if (!Proxies.common.isSimulating(player.worldObj)) {
|
||||
|
||||
PacketPayload payload = new PacketPayload(1, 0, 0);
|
||||
payload.intPayload[0] = slot;
|
||||
Proxies.net.sendToServer(new PacketUpdate(PacketIds.PIPETTE_CLICK, payload));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
IToolPipette pipette = (IToolPipette) held;
|
||||
int liquidAmount = tanks.getTanks()[slot].getFluid().amount;
|
||||
StandardTank tank = tile.getTankManager().get(slot);
|
||||
int liquidAmount = tank.getFluid().amount;
|
||||
|
||||
if (pipette.canPipette(itemstack) && liquidAmount > 0) {
|
||||
|
||||
if (liquidAmount > 0) {
|
||||
int filled = pipette.fill(itemstack, tanks.getTanks()[slot].drain(1000, false),
|
||||
true);
|
||||
tanks.getTanks()[slot].drain(filled, true);
|
||||
FluidStack fillAmount = tank.drain(1000, false);
|
||||
int filled = pipette.fill(itemstack, fillAmount, true);
|
||||
tank.drain(filled, true);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
IFluidTank tank = tanks.getTanks()[slot];
|
||||
FluidStack potential = pipette.drain(itemstack, pipette.getCapacity(itemstack), false);
|
||||
if (potential != null)
|
||||
pipette.drain(itemstack, tank.fill(potential, true), true);
|
||||
|
||||
}
|
||||
}
|
||||
private Map<Integer, StandardTank> syncedFluids = new HashMap<Integer, StandardTank>();
|
||||
|
||||
@Override
|
||||
public void updateProgressBar(int messageId, int data) {
|
||||
super.updateProgressBar(messageId, data);
|
||||
|
||||
tile.getTankManager().processGuiUpdate(messageId, data);
|
||||
tile.getGUINetworkData(messageId, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
|
||||
for (int i = 0; i < tanks.getTanks().length; i++) {
|
||||
StandardTank tank = tanks.getTanks()[i];
|
||||
|
||||
// If null has been synced
|
||||
if (tank.getFluid() == null && getTank(i).getFluidAmount() <= 0)
|
||||
continue;
|
||||
// If fluid has been synced
|
||||
if (tank.getFluid() != null && tank.getFluid().isFluidStackIdentical(getTank(i).getFluid()))
|
||||
continue;
|
||||
|
||||
for (int j = 0; j < this.crafters.size(); ++j) {
|
||||
if (this.crafters.get(j) instanceof EntityPlayerMP) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) this.crafters.get(j);
|
||||
Proxies.net.sendToPlayer(new PacketTankUpdate(i, tank), player);
|
||||
}
|
||||
}
|
||||
|
||||
syncedFluids.put(i, new StandardTank(tank.getFluid() == null ? null : tank.getFluid().copy(), tank.getCapacity()));
|
||||
|
||||
}
|
||||
tile.getTankManager().updateGuiData(this, crafters);
|
||||
for (int i = 0; i < crafters.size(); i++)
|
||||
tile.sendGUINetworkData(this, (ICrafting) crafters.get(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTankUpdate(NBTTagCompound nbt) {
|
||||
int tankID = nbt.getByte("tank");
|
||||
int capacity = nbt.getShort("capacity");
|
||||
tanks.getTanks()[tankID].readFromNBT(nbt);
|
||||
|
||||
StandardTank tank = new StandardTank(capacity);
|
||||
tank.readFromNBT(nbt);
|
||||
syncedFluids.put(tankID, tank);
|
||||
public void addCraftingToCrafters(ICrafting icrafting) {
|
||||
super.addCraftingToCrafters(icrafting);
|
||||
tile.getTankManager().initGuiData(this, icrafting);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardTank getTank(int slot) {
|
||||
return syncedFluids.get(slot) == null ? FakeTank.INSTANCE : syncedFluids.get(slot);
|
||||
return tile.getTankManager().get(slot);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gui.widgets;
|
||||
|
||||
import forestry.farming.gui.ContainerFarm;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
@@ -49,7 +51,12 @@ public class TankWidget extends Widget {
|
||||
}
|
||||
|
||||
public StandardTank getTank() {
|
||||
return ((ContainerForestry) manager.gui.inventorySlots).getTank(slot);
|
||||
Container container = manager.gui.inventorySlots;
|
||||
if (container instanceof ContainerLiquidTanks)
|
||||
return ((ContainerLiquidTanks) container).getTank(slot);
|
||||
else if (container instanceof ContainerFarm)
|
||||
return ((ContainerFarm) container).getTank(slot);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,11 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.interfaces;
|
||||
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
public interface ILiquidTankContainer extends IFluidHandler {
|
||||
|
||||
StandardTank[] getTanks();
|
||||
TankManager getTankManager();
|
||||
void getGUINetworkData(int messageId, int data);
|
||||
void sendGUINetworkData(Container container, ICrafting iCrafting);
|
||||
|
||||
}
|
||||
@@ -141,10 +141,9 @@ public class PacketHandler {
|
||||
packetTR.readData(data);
|
||||
onGenomeTrackerUpdate(packetTR);
|
||||
break;
|
||||
case PacketIds.TANK_UPDATE:
|
||||
PacketTankUpdate packetAB = new PacketTankUpdate();
|
||||
packetAB.readData(data);
|
||||
onTankUpdate(packetAB);
|
||||
case PacketIds.GUI_INTEGER:
|
||||
PacketGuiInteger packet = new PacketGuiInteger();
|
||||
packet.readData(data);
|
||||
break;
|
||||
default:
|
||||
for (forestry.core.interfaces.IPacketHandler handler : PluginManager.packetHandlers)
|
||||
@@ -168,17 +167,6 @@ public class PacketHandler {
|
||||
channel.sendTo(packet, player);
|
||||
}
|
||||
|
||||
|
||||
private void onTankUpdate(PacketTankUpdate packetAB) {
|
||||
assert FMLCommonHandler.instance().getEffectiveSide().isClient();
|
||||
|
||||
EntityPlayer player = Proxies.common.getPlayer();
|
||||
|
||||
if (player.openContainer instanceof ContainerForestry) {
|
||||
((ContainerForestry)player.openContainer).onTankUpdate(packetAB.nbttagcompound);
|
||||
}
|
||||
}
|
||||
|
||||
private void onGenomeTrackerUpdate(PacketNBT packet) {
|
||||
assert FMLCommonHandler.instance().getEffectiveSide().isClient();
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@ public class PacketIds {
|
||||
|
||||
public static final int LEAF_UPDATE = 90;
|
||||
|
||||
public static final int TANK_UPDATE = 91;
|
||||
public static final int GUI_INTEGER = 92;
|
||||
|
||||
// Propolis pipe
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* 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.network;
|
||||
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
|
||||
public class PacketTankUpdate extends PacketNBT {
|
||||
|
||||
public PacketTankUpdate(int tankSlot, StandardTank tank) {
|
||||
super(PacketIds.TANK_UPDATE);
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setByte("tank", (byte) tankSlot);
|
||||
nbt.setShort("capacity", (short) tank.getCapacity());
|
||||
tank.writeToNBT(nbt);
|
||||
this.nbttagcompound = nbt;
|
||||
}
|
||||
|
||||
public PacketTankUpdate() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.ISpecialInventory;
|
||||
@@ -29,7 +30,9 @@ import forestry.api.fuels.FuelManager;
|
||||
import forestry.core.EnumErrorCode;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.gadgets.Engine;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
@@ -65,8 +68,9 @@ public class EngineBronze extends Engine implements ISpecialInventory, ILiquidTa
|
||||
else
|
||||
shutdown = false;
|
||||
}
|
||||
public StandardTank fuelTank = new StandardTank(Defaults.ENGINE_TANK_CAPACITY);
|
||||
public StandardTank heatingTank = new StandardTank(Defaults.ENGINE_TANK_CAPACITY);
|
||||
public FilteredTank fuelTank;
|
||||
public FilteredTank heatingTank;
|
||||
private final TankManager tankManager;
|
||||
private final TileInventoryAdapter inventory;
|
||||
public int burnTime;
|
||||
public int totalTime;
|
||||
@@ -81,6 +85,16 @@ public class EngineBronze extends Engine implements ISpecialInventory, ILiquidTa
|
||||
setHints(Config.hints.get("engine.bronze"));
|
||||
|
||||
inventory = new TileInventoryAdapter(this, 1, "Items");
|
||||
|
||||
fuelTank = new FilteredTank(Defaults.ENGINE_TANK_CAPACITY, FuelManager.bronzeEngineFuel.keySet());
|
||||
fuelTank.tankMode = StandardTank.TankMode.INPUT;
|
||||
heatingTank = new FilteredTank(Defaults.ENGINE_TANK_CAPACITY, FluidRegistry.LAVA);
|
||||
heatingTank.tankMode = StandardTank.TankMode.INPUT;
|
||||
this.tankManager = new TankManager(fuelTank, heatingTank);
|
||||
}
|
||||
|
||||
public TankManager getTankManager() {
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,9 +115,9 @@ public class EngineBronze extends Engine implements ISpecialInventory, ILiquidTa
|
||||
|
||||
StandardTank tank = null;
|
||||
|
||||
if (container.fluid.isFluidEqual(LiquidHelper.getLiquid(Defaults.LIQUID_LAVA, 1)))
|
||||
if (heatingTank.accepts(container.fluid.getFluid()))
|
||||
tank = heatingTank;
|
||||
else if (FuelManager.bronzeEngineFuel.containsKey(container.fluid))
|
||||
else if (fuelTank.accepts(container.fluid.getFluid()))
|
||||
tank = fuelTank;
|
||||
|
||||
if (tank != null) {
|
||||
@@ -219,7 +233,7 @@ public class EngineBronze extends Engine implements ISpecialInventory, ILiquidTa
|
||||
* Returns the fuel value (power per cycle) an item of the passed ItemStack
|
||||
* provides
|
||||
*
|
||||
* @param item
|
||||
* @param fluid
|
||||
* @return
|
||||
*/
|
||||
private int determineFuelValue(Fluid fluid) {
|
||||
@@ -231,16 +245,31 @@ public class EngineBronze extends Engine implements ISpecialInventory, ILiquidTa
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fuelid
|
||||
* @param fluid
|
||||
* @return Duration of burn cycle of one bucket
|
||||
*/
|
||||
private int determineBurnTime(Fluid item) {
|
||||
if (FuelManager.bronzeEngineFuel.containsKey(item))
|
||||
return FuelManager.bronzeEngineFuel.get(item).burnDuration;
|
||||
private int determineBurnTime(Fluid fluid) {
|
||||
if (FuelManager.bronzeEngineFuel.containsKey(fluid))
|
||||
return FuelManager.bronzeEngineFuel.get(fluid).burnDuration;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected ItemStack replenishByContainer(ItemStack inventoryStack, FluidContainerData container, StandardTank tank) {
|
||||
if (container == null)
|
||||
return inventoryStack;
|
||||
|
||||
if (tank.fill(container.fluid, false) >= container.fluid.amount) {
|
||||
tank.fill(container.fluid, true);
|
||||
if (container.filledContainer != null && container.filledContainer.getItem().hasContainerItem(container.filledContainer))
|
||||
inventoryStack = container.emptyContainer.copy();
|
||||
else
|
||||
inventoryStack.stackSize--;
|
||||
}
|
||||
|
||||
return inventoryStack;
|
||||
}
|
||||
|
||||
// / STATE INFORMATION
|
||||
@Override
|
||||
public boolean isBurning() {
|
||||
@@ -284,13 +313,7 @@ public class EngineBronze extends Engine implements ISpecialInventory, ILiquidTa
|
||||
currentFluidId = fluid.getID();
|
||||
}
|
||||
|
||||
fuelTank = new StandardTank(Defaults.ENGINE_TANK_CAPACITY);
|
||||
heatingTank = new StandardTank(Defaults.ENGINE_TANK_CAPACITY);
|
||||
if (nbt.hasKey("FuelSlot")) {
|
||||
fuelTank.readFromNBT(nbt.getCompoundTag("FuelSlot"));
|
||||
heatingTank.readFromNBT(nbt.getCompoundTag("HeatingSlot"));
|
||||
}
|
||||
|
||||
tankManager.readTanksFromNBT(nbt);
|
||||
inventory.readFromNBT(nbt);
|
||||
|
||||
}
|
||||
@@ -310,21 +333,14 @@ public class EngineBronze extends Engine implements ISpecialInventory, ILiquidTa
|
||||
if (fluid != null)
|
||||
nbt.setString("currentFluid", fluid.getName());
|
||||
|
||||
NBTTagCompound nbtFuelSlot = new NBTTagCompound();
|
||||
NBTTagCompound nbtHeatingSlot = new NBTTagCompound();
|
||||
|
||||
fuelTank.writeToNBT(nbtFuelSlot);
|
||||
heatingTank.writeToNBT(nbtHeatingSlot);
|
||||
|
||||
nbt.setTag("FuelSlot", nbtFuelSlot);
|
||||
nbt.setTag("HeatingSlot", nbtHeatingSlot);
|
||||
|
||||
tankManager.writeTanksToNBT(nbt);
|
||||
inventory.writeToNBT(nbt);
|
||||
}
|
||||
|
||||
/* GUI */
|
||||
@Override
|
||||
public void getGUINetworkData(int id, int data) {
|
||||
id -= tankManager.maxMessageId() + 1;
|
||||
|
||||
switch (id) {
|
||||
case 0:
|
||||
@@ -350,12 +366,13 @@ public class EngineBronze extends Engine implements ISpecialInventory, ILiquidTa
|
||||
|
||||
@Override
|
||||
public void sendGUINetworkData(Container containerEngine, ICrafting iCrafting) {
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, 0, burnTime);
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, 1, totalTime);
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, 2, currentOutput);
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, 3, (int) storedEnergy);
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, 4, heat);
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, 5, currentFluidId);
|
||||
int i = tankManager.maxMessageId() + 1;
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, i, burnTime);
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, i + 1, totalTime);
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, i + 2, currentOutput);
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, i + 3, (int) storedEnergy);
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, i + 4, heat);
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, i + 5, currentFluidId);
|
||||
}
|
||||
|
||||
/* IINVENTORY */
|
||||
@@ -423,6 +440,13 @@ public class EngineBronze extends Engine implements ISpecialInventory, ILiquidTa
|
||||
*/
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
|
||||
if (slotIndex == SLOT_CAN) {
|
||||
FluidStack fluid = LiquidHelper.getFluidStackInContainer(itemstack);
|
||||
if (fluid == null || fluid.amount <= 0)
|
||||
return false;
|
||||
return fuelTank.accepts(fluid.getFluid()) || heatingTank.accepts(fluid.getFluid());
|
||||
}
|
||||
|
||||
return super.isItemValidForSlot(slotIndex, itemstack);
|
||||
}
|
||||
|
||||
@@ -441,23 +465,36 @@ public class EngineBronze extends Engine implements ISpecialInventory, ILiquidTa
|
||||
return null;
|
||||
}
|
||||
|
||||
// / ITANKCONTAINER
|
||||
// IFluidHandler
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
// We only accept biomass and water as fuel
|
||||
int used = 0;
|
||||
|
||||
if (FuelManager.bronzeEngineFuel.containsKey(resource))
|
||||
used = fuelTank.fill(resource, doFill);
|
||||
|
||||
if (LiquidHelper.isLiquid(Defaults.LIQUID_LAVA, resource))
|
||||
used = heatingTank.fill(resource, doFill);
|
||||
|
||||
return used;
|
||||
return tankManager.fill(from, resource, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardTank[] getTanks() {
|
||||
return new StandardTank[] { fuelTank, heatingTank };
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -204,7 +204,7 @@ public class EngineCopper extends Engine implements ISpecialInventory, ISidedInv
|
||||
/**
|
||||
* Returns the fuel value (power per cycle) an item of the passed ItemStack provides
|
||||
*
|
||||
* @param item
|
||||
* @param fuel
|
||||
* @return
|
||||
*/
|
||||
private int determineFuelValue(ItemStack fuel) {
|
||||
@@ -217,7 +217,7 @@ public class EngineCopper extends Engine implements ISpecialInventory, ISidedInv
|
||||
/**
|
||||
* Returns the fuel value (power per cycle) an item of the passed ItemStack provides
|
||||
*
|
||||
* @param item
|
||||
* @param fuel
|
||||
* @return
|
||||
*/
|
||||
private int determineBurnDuration(ItemStack fuel) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
@@ -30,6 +31,8 @@ import forestry.core.EnumErrorCode;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.interfaces.IRenderableMachine;
|
||||
@@ -41,6 +44,8 @@ import forestry.core.utils.LiquidHelper;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.Utils;
|
||||
import forestry.plugins.PluginIC2;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
public class MachineGenerator extends TileBase implements ISpecialInventory, ILiquidTankContainer, IRenderableMachine {
|
||||
|
||||
@@ -49,7 +54,8 @@ public class MachineGenerator extends TileBase implements ISpecialInventory, ILi
|
||||
public static final int maxEnergy = 30000;
|
||||
|
||||
@EntityNetData
|
||||
public StandardTank resourceTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
public FilteredTank resourceTank;
|
||||
private final TankManager tankManager;
|
||||
private int tickCount = 0;
|
||||
|
||||
InventoryAdapter inventory = new InventoryAdapter(1, "Items");
|
||||
@@ -58,6 +64,9 @@ public class MachineGenerator extends TileBase implements ISpecialInventory, ILi
|
||||
public MachineGenerator() {
|
||||
setHints(Config.hints.get("generator"));
|
||||
|
||||
resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, FuelManager.generatorFuel.keySet());
|
||||
tankManager = new TankManager(resourceTank);
|
||||
|
||||
if (PluginIC2.instance.isAvailable()) {
|
||||
ic2EnergySource = new BasicSource(this, maxEnergy, 1);
|
||||
}
|
||||
@@ -79,10 +88,7 @@ public class MachineGenerator extends TileBase implements ISpecialInventory, ILi
|
||||
|
||||
if (ic2EnergySource != null) ic2EnergySource.writeToNBT(nbttagcompound);
|
||||
|
||||
NBTTagCompound NBTresourceSlot = new NBTTagCompound();
|
||||
resourceTank.writeToNBT(NBTresourceSlot);
|
||||
nbttagcompound.setTag("ResourceTank", NBTresourceSlot);
|
||||
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
inventory.writeToNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@@ -92,10 +98,7 @@ public class MachineGenerator extends TileBase implements ISpecialInventory, ILi
|
||||
|
||||
if (ic2EnergySource != null) ic2EnergySource.readFromNBT(nbttagcompound);
|
||||
|
||||
resourceTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
if (nbttagcompound.hasKey("ResourceTank"))
|
||||
resourceTank.readFromNBT(nbttagcompound.getCompoundTag("ResourceTank"));
|
||||
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
inventory.readFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@@ -120,7 +123,8 @@ public class MachineGenerator extends TileBase implements ISpecialInventory, ILi
|
||||
if (inventory.getStackInSlot(SLOT_CAN) != null) {
|
||||
FluidContainerData container = LiquidHelper.getLiquidContainer(inventory.getStackInSlot(SLOT_CAN));
|
||||
if (container != null)
|
||||
if (FuelManager.generatorFuel.containsKey(container.fluid)) {
|
||||
|
||||
if (resourceTank.accepts(container.fluid.getFluid())) {
|
||||
inventory.setInventorySlotContents(SLOT_CAN, StackUtils.replenishByContainer(this, inventory.getStackInSlot(SLOT_CAN), container, resourceTank));
|
||||
if (inventory.getStackInSlot(SLOT_CAN).stackSize <= 0)
|
||||
inventory.setInventorySlotContents(SLOT_CAN, null);
|
||||
@@ -135,7 +139,7 @@ public class MachineGenerator extends TileBase implements ISpecialInventory, ILi
|
||||
|
||||
ic2EnergySource.updateEntity();
|
||||
|
||||
if (resourceTank.getFluidAmount() > 0 && FuelManager.generatorFuel.containsKey(resourceTank.getFluid())) {
|
||||
if (resourceTank.getFluidAmount() > 0) {
|
||||
GeneratorFuel fuel = FuelManager.generatorFuel.get(resourceTank.getFluid());
|
||||
|
||||
if (resourceTank.getFluidAmount() >= fuel.fuelConsumed.amount &&
|
||||
@@ -183,17 +187,16 @@ public class MachineGenerator extends TileBase implements ISpecialInventory, ILi
|
||||
|
||||
/* SMP GUI */
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
|
||||
switch (i) {
|
||||
case 0:
|
||||
int firstMessageId = tankManager.maxMessageId() + 1;
|
||||
if (i == firstMessageId) {
|
||||
if (ic2EnergySource != null) ic2EnergySource.setEnergyStored(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
||||
int firstMessageId = tankManager.maxMessageId() + 1;
|
||||
if (ic2EnergySource != null) {
|
||||
iCrafting.sendProgressBarUpdate(container, 0, (short) ic2EnergySource.getEnergyStored());
|
||||
iCrafting.sendProgressBarUpdate(container, firstMessageId, (short) ic2EnergySource.getEnergyStored());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,24 +271,39 @@ public class MachineGenerator extends TileBase implements ISpecialInventory, ILi
|
||||
return null;
|
||||
}
|
||||
|
||||
/* ILIQUIDCONTAINER IMPLEMENTATION */
|
||||
/* ILiquidTankContainer */
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
// We only accept water
|
||||
if (!FuelManager.generatorFuel.containsKey(resource))
|
||||
return 0;
|
||||
|
||||
int used = resourceTank.fill(resource, doFill);
|
||||
|
||||
if (doFill && used > 0)
|
||||
// TODO: Slow down updates
|
||||
sendNetworkUpdate();
|
||||
|
||||
return used;
|
||||
return tankManager.fill(from, resource, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardTank[] getTanks() {
|
||||
return new StandardTank[] { resourceTank };
|
||||
public TankManager getTankManager() {
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -43,17 +43,4 @@ public class ContainerEngineBronze extends ContainerLiquidTanks {
|
||||
return engine.isUseableByPlayer(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressBar(int i, int j) {
|
||||
engine.getGUINetworkData(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
|
||||
for (int i = 0; i < crafters.size(); i++)
|
||||
engine.sendGUINetworkData(this, (ICrafting) crafters.get(i));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,19 +37,6 @@ public class ContainerGenerator extends ContainerLiquidTanks {
|
||||
this.addSlot(new Slot(player, i, 8 + i * 18, 142));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressBar(int i, int j) {
|
||||
tile.getGUINetworkData(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
|
||||
for (int i = 0; i < crafters.size(); i++)
|
||||
tile.sendGUINetworkData(this, (ICrafting) crafters.get(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer entityplayer) {
|
||||
return tile.isUseableByPlayer(entityplayer);
|
||||
|
||||
@@ -12,10 +12,12 @@ package forestry.factory.gadgets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
@@ -25,21 +27,22 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
import buildcraft.api.gates.ITrigger;
|
||||
import buildcraft.api.power.PowerHandler;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.recipes.IBottlerManager;
|
||||
import forestry.api.recipes.RecipeManagers;
|
||||
import forestry.core.EnumErrorCode;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.gadgets.TilePowered;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
@@ -86,10 +89,13 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq
|
||||
|
||||
public static class RecipeManager implements IBottlerManager {
|
||||
public static ArrayList<MachineBottler.Recipe> recipes = new ArrayList<MachineBottler.Recipe>();
|
||||
public static HashSet<Fluid> recipeFluids = new HashSet<Fluid>();
|
||||
|
||||
@Override
|
||||
public void addRecipe(int cyclesPerUnit, FluidStack input, ItemStack can, ItemStack bottled) {
|
||||
recipes.add(new MachineBottler.Recipe(cyclesPerUnit, input, can, bottled));
|
||||
if (input != null)
|
||||
recipeFluids.add(input.getFluid());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,8 +119,8 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq
|
||||
if(FluidContainerRegistry.isEmptyContainer(empty)) {
|
||||
ItemStack filled = FluidContainerRegistry.fillFluidContainer(res, empty);
|
||||
if(filled != null) {
|
||||
RecipeManagers.bottlerManager.addRecipe(CYCLES_FILLING_DEFAULT, FluidContainerRegistry.getFluidForFilledItem(filled), empty, filled);
|
||||
return findMatchingRecipe(res, empty);
|
||||
FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(filled);
|
||||
return findMatchingRecipe(fluidStack, empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,14 +133,7 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq
|
||||
* @return true if any recipe has a matching input
|
||||
*/
|
||||
public static boolean isInput(FluidStack res) {
|
||||
for (int i = 0; i < recipes.size(); i++) {
|
||||
Recipe recipe = recipes.get(i);
|
||||
if (recipe.hasInput(res))
|
||||
return true;
|
||||
}
|
||||
|
||||
return FluidRegistry.isFluidRegistered(res.getFluid());
|
||||
|
||||
return recipeFluids.contains(res.getFluid());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -149,7 +148,8 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq
|
||||
}
|
||||
|
||||
@EntityNetData
|
||||
public StandardTank resourceTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
public FilteredTank resourceTank;
|
||||
private final TankManager tankManager;
|
||||
|
||||
private final InventoryAdapter inventory = new InventoryAdapter(3, "Items");
|
||||
|
||||
@@ -162,6 +162,8 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq
|
||||
|
||||
public MachineBottler() {
|
||||
setHints(Config.hints.get("bottler"));
|
||||
resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluids);
|
||||
tankManager = new TankManager(resourceTank);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,10 +191,7 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq
|
||||
nbttagcompound.setInteger("FillingTotalTime", fillingTotalTime);
|
||||
nbttagcompound.setBoolean("ProductPending", productPending);
|
||||
|
||||
NBTTagCompound NBTresourceSlot = new NBTTagCompound();
|
||||
resourceTank.writeToNBT(NBTresourceSlot);
|
||||
nbttagcompound.setTag("ResourceTank", NBTresourceSlot);
|
||||
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
inventory.writeToNBT(nbttagcompound);
|
||||
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
@@ -215,9 +214,7 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq
|
||||
fillingTotalTime = nbttagcompound.getInteger("FillingTotalTime");
|
||||
productPending = nbttagcompound.getBoolean("ProductPending");
|
||||
|
||||
resourceTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
if (nbttagcompound.hasKey("ResourceTank"))
|
||||
resourceTank.readFromNBT(nbttagcompound.getCompoundTag("ResourceTank"));
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
|
||||
inventory.readFromNBT(nbttagcompound);
|
||||
|
||||
@@ -371,7 +368,7 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq
|
||||
|
||||
/* SMP GUI */
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
|
||||
i -= tankManager.maxMessageId() + 1;
|
||||
switch (i) {
|
||||
case 0:
|
||||
fillingTime = j;
|
||||
@@ -383,8 +380,9 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq
|
||||
}
|
||||
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
||||
iCrafting.sendProgressBarUpdate(container, 0, fillingTime);
|
||||
iCrafting.sendProgressBarUpdate(container, 1, fillingTotalTime);
|
||||
int i = tankManager.maxMessageId() + 1;
|
||||
iCrafting.sendProgressBarUpdate(container, i, fillingTime);
|
||||
iCrafting.sendProgressBarUpdate(container, i + 1, fillingTotalTime);
|
||||
}
|
||||
|
||||
/* IINVENTORY */
|
||||
@@ -479,23 +477,37 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq
|
||||
|
||||
/* ILIQUIDCONTAINER */
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
|
||||
if (!RecipeManager.isInput(resource))
|
||||
return 0;
|
||||
|
||||
int used = resourceTank.fill(resource, doFill);
|
||||
|
||||
if (doFill && used > 0)
|
||||
// TODO: Slow down updates
|
||||
sendNetworkUpdate();
|
||||
|
||||
return used;
|
||||
public TankManager getTankManager() {
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardTank[] getTanks() {
|
||||
return new StandardTank[] { resourceTank };
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
return tankManager.fill(from, resource, doFill);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// ITRIGGERPROVIDER
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.factory.gadgets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -27,9 +28,11 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
import buildcraft.api.gates.ITrigger;
|
||||
import buildcraft.api.power.PowerHandler;
|
||||
@@ -41,6 +44,8 @@ import forestry.core.config.Config;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.config.ForestryItem;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.gadgets.TilePowered;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
@@ -141,6 +146,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
|
||||
public static class RecipeManager implements ICarpenterManager {
|
||||
|
||||
public static ArrayList<MachineCarpenter.Recipe> recipes = new ArrayList<MachineCarpenter.Recipe>();
|
||||
public static HashSet<Fluid> recipeFluids = new HashSet<Fluid>();
|
||||
|
||||
@Override
|
||||
public void addCrating(ItemStack itemStack) {
|
||||
@@ -170,6 +176,8 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
|
||||
@Override
|
||||
public void addRecipe(int packagingTime, FluidStack liquid, ItemStack box, ItemStack product, Object materials[]) {
|
||||
recipes.add(new Recipe(packagingTime, liquid, box, ShapedRecipeCustom.createShapedRecipe(product, materials)));
|
||||
if (liquid != null)
|
||||
recipeFluids.add(liquid.getFluid());
|
||||
}
|
||||
|
||||
public static Recipe findMatchingRecipe(FluidStack liquid, ItemStack item, InventoryCrafting inventorycrafting, World world) {
|
||||
@@ -182,12 +190,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
|
||||
}
|
||||
|
||||
public static boolean isResourceLiquid(FluidStack liquid) {
|
||||
for (Recipe recipe : recipes) {
|
||||
if (recipe.hasLiquid(liquid))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return recipeFluids.contains(liquid.getFluid());
|
||||
}
|
||||
|
||||
public static boolean isBox(ItemStack resource) {
|
||||
@@ -214,7 +217,8 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
|
||||
|
||||
/* MEMBER */
|
||||
@EntityNetData
|
||||
public StandardTank resourceTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
public FilteredTank resourceTank;
|
||||
private final TankManager tankManager;
|
||||
private final TileInventoryAdapter craftingInventory;
|
||||
private final TileInventoryAdapter accessibleInventory;
|
||||
public MachineCarpenter.Recipe currentRecipe;
|
||||
@@ -231,8 +235,11 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
|
||||
|
||||
public MachineCarpenter() {
|
||||
setHints(Config.hints.get("carpenter"));
|
||||
resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluids);
|
||||
craftingInventory = new TileInventoryAdapter(this, 10, "CraftItems");
|
||||
accessibleInventory = (TileInventoryAdapter) new TileInventoryAdapter(this, 30, "Items").configureSided(Defaults.FACINGS, SLOT_BOX, 20);
|
||||
|
||||
tankManager = new TankManager(resourceTank);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -258,10 +265,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
|
||||
nbttagcompound.setInteger("PackageTime", packageTime);
|
||||
nbttagcompound.setInteger("PackageTotalTime", totalTime);
|
||||
|
||||
NBTTagCompound NBTresourceSlot = new NBTTagCompound();
|
||||
|
||||
resourceTank.writeToNBT(NBTresourceSlot);
|
||||
nbttagcompound.setTag("ResourceTank", NBTresourceSlot);
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
|
||||
craftingInventory.writeToNBT(nbttagcompound);
|
||||
accessibleInventory.writeToNBT(nbttagcompound);
|
||||
@@ -287,9 +291,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
|
||||
packageTime = nbttagcompound.getInteger("PackageTime");
|
||||
totalTime = nbttagcompound.getInteger("PackageTotalTime");
|
||||
|
||||
resourceTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
if (nbttagcompound.hasKey("ResourceTank"))
|
||||
resourceTank.readFromNBT(nbttagcompound.getCompoundTag("ResourceTank"));
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
|
||||
if (nbttagcompound.hasKey("CraftItems"))
|
||||
craftingInventory.readFromNBT(nbttagcompound);
|
||||
@@ -602,7 +604,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
|
||||
|
||||
/* SMP GUI */
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
|
||||
i -= tankManager.maxMessageId() + 1;
|
||||
switch (i) {
|
||||
case 0:
|
||||
packageTime = j;
|
||||
@@ -614,8 +616,9 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
|
||||
}
|
||||
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
||||
iCrafting.sendProgressBarUpdate(container, 0, packageTime);
|
||||
iCrafting.sendProgressBarUpdate(container, 1, totalTime);
|
||||
int i = tankManager.maxMessageId() + 1;
|
||||
iCrafting.sendProgressBarUpdate(container, i, packageTime);
|
||||
iCrafting.sendProgressBarUpdate(container, i + 1, totalTime);
|
||||
}
|
||||
|
||||
/* ISIDEDINVENTORY */
|
||||
@@ -670,18 +673,40 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
|
||||
// ILIQUIDCONTAINER IMPLEMENTATION
|
||||
@Override
|
||||
public int fill(ForgeDirection direction, FluidStack resource, boolean doFill) {
|
||||
int used = resourceTank.fill(resource, doFill);
|
||||
|
||||
if (doFill && used > 0)
|
||||
// TODO: Slow down updates
|
||||
sendNetworkUpdate();
|
||||
|
||||
return used;
|
||||
return tankManager.fill(direction, resource, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardTank[] getTanks() {
|
||||
return new StandardTank[] { resourceTank };
|
||||
public TankManager getTankManager() {
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public void resetProductDisplay(InventoryCrafting craftMatrix) {
|
||||
setCurrentRecipe(RecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), craftMatrix, getWorldObj()));
|
||||
}
|
||||
|
||||
// ITRIGGERPROVIDER
|
||||
|
||||
@@ -23,6 +23,8 @@ import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import buildcraft.api.power.PowerHandler;
|
||||
@@ -38,9 +40,12 @@ import forestry.core.interfaces.ICraftingPlan;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.ShapedRecipeCustom;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
public class MachineFabricator extends TilePowered implements ICrafter, ISpecialInventory, ILiquidTankContainer {
|
||||
|
||||
@@ -229,14 +234,21 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
public static final short SLOT_INVENTORY_COUNT = 18;
|
||||
|
||||
/* MEMBER */
|
||||
private final TankManager tankManager;
|
||||
private FilteredTank moltenTank;
|
||||
private final InventoryAdapter inventory = new InventoryAdapter(30, "Items");
|
||||
private StandardTank moltenTank = new StandardTank(2 * Defaults.BUCKET_VOLUME);
|
||||
private final int moltenTankIndex;
|
||||
private int heat = 0;
|
||||
private int guiMeltingPoint = 0;
|
||||
|
||||
private FluidStack pendingSmelt;
|
||||
|
||||
public MachineFabricator() {
|
||||
Fluid liquidGlass = FluidRegistry.getFluid(Defaults.LIQUID_GLASS);
|
||||
moltenTank = new FilteredTank(2 * Defaults.BUCKET_VOLUME, liquidGlass);
|
||||
moltenTank.tankMode = StandardTank.TankMode.INTERNAL;
|
||||
tankManager = new TankManager(moltenTank);
|
||||
moltenTankIndex = moltenTank.getTankIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -262,9 +274,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
nbttagcompound.setInteger("Heat", heat);
|
||||
|
||||
// Tank
|
||||
NBTTagCompound nbtMoltenTank = new NBTTagCompound();
|
||||
moltenTank.writeToNBT(nbtMoltenTank);
|
||||
nbttagcompound.setTag("MoltenTank", nbtMoltenTank);
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
|
||||
// Pending Smelt
|
||||
if (pendingSmelt != null) {
|
||||
@@ -284,9 +294,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
heat = nbttagcompound.getInteger("Heat");
|
||||
|
||||
// Tank
|
||||
moltenTank = new StandardTank(Defaults.BUCKET_VOLUME * 2);
|
||||
if (nbttagcompound.hasKey("MoltenTank"))
|
||||
moltenTank.readFromNBT(nbttagcompound.getCompoundTag("MoltenTank"));
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
|
||||
// Pending Smelt
|
||||
if (nbttagcompound.hasKey("PendingSmelt")) {
|
||||
@@ -303,13 +311,6 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
|
||||
// Remove smelt if we have gone below metling point
|
||||
if (moltenTank.getFluidAmount() > 0) {
|
||||
Smelting smelt = RecipeManager.findMatchingSmelting(moltenTank.getFluid());
|
||||
if (smelt != null && heat < smelt.meltingPoint)
|
||||
moltenTank.drain(5, true);
|
||||
}
|
||||
|
||||
// Add pending smelt
|
||||
if (pendingSmelt != null) {
|
||||
|
||||
@@ -319,16 +320,19 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
if (pendingSmelt.amount <= 0)
|
||||
pendingSmelt = null;
|
||||
// Smelt if necessary and possible
|
||||
} else if (moltenTank.getFluidAmount() < moltenTank.getCapacity())
|
||||
if (inventory.getStackInSlot(SLOT_METAL) != null) {
|
||||
} else if (moltenTank.getFluidAmount() < moltenTank.getCapacity() && inventory.getStackInSlot(SLOT_METAL) != null) {
|
||||
Smelting smelt = RecipeManager.findMatchingSmelting(inventory.getStackInSlot(SLOT_METAL));
|
||||
if (smelt != null && smelt.meltingPoint <= heat) {
|
||||
|
||||
Smelting smelt = RecipeManager.findMatchingSmelting(inventory.getStackInSlot(SLOT_METAL));
|
||||
if (smelt != null && smelt.meltingPoint <= heat) {
|
||||
|
||||
this.decrStackSize(SLOT_METAL, 1);
|
||||
pendingSmelt = smelt.product.copy();
|
||||
}
|
||||
this.decrStackSize(SLOT_METAL, 1);
|
||||
pendingSmelt = smelt.product.copy();
|
||||
}
|
||||
} else if (moltenTank.getFluidAmount() > 0) {
|
||||
// Remove smelt if we have gone below melting point
|
||||
Smelting smelt = RecipeManager.findMatchingSmelting(moltenTank.getFluid());
|
||||
if (smelt != null && heat < smelt.meltingPoint)
|
||||
moltenTank.drain(5, true);
|
||||
}
|
||||
|
||||
this.dissipateHeat();
|
||||
}
|
||||
@@ -475,19 +479,18 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
|
||||
/* SMP */
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
int messageId = tankManager.maxMessageId() + 1;
|
||||
|
||||
if (i == messageId)
|
||||
heat = j;
|
||||
break;
|
||||
case 1:
|
||||
else if (i == messageId + 1)
|
||||
guiMeltingPoint = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
||||
iCrafting.sendProgressBarUpdate(container, 0, heat);
|
||||
iCrafting.sendProgressBarUpdate(container, 1, getMeltingPoint());
|
||||
int messageId = tankManager.maxMessageId() + 1;
|
||||
iCrafting.sendProgressBarUpdate(container, messageId, heat);
|
||||
iCrafting.sendProgressBarUpdate(container, messageId + 1, getMeltingPoint());
|
||||
}
|
||||
|
||||
// / ISPECIALINVENTORY
|
||||
@@ -579,7 +582,38 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
|
||||
/* ILIQUIDCONTAINER */
|
||||
@Override
|
||||
public StandardTank[] getTanks() {
|
||||
return new StandardTank[] { moltenTank };
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,9 +12,11 @@ package forestry.factory.gadgets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
@@ -23,6 +25,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
@@ -44,10 +47,12 @@ import forestry.core.network.GuiId;
|
||||
import forestry.core.triggers.ForestryTrigger;
|
||||
import forestry.core.utils.EnumTankLevel;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.LiquidHelper;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.Utils;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
public class MachineFermenter extends TilePowered implements ISidedInventory, ILiquidTankContainer {
|
||||
|
||||
@@ -117,10 +122,16 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
public static class RecipeManager implements IFermenterManager {
|
||||
|
||||
public static ArrayList<MachineFermenter.Recipe> recipes = new ArrayList<MachineFermenter.Recipe>();
|
||||
public static HashSet<Fluid> recipeFluidInputs = new HashSet<Fluid>();
|
||||
public static HashSet<Fluid> recipeFluidOutputs = new HashSet<Fluid>();
|
||||
|
||||
@Override
|
||||
public void addRecipe(ItemStack resource, int fermentationValue, float modifier, FluidStack output, FluidStack liquid) {
|
||||
recipes.add(new Recipe(resource, fermentationValue, modifier, output, liquid));
|
||||
if (liquid != null)
|
||||
recipeFluidInputs.add(liquid.getFluid());
|
||||
if (output != null)
|
||||
recipeFluidOutputs.add(output.getFluid());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -151,21 +162,11 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
}
|
||||
|
||||
public static boolean isLiquidResource(FluidStack liquid) {
|
||||
for (int i = 0; i < recipes.size(); i++) {
|
||||
Recipe recipe = recipes.get(i);
|
||||
if (recipe.liquid.isFluidEqual(liquid))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return recipeFluidInputs.contains(liquid.getFluid());
|
||||
}
|
||||
|
||||
public static boolean isLiquidProduct(FluidStack liquid) {
|
||||
for (int i = 0; i < recipes.size(); i++) {
|
||||
Recipe recipe = recipes.get(i);
|
||||
if (recipe.output.isFluidEqual(liquid))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return recipeFluidOutputs.contains(liquid.getFluid());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -180,9 +181,12 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
}
|
||||
}
|
||||
@EntityNetData
|
||||
public StandardTank resourceTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
public FilteredTank resourceTank;
|
||||
@EntityNetData
|
||||
public StandardTank productTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
public FilteredTank productTank;
|
||||
|
||||
private final TankManager tankManager;
|
||||
|
||||
private final InventoryAdapter inventory = new InventoryAdapter(5, "Items");
|
||||
private Recipe currentRecipe;
|
||||
private float currentResourceModifier;
|
||||
@@ -194,6 +198,11 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
|
||||
public MachineFermenter() {
|
||||
setHints(Config.hints.get("fermenter"));
|
||||
resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluidInputs);
|
||||
resourceTank.tankMode = StandardTank.TankMode.INPUT;
|
||||
productTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluidOutputs);
|
||||
productTank.tankMode = StandardTank.TankMode.OUTPUT;
|
||||
tankManager = new TankManager(resourceTank, productTank);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -221,15 +230,7 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
nbttagcompound.setInteger("FuelTotalTime", fuelTotalTime);
|
||||
nbttagcompound.setInteger("FuelCurrentFerment", fuelCurrentFerment);
|
||||
|
||||
NBTTagCompound NBTresourceSlot = new NBTTagCompound();
|
||||
NBTTagCompound NBTproductSlot = new NBTTagCompound();
|
||||
|
||||
resourceTank.writeToNBT(NBTresourceSlot);
|
||||
productTank.writeToNBT(NBTproductSlot);
|
||||
|
||||
nbttagcompound.setTag("ResourceTank", NBTresourceSlot);
|
||||
nbttagcompound.setTag("ProductTank", NBTproductSlot);
|
||||
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
inventory.writeToNBT(nbttagcompound);
|
||||
|
||||
}
|
||||
@@ -244,13 +245,7 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
fuelTotalTime = nbttagcompound.getInteger("FuelTotalTime");
|
||||
fuelCurrentFerment = nbttagcompound.getInteger("FuelCurrentFerment");
|
||||
|
||||
resourceTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
productTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
if (nbttagcompound.hasKey("ResourceTank")) {
|
||||
resourceTank.readFromNBT(nbttagcompound.getCompoundTag("ResourceTank"));
|
||||
productTank.readFromNBT(nbttagcompound.getCompoundTag("ProductTank"));
|
||||
}
|
||||
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
inventory.readFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@@ -511,28 +506,25 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
|
||||
/* SMP GUI */
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
int firstMessageId = tankManager.maxMessageId() + 1;
|
||||
|
||||
switch (i) {
|
||||
case 0:
|
||||
if (i == firstMessageId)
|
||||
fuelBurnTime = j;
|
||||
break;
|
||||
case 1:
|
||||
else if (i == firstMessageId + 1)
|
||||
fuelTotalTime = j;
|
||||
break;
|
||||
case 2:
|
||||
else if (i == firstMessageId + 2)
|
||||
fermentationTime = j;
|
||||
break;
|
||||
case 3:
|
||||
else if (i == firstMessageId + 3)
|
||||
fermentationTotalTime = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
||||
iCrafting.sendProgressBarUpdate(container, 0, fuelBurnTime);
|
||||
iCrafting.sendProgressBarUpdate(container, 1, fuelTotalTime);
|
||||
iCrafting.sendProgressBarUpdate(container, 2, fermentationTime);
|
||||
iCrafting.sendProgressBarUpdate(container, 3, fermentationTotalTime);
|
||||
int firstMessageId = tankManager.maxMessageId() + 1;
|
||||
|
||||
iCrafting.sendProgressBarUpdate(container, firstMessageId, fuelBurnTime);
|
||||
iCrafting.sendProgressBarUpdate(container, firstMessageId + 1, fuelTotalTime);
|
||||
iCrafting.sendProgressBarUpdate(container, firstMessageId + 2, fermentationTime);
|
||||
iCrafting.sendProgressBarUpdate(container, firstMessageId + 3, fermentationTotalTime);
|
||||
}
|
||||
|
||||
/* INVENTORY */
|
||||
@@ -663,20 +655,15 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
return super.getAccessibleSlotsFromSide(side);
|
||||
}
|
||||
|
||||
// ILIQUIDCONTAINER IMPLEMENTATION
|
||||
/* ILiquidTankContainer */
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
return resourceTank.fill(resource, doFill);
|
||||
}
|
||||
|
||||
if (!RecipeManager.isLiquidResource(resource))
|
||||
return 0;
|
||||
|
||||
int used = resourceTank.fill(resource, doFill);
|
||||
|
||||
if (doFill && used > 0)
|
||||
// updateNetworkTime.markTime(worldObj);
|
||||
sendNetworkUpdate();
|
||||
|
||||
return used;
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
||||
return tankManager.drain(from, resource, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -685,8 +672,22 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardTank[] getTanks() {
|
||||
return new StandardTank[] { resourceTank, productTank };
|
||||
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 TankManager getTankManager() {
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
return tankManager.getTankInfo(from);
|
||||
}
|
||||
|
||||
// ITRIGGERPROVIDER
|
||||
|
||||
@@ -23,7 +23,9 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import buildcraft.api.gates.ITrigger;
|
||||
@@ -43,11 +45,13 @@ import forestry.core.network.EntityNetData;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.triggers.ForestryTrigger;
|
||||
import forestry.core.utils.EnumTankLevel;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.LiquidHelper;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.Utils;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
public class MachineMoistener extends TilePowered implements ISpecialInventory, ISidedInventory, ILiquidTankContainer {
|
||||
|
||||
@@ -127,7 +131,8 @@ public class MachineMoistener extends TilePowered implements ISpecialInventory,
|
||||
}
|
||||
|
||||
@EntityNetData
|
||||
public StandardTank resourceTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
public FilteredTank resourceTank;
|
||||
private final TankManager tankManager;
|
||||
private final InventoryAdapter inventory = new InventoryAdapter(12, "Items");
|
||||
//private ItemStack[] inventoryStacks = new ItemStack[12];
|
||||
public MachineMoistener.Recipe currentRecipe;
|
||||
@@ -141,6 +146,8 @@ public class MachineMoistener extends TilePowered implements ISpecialInventory,
|
||||
|
||||
public MachineMoistener() {
|
||||
setHints(Config.hints.get("moistener"));
|
||||
resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, FluidRegistry.WATER);
|
||||
tankManager = new TankManager(resourceTank);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -162,11 +169,7 @@ public class MachineMoistener extends TilePowered implements ISpecialInventory,
|
||||
nbttagcompound.setInteger("TotalTime", totalTime);
|
||||
nbttagcompound.setInteger("ProductionTime", productionTime);
|
||||
|
||||
NBTTagCompound NBTresourceSlot = new NBTTagCompound();
|
||||
|
||||
resourceTank.writeToNBT(NBTresourceSlot);
|
||||
nbttagcompound.setTag("ResourceTank", NBTresourceSlot);
|
||||
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
inventory.writeToNBT(nbttagcompound);
|
||||
|
||||
// Write pending product
|
||||
@@ -190,10 +193,7 @@ public class MachineMoistener extends TilePowered implements ISpecialInventory,
|
||||
totalTime = nbttagcompound.getInteger("TotalTime");
|
||||
productionTime = nbttagcompound.getInteger("ProductionTime");
|
||||
|
||||
resourceTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
if (nbttagcompound.hasKey("ResourceTank"))
|
||||
resourceTank.readFromNBT(nbttagcompound.getCompoundTag("ResourceTank"));
|
||||
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
inventory.readFromNBT(nbttagcompound);
|
||||
|
||||
// Load pending product
|
||||
@@ -215,7 +215,7 @@ public class MachineMoistener extends TilePowered implements ISpecialInventory,
|
||||
// Check if we have suitable water container waiting in the item slot
|
||||
if (inventory.getStackInSlot(SLOT_PRODUCT) != null) {
|
||||
FluidContainerData container = LiquidHelper.getLiquidContainer(inventory.getStackInSlot(SLOT_PRODUCT));
|
||||
if (container != null && container.fluid.isFluidEqual(STACK_WATER)) {
|
||||
if (container != null && resourceTank.accepts(container.fluid.getFluid())) {
|
||||
|
||||
inventory.setInventorySlotContents(SLOT_PRODUCT, StackUtils.replenishByContainer(this, inventory.getStackInSlot(SLOT_PRODUCT), container, resourceTank));
|
||||
if (inventory.getStackInSlot(SLOT_PRODUCT).stackSize <= 0)
|
||||
@@ -633,7 +633,7 @@ public class MachineMoistener extends TilePowered implements ISpecialInventory,
|
||||
public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) {
|
||||
|
||||
FluidContainerData container = LiquidHelper.getLiquidContainer(stack);
|
||||
if (container != null && container.fluid.isFluidEqual(STACK_WATER)) {
|
||||
if (container != null && resourceTank.accepts(container.fluid.getFluid())) {
|
||||
return inventory.addStack(stack, SLOT_PRODUCT, 1, false, doAdd);
|
||||
}
|
||||
|
||||
@@ -675,24 +675,44 @@ public class MachineMoistener extends TilePowered implements ISpecialInventory,
|
||||
return StackUtils.EMPTY_STACK_ARRAY;
|
||||
}
|
||||
|
||||
/* ILIQUIDCONTAINER */
|
||||
/* ILiquidTankContainer */
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
int used = resourceTank.fill(resource, doFill);
|
||||
|
||||
if (doFill && used > 0)
|
||||
sendNetworkUpdate();
|
||||
|
||||
return used;
|
||||
return tankManager.fill(from, resource, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardTank[] getTanks() {
|
||||
return new StandardTank[] { resourceTank };
|
||||
public TankManager getTankManager() {
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/* SMP GUI */
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
i -= tankManager.maxMessageId() + 1;
|
||||
|
||||
switch (i) {
|
||||
case 0:
|
||||
@@ -711,10 +731,11 @@ public class MachineMoistener extends TilePowered implements ISpecialInventory,
|
||||
}
|
||||
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
||||
iCrafting.sendProgressBarUpdate(container, 0, burnTime);
|
||||
iCrafting.sendProgressBarUpdate(container, 1, totalTime);
|
||||
iCrafting.sendProgressBarUpdate(container, 2, productionTime);
|
||||
iCrafting.sendProgressBarUpdate(container, 3, timePerItem);
|
||||
int i = tankManager.maxMessageId() + 1;
|
||||
iCrafting.sendProgressBarUpdate(container, i, burnTime);
|
||||
iCrafting.sendProgressBarUpdate(container, i + 1, totalTime);
|
||||
iCrafting.sendProgressBarUpdate(container, i + 2, productionTime);
|
||||
iCrafting.sendProgressBarUpdate(container, i + 3, timePerItem);
|
||||
}
|
||||
|
||||
// ITRIGGERPROVIDER
|
||||
|
||||
@@ -21,6 +21,8 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import buildcraft.api.gates.ITrigger;
|
||||
@@ -35,11 +37,13 @@ import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.triggers.ForestryTrigger;
|
||||
import forestry.core.utils.Fluids;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.LiquidHelper;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.Utils;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
public class MachineRaintank extends TileBase implements ISidedInventory, ILiquidTankContainer {
|
||||
|
||||
@@ -49,7 +53,8 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
private static final FluidStack STACK_WATER = LiquidHelper.getLiquid(Defaults.LIQUID_WATER, Defaults.RAINTANK_AMOUNT_PER_UPDATE);
|
||||
|
||||
/* MEMBER */
|
||||
public StandardTank resourceTank = new StandardTank(Defaults.RAINTANK_TANK_CAPACITY);
|
||||
public FilteredTank resourceTank;
|
||||
private final TankManager tankManager;
|
||||
private final InventoryAdapter inventory = new InventoryAdapter(3, "Items");
|
||||
private boolean isValidBiome = true;
|
||||
private int fillingTime;
|
||||
@@ -58,6 +63,9 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
public MachineRaintank() {
|
||||
setHints(Config.hints.get("raintank"));
|
||||
|
||||
resourceTank = new FilteredTank(Defaults.RAINTANK_TANK_CAPACITY, FluidRegistry.WATER);
|
||||
tankManager = new TankManager(resourceTank);
|
||||
|
||||
// Raintanks in desert and snow biomes are useless
|
||||
if (worldObj != null) {
|
||||
BiomeGenBase biome = Utils.getBiomeAt(worldObj, xCoord, zCoord);
|
||||
@@ -84,10 +92,7 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
|
||||
nbttagcompound.setBoolean("IsValidBiome", isValidBiome);
|
||||
|
||||
NBTTagCompound NBTresourceSlot = new NBTTagCompound();
|
||||
resourceTank.writeToNBT(NBTresourceSlot);
|
||||
nbttagcompound.setTag("ResourceTank", NBTresourceSlot);
|
||||
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
inventory.writeToNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@@ -97,10 +102,7 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
|
||||
isValidBiome = nbttagcompound.getBoolean("IsValidBiome");
|
||||
|
||||
resourceTank = new StandardTank(Defaults.RAINTANK_TANK_CAPACITY);
|
||||
if (nbttagcompound.hasKey("ResourceTank"))
|
||||
resourceTank.readFromNBT(nbttagcompound.getCompoundTag("ResourceTank"));
|
||||
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
inventory.readFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@@ -267,6 +269,7 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
|
||||
/* SMP GUI */
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
i -= tankManager.maxMessageId() + 1;
|
||||
switch (i) {
|
||||
case 0:
|
||||
fillingTime = j;
|
||||
@@ -275,33 +278,43 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
}
|
||||
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
||||
iCrafting.sendProgressBarUpdate(container, 0, fillingTime);
|
||||
int i = tankManager.maxMessageId() + 1;
|
||||
iCrafting.sendProgressBarUpdate(container, i, fillingTime);
|
||||
}
|
||||
|
||||
// / ILIQUIDCONTAINER IMPLEMENTATION
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
// We only accept water
|
||||
if (!resource.isFluidEqual(STACK_WATER))
|
||||
return 0;
|
||||
|
||||
int used = resourceTank.fill(resource, doFill);
|
||||
|
||||
if (doFill && used > 0)
|
||||
// updateNetworkTime.markTime(worldObj);
|
||||
sendNetworkUpdate();
|
||||
|
||||
return used;
|
||||
return tankManager.fill(from, resource, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int quantityMax, boolean doEmpty) {
|
||||
return resourceTank.drain(quantityMax, doEmpty);
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
||||
return tankManager.drain(from, resource, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardTank[] getTanks() {
|
||||
return new StandardTank[] { resourceTank };
|
||||
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 TankManager getTankManager() {
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
return tankManager.getTankInfo(from);
|
||||
}
|
||||
|
||||
/* ITRIGGERPROVIDER */
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.factory.gadgets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
@@ -25,6 +26,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
@@ -45,10 +47,13 @@ import forestry.core.network.GuiId;
|
||||
import forestry.core.triggers.ForestryTrigger;
|
||||
import forestry.core.utils.EnumTankLevel;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.LiquidHelper;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.Utils;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
public class MachineSqueezer extends TilePowered implements ISpecialInventory, ISidedInventory, ILiquidTankContainer {
|
||||
|
||||
@@ -82,10 +87,13 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
|
||||
public static class RecipeManager implements ISqueezerManager {
|
||||
public static ArrayList<MachineSqueezer.Recipe> recipes = new ArrayList<MachineSqueezer.Recipe>();
|
||||
public static HashSet<Fluid> recipeFluids = new HashSet<Fluid>();
|
||||
|
||||
@Override
|
||||
public void addRecipe(int timePerItem, ItemStack[] resources, FluidStack liquid, ItemStack remnants, int chance) {
|
||||
recipes.add(new MachineSqueezer.Recipe(timePerItem, resources, liquid, remnants, chance));
|
||||
if (liquid != null)
|
||||
recipeFluids.add(liquid.getFluid());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,8 +123,9 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
}
|
||||
|
||||
/* MEMBER */
|
||||
private final TankManager tankManager;
|
||||
@EntityNetData
|
||||
public StandardTank productTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
public FilteredTank productTank;
|
||||
|
||||
private final InventoryAdapter inventory = new InventoryAdapter(12, "Items");
|
||||
private Recipe currentRecipe;
|
||||
@@ -128,6 +137,9 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
|
||||
public MachineSqueezer() {
|
||||
setHints(Config.hints.get("squeezer"));
|
||||
productTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluids);
|
||||
productTank.tankMode = StandardTank.TankMode.OUTPUT;
|
||||
tankManager = new TankManager(productTank);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -180,10 +192,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
}
|
||||
nbttagcompound.setTag("PendingLiquids", nbttaglist);
|
||||
|
||||
// ProductTank
|
||||
NBTTagCompound NBTproductSlot = new NBTTagCompound();
|
||||
productTank.writeToNBT(NBTproductSlot);
|
||||
nbttagcompound.setTag("ProductTank", NBTproductSlot);
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -210,10 +219,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
pendingLiquids.add(FluidStack.loadFluidStackFromNBT(nbttagcompound1));
|
||||
}
|
||||
|
||||
// Product tank
|
||||
productTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
if (nbttagcompound.hasKey("ProductTank"))
|
||||
productTank.readFromNBT(nbttagcompound.getCompoundTag("ProductTank"));
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
|
||||
checkRecipe();
|
||||
}
|
||||
@@ -377,6 +383,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
|
||||
/* SMP GUI */
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
i -= tankManager.maxMessageId() + 1;
|
||||
switch (i) {
|
||||
case 0:
|
||||
productionTime = j;
|
||||
@@ -388,8 +395,9 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
}
|
||||
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
||||
iCrafting.sendProgressBarUpdate(container, 0, productionTime);
|
||||
iCrafting.sendProgressBarUpdate(container, 1, timePerItem);
|
||||
int i = tankManager.maxMessageId() + 1;
|
||||
iCrafting.sendProgressBarUpdate(container, i, productionTime);
|
||||
iCrafting.sendProgressBarUpdate(container, i + 1, timePerItem);
|
||||
}
|
||||
|
||||
/* IINVENTORY */
|
||||
@@ -477,7 +485,10 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
}
|
||||
|
||||
if(slotIndex >= SLOT_RESOURCE_1 && slotIndex < SLOT_RESOURCE_1 + SLOTS_RESOURCE_COUNT) {
|
||||
return !LiquidHelper.isEmptyContainer(itemstack);
|
||||
if (LiquidHelper.isEmptyContainer(itemstack))
|
||||
return false;
|
||||
FluidStack fluid = LiquidHelper.getFluidStackInContainer(itemstack);
|
||||
return productTank.accepts(fluid.getFluid());
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -521,13 +532,37 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
|
||||
/* ILIQUIDCONTAINER IMPLEMENTATION */
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int quantityMax, boolean doEmpty) {
|
||||
return productTank.drain(quantityMax, doEmpty);
|
||||
public TankManager getTankManager() {
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardTank[] getTanks() {
|
||||
return new StandardTank[] { productTank };
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
return tankManager.fill(from, resource, doFill);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/* ITRIGGERPROVIDER */
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.factory.gadgets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -23,6 +24,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
@@ -43,10 +45,13 @@ import forestry.core.network.GuiId;
|
||||
import forestry.core.triggers.ForestryTrigger;
|
||||
import forestry.core.utils.EnumTankLevel;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.LiquidHelper;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.Utils;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
public class MachineStill extends TilePowered implements ISpecialInventory, ISidedInventory, ILiquidTankContainer {
|
||||
|
||||
@@ -84,10 +89,16 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
|
||||
public static class RecipeManager implements IStillManager {
|
||||
public static ArrayList<MachineStill.Recipe> recipes = new ArrayList<MachineStill.Recipe>();
|
||||
public static HashSet<Fluid> recipeFluidInputs = new HashSet<Fluid>();
|
||||
public static HashSet<Fluid> recipeFluidOutputs = new HashSet<Fluid>();
|
||||
|
||||
@Override
|
||||
public void addRecipe(int timePerUnit, FluidStack input, FluidStack output) {
|
||||
recipes.add(new MachineStill.Recipe(timePerUnit, input, output));
|
||||
if (input != null)
|
||||
recipeFluidInputs.add(input.getFluid());
|
||||
if (output != null)
|
||||
recipeFluidOutputs.add(output.getFluid());
|
||||
}
|
||||
|
||||
public static Recipe findMatchingRecipe(FluidStack item) {
|
||||
@@ -100,7 +111,7 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
}
|
||||
|
||||
public static boolean isInput(FluidStack res) {
|
||||
return findMatchingRecipe(res) != null;
|
||||
return recipeFluidInputs.contains(res.getFluid());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -116,9 +127,10 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
|
||||
/* MEMBER */
|
||||
@EntityNetData
|
||||
public StandardTank resourceTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
public FilteredTank resourceTank;
|
||||
@EntityNetData
|
||||
public StandardTank productTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
public FilteredTank productTank;
|
||||
private final TankManager tankManager;
|
||||
|
||||
private final InventoryAdapter inventory = new InventoryAdapter(3, "Items");
|
||||
|
||||
@@ -129,6 +141,11 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
|
||||
public MachineStill() {
|
||||
setHints(Config.hints.get("still"));
|
||||
resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluidInputs);
|
||||
resourceTank.tankMode = StandardTank.TankMode.INPUT;
|
||||
productTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluidOutputs);
|
||||
productTank.tankMode = StandardTank.TankMode.OUTPUT;
|
||||
tankManager = new TankManager(resourceTank, productTank);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -153,15 +170,7 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
nbttagcompound.setInteger("DistillationTime", distillationTime);
|
||||
nbttagcompound.setInteger("DistillationTotalTime", distillationTotalTime);
|
||||
|
||||
NBTTagCompound NBTresourceSlot = new NBTTagCompound();
|
||||
NBTTagCompound NBTproductSlot = new NBTTagCompound();
|
||||
|
||||
resourceTank.writeToNBT(NBTresourceSlot);
|
||||
productTank.writeToNBT(NBTproductSlot);
|
||||
|
||||
nbttagcompound.setTag("ResourceTank", NBTresourceSlot);
|
||||
nbttagcompound.setTag("ProductTank", NBTproductSlot);
|
||||
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
inventory.writeToNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@@ -172,13 +181,7 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
distillationTime = nbttagcompound.getInteger("DistillationTime");
|
||||
distillationTotalTime = nbttagcompound.getInteger("DistillationTotalTime");
|
||||
|
||||
resourceTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
productTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
if (nbttagcompound.hasKey("ResourceTank")) {
|
||||
resourceTank.readFromNBT(nbttagcompound.getCompoundTag("ResourceTank"));
|
||||
productTank.readFromNBT(nbttagcompound.getCompoundTag("ProductTank"));
|
||||
}
|
||||
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
inventory.readFromNBT(nbttagcompound);
|
||||
|
||||
checkRecipe();
|
||||
@@ -191,7 +194,7 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
if (inventory.getStackInSlot(SLOT_CAN) != null) {
|
||||
FluidContainerData container = LiquidHelper.getLiquidContainer(inventory.getStackInSlot(SLOT_CAN));
|
||||
|
||||
if (container != null && RecipeManager.isInput(container.fluid)) {
|
||||
if (container != null && resourceTank.accepts(container.fluid.getFluid())) {
|
||||
|
||||
inventory.setInventorySlotContents(SLOT_CAN, StackUtils.replenishByContainer(this, inventory.getStackInSlot(SLOT_CAN), container, resourceTank));
|
||||
if (inventory.getStackInSlot(SLOT_CAN).stackSize <= 0)
|
||||
@@ -319,7 +322,7 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
|
||||
/* SMP GUI */
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
|
||||
i -= tankManager.maxMessageId() + 1;
|
||||
switch (i) {
|
||||
case 0:
|
||||
distillationTime = j;
|
||||
@@ -331,8 +334,9 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
}
|
||||
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
||||
iCrafting.sendProgressBarUpdate(container, 0, distillationTime);
|
||||
iCrafting.sendProgressBarUpdate(container, 1, distillationTotalTime);
|
||||
int i = tankManager.maxMessageId() + 1;
|
||||
iCrafting.sendProgressBarUpdate(container, i, distillationTime);
|
||||
iCrafting.sendProgressBarUpdate(container, i + 1, distillationTotalTime);
|
||||
}
|
||||
|
||||
/* ISPECIALINVENTORY */
|
||||
@@ -341,7 +345,7 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
int inventorySlot;
|
||||
|
||||
FluidContainerData container = LiquidHelper.getLiquidContainer(stack);
|
||||
if (container != null && RecipeManager.isInput(container.fluid))
|
||||
if (container != null && resourceTank.accepts(container.fluid.getFluid()))
|
||||
inventorySlot = SLOT_CAN;
|
||||
else if (LiquidHelper.isEmptyContainer(stack))
|
||||
inventorySlot = SLOT_RESOURCE;
|
||||
@@ -456,35 +460,45 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
|
||||
if(slotIndex == SLOT_CAN) {
|
||||
FluidContainerData container = LiquidHelper.getLiquidContainer(itemstack);
|
||||
return container != null && RecipeManager.isInput(container.fluid);
|
||||
return container != null && resourceTank.accepts(container.fluid.getFluid());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ILIQUIDCONTAINER */
|
||||
/* ILiquidTankContainer */
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
return tankManager.fill(from, resource, doFill);
|
||||
}
|
||||
|
||||
if (!MachineStill.RecipeManager.isInput(resource))
|
||||
return 0;
|
||||
|
||||
int used = resourceTank.fill(resource, doFill);
|
||||
|
||||
if (doFill && used > 0)
|
||||
sendNetworkUpdate();
|
||||
|
||||
return used;
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
||||
return tankManager.drain(from, resource, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int quantityMax, boolean doEmpty) {
|
||||
return productTank.drain(quantityMax, doEmpty);
|
||||
return tankManager.drain(from, quantityMax, doEmpty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardTank[] getTanks() {
|
||||
return new StandardTank[] { resourceTank, productTank };
|
||||
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 TankManager getTankManager() {
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
return tankManager.getTankInfo(from);
|
||||
}
|
||||
|
||||
/* ITRIGGERPROVIDER */
|
||||
|
||||
@@ -42,19 +42,6 @@ public class ContainerBottler extends ContainerLiquidTanks {
|
||||
|
||||
}
|
||||
|
||||
// @Override client side only
|
||||
public void updateProgressBar(int i, int j) {
|
||||
tile.getGUINetworkData(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
|
||||
for (int i = 0; i < crafters.size(); i++)
|
||||
tile.sendGUINetworkData(this, (ICrafting) crafters.get(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer entityplayer) {
|
||||
return tile.isUseableByPlayer(entityplayer);
|
||||
|
||||
@@ -12,7 +12,6 @@ package forestry.factory.gui;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCraftResult;
|
||||
import net.minecraft.inventory.Slot;
|
||||
@@ -110,19 +109,9 @@ public class ContainerCarpenter extends ContainerLiquidTanks implements IContain
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressBar(int i, int j) {
|
||||
machine.getGUINetworkData(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
|
||||
for (int i = 0; i < crafters.size(); i++) {
|
||||
machine.sendGUINetworkData(this, (ICrafting) crafters.get(i));
|
||||
}
|
||||
|
||||
updateProductSlot();
|
||||
}
|
||||
|
||||
@@ -150,8 +139,7 @@ public class ContainerCarpenter extends ContainerLiquidTanks implements IContain
|
||||
|
||||
private void resetProductDisplay() {
|
||||
if (machine != null) {
|
||||
machine.setCurrentRecipe(MachineCarpenter.RecipeManager.findMatchingRecipe(machine.resourceTank.getFluid(), machine.getBoxStack(), craftMatrix,
|
||||
machine.getWorldObj()));
|
||||
machine.resetProductDisplay(craftMatrix);
|
||||
updateProductSlot();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,17 +55,4 @@ public class ContainerFabricator extends ContainerLiquidTanks {
|
||||
|
||||
}
|
||||
|
||||
// @Override client side only
|
||||
public void updateProgressBar(int i, int j) {
|
||||
tile.getGUINetworkData(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
|
||||
for (int i = 0; i < crafters.size(); i++)
|
||||
tile.sendGUINetworkData(this, (ICrafting) crafters.get(i));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -43,19 +43,6 @@ public class ContainerFermenter extends ContainerLiquidTanks {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressBar(int i, int j) {
|
||||
fermenter.getGUINetworkData(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
|
||||
for (int i = 0; i < crafters.size(); i++)
|
||||
fermenter.sendGUINetworkData(this, (ICrafting) crafters.get(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer entityplayer) {
|
||||
return fermenter.isUseableByPlayer(entityplayer);
|
||||
|
||||
@@ -57,19 +57,6 @@ public class ContainerMoistener extends ContainerLiquidTanks implements IContain
|
||||
|
||||
}
|
||||
|
||||
// @Override client side only
|
||||
public void updateProgressBar(int i, int j) {
|
||||
tile.getGUINetworkData(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
|
||||
for (int i = 0; i < crafters.size(); i++)
|
||||
tile.sendGUINetworkData(this, (ICrafting) crafters.get(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraftMatrixChanged(IInventory iinventory, int slot) {
|
||||
inventory.setInventorySlotContents(slot, iinventory.getStackInSlot(slot));
|
||||
|
||||
@@ -40,19 +40,6 @@ public class ContainerRaintank extends ContainerLiquidTanks {
|
||||
|
||||
}
|
||||
|
||||
// @Override client side only
|
||||
public void updateProgressBar(int i, int j) {
|
||||
tile.getGUINetworkData(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
|
||||
for (int i = 0; i < crafters.size(); i++)
|
||||
tile.sendGUINetworkData(this, (ICrafting) crafters.get(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer entityplayer) {
|
||||
return tile.isUseableByPlayer(entityplayer);
|
||||
|
||||
@@ -50,17 +50,4 @@ public class ContainerSqueezer extends ContainerLiquidTanks {
|
||||
addSlot(new Slot(player, j1, 8 + j1 * 18, 142));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressBar(int i, int j) {
|
||||
tile.getGUINetworkData(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
|
||||
for (int i = 0; i < crafters.size(); i++)
|
||||
tile.sendGUINetworkData(this, (ICrafting) crafters.get(i));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,19 +39,6 @@ public class ContainerStill extends ContainerLiquidTanks {
|
||||
|
||||
}
|
||||
|
||||
// @Override client side only
|
||||
public void updateProgressBar(int i, int j) {
|
||||
processor.getGUINetworkData(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
|
||||
for (int i = 0; i < crafters.size(); i++)
|
||||
processor.sendGUINetworkData(this, (ICrafting) crafters.get(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer entityplayer) {
|
||||
return processor.isUseableByPlayer(entityplayer);
|
||||
|
||||
@@ -284,7 +284,7 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent {
|
||||
@Override
|
||||
public ITileStructure getCentralTE() {
|
||||
|
||||
if (!isIntegratedIntoStructure())
|
||||
if (!isIntegratedIntoStructure() || !hasMaster())
|
||||
return null;
|
||||
|
||||
if (!isMaster) {
|
||||
|
||||
@@ -29,8 +29,11 @@ import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
import forestry.api.circuits.ChipsetManager;
|
||||
import forestry.api.circuits.ICircuitBoard;
|
||||
@@ -49,9 +52,12 @@ import forestry.core.config.Defaults;
|
||||
import forestry.core.interfaces.IClimatised;
|
||||
import forestry.core.interfaces.IHintSource;
|
||||
import forestry.core.interfaces.ISocketable;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.DelayTimer;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.LiquidHelper;
|
||||
import forestry.core.utils.StackUtils;
|
||||
@@ -61,7 +67,7 @@ import forestry.farming.FarmTarget;
|
||||
import forestry.farming.logic.FarmLogicArboreal;
|
||||
import forestry.plugins.PluginFarming;
|
||||
|
||||
public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable, IClimatised, IHintSource {
|
||||
public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable, IClimatised, IHintSource, ILiquidTankContainer {
|
||||
|
||||
public static final int SLOT_RESOURCES_1 = 0;
|
||||
public static final int SLOT_GERMLINGS_1 = 6;
|
||||
@@ -74,8 +80,6 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
|
||||
public static final int SLOT_COUNT = 22;
|
||||
|
||||
public static final FluidStack STACK_WATER = LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1);
|
||||
|
||||
public static final int DELAY_HYDRATION = 100;
|
||||
public static final float RAINFALL_MODIFIER_CAP = 15f;
|
||||
public static final int BUFFER_FERTILIZER = 200;
|
||||
@@ -88,7 +92,8 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
|
||||
private final InventoryAdapter sockets = new InventoryAdapter(1, "sockets");
|
||||
|
||||
private StandardTank liquidTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
private FilteredTank liquidTank;
|
||||
private final TankManager tankManager;
|
||||
|
||||
private IFarmLogic harvestProvider; // The farm logic which supplied the pending crops.
|
||||
private final Stack<ICrop> pendingCrops = new Stack<ICrop>();
|
||||
@@ -107,6 +112,8 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
|
||||
public TileFarmPlain() {
|
||||
fertilizerValue = GameMode.getGameMode().getIntegerSetting("farms.fertilizer.value");
|
||||
liquidTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, FluidRegistry.WATER);
|
||||
tankManager = new TankManager(liquidTank);
|
||||
}
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@@ -121,9 +128,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
|
||||
refreshFarmLogics();
|
||||
|
||||
liquidTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
if (nbttagcompound.hasKey("LiquidTank"))
|
||||
liquidTank.readFromNBT(nbttagcompound.getCompoundTag("LiquidTank"));
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -135,10 +140,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
nbttagcompound.setInteger("HydrationDelay", hydrationDelay);
|
||||
nbttagcompound.setInteger("TicksSinceRainfall", ticksSinceRainfall);
|
||||
|
||||
NBTTagCompound NBTresourceSlot = new NBTTagCompound();
|
||||
liquidTank.writeToNBT(NBTresourceSlot);
|
||||
nbttagcompound.setTag("LiquidTank", NBTresourceSlot);
|
||||
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
/* UPDATING */
|
||||
@@ -171,7 +173,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
// Check if we have suitable items waiting in the item slot
|
||||
if (inventory.getStackInSlot(SLOT_CAN) != null) {
|
||||
FluidContainerData container = LiquidHelper.getLiquidContainer(inventory.getStackInSlot(SLOT_CAN));
|
||||
if (container != null && LiquidHelper.isLiquid(Defaults.LIQUID_WATER, container.fluid)) {
|
||||
if (container != null && liquidTank.accepts(container.fluid.getFluid())) {
|
||||
|
||||
inventory.setInventorySlotContents(SLOT_CAN, StackUtils.replenishByContainer(this, inventory.getStackInSlot(SLOT_CAN), container, liquidTank));
|
||||
if (inventory.getStackInSlot(SLOT_CAN).stackSize <= 0)
|
||||
@@ -666,8 +668,6 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
@Override
|
||||
public void makeMaster() {
|
||||
super.makeMaster();
|
||||
if (liquidTank == null)
|
||||
liquidTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY);
|
||||
refreshFarmLogics();
|
||||
}
|
||||
|
||||
@@ -676,8 +676,13 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
super.onStructureReset();
|
||||
}
|
||||
|
||||
public StandardTank getTank() {
|
||||
return liquidTank;
|
||||
public StandardTank[] getTanks() {
|
||||
return new StandardTank[] {liquidTank};
|
||||
}
|
||||
|
||||
@Override
|
||||
public TankManager getTankManager() {
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -764,7 +769,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
|
||||
@Override
|
||||
public boolean hasLiquid(FluidStack liquid) {
|
||||
return liquidTank.getFluidAmount() >= liquid.amount && liquidTank.getFluid().isFluidEqual(liquid);
|
||||
return liquidTank.getFluidAmount() >= liquid.amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -875,7 +880,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
|
||||
/* NETWORK GUI */
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
|
||||
i -= tankManager.maxMessageId() + 1;
|
||||
switch (i) {
|
||||
case 0:
|
||||
storedFertilizer = j;
|
||||
@@ -893,10 +898,11 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
}
|
||||
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
||||
iCrafting.sendProgressBarUpdate(container, 0, storedFertilizer);
|
||||
iCrafting.sendProgressBarUpdate(container, 3, Math.round(temperature * 100));
|
||||
iCrafting.sendProgressBarUpdate(container, 4, Math.round(humidity * 100));
|
||||
iCrafting.sendProgressBarUpdate(container, 5, ticksSinceRainfall);
|
||||
int i = tankManager.maxMessageId() + 1;
|
||||
iCrafting.sendProgressBarUpdate(container, i, storedFertilizer);
|
||||
iCrafting.sendProgressBarUpdate(container, i + 3, Math.round(temperature * 100));
|
||||
iCrafting.sendProgressBarUpdate(container, i + 4, Math.round(humidity * 100));
|
||||
iCrafting.sendProgressBarUpdate(container, i + 5, ticksSinceRainfall);
|
||||
}
|
||||
|
||||
/* ICLIMATISED */
|
||||
@@ -967,4 +973,34 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ILiquidTankContainer */
|
||||
@Override
|
||||
public int fill(ForgeDirection direction, FluidStack resource, boolean doFill) {
|
||||
return tankManager.fill(direction, 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);
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.gadgets;
|
||||
|
||||
import forestry.core.fluids.tanks.FakeTank;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.FakeTank;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
public class TileValve extends TileFarm implements ILiquidTankContainer {
|
||||
|
||||
@@ -34,42 +38,74 @@ public class TileValve extends TileFarm implements ILiquidTankContainer {
|
||||
}
|
||||
|
||||
/* ILIQUIDTANKCONTAINER */
|
||||
private StandardTank getMasterTank() {
|
||||
if (!isIntegratedIntoStructure() || !hasMaster())
|
||||
return null;
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
TankManager tankManager = getTankManager();
|
||||
if (tankManager == null)
|
||||
return FakeTank.INSTANCE.fill(resource, doFill);
|
||||
|
||||
TileFarmPlain central = (TileFarmPlain) getCentralTE();
|
||||
if (central == null)
|
||||
return null;
|
||||
|
||||
return central.getTank();
|
||||
return tankManager.fill(from, resource, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
StandardTank tank = getMasterTank();
|
||||
if (tank == null)
|
||||
return 0;
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
||||
TankManager tankManager = getTankManager();
|
||||
if (tankManager == null)
|
||||
return null;
|
||||
|
||||
return tank.fill(resource, doFill);
|
||||
return tankManager.drain(from, resource, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
|
||||
StandardTank tank = getMasterTank();
|
||||
if (tank == null)
|
||||
return null;
|
||||
TankManager tankManager = getTankManager();
|
||||
if (tankManager == null)
|
||||
return FakeTank.INSTANCE.drain(maxDrain, doDrain);
|
||||
|
||||
return tank.drain(maxDrain, doDrain);
|
||||
return tankManager.drain(from, maxDrain, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardTank[] getTanks() {
|
||||
StandardTank tank = getMasterTank();
|
||||
if (tank == null)
|
||||
return FakeTank.ARRAY;
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid) {
|
||||
TankManager tankManager = getTankManager();
|
||||
if (tankManager == null)
|
||||
return true;
|
||||
|
||||
return new StandardTank[] { tank };
|
||||
return tankManager.canFill(from, fluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid) {
|
||||
TankManager tankManager = getTankManager();
|
||||
if (tankManager == null)
|
||||
return false;
|
||||
|
||||
return tankManager.canDrain(from, fluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
TankManager tankManager = getTankManager();
|
||||
if (tankManager == null)
|
||||
return FakeTank.INFO;
|
||||
|
||||
return tankManager.getTankInfo(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TankManager getTankManager() {
|
||||
TileFarmPlain central = (TileFarmPlain) getCentralTE();
|
||||
if (central == null)
|
||||
return null;
|
||||
|
||||
return central.getTankManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getGUINetworkData(int messageId, int data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
||||
}
|
||||
}
|
||||
@@ -10,28 +10,20 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.gui;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.core.fluids.tanks.FakeTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.gui.ContainerSocketed;
|
||||
import forestry.core.gui.slots.SlotCustom;
|
||||
import forestry.core.gui.slots.SlotForestry;
|
||||
import forestry.core.gui.slots.SlotLiquidContainer;
|
||||
import forestry.core.gui.slots.SlotOutput;
|
||||
import forestry.core.network.PacketTankUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.utils.TileInventoryAdapter;
|
||||
import forestry.farming.gadgets.TileFarmPlain;
|
||||
import forestry.plugins.PluginFarming;
|
||||
@@ -135,47 +127,32 @@ public class ContainerFarm extends ContainerSocketed {
|
||||
@Override
|
||||
public void updateProgressBar(int i, int j) {
|
||||
tile.getGUINetworkData(i, j);
|
||||
TankManager tankManager = tile.getTankManager();
|
||||
if (tankManager != null)
|
||||
tankManager.processGuiUpdate(i, j);
|
||||
}
|
||||
private Map<Integer, StandardTank> syncedFluids = new HashMap<Integer, StandardTank>();
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
TankManager tankManager = tile.getTankManager();
|
||||
if (tankManager != null)
|
||||
tankManager.updateGuiData(this, crafters);
|
||||
|
||||
for (int i = 0; i < crafters.size(); i++) {
|
||||
tile.sendGUINetworkData(this, (ICrafting) crafters.get(i));
|
||||
}
|
||||
|
||||
StandardTank tank = tile.getTank();
|
||||
|
||||
// If null has been synced
|
||||
if (tank.getFluid() == null && getTank(0).getFluidAmount() <= 0)
|
||||
return;
|
||||
// If fluid has been synced
|
||||
if (tank.getFluid() != null && tank.getFluid().isFluidStackIdentical(getTank(0).getFluid()))
|
||||
return;
|
||||
|
||||
for (int j = 0; j < this.crafters.size(); ++j) {
|
||||
if (this.crafters.get(j) instanceof EntityPlayerMP) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) this.crafters.get(j);
|
||||
Proxies.net.sendToPlayer(new PacketTankUpdate(0, tank), player);
|
||||
}
|
||||
}
|
||||
syncedFluids.put(0, new StandardTank(tank.getFluid() == null ? null : tank.getFluid().copy(), tank.getCapacity()));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTankUpdate(NBTTagCompound nbt) {
|
||||
int tankID = nbt.getByte("tank");
|
||||
int capacity = nbt.getShort("capacity");
|
||||
StandardTank tank = new StandardTank(capacity);
|
||||
tank.readFromNBT(nbt);
|
||||
syncedFluids.put(tankID, tank);
|
||||
public void addCraftingToCrafters(ICrafting iCrafting) {
|
||||
super.addCraftingToCrafters(iCrafting);
|
||||
TankManager tankManager = tile.getTankManager();
|
||||
if (tankManager != null)
|
||||
tankManager.initGuiData(this, iCrafting);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardTank getTank(int slot) {
|
||||
return syncedFluids.get(slot) == null ? FakeTank.INSTANCE : syncedFluids.get(slot);
|
||||
return tile.getTankManager().get(slot);
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,10 @@ import buildcraft.api.gates.ITriggerParameter;
|
||||
|
||||
import forestry.api.core.ITileStructure;
|
||||
import forestry.core.triggers.Trigger;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.farming.gadgets.TileFarmPlain;
|
||||
import forestry.farming.gadgets.TileHatch;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
public class TriggerLowLiquid extends Trigger {
|
||||
|
||||
@@ -49,7 +50,8 @@ public class TriggerLowLiquid extends Trigger {
|
||||
if (central == null || !(central instanceof TileFarmPlain))
|
||||
return false;
|
||||
|
||||
StandardTank tank = ((TileFarmPlain) central).getTank();
|
||||
return ((float) tank.getFluidAmount() / tank.getCapacity()) <= threshold;
|
||||
TankManager tankManager = ((TileFarmPlain) central).getTankManager();
|
||||
FluidTankInfo info = tankManager.getTankInfo(0);
|
||||
return ((float) info.fluid.amount / info.capacity) <= threshold;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user