2013-08-27 00:49:32 +02:00
|
|
|
package mekanism.common.tileentity;
|
2013-04-28 21:23:08 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2013-12-20 22:09:09 +01:00
|
|
|
import mekanism.api.Coord4D;
|
2013-08-27 00:49:32 +02:00
|
|
|
import mekanism.common.Mekanism;
|
|
|
|
import mekanism.common.PacketHandler;
|
2013-06-13 23:37:30 +02:00
|
|
|
import mekanism.common.PacketHandler.Transmission;
|
2013-12-19 22:55:41 +01:00
|
|
|
import mekanism.common.SynchronizedTankData;
|
2013-04-28 21:23:08 +02:00
|
|
|
import mekanism.common.SynchronizedTankData.ValveData;
|
2013-12-19 22:55:41 +01:00
|
|
|
import mekanism.common.TankUpdateProtocol;
|
2013-06-13 23:37:30 +02:00
|
|
|
import mekanism.common.network.PacketTileEntity;
|
2013-08-27 00:57:08 +02:00
|
|
|
import mekanism.common.util.MekanismUtils;
|
2013-04-28 21:23:08 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2013-12-19 22:55:41 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2013-04-28 21:23:08 +02:00
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
|
|
|
import net.minecraftforge.common.ForgeDirection;
|
2013-07-20 18:10:14 +02:00
|
|
|
import net.minecraftforge.fluids.FluidContainerRegistry;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
2013-04-28 21:23:08 +02:00
|
|
|
|
|
|
|
import com.google.common.io.ByteArrayDataInput;
|
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
public class TileEntityDynamicTank extends TileEntityContainerBlock
|
|
|
|
{
|
|
|
|
/** Unique inventory ID for the dynamic tank, serves as a way to retrieve cached inventories. */
|
|
|
|
public int inventoryID = -1;
|
|
|
|
|
|
|
|
/** The tank data for this structure. */
|
|
|
|
public SynchronizedTankData structure;
|
|
|
|
|
2013-05-03 02:12:51 +02:00
|
|
|
/** Whether or not to send this tank's structure in the next update packet. */
|
2013-05-02 03:00:48 +02:00
|
|
|
public boolean sendStructure;
|
|
|
|
|
2013-05-03 02:12:51 +02:00
|
|
|
/** This tank's previous "has structure" state. */
|
2013-04-28 21:23:08 +02:00
|
|
|
public boolean prevStructure;
|
|
|
|
|
2013-05-03 02:12:51 +02:00
|
|
|
/** Whether or not this tank has it's structure, for the client side mechanics. */
|
2013-04-28 21:23:08 +02:00
|
|
|
public boolean clientHasStructure;
|
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
/** The cached fluid this tank segment contains. */
|
|
|
|
public FluidStack cachedFluid;
|
2013-04-28 21:23:08 +02:00
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
/** A client-sided and server-sided map of valves on this tank's structure, used on the client for rendering fluids. */
|
2013-04-28 21:23:08 +02:00
|
|
|
public Map<ValveData, Integer> valveViewing = new HashMap<ValveData, Integer>();
|
|
|
|
|
2013-05-03 02:12:51 +02:00
|
|
|
/** The capacity this tank has on the client-side. */
|
2013-04-28 21:23:08 +02:00
|
|
|
public int clientCapacity;
|
|
|
|
|
2013-05-03 02:12:51 +02:00
|
|
|
/** Whether or not this tank segment is rendering the structure. */
|
2013-04-28 21:23:08 +02:00
|
|
|
public boolean isRendering;
|
|
|
|
|
2013-12-13 04:31:27 +01:00
|
|
|
public float prevScale;
|
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
public TileEntityDynamicTank()
|
|
|
|
{
|
2013-11-30 06:28:02 +01:00
|
|
|
this("DynamicTank");
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public TileEntityDynamicTank(String name)
|
|
|
|
{
|
|
|
|
super(name);
|
|
|
|
inventory = new ItemStack[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
public void update()
|
|
|
|
{
|
2013-08-04 09:33:40 +02:00
|
|
|
if(!worldObj.isRemote && (structure == null || !structure.didTick))
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
|
|
|
new TankUpdateProtocol(this).updateTanks();
|
|
|
|
|
|
|
|
if(structure != null)
|
|
|
|
{
|
|
|
|
structure.didTick = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate()
|
|
|
|
{
|
|
|
|
if(worldObj.isRemote)
|
|
|
|
{
|
|
|
|
if(structure == null)
|
|
|
|
{
|
|
|
|
structure = new SynchronizedTankData();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(structure != null && clientHasStructure && isRendering)
|
|
|
|
{
|
|
|
|
for(ValveData data : valveViewing.keySet())
|
|
|
|
{
|
|
|
|
if(valveViewing.get(data) > 0)
|
|
|
|
{
|
|
|
|
valveViewing.put(data, valveViewing.get(data)-1);
|
|
|
|
}
|
|
|
|
}
|
2013-05-14 17:34:26 +02:00
|
|
|
|
|
|
|
if(!prevStructure)
|
|
|
|
{
|
|
|
|
Mekanism.proxy.doTankAnimation(this);
|
|
|
|
}
|
2013-12-13 04:31:27 +01:00
|
|
|
|
|
|
|
float targetScale = (float)(structure.fluidStored != null ? structure.fluidStored.amount : 0)/clientCapacity;
|
|
|
|
|
|
|
|
if(Math.abs(prevScale - targetScale) > 0.01)
|
|
|
|
{
|
|
|
|
prevScale = (9*prevScale + targetScale)/10;
|
|
|
|
}
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
|
2013-05-14 17:34:26 +02:00
|
|
|
prevStructure = clientHasStructure;
|
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
if(!clientHasStructure || !isRendering)
|
|
|
|
{
|
2013-05-07 01:42:03 +02:00
|
|
|
for(ValveData data : valveViewing.keySet())
|
|
|
|
{
|
|
|
|
TileEntityDynamicTank tileEntity = (TileEntityDynamicTank)data.location.getTileEntity(worldObj);
|
|
|
|
|
|
|
|
if(tileEntity != null)
|
|
|
|
{
|
|
|
|
tileEntity.clientHasStructure = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
valveViewing.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(playersUsing.size() > 0 && ((worldObj.isRemote && !clientHasStructure) || (!worldObj.isRemote && structure == null)))
|
|
|
|
{
|
|
|
|
for(EntityPlayer player : playersUsing)
|
|
|
|
{
|
|
|
|
player.closeScreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!worldObj.isRemote)
|
|
|
|
{
|
|
|
|
if(structure == null)
|
|
|
|
{
|
|
|
|
isRendering = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(inventoryID != -1 && structure == null)
|
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
MekanismUtils.updateCache(inventoryID, cachedFluid, inventory, this);
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
|
2013-11-14 22:31:02 +01:00
|
|
|
if(structure == null && ticker == 5)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2013-11-14 22:31:02 +01:00
|
|
|
if(structure != null && isRendering && ticker % 20 == 0)
|
2013-05-07 01:42:03 +02:00
|
|
|
{
|
|
|
|
sendStructure = true;
|
2013-12-20 22:09:09 +01:00
|
|
|
PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketTileEntity().setParams(Coord4D.get(this), getNetworkedData(new ArrayList())), Coord4D.get(this), 50D);
|
2013-05-07 01:42:03 +02:00
|
|
|
}
|
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
if(prevStructure != (structure != null))
|
|
|
|
{
|
2013-05-02 03:00:48 +02:00
|
|
|
if(structure != null && !structure.hasRenderer)
|
|
|
|
{
|
|
|
|
structure.hasRenderer = true;
|
|
|
|
isRendering = true;
|
|
|
|
sendStructure = true;
|
|
|
|
}
|
|
|
|
|
2013-12-19 22:55:41 +01:00
|
|
|
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
|
|
|
{
|
2013-12-20 22:09:09 +01:00
|
|
|
Coord4D obj = Coord4D.get(this).getFromSide(side);
|
2013-12-19 22:55:41 +01:00
|
|
|
|
|
|
|
if(!(obj.getTileEntity(worldObj) instanceof TileEntityDynamicTank))
|
|
|
|
{
|
|
|
|
worldObj.notifyBlockOfNeighborChange(obj.xCoord, obj.yCoord, obj.zCoord, getBlockType().blockID);
|
|
|
|
}
|
|
|
|
}
|
2013-12-19 22:32:00 +01:00
|
|
|
|
2013-12-20 22:09:09 +01:00
|
|
|
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTileEntity().setParams(Coord4D.get(this), getNetworkedData(new ArrayList())));
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
prevStructure = structure != null;
|
|
|
|
|
|
|
|
if(structure != null)
|
|
|
|
{
|
|
|
|
structure.didTick = false;
|
|
|
|
|
|
|
|
if(inventoryID != -1)
|
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
MekanismUtils.updateCache(inventoryID, structure.fluidStored, structure.inventory, this);
|
2013-04-28 21:23:08 +02:00
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
cachedFluid = structure.fluidStored;
|
2013-04-28 21:23:08 +02:00
|
|
|
inventory = structure.inventory;
|
|
|
|
}
|
|
|
|
|
|
|
|
manageInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-02 03:00:48 +02:00
|
|
|
@Override
|
|
|
|
public void validate()
|
|
|
|
{
|
|
|
|
//no super for no packets!
|
|
|
|
tileEntityInvalid = false;
|
|
|
|
}
|
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
public void manageInventory()
|
|
|
|
{
|
2013-11-27 04:44:14 +01:00
|
|
|
int max = structure.volume*TankUpdateProtocol.FLUID_PER_TANK;
|
2013-04-28 21:23:08 +02:00
|
|
|
|
|
|
|
if(structure.inventory[0] != null)
|
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
if(FluidContainerRegistry.isEmptyContainer(structure.inventory[0]))
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
if(structure.fluidStored != null && structure.fluidStored.amount >= FluidContainerRegistry.BUCKET_VOLUME)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
ItemStack filled = FluidContainerRegistry.fillFluidContainer(structure.fluidStored, structure.inventory[0]);
|
2013-04-28 21:23:08 +02:00
|
|
|
|
|
|
|
if(filled != null)
|
|
|
|
{
|
|
|
|
if(structure.inventory[1] == null || (structure.inventory[1].isItemEqual(filled) && structure.inventory[1].stackSize+1 <= filled.getMaxStackSize()))
|
|
|
|
{
|
|
|
|
structure.inventory[0].stackSize--;
|
|
|
|
|
|
|
|
if(structure.inventory[0].stackSize <= 0)
|
|
|
|
{
|
|
|
|
structure.inventory[0] = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(structure.inventory[1] == null)
|
|
|
|
{
|
|
|
|
structure.inventory[1] = filled;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
structure.inventory[1].stackSize++;
|
|
|
|
}
|
|
|
|
|
2013-12-16 05:22:39 +01:00
|
|
|
onInventoryChanged();
|
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
structure.fluidStored.amount -= FluidContainerRegistry.getFluidForFilledItem(filled).amount;
|
2013-04-28 21:23:08 +02:00
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
if(structure.fluidStored.amount == 0)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
structure.fluidStored = null;
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
|
2013-12-20 22:09:09 +01:00
|
|
|
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTileEntity().setParams(Coord4D.get(this), getNetworkedData(new ArrayList())));
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-20 18:10:14 +02:00
|
|
|
else if(FluidContainerRegistry.isFilledContainer(structure.inventory[0]))
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
FluidStack itemFluid = FluidContainerRegistry.getFluidForFilledItem(structure.inventory[0]);
|
2013-04-28 21:23:08 +02:00
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
if((structure.fluidStored == null && itemFluid.amount <= max) || structure.fluidStored.amount+itemFluid.amount <= max)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
if(structure.fluidStored != null && !structure.fluidStored.isFluidEqual(itemFluid))
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-28 22:01:23 +01:00
|
|
|
ItemStack containerItem = structure.inventory[0].getItem().getContainerItemStack(structure.inventory[0]);
|
2013-04-28 21:23:08 +02:00
|
|
|
|
|
|
|
boolean filled = false;
|
|
|
|
|
2013-11-28 22:01:23 +01:00
|
|
|
if(containerItem != null)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-11-28 22:01:23 +01:00
|
|
|
if(structure.inventory[1] == null || (structure.inventory[1].isItemEqual(containerItem) && structure.inventory[1].stackSize+1 <= containerItem.getMaxStackSize()))
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
|
|
|
structure.inventory[0] = null;
|
|
|
|
|
|
|
|
if(structure.inventory[1] == null)
|
|
|
|
{
|
2013-11-28 22:01:23 +01:00
|
|
|
structure.inventory[1] = containerItem;
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
structure.inventory[1].stackSize++;
|
|
|
|
}
|
|
|
|
|
2013-12-16 05:22:39 +01:00
|
|
|
onInventoryChanged();
|
2013-04-28 21:23:08 +02:00
|
|
|
filled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
structure.inventory[0].stackSize--;
|
|
|
|
|
|
|
|
if(structure.inventory[0].stackSize == 0)
|
|
|
|
{
|
|
|
|
structure.inventory[0] = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
filled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(filled)
|
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
if(structure.fluidStored == null)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
structure.fluidStored = itemFluid.copy();
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-07-20 18:10:14 +02:00
|
|
|
structure.fluidStored.amount += itemFluid.amount;
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-20 22:09:09 +01:00
|
|
|
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTileEntity().setParams(Coord4D.get(this), getNetworkedData(new ArrayList())));
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ArrayList getNetworkedData(ArrayList data)
|
|
|
|
{
|
|
|
|
super.getNetworkedData(data);
|
|
|
|
|
|
|
|
data.add(isRendering);
|
|
|
|
data.add(structure != null);
|
2013-11-27 04:44:14 +01:00
|
|
|
data.add(structure != null ? structure.volume*TankUpdateProtocol.FLUID_PER_TANK : 0);
|
2013-04-28 21:23:08 +02:00
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
if(structure != null && structure.fluidStored != null)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
|
|
|
data.add(1);
|
2013-07-20 18:10:14 +02:00
|
|
|
data.add(structure.fluidStored.fluidID);
|
|
|
|
data.add(structure.fluidStored.amount);
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
data.add(0);
|
|
|
|
}
|
|
|
|
|
2013-05-02 03:00:48 +02:00
|
|
|
if(structure != null && isRendering)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-05-02 03:00:48 +02:00
|
|
|
if(sendStructure)
|
|
|
|
{
|
|
|
|
sendStructure = false;
|
|
|
|
|
|
|
|
data.add(true);
|
|
|
|
|
|
|
|
data.add(structure.volHeight);
|
|
|
|
data.add(structure.volWidth);
|
|
|
|
data.add(structure.volLength);
|
|
|
|
data.add(structure.renderLocation.xCoord);
|
|
|
|
data.add(structure.renderLocation.yCoord);
|
|
|
|
data.add(structure.renderLocation.zCoord);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data.add(false);
|
|
|
|
}
|
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
data.add(structure.valves.size());
|
|
|
|
|
|
|
|
for(ValveData valveData : structure.valves)
|
|
|
|
{
|
|
|
|
data.add(valveData.location.xCoord);
|
|
|
|
data.add(valveData.location.yCoord);
|
|
|
|
data.add(valveData.location.zCoord);
|
|
|
|
|
|
|
|
data.add(valveData.side.ordinal());
|
2013-07-20 18:10:14 +02:00
|
|
|
data.add(valveData.serverFluid);
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handlePacketData(ByteArrayDataInput dataStream)
|
|
|
|
{
|
|
|
|
super.handlePacketData(dataStream);
|
|
|
|
|
|
|
|
if(structure == null)
|
|
|
|
{
|
|
|
|
structure = new SynchronizedTankData();
|
|
|
|
}
|
|
|
|
|
|
|
|
isRendering = dataStream.readBoolean();
|
|
|
|
clientHasStructure = dataStream.readBoolean();
|
|
|
|
|
|
|
|
clientCapacity = dataStream.readInt();
|
|
|
|
|
|
|
|
if(dataStream.readInt() == 1)
|
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
structure.fluidStored = new FluidStack(dataStream.readInt(), dataStream.readInt());
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-07-20 18:10:14 +02:00
|
|
|
structure.fluidStored = null;
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
|
2013-05-02 03:00:48 +02:00
|
|
|
if(clientHasStructure && isRendering)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-05-02 03:00:48 +02:00
|
|
|
if(dataStream.readBoolean())
|
|
|
|
{
|
|
|
|
structure.volHeight = dataStream.readInt();
|
|
|
|
structure.volWidth = dataStream.readInt();
|
|
|
|
structure.volLength = dataStream.readInt();
|
2013-12-20 22:09:09 +01:00
|
|
|
structure.renderLocation = new Coord4D(dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
|
2013-05-02 03:00:48 +02:00
|
|
|
}
|
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
int size = dataStream.readInt();
|
|
|
|
|
|
|
|
for(int i = 0; i < size; i++)
|
|
|
|
{
|
|
|
|
ValveData data = new ValveData();
|
2013-12-20 22:09:09 +01:00
|
|
|
data.location = new Coord4D(dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
|
2013-04-28 21:23:08 +02:00
|
|
|
data.side = ForgeDirection.getOrientation(dataStream.readInt());
|
|
|
|
int viewingTicks = 0;
|
|
|
|
|
|
|
|
if(dataStream.readBoolean())
|
|
|
|
{
|
|
|
|
viewingTicks = 30;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(viewingTicks == 0)
|
|
|
|
{
|
|
|
|
if(valveViewing.containsKey(data) && valveViewing.get(data) > 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
valveViewing.put(data, viewingTicks);
|
2013-05-07 01:42:03 +02:00
|
|
|
|
|
|
|
TileEntityDynamicTank tileEntity = (TileEntityDynamicTank)data.location.getTileEntity(worldObj);
|
|
|
|
|
|
|
|
if(tileEntity != null)
|
|
|
|
{
|
|
|
|
tileEntity.clientHasStructure = true;
|
|
|
|
}
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void sendPacketToRenderer()
|
|
|
|
{
|
|
|
|
if(structure != null)
|
|
|
|
{
|
2013-12-20 22:09:09 +01:00
|
|
|
for(Coord4D obj : structure.locations)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
|
|
|
TileEntityDynamicTank tileEntity = (TileEntityDynamicTank)obj.getTileEntity(worldObj);
|
|
|
|
|
|
|
|
if(tileEntity != null && tileEntity.isRendering)
|
|
|
|
{
|
2013-12-20 22:09:09 +01:00
|
|
|
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTileEntity().setParams(Coord4D.get(tileEntity), tileEntity.getNetworkedData(new ArrayList())));
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
public int getScaledFluidLevel(int i)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
if(clientCapacity == 0 || structure.fluidStored == null)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
return structure.fluidStored.amount*i / clientCapacity;
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getStackInSlot(int slotID)
|
|
|
|
{
|
|
|
|
return structure != null ? structure.inventory[slotID] : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setInventorySlotContents(int slotID, ItemStack itemstack)
|
|
|
|
{
|
|
|
|
if(structure != null)
|
|
|
|
{
|
|
|
|
structure.inventory[slotID] = itemstack;
|
|
|
|
|
|
|
|
if(itemstack != null && itemstack.stackSize > getInventoryStackLimit())
|
|
|
|
{
|
|
|
|
itemstack.stackSize = getInventoryStackLimit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound nbtTags)
|
|
|
|
{
|
|
|
|
super.readFromNBT(nbtTags);
|
|
|
|
|
2013-05-02 03:00:48 +02:00
|
|
|
if(structure == null)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-05-02 03:00:48 +02:00
|
|
|
inventoryID = nbtTags.getInteger("inventoryID");
|
|
|
|
|
|
|
|
if(inventoryID != -1)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
if(nbtTags.hasKey("cachedFluid"))
|
2013-05-02 03:00:48 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
cachedFluid = FluidStack.loadFluidStackFromNBT(nbtTags.getCompoundTag("cachedFluid"));
|
2013-05-02 03:00:48 +02:00
|
|
|
}
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound nbtTags)
|
|
|
|
{
|
|
|
|
super.writeToNBT(nbtTags);
|
|
|
|
|
|
|
|
nbtTags.setInteger("inventoryID", inventoryID);
|
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
if(cachedFluid != null)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
nbtTags.setTag("cachedFluid", cachedFluid.writeToNBT(new NBTTagCompound()));
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public AxisAlignedBB getRenderBoundingBox()
|
|
|
|
{
|
|
|
|
return INFINITE_EXTENT_AABB;
|
|
|
|
}
|
|
|
|
}
|