2014-01-08 02:55:50 +01:00
|
|
|
package mekanism.common.tile;
|
2013-04-28 21:23:08 +02:00
|
|
|
|
2014-06-02 16:52:13 +02:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
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;
|
2014-07-10 23:51:26 +02:00
|
|
|
import mekanism.common.IFluidContainerManager;
|
2013-08-27 00:49:32 +02:00
|
|
|
import mekanism.common.Mekanism;
|
2014-06-11 11:57:49 +02:00
|
|
|
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
2014-07-10 23:51:26 +02:00
|
|
|
import mekanism.common.tank.DynamicTankCache;
|
2014-01-08 02:55:50 +01:00
|
|
|
import mekanism.common.tank.SynchronizedTankData;
|
|
|
|
import mekanism.common.tank.SynchronizedTankData.ValveData;
|
2014-06-02 16:52:13 +02:00
|
|
|
import mekanism.common.tank.TankUpdateProtocol;
|
2014-07-10 23:51:26 +02:00
|
|
|
import mekanism.common.util.FluidContainerUtils.ContainerEditMode;
|
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;
|
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
2014-04-20 04:44:06 +02:00
|
|
|
import net.minecraftforge.common.util.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 cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
2014-07-10 23:51:26 +02:00
|
|
|
public class TileEntityDynamicTank extends TileEntityContainerBlock implements IFluidContainerManager
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
|
|
|
/** Unique inventory ID for the dynamic tank, serves as a way to retrieve cached inventories. */
|
|
|
|
public int inventoryID = -1;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
/** The tank data for this structure. */
|
|
|
|
public SynchronizedTankData structure;
|
2014-07-10 23:51:26 +02:00
|
|
|
|
|
|
|
/** The cache used by this specific tank segment */
|
|
|
|
public DynamicTankCache cachedData = new DynamicTankCache();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
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;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
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;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
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;
|
2014-03-08 02:00:25 +01: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>();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
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;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
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;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-12-13 04:31:27 +01:00
|
|
|
public float prevScale;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
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
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
public TileEntityDynamicTank(String name)
|
|
|
|
{
|
|
|
|
super(name);
|
|
|
|
inventory = new ItemStack[2];
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
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();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
if(structure != null)
|
|
|
|
{
|
|
|
|
structure.didTick = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
@Override
|
|
|
|
public void onUpdate()
|
|
|
|
{
|
|
|
|
if(worldObj.isRemote)
|
|
|
|
{
|
|
|
|
if(structure == null)
|
|
|
|
{
|
|
|
|
structure = new SynchronizedTankData();
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
if(structure != null && clientHasStructure && isRendering)
|
|
|
|
{
|
|
|
|
for(ValveData data : valveViewing.keySet())
|
|
|
|
{
|
|
|
|
if(valveViewing.get(data) > 0)
|
|
|
|
{
|
|
|
|
valveViewing.put(data, valveViewing.get(data)-1);
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-05-14 17:34:26 +02:00
|
|
|
if(!prevStructure)
|
|
|
|
{
|
|
|
|
Mekanism.proxy.doTankAnimation(this);
|
|
|
|
}
|
2014-03-08 02:00:25 +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
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-05-14 17:34:26 +02:00
|
|
|
prevStructure = clientHasStructure;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
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);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-05-07 01:42:03 +02:00
|
|
|
if(tileEntity != null)
|
|
|
|
{
|
|
|
|
tileEntity.clientHasStructure = false;
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
valveViewing.clear();
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
if(playersUsing.size() > 0 && ((worldObj.isRemote && !clientHasStructure) || (!worldObj.isRemote && structure == null)))
|
|
|
|
{
|
|
|
|
for(EntityPlayer player : playersUsing)
|
|
|
|
{
|
|
|
|
player.closeScreen();
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
if(!worldObj.isRemote)
|
|
|
|
{
|
|
|
|
if(structure == null)
|
|
|
|
{
|
|
|
|
isRendering = false;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
if(inventoryID != -1 && structure == null)
|
|
|
|
{
|
2014-07-10 23:51:26 +02:00
|
|
|
MekanismUtils.updateCache(inventoryID, cachedData, this);
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-11-14 22:31:02 +01:00
|
|
|
if(structure == null && ticker == 5)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
|
|
|
update();
|
|
|
|
}
|
2014-03-08 02:00:25 +01: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;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
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);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-12-19 22:55:41 +01:00
|
|
|
if(!(obj.getTileEntity(worldObj) instanceof TileEntityDynamicTank))
|
|
|
|
{
|
2014-05-07 22:37:58 +02:00
|
|
|
worldObj.notifyBlockOfNeighborChange(obj.xCoord, obj.yCoord, obj.zCoord, getBlockType());
|
2013-12-19 22:55:41 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-06-11 11:57:49 +02:00
|
|
|
Mekanism.packetHandler.sendToAll(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())));
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
prevStructure = structure != null;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
if(structure != null)
|
|
|
|
{
|
|
|
|
structure.didTick = false;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
if(inventoryID != -1)
|
|
|
|
{
|
2014-07-10 23:51:26 +02:00
|
|
|
cachedData.sync(structure);
|
|
|
|
MekanismUtils.updateCache(inventoryID, cachedData, this);
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
manageInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
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;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
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]);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
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--;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
if(structure.inventory[0].stackSize <= 0)
|
|
|
|
{
|
|
|
|
structure.inventory[0] = null;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
if(structure.inventory[1] == null)
|
|
|
|
{
|
|
|
|
structure.inventory[1] = filled;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
structure.inventory[1].stackSize++;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-04-20 22:15:44 +02:00
|
|
|
markDirty();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
structure.fluidStored.amount -= FluidContainerRegistry.getFluidForFilledItem(filled).amount;
|
2014-03-08 02:00:25 +01: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
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-06-11 11:57:49 +02:00
|
|
|
Mekanism.packetHandler.sendToAll(new TileEntityMessage(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]);
|
2014-03-08 02:00:25 +01: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;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-05-07 22:37:58 +02:00
|
|
|
ItemStack containerItem = structure.inventory[0].getItem().getContainerItem(structure.inventory[0]);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
boolean filled = false;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
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;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
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++;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-04-20 22:15:44 +02:00
|
|
|
markDirty();
|
2013-04-28 21:23:08 +02:00
|
|
|
filled = true;
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
else {
|
2013-04-28 21:23:08 +02:00
|
|
|
structure.inventory[0].stackSize--;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
if(structure.inventory[0].stackSize == 0)
|
|
|
|
{
|
|
|
|
structure.inventory[0] = null;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
filled = true;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-06-11 11:57:49 +02:00
|
|
|
Mekanism.packetHandler.sendToAll(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())));
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
@Override
|
|
|
|
public ArrayList getNetworkedData(ArrayList data)
|
|
|
|
{
|
|
|
|
super.getNetworkedData(data);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
data.add(isRendering);
|
|
|
|
data.add(structure != null);
|
2014-07-10 23:51:26 +02:00
|
|
|
|
|
|
|
if(structure != null)
|
|
|
|
{
|
|
|
|
data.add(structure.volume*TankUpdateProtocol.FLUID_PER_TANK);
|
|
|
|
data.add(structure.editMode.ordinal());
|
|
|
|
}
|
2014-03-08 02:00:25 +01: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);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
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;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-05-02 03:00:48 +02:00
|
|
|
data.add(true);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-05-02 03:00:48 +02:00
|
|
|
data.add(structure.volHeight);
|
|
|
|
data.add(structure.volWidth);
|
|
|
|
data.add(structure.volLength);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-12-23 23:06:22 +01:00
|
|
|
structure.renderLocation.write(data);
|
2013-05-02 03:00:48 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
data.add(false);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
data.add(structure.valves.size());
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
for(ValveData valveData : structure.valves)
|
|
|
|
{
|
2013-12-23 23:06:22 +01:00
|
|
|
valveData.location.write(data);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
return data;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
@Override
|
2014-06-02 16:52:13 +02:00
|
|
|
public void handlePacketData(ByteBuf dataStream)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
|
|
|
super.handlePacketData(dataStream);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
if(structure == null)
|
|
|
|
{
|
|
|
|
structure = new SynchronizedTankData();
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
isRendering = dataStream.readBoolean();
|
|
|
|
clientHasStructure = dataStream.readBoolean();
|
2014-07-10 23:51:26 +02:00
|
|
|
|
|
|
|
if(clientHasStructure)
|
|
|
|
{
|
|
|
|
clientCapacity = dataStream.readInt();
|
|
|
|
structure.editMode = ContainerEditMode.values()[dataStream.readInt()];
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
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
|
|
|
}
|
2014-03-08 02:00:25 +01: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();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-12-23 23:06:22 +01:00
|
|
|
structure.renderLocation = Coord4D.read(dataStream);
|
2013-05-02 03:00:48 +02:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
int size = dataStream.readInt();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
for(int i = 0; i < size; i++)
|
|
|
|
{
|
|
|
|
ValveData data = new ValveData();
|
2013-12-23 23:06:22 +01:00
|
|
|
data.location = Coord4D.read(dataStream);
|
2013-04-28 21:23:08 +02:00
|
|
|
data.side = ForgeDirection.getOrientation(dataStream.readInt());
|
|
|
|
int viewingTicks = 0;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
if(dataStream.readBoolean())
|
|
|
|
{
|
|
|
|
viewingTicks = 30;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
if(viewingTicks == 0)
|
|
|
|
{
|
|
|
|
if(valveViewing.containsKey(data) && valveViewing.get(data) > 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
valveViewing.put(data, viewingTicks);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-05-07 01:42:03 +02:00
|
|
|
TileEntityDynamicTank tileEntity = (TileEntityDynamicTank)data.location.getTileEntity(worldObj);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-05-07 01:42:03 +02:00
|
|
|
if(tileEntity != null)
|
|
|
|
{
|
|
|
|
tileEntity.clientHasStructure = true;
|
|
|
|
}
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
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);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
if(tileEntity != null && tileEntity.isRendering)
|
|
|
|
{
|
2014-06-11 11:57:49 +02:00
|
|
|
Mekanism.packetHandler.sendToAll(new TileEntityMessage(Coord4D.get(tileEntity), tileEntity.getNetworkedData(new ArrayList())));
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01: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;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
return structure.fluidStored.amount*i / clientCapacity;
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
@Override
|
2014-03-08 02:00:25 +01:00
|
|
|
public ItemStack getStackInSlot(int slotID)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
|
|
|
return structure != null ? structure.inventory[slotID] : null;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
@Override
|
2014-03-08 02:00:25 +01:00
|
|
|
public void setInventorySlotContents(int slotID, ItemStack itemstack)
|
|
|
|
{
|
2013-04-28 21:23:08 +02:00
|
|
|
if(structure != null)
|
|
|
|
{
|
2014-03-08 02:00:25 +01:00
|
|
|
structure.inventory[slotID] = itemstack;
|
|
|
|
|
|
|
|
if(itemstack != null && itemstack.stackSize > getInventoryStackLimit())
|
|
|
|
{
|
|
|
|
itemstack.stackSize = getInventoryStackLimit();
|
|
|
|
}
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
}
|
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
@Override
|
2014-03-08 02:00:25 +01:00
|
|
|
public void readFromNBT(NBTTagCompound nbtTags)
|
|
|
|
{
|
|
|
|
super.readFromNBT(nbtTags);
|
|
|
|
|
|
|
|
if(structure == null)
|
|
|
|
{
|
|
|
|
inventoryID = nbtTags.getInteger("inventoryID");
|
|
|
|
|
|
|
|
if(inventoryID != -1)
|
|
|
|
{
|
2014-07-10 23:51:26 +02:00
|
|
|
cachedData.load(nbtTags);
|
2014-03-08 02:00:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-28 21:23:08 +02:00
|
|
|
|
|
|
|
@Override
|
2014-03-08 02:00:25 +01:00
|
|
|
public void writeToNBT(NBTTagCompound nbtTags)
|
|
|
|
{
|
|
|
|
super.writeToNBT(nbtTags);
|
|
|
|
|
|
|
|
nbtTags.setInteger("inventoryID", inventoryID);
|
|
|
|
|
2014-07-10 23:51:26 +02:00
|
|
|
if(inventoryID != -1)
|
2014-03-08 02:00:25 +01:00
|
|
|
{
|
2014-07-10 23:51:26 +02:00
|
|
|
cachedData.save(nbtTags);
|
2014-03-08 02:00:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public AxisAlignedBB getRenderBoundingBox()
|
|
|
|
{
|
|
|
|
return INFINITE_EXTENT_AABB;
|
|
|
|
}
|
2014-07-10 23:51:26 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ContainerEditMode getContainerEditMode()
|
|
|
|
{
|
|
|
|
if(structure != null)
|
|
|
|
{
|
|
|
|
return structure.editMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ContainerEditMode.BOTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setContainerEditMode(ContainerEditMode mode)
|
|
|
|
{
|
|
|
|
if(structure == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
structure.editMode = mode;
|
|
|
|
}
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|