finished fixing #19
This commit is contained in:
parent
8a1f0a18cd
commit
379b6a96da
3 changed files with 47 additions and 7 deletions
|
@ -14,13 +14,14 @@ import techreborn.init.ModBlocks;
|
|||
import techreborn.init.ModFluids;
|
||||
import techreborn.util.FluidUtils;
|
||||
import techreborn.util.Inventory;
|
||||
import techreborn.util.Tank;
|
||||
|
||||
public class TileGrinder extends TileMachineBase implements IWrenchable, IEnergyTile, IFluidHandler {
|
||||
|
||||
public int tickTime;
|
||||
public BasicSink energy;
|
||||
public Inventory inventory = new Inventory(6, "TileGrinder", 64);
|
||||
public FluidTank tank = new FluidTank(16000);
|
||||
public Tank tank = new Tank("TileGrinder",16000, this);
|
||||
public RecipeCrafter crafter;
|
||||
|
||||
public TileGrinder() {
|
||||
|
@ -112,7 +113,9 @@ public class TileGrinder extends TileMachineBase implements IWrenchable, IEnergy
|
|||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
if(resource.getFluid() == FluidRegistry.WATER || resource.getFluid() == ModFluids.fluidMercury || resource.getFluid() == ModFluids.fluidSodiumpersulfate) {
|
||||
return tank.fill(resource, doFill);
|
||||
int filled = tank.fill(resource, doFill);
|
||||
tank.compareAndUpdate();
|
||||
return filled;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -122,12 +125,16 @@ public class TileGrinder extends TileMachineBase implements IWrenchable, IEnergy
|
|||
if (resource == null || !resource.isFluidEqual(tank.getFluid())) {
|
||||
return null;
|
||||
}
|
||||
return tank.drain(resource.amount, doDrain);
|
||||
FluidStack fluidStack = tank.drain(resource.amount, doDrain);
|
||||
tank.compareAndUpdate();
|
||||
return fluidStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
|
||||
return tank.drain(maxDrain, doDrain);
|
||||
FluidStack drained = tank.drain(maxDrain, doDrain);
|
||||
tank.compareAndUpdate();
|
||||
return drained;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -97,20 +97,25 @@ public class TileSemifluidGenerator extends TileEntity implements IWrenchable,
|
|||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
return tank.fill(resource, doFill);
|
||||
int filled = tank.fill(resource, doFill);
|
||||
return filled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource,
|
||||
boolean doDrain)
|
||||
{
|
||||
return tank.drain(resource.amount, doDrain);
|
||||
FluidStack drained = tank.drain(resource.amount, doDrain);
|
||||
tank.compareAndUpdate();
|
||||
return drained;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
return tank.drain(maxDrain, doDrain);
|
||||
FluidStack drained = tank.drain(maxDrain, doDrain);
|
||||
tank.compareAndUpdate();
|
||||
return drained;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,12 +3,16 @@ package techreborn.util;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
import techreborn.packets.PacketHandler;
|
||||
|
||||
public class Tank extends FluidTank {
|
||||
|
||||
private final String name;
|
||||
|
||||
private FluidStack lastBeforeUpdate = null;
|
||||
|
||||
public Tank(String name, int capacity, TileEntity tile)
|
||||
{
|
||||
super(capacity);
|
||||
|
@ -54,4 +58,28 @@ public class Tank extends FluidTank {
|
|||
return this;
|
||||
}
|
||||
|
||||
public void compareAndUpdate() {
|
||||
FluidStack current = this.getFluid();
|
||||
if (current != null) {
|
||||
if (lastBeforeUpdate != null) {
|
||||
if (Math.abs(current.amount - lastBeforeUpdate.amount) >= 500) {
|
||||
PacketHandler.sendPacketToAllPlayers(tile.getDescriptionPacket(), tile.getWorldObj());
|
||||
lastBeforeUpdate = current.copy();
|
||||
}
|
||||
else if (lastBeforeUpdate.amount < this.getCapacity() && current.amount == this.getCapacity() || lastBeforeUpdate.amount == this.getCapacity() && current.amount < this.getCapacity()) {
|
||||
PacketHandler.sendPacketToAllPlayers(tile.getDescriptionPacket(), tile.getWorldObj());
|
||||
lastBeforeUpdate = current.copy();
|
||||
}
|
||||
}
|
||||
else {
|
||||
PacketHandler.sendPacketToAllPlayers(tile.getDescriptionPacket(), tile.getWorldObj());
|
||||
lastBeforeUpdate = current.copy();
|
||||
}
|
||||
}
|
||||
else if (lastBeforeUpdate != null) {
|
||||
PacketHandler.sendPacketToAllPlayers(tile.getDescriptionPacket(), tile.getWorldObj());
|
||||
lastBeforeUpdate = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue