mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-27 23:33:00 +00:00
Fix #938 Squeezer tank level does not update unless gui interacted
This commit is contained in:
1 parent
1594edd4d4
commit
9a745b10d7
14 files changed
+123
-68
No files matched your search
@@ -0,0 +1,27 @@
|
||||
/*******************************************************************************
|
||||
* 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.fluids;
|
||||
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
|
||||
public class FakeTankUpdateHandler implements ITankUpdateHandler {
|
||||
|
||||
public static FakeTankUpdateHandler instance = new FakeTankUpdateHandler();
|
||||
|
||||
private FakeTankUpdateHandler() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTankLevels(StandardTank tank) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -144,7 +144,11 @@ public final class FluidHelper {
|
||||
return FillStatus.NO_FLUID; // standard containers will not fill if there isn't enough fluid
|
||||
}
|
||||
|
||||
boolean moveToOutput = (getFluidStackInContainer(filled).amount >= containerCapacity);
|
||||
FluidStack fluidInContainer = getFluidStackInContainer(filled);
|
||||
if (fluidInContainer == null) {
|
||||
return FillStatus.INVALID_INPUT;
|
||||
}
|
||||
boolean moveToOutput = (fluidInContainer.amount >= containerCapacity);
|
||||
if (moveToOutput) {
|
||||
if ((output != null) && (output.stackSize >= output.getMaxStackSize() || !InventoryUtil.isItemEqual(filled, output))) {
|
||||
return FillStatus.NO_SPACE;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*******************************************************************************
|
||||
* 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.fluids;
|
||||
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
|
||||
public interface ITankUpdateHandler {
|
||||
void updateTankLevels(StandardTank tank);
|
||||
}
|
||||
@@ -51,7 +51,7 @@ import forestry.core.utils.NBTUtil.NBTList;
|
||||
/**
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
public class TankManager implements ITankManager, IStreamable, INBTTagable {
|
||||
public class TankManager implements ITankManager, ITankUpdateHandler, IStreamable, INBTTagable {
|
||||
|
||||
private final List<StandardTank> tanks = new ArrayList<>();
|
||||
|
||||
@@ -82,6 +82,7 @@ public class TankManager implements ITankManager, IStreamable, INBTTagable {
|
||||
public boolean add(@Nonnull StandardTank tank) {
|
||||
boolean added = tanks.add(tank);
|
||||
int index = tanks.indexOf(tank);
|
||||
tank.setTankUpdateHandler(this);
|
||||
tank.setTankIndex(index);
|
||||
tankLevels.add(EnumTankLevel.rateTankLevel(tank));
|
||||
return added;
|
||||
@@ -204,30 +205,29 @@ public class TankManager implements ITankManager, IStreamable, INBTTagable {
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
for (StandardTank tank : tanks) {
|
||||
if (tankAcceptsFluid(tank, resource)) {
|
||||
return fill(tank.getTankIndex(), resource, doFill, true);
|
||||
return fill(tank.getTankIndex(), resource, doFill);
|
||||
}
|
||||
}
|
||||
|
||||
return FakeTank.INSTANCE.fill(resource, doFill);
|
||||
}
|
||||
|
||||
public int fill(int tankIndex, FluidStack resource, boolean doFill, boolean external) {
|
||||
public int fill(int tankIndex, FluidStack resource, boolean doFill) {
|
||||
if (tankIndex < 0 || tankIndex >= tanks.size() || resource == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
StandardTank tank = tanks.get(tankIndex);
|
||||
if (external && !tank.canBeFilledExternally()) {
|
||||
if (!tank.canBeFilledExternally()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fill = tank.fill(resource, doFill);
|
||||
return tank.fill(resource, doFill);
|
||||
}
|
||||
|
||||
if (doFill) {
|
||||
updateTankLevels(tank, true);
|
||||
}
|
||||
|
||||
return fill;
|
||||
@Override
|
||||
public void updateTankLevels(StandardTank tank) {
|
||||
updateTankLevels(tank, true);
|
||||
}
|
||||
|
||||
private void updateTankLevels(StandardTank tank, boolean sendUpdate) {
|
||||
@@ -249,47 +249,30 @@ public class TankManager implements ITankManager, IStreamable, INBTTagable {
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
|
||||
for (StandardTank tank : tanks) {
|
||||
if (tankCanDrain(tank, true)) {
|
||||
return drain(tank.getTankIndex(), maxDrain, true, doDrain);
|
||||
if (tankCanDrain(tank)) {
|
||||
return drain(tank.getTankIndex(), maxDrain, doDrain);
|
||||
}
|
||||
}
|
||||
return FakeTank.INSTANCE.drain(maxDrain, doDrain);
|
||||
}
|
||||
|
||||
public FluidStack drain(int tankIndex, int maxDrain, boolean external, boolean doDrain) {
|
||||
public FluidStack drain(int tankIndex, int maxDrain, boolean doDrain) {
|
||||
if (tankIndex < 0 || tankIndex >= tanks.size()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
StandardTank tank = tanks.get(tankIndex);
|
||||
if (external && !tank.canBeDrainedExternally()) {
|
||||
if (!tank.canBeDrainedExternally()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
FluidStack drained = tank.drain(maxDrain, doDrain);
|
||||
|
||||
if (doDrain) {
|
||||
updateTankLevels(tank, true);
|
||||
}
|
||||
|
||||
return drained;
|
||||
}
|
||||
|
||||
public FluidStack drain(Fluid resource, int amount, boolean doDrain) {
|
||||
if (resource == null) {
|
||||
return null;
|
||||
}
|
||||
return drain(new FluidStack(resource, amount), false, doDrain);
|
||||
return tank.drain(maxDrain, doDrain);
|
||||
}
|
||||
|
||||
public FluidStack drain(FluidStack resource, boolean doDrain) {
|
||||
return drain(resource, false, doDrain);
|
||||
}
|
||||
|
||||
public FluidStack drain(FluidStack resource, boolean external, boolean doDrain) {
|
||||
for (StandardTank tank : tanks) {
|
||||
if (tankCanDrainFluid(tank, resource, external)) {
|
||||
return drain(tank.getTankIndex(), resource.amount, external, doDrain);
|
||||
if (tankCanDrainFluid(tank, resource)) {
|
||||
return drain(tank.getTankIndex(), resource.amount, doDrain);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -297,7 +280,7 @@ public class TankManager implements ITankManager, IStreamable, INBTTagable {
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
||||
return drain(resource, true, doDrain);
|
||||
return drain(resource, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -359,21 +342,21 @@ public class TankManager implements ITankManager, IStreamable, INBTTagable {
|
||||
return tank.fill(fluidStack, false) > 0;
|
||||
}
|
||||
|
||||
private static boolean tankCanDrain(StandardTank tank, boolean external) {
|
||||
if (external && !tank.canBeDrainedExternally()) {
|
||||
private static boolean tankCanDrain(StandardTank tank) {
|
||||
if (!tank.canBeDrainedExternally()) {
|
||||
return false;
|
||||
}
|
||||
FluidStack drained = tank.drain(1, false);
|
||||
return drained != null && drained.amount > 0;
|
||||
}
|
||||
|
||||
private static boolean tankCanDrainFluid(StandardTank tank, FluidStack fluidStack, boolean external) {
|
||||
private static boolean tankCanDrainFluid(StandardTank tank, FluidStack fluidStack) {
|
||||
if (fluidStack == null) {
|
||||
return false;
|
||||
}
|
||||
if (!Fluids.areEqual(tank.getFluidType(), fluidStack)) {
|
||||
return false;
|
||||
}
|
||||
return tankCanDrain(tank, external);
|
||||
return tankCanDrain(tank);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.fluids.tanks;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -20,6 +21,9 @@ import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
|
||||
import forestry.core.fluids.FakeTankUpdateHandler;
|
||||
import forestry.core.fluids.ITankUpdateHandler;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.gui.tooltips.ToolTip;
|
||||
import forestry.core.gui.tooltips.ToolTipLine;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
@@ -37,6 +41,8 @@ public class StandardTank extends FluidTank implements IStreamable {
|
||||
|
||||
public TankMode tankMode = TankMode.DEFAULT;
|
||||
private static final int DEFAULT_COLOR = 0xFFFFFF;
|
||||
@Nonnull
|
||||
private ITankUpdateHandler tankUpdateHandler = FakeTankUpdateHandler.instance;
|
||||
private int tankIndex;
|
||||
|
||||
public StandardTank(int capacity) {
|
||||
@@ -63,6 +69,10 @@ public class StandardTank extends FluidTank implements IStreamable {
|
||||
this.tankIndex = index;
|
||||
}
|
||||
|
||||
public void setTankUpdateHandler(@Nonnull TankManager tankUpdateHandler) {
|
||||
this.tankUpdateHandler = tankUpdateHandler;
|
||||
}
|
||||
|
||||
public int getTankIndex() {
|
||||
return tankIndex;
|
||||
}
|
||||
@@ -102,7 +112,11 @@ public class StandardTank extends FluidTank implements IStreamable {
|
||||
if (!accepts(resource.getFluid())) {
|
||||
return 0;
|
||||
}
|
||||
return super.fill(resource, doFill);
|
||||
int filled = super.fill(resource, doFill);
|
||||
if (doFill && filled > 0) {
|
||||
tankUpdateHandler.updateTankLevels(this);
|
||||
}
|
||||
return filled;
|
||||
}
|
||||
|
||||
public boolean accepts(Fluid fluid) {
|
||||
@@ -144,12 +158,21 @@ public class StandardTank extends FluidTank implements IStreamable {
|
||||
return (drained != null) && (drained.amount == amount);
|
||||
}
|
||||
|
||||
public boolean canDrain(FluidStack toDrain) {
|
||||
FluidStack drained = drain(toDrain.amount, false);
|
||||
return drained.isFluidStackIdentical(toDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(int maxDrain, boolean doDrain) {
|
||||
if (maxDrain <= 0) {
|
||||
return null;
|
||||
}
|
||||
return super.drain(maxDrain, doDrain);
|
||||
FluidStack drained = super.drain(maxDrain, doDrain);
|
||||
if (doDrain && drained != null && drained.amount > 0) {
|
||||
tankUpdateHandler.updateTankLevels(this);
|
||||
}
|
||||
return drained;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -240,8 +240,10 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
|
||||
|
||||
if (specimenToAnalyze.isAnalyzed()) {
|
||||
setTicksPerWorkCycle(1);
|
||||
setEnergyPerWorkCycle(0);
|
||||
} else {
|
||||
setTicksPerWorkCycle(TIME_TO_ANALYZE);
|
||||
setEnergyPerWorkCycle(ENERGY_PER_WORK_CYCLE);
|
||||
}
|
||||
|
||||
PacketItemStackDisplay packet = new PacketItemStackDisplay(this, getIndividualOnDisplay());
|
||||
|
||||
@@ -148,15 +148,13 @@ public class TileGenerator extends TileBase implements ISidedInventory, ILiquidT
|
||||
|
||||
if (resourceTank.getFluidAmount() > 0) {
|
||||
GeneratorFuel fuel = FuelManager.generatorFuel.get(resourceTank.getFluid().getFluid());
|
||||
|
||||
if (resourceTank.getFluidAmount() >= fuel.fuelConsumed.amount
|
||||
&& ic2EnergySource.getFreeCapacity() >= fuel.eu) {
|
||||
if (resourceTank.canDrain(fuel.fuelConsumed) && ic2EnergySource.getFreeCapacity() >= fuel.eu) {
|
||||
ic2EnergySource.addEnergy(fuel.eu);
|
||||
this.tickCount++;
|
||||
|
||||
if (tickCount >= fuel.rate) {
|
||||
tickCount = 0;
|
||||
tankManager.drain(fuel.fuelConsumed, true);
|
||||
resourceTank.drain(fuel.fuelConsumed.amount, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -170,12 +170,11 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
|
||||
|
||||
FluidStack fluid = currentRecipe.getFluidResource();
|
||||
if (fluid != null) {
|
||||
FluidStack amountDrained = tankManager.drain(fluid, false);
|
||||
if (amountDrained == null || amountDrained.amount != fluid.amount) {
|
||||
if (!resourceTank.canDrain(fluid)) {
|
||||
return false;
|
||||
}
|
||||
if (doRemove) {
|
||||
tankManager.drain(fluid, true);
|
||||
resourceTank.drain(fluid.amount, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
|
||||
if (!moltenTank.isEmpty()) {
|
||||
// Remove smelt if we have gone below melting point
|
||||
if (heat < (getMeltingPoint() - 100)) {
|
||||
tankManager.drain(moltenTank.getFluidType(), 5, true);
|
||||
moltenTank.drain(5, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
|
||||
}
|
||||
|
||||
FluidStack smeltFluid = smelt.getProduct();
|
||||
if (moltenTank.fill(smeltFluid, false) == smeltFluid.amount) {
|
||||
if (moltenTank.canFill(smeltFluid)) {
|
||||
this.decrStackSize(SLOT_METAL, 1);
|
||||
moltenTank.fill(smeltFluid, true);
|
||||
meltingPoint = smelt.getMeltingPoint();
|
||||
@@ -267,13 +267,12 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
|
||||
return;
|
||||
}
|
||||
|
||||
FluidStack canDrain = tankManager.drain(liquid, false);
|
||||
if (canDrain == null || !canDrain.isFluidStackIdentical(liquid)) {
|
||||
if (!moltenTank.canDrain(liquid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
removeFromInventory(crafting, player, true);
|
||||
tankManager.drain(liquid, true);
|
||||
moltenTank.drain(liquid.amount, true);
|
||||
|
||||
// Damage plan
|
||||
if (inventory.getStackInSlot(SLOT_PLAN) != null) {
|
||||
|
||||
@@ -159,7 +159,7 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
|
||||
productTank.fill(new FluidStack(currentRecipe.getOutput(), productAmount), true);
|
||||
|
||||
fuelBurnTime--;
|
||||
tankManager.drain(resourceTank.getFluidType(), fuelCurrentFerment, true);
|
||||
resourceTank.drain(fuelCurrentFerment, true);
|
||||
fermentationTime -= this.fuelCurrentFerment;
|
||||
|
||||
// Not done yet
|
||||
@@ -353,7 +353,7 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int quantityMax, boolean doEmpty) {
|
||||
return tankManager.drain(productTank.getFluidType(), quantityMax, doEmpty);
|
||||
return tankManager.drain(from, quantityMax, doEmpty);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -399,7 +399,7 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
|
||||
Fluid fluid = FluidHelper.getFluidInContainer(itemStack);
|
||||
return tile.resourceTank.accepts(fluid);
|
||||
} else if (slotIndex == SLOT_CAN_INPUT) {
|
||||
return FluidHelper.isEmptyContainer(itemStack);
|
||||
return FluidHelper.isFillableContainer(itemStack);
|
||||
} else if (slotIndex == SLOT_FUEL) {
|
||||
return FuelManager.fermenterFuel.containsKey(itemStack);
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT
|
||||
return;
|
||||
}
|
||||
|
||||
tankManager.drain(resourceTank.getFluidType(), 1, true);
|
||||
resourceTank.drain(1, true);
|
||||
burnTime -= speed;
|
||||
productionTime -= speed;
|
||||
|
||||
|
||||
@@ -196,7 +196,7 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve
|
||||
hasRecipe = (currentRecipe != null);
|
||||
if (hasRecipe) {
|
||||
FluidStack resultFluid = currentRecipe.getFluidOutput();
|
||||
canFill = (productTank.fill(resultFluid, false) == resultFluid.amount);
|
||||
canFill = productTank.canFill(resultFluid);
|
||||
|
||||
if (currentRecipe.getRemnants() != null) {
|
||||
canAdd = inventory.addRemnant(currentRecipe.getRemnants(), false);
|
||||
|
||||
@@ -128,8 +128,8 @@ public class TileStill extends TilePowered implements ISidedInventory, ILiquidTa
|
||||
int cycles = currentRecipe.getCyclesPerUnit();
|
||||
FluidStack output = currentRecipe.getOutput();
|
||||
|
||||
FluidStack drain = new FluidStack(output, output.amount * cycles);
|
||||
tankManager.fill(productTank.getTankIndex(), drain, true, false);
|
||||
FluidStack product = new FluidStack(output, output.amount * cycles);
|
||||
productTank.fill(product, true);
|
||||
|
||||
bufferedLiquid = null;
|
||||
|
||||
@@ -161,10 +161,11 @@ public class TileStill extends TilePowered implements ISidedInventory, ILiquidTa
|
||||
if (bufferedLiquid == null) {
|
||||
int cycles = currentRecipe.getCyclesPerUnit();
|
||||
FluidStack input = currentRecipe.getInput();
|
||||
hasFluidResource = resourceTank.canDrain(cycles * input.amount);
|
||||
int drainAmount = cycles * input.amount;
|
||||
hasFluidResource = resourceTank.canDrain(drainAmount);
|
||||
if (hasFluidResource) {
|
||||
bufferedLiquid = new FluidStack(input, cycles * input.amount);
|
||||
tankManager.drain(bufferedLiquid, true);
|
||||
bufferedLiquid = new FluidStack(input, drainAmount);
|
||||
resourceTank.drain(drainAmount, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ import forestry.core.errors.EnumErrorCode;
|
||||
import forestry.core.fluids.Fluids;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.inventory.FakeInventoryAdapter;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.inventory.InventoryAdapter;
|
||||
@@ -125,6 +126,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
private final InventoryAdapter sockets;
|
||||
private final FarmInventory inventory;
|
||||
private final TankManager tankManager;
|
||||
private final StandardTank resourceTank;
|
||||
private final FarmHydrationManager hydrationManager;
|
||||
private final FarmFertilizerManager fertilizerManager;
|
||||
|
||||
@@ -136,8 +138,8 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
public FarmController(World world) {
|
||||
super(world);
|
||||
|
||||
FilteredTank liquidTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, FluidRegistry.WATER);
|
||||
this.tankManager = new TankManager(this, liquidTank);
|
||||
this.resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, FluidRegistry.WATER);
|
||||
this.tankManager = new TankManager(this, resourceTank);
|
||||
|
||||
this.inventory = new FarmInventory(this);
|
||||
this.sockets = new InventoryAdapter(1, "sockets");
|
||||
@@ -800,12 +802,12 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
@Override
|
||||
public boolean hasLiquid(FluidStack liquid) {
|
||||
return tankManager.getFluidAmount(0) >= liquid.amount;
|
||||
return resourceTank.canDrain(liquid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLiquid(FluidStack liquid) {
|
||||
tankManager.drain(liquid, true);
|
||||
resourceTank.drain(liquid.amount, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user