finished fixing #19

This commit is contained in:
modmuss50 2015-06-06 07:52:00 +01:00
parent 8a1f0a18cd
commit 379b6a96da
3 changed files with 47 additions and 7 deletions

View file

@ -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;
}
}
}