mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-18 19:29:17 +00:00
Fix #365 Fluid pipe connected to farmblock
This commit is contained in:
1 parent
2242dfdfb9
commit
5c4bd5307c
8 files changed
+65
-127
No files matched your search
@@ -11,13 +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;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.NBTUtil;
|
||||
import forestry.core.utils.NBTUtil.NBTList;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -26,19 +20,26 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
|
||||
import forestry.core.fluids.tanks.FakeTank;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.inventory.ITileFilter;
|
||||
import forestry.core.network.PacketGuiInteger;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.NBTUtil;
|
||||
import forestry.core.utils.NBTUtil.NBTList;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -287,14 +288,18 @@ public class TankManager extends ForwardingList<StandardTank> implements IFluidH
|
||||
return tank.drain(maxDrain, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
||||
public FluidStack drain(FluidStack resource, boolean doDrain) {
|
||||
for (StandardTank tank : tanks)
|
||||
if (tankCanDrainFluid(tank, resource))
|
||||
return tank.drain(resource.amount, doDrain);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
||||
return drain(resource, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid) {
|
||||
return true;
|
||||
@@ -345,6 +350,14 @@ public class TankManager extends ForwardingList<StandardTank> implements IFluidH
|
||||
return tank;
|
||||
}
|
||||
|
||||
public boolean accepts(Fluid fluid) {
|
||||
for (StandardTank tank : tanks)
|
||||
if (tank.accepts(fluid))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean tankAcceptsFluid(StandardTank tank, FluidStack fluidStack) {
|
||||
if (fluidStack == null)
|
||||
return false;
|
||||
|
||||
@@ -62,10 +62,6 @@ public class TileControl extends TileFarm implements IFarmListener {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createInventory() {
|
||||
}
|
||||
|
||||
/* IFARMLISTENER */
|
||||
@Override
|
||||
public boolean cancelTask(IFarmLogic logic, ForgeDirection direction) {
|
||||
|
||||
@@ -228,19 +228,21 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent {
|
||||
/* INVENTORY MANAGMENT */
|
||||
protected TileInventoryAdapter inventory;
|
||||
|
||||
protected abstract void createInventory();
|
||||
|
||||
/* TILEFORESTRY */
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
PacketPayload payload = new PacketPayload(0, 1);
|
||||
PacketPayload payload = new PacketPayload(0, 2);
|
||||
payload.shortPayload[0] = (short) farmBlock.ordinal();
|
||||
payload.shortPayload[1] = (short) (isMaster() ? 1 : 0);
|
||||
return payload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromPacketPayload(PacketPayload payload) {
|
||||
EnumFarmBlock farmType = EnumFarmBlock.values()[payload.shortPayload[0]];
|
||||
if (payload.shortPayload[1] > 0)
|
||||
makeMaster();
|
||||
|
||||
if (this.farmBlock != farmType) {
|
||||
this.farmBlock = farmType;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
@@ -267,9 +269,6 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent {
|
||||
public void makeMaster() {
|
||||
setCentralTE(null);
|
||||
this.isMaster = true;
|
||||
|
||||
if (inventory == null)
|
||||
createInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -284,22 +283,19 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent {
|
||||
@Override
|
||||
public ITileStructure getCentralTE() {
|
||||
|
||||
if (!isIntegratedIntoStructure() || !hasMaster())
|
||||
if (!isIntegratedIntoStructure())
|
||||
return null;
|
||||
|
||||
if (!isMaster) {
|
||||
TileEntity tile = worldObj.getTileEntity(masterX, masterY, masterZ);
|
||||
if (tile instanceof ITileStructure) {
|
||||
ITileStructure master = (ITileStructure) worldObj.getTileEntity(masterX, masterY, masterZ);
|
||||
if (master.isMaster())
|
||||
return master;
|
||||
else
|
||||
return null;
|
||||
} else
|
||||
return null;
|
||||
} else
|
||||
if (isMaster)
|
||||
return this;
|
||||
|
||||
TileEntity tile = worldObj.getTileEntity(masterX, masterY, masterZ);
|
||||
if (tile instanceof ITileStructure) {
|
||||
ITileStructure master = (ITileStructure)tile;
|
||||
if (master.isMaster())
|
||||
return master;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isSameTile(TileEntity tile) {
|
||||
|
||||
@@ -19,8 +19,6 @@ import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import forestry.api.core.BiomeHelper;
|
||||
import forestry.core.utils.Utils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
@@ -31,14 +29,14 @@ 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;
|
||||
import forestry.api.core.BiomeHelper;
|
||||
import forestry.api.core.EnumErrorCode;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.farming.ICrop;
|
||||
@@ -47,29 +45,28 @@ import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmListener;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.api.core.EnumErrorCode;
|
||||
import forestry.core.GameMode;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
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;
|
||||
import forestry.core.utils.TileInventoryAdapter;
|
||||
import forestry.core.utils.Utils;
|
||||
import forestry.core.utils.Vect;
|
||||
import forestry.farming.FarmTarget;
|
||||
import forestry.farming.logic.FarmLogicArboreal;
|
||||
import forestry.plugins.PluginFarming;
|
||||
|
||||
public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable, IClimatised, IHintSource, ILiquidTankContainer {
|
||||
public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable, IClimatised, IHintSource {
|
||||
|
||||
public static final int SLOT_RESOURCES_1 = 0;
|
||||
public static final int SLOT_GERMLINGS_1 = 6;
|
||||
@@ -82,9 +79,9 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
|
||||
public static final int SLOT_COUNT = 22;
|
||||
|
||||
public static final int DELAY_HYDRATION = 100;
|
||||
public static final float RAINFALL_MODIFIER_CAP = 15f;
|
||||
public static final int BUFFER_FERTILIZER = 200;
|
||||
private static final int DELAY_HYDRATION = 100;
|
||||
private static final float RAINFALL_MODIFIER_CAP = 15f;
|
||||
private static final int BUFFER_FERTILIZER = 200;
|
||||
|
||||
private IFarmLogic[] farmLogics = new IFarmLogic[4];
|
||||
|
||||
@@ -94,8 +91,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
|
||||
private final InventoryAdapter sockets = new InventoryAdapter(1, "sockets");
|
||||
|
||||
private final FilteredTank liquidTank;
|
||||
private final TankManager tankManager;
|
||||
private TankManager tankManager;
|
||||
|
||||
private IFarmLogic harvestProvider; // The farm logic which supplied the pending crops.
|
||||
private final Stack<ICrop> pendingCrops = new Stack<ICrop>();
|
||||
@@ -112,8 +108,6 @@ 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -134,7 +128,8 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
|
||||
refreshFarmLogics();
|
||||
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
if (tankManager != null)
|
||||
tankManager.readTanksFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,15 +141,11 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
nbttagcompound.setInteger("HydrationDelay", hydrationDelay);
|
||||
nbttagcompound.setInteger("TicksSinceRainfall", ticksSinceRainfall);
|
||||
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
if (tankManager != null)
|
||||
tankManager.writeTanksToNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
/* UPDATING */
|
||||
@Override
|
||||
public void initialize() {
|
||||
setBiomeInformation();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateServerSide() {
|
||||
super.updateServerSide();
|
||||
@@ -179,8 +170,8 @@ 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 && liquidTank.accepts(container.fluid.getFluid())) {
|
||||
|
||||
if (container != null && tankManager.accepts(container.fluid.getFluid())) {
|
||||
StandardTank liquidTank = tankManager.get(0);
|
||||
inventory.setInventorySlotContents(SLOT_CAN, StackUtils.replenishByContainer(this, inventory.getStackInSlot(SLOT_CAN), container, liquidTank));
|
||||
if (inventory.getStackInSlot(SLOT_CAN).stackSize <= 0)
|
||||
inventory.setInventorySlotContents(SLOT_CAN, null);
|
||||
@@ -366,16 +357,14 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createInventory() {
|
||||
inventory = new TileInventoryAdapter(this, SLOT_COUNT, "Items");
|
||||
FilteredTank liquidTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, FluidRegistry.WATER);
|
||||
tankManager = new TankManager(liquidTank);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doWork() {
|
||||
|
||||
setBiomeInformation();
|
||||
|
||||
// System.out.println("Starting doWork()");
|
||||
if (targets == null) {
|
||||
createTargets();
|
||||
@@ -681,18 +670,9 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
public void makeMaster() {
|
||||
super.makeMaster();
|
||||
refreshFarmLogics();
|
||||
createInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStructureReset() {
|
||||
super.onStructureReset();
|
||||
}
|
||||
|
||||
public StandardTank[] getTanks() {
|
||||
return new StandardTank[] {liquidTank};
|
||||
}
|
||||
|
||||
@Override
|
||||
public TankManager getTankManager() {
|
||||
return tankManager;
|
||||
}
|
||||
@@ -792,12 +772,12 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
|
||||
@Override
|
||||
public boolean hasLiquid(FluidStack liquid) {
|
||||
return liquidTank.getFluidAmount() >= liquid.amount;
|
||||
return tankManager.get(0).getFluidAmount() >= liquid.amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLiquid(FluidStack liquid) {
|
||||
liquidTank.drain(liquid.amount, true);
|
||||
tankManager.drain(liquid, true);
|
||||
}
|
||||
|
||||
public boolean hasGermlings(ItemStack[] germlings) {
|
||||
@@ -877,9 +857,9 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
return StackUtils.isIdenticalItem(PluginFarming.farmFertilizer, itemstack);
|
||||
}
|
||||
|
||||
int[] coords;
|
||||
int[] offset;
|
||||
int[] area;
|
||||
private int[] coords;
|
||||
private int[] offset;
|
||||
private int[] area;
|
||||
|
||||
@Override
|
||||
public int[] getCoords() {
|
||||
@@ -989,35 +969,4 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
public boolean isOwnable() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -33,10 +33,6 @@ public class TileGearbox extends TileFarm implements IPowerHandler {
|
||||
fixedType = TYPE_GEARS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFunction() {
|
||||
return true;
|
||||
|
||||
@@ -42,10 +42,6 @@ public class TileHatch extends TileFarm implements ISidedInventory {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateServerSide() {
|
||||
if (worldObj.getTotalWorldTime() % 40 == 0)
|
||||
|
||||
@@ -33,10 +33,6 @@ public class TileValve extends TileFarm implements ILiquidTankContainer {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createInventory() {
|
||||
}
|
||||
|
||||
/* ILIQUIDTANKCONTAINER */
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
|
||||
@@ -24,7 +24,6 @@ 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.utils.TileInventoryAdapter;
|
||||
import forestry.farming.gadgets.TileFarmPlain;
|
||||
import forestry.plugins.PluginFarming;
|
||||
|
||||
@@ -38,9 +37,6 @@ public class ContainerFarm extends ContainerSocketed {
|
||||
this.tile = tile;
|
||||
|
||||
IInventory inventory = tile.getInventory();
|
||||
// Tile will not have an inventory client side.
|
||||
if (inventory == null)
|
||||
inventory = new TileInventoryAdapter(tile, TileFarmPlain.SLOT_COUNT, "Items");
|
||||
|
||||
// Resources
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
||||
Reference in new issue
Block a user