mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-25 14:24:35 +00:00
Work on boilers
This commit is contained in:
1 parent
3c1496740c
commit
2d972edf45
8 files changed
+175
-278
No files matched your search
@@ -3,12 +3,11 @@ package mekanism.common.tile;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.IHeatTransfer;
|
||||
import mekanism.api.Range4D;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.base.IFluidContainerManager;
|
||||
import mekanism.common.content.boiler.BoilerCache;
|
||||
@@ -16,28 +15,25 @@ import mekanism.common.content.boiler.BoilerUpdateProtocol;
|
||||
import mekanism.common.content.boiler.SynchronizedBoilerData;
|
||||
import mekanism.common.content.boiler.SynchronizedBoilerData.ValveData;
|
||||
import mekanism.common.multiblock.MultiblockManager;
|
||||
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||
import mekanism.common.util.FluidContainerUtils;
|
||||
import mekanism.common.util.FluidContainerUtils.ContainerEditMode;
|
||||
import mekanism.common.util.HeatUtils;
|
||||
import mekanism.common.util.LangUtils;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
|
||||
public class TileEntityBoilerCasing extends TileEntityMultiblock<SynchronizedBoilerData> implements IFluidContainerManager, IHeatTransfer
|
||||
{
|
||||
/** A client-sided and server-sided map of valves on this tank's structure, used on the client for rendering fluids. */
|
||||
public Map<ValveData, Integer> valveViewing = new HashMap<ValveData, Integer>();
|
||||
/** A client-sided set of valves on this tank's structure that are currently active, used on the client for rendering fluids. */
|
||||
public Set<ValveData> valveViewing = new HashSet<ValveData>();
|
||||
|
||||
/** The capacity this tank has on the client-side. */
|
||||
public int clientWaterCapacity;
|
||||
public int clientSteamCapacity;
|
||||
|
||||
public float prevWaterScale;
|
||||
public float prevSteamScale;
|
||||
|
||||
public ForgeDirection innerSide;
|
||||
|
||||
@@ -65,34 +61,19 @@ public class TileEntityBoilerCasing extends TileEntityMultiblock<SynchronizedBoi
|
||||
{
|
||||
if(structure != null && clientHasStructure && isRendering)
|
||||
{
|
||||
for(ValveData data : valveViewing.keySet())
|
||||
{
|
||||
if(valveViewing.get(data) > 0)
|
||||
{
|
||||
valveViewing.put(data, valveViewing.get(data)-1);
|
||||
}
|
||||
}
|
||||
|
||||
float targetScale = (float)(structure.waterStored != null ? structure.waterStored.amount : 0)/clientWaterCapacity;
|
||||
|
||||
if(Math.abs(prevWaterScale - targetScale) > 0.01)
|
||||
{
|
||||
prevWaterScale = (9*prevWaterScale + targetScale)/10;
|
||||
}
|
||||
|
||||
targetScale = (float)(structure.steamStored != null ? structure.steamStored.amount : 0)/clientSteamCapacity;
|
||||
|
||||
if(Math.abs(prevSteamScale - targetScale) > 0.01)
|
||||
{
|
||||
prevSteamScale = (9*prevSteamScale+ targetScale)/10;
|
||||
}
|
||||
}
|
||||
|
||||
if(!clientHasStructure || !isRendering)
|
||||
{
|
||||
for(ValveData data : valveViewing.keySet())
|
||||
for(ValveData data : valveViewing)
|
||||
{
|
||||
TileEntityDynamicTank tileEntity = (TileEntityDynamicTank)data.location.getTileEntity(worldObj);
|
||||
TileEntityBoilerCasing tileEntity = (TileEntityBoilerCasing)data.location.getTileEntity(worldObj);
|
||||
|
||||
if(tileEntity != null)
|
||||
{
|
||||
@@ -108,166 +89,44 @@ public class TileEntityBoilerCasing extends TileEntityMultiblock<SynchronizedBoi
|
||||
{
|
||||
if(structure != null)
|
||||
{
|
||||
manageInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void manageInventory()
|
||||
{
|
||||
int max = structure.volume * BoilerUpdateProtocol.WATER_PER_TANK;
|
||||
|
||||
if(structure.inventory[0] != null)
|
||||
{
|
||||
if(structure.inventory[0].getItem() instanceof IFluidContainerItem)
|
||||
{
|
||||
if(structure.editMode == ContainerEditMode.FILL && structure.waterStored != null)
|
||||
if(structure.waterStored != null && structure.waterStored.amount <= 0)
|
||||
{
|
||||
int prev = structure.waterStored.amount;
|
||||
|
||||
structure.waterStored.amount -= FluidContainerUtils.insertFluid(structure.waterStored, structure.inventory[0]);
|
||||
|
||||
if(prev == structure.waterStored.amount || structure.waterStored.amount == 0)
|
||||
{
|
||||
if(structure.inventory[1] == null)
|
||||
{
|
||||
structure.inventory[1] = structure.inventory[0].copy();
|
||||
structure.inventory[0] = null;
|
||||
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
if(structure.waterStored.amount == 0)
|
||||
{
|
||||
structure.waterStored = null;
|
||||
}
|
||||
structure.waterStored = null;
|
||||
markDirty();
|
||||
}
|
||||
else if(structure.editMode == ContainerEditMode.EMPTY)
|
||||
|
||||
if(structure.steamStored != null && structure.steamStored.amount <= 0)
|
||||
{
|
||||
if(structure.waterStored != null)
|
||||
{
|
||||
FluidStack received = FluidContainerUtils.extractFluid(max-structure.waterStored.amount, structure.inventory[0], structure.waterStored.getFluid());
|
||||
|
||||
if(received != null)
|
||||
{
|
||||
structure.waterStored.amount += received.amount;
|
||||
}
|
||||
}
|
||||
else {
|
||||
structure.waterStored = FluidContainerUtils.extractFluid(max, structure.inventory[0], null);
|
||||
}
|
||||
|
||||
int newStored = structure.waterStored != null ? structure.waterStored.amount : 0;
|
||||
|
||||
if(((IFluidContainerItem)structure.inventory[0].getItem()).getFluid(structure.inventory[0]) == null || newStored == max)
|
||||
{
|
||||
if(structure.inventory[1] == null)
|
||||
{
|
||||
structure.inventory[1] = structure.inventory[0].copy();
|
||||
structure.inventory[0] = null;
|
||||
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
structure.steamStored = null;
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
else if(FluidContainerRegistry.isEmptyContainer(structure.inventory[0]) && (structure.editMode == ContainerEditMode.BOTH || structure.editMode == ContainerEditMode.FILL))
|
||||
{
|
||||
if(structure.waterStored != null && structure.waterStored.amount >= FluidContainerRegistry.BUCKET_VOLUME)
|
||||
|
||||
if(isRendering)
|
||||
{
|
||||
ItemStack filled = FluidContainerRegistry.fillFluidContainer(structure.waterStored, structure.inventory[0]);
|
||||
|
||||
if(filled != null)
|
||||
boolean needsValveUpdate = false;
|
||||
|
||||
for(ValveData data : structure.valves)
|
||||
{
|
||||
if(structure.inventory[1] == null || (structure.inventory[1].isItemEqual(filled) && structure.inventory[1].stackSize+1 <= filled.getMaxStackSize()))
|
||||
if(data.activeTicks > 0)
|
||||
{
|
||||
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++;
|
||||
}
|
||||
|
||||
markDirty();
|
||||
|
||||
structure.waterStored.amount -= FluidContainerRegistry.getFluidForFilledItem(filled).amount;
|
||||
|
||||
if(structure.waterStored.amount == 0)
|
||||
{
|
||||
structure.waterStored = null;
|
||||
}
|
||||
|
||||
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(this)));
|
||||
data.activeTicks--;
|
||||
}
|
||||
|
||||
if(data.activeTicks > 0 != data.prevActive)
|
||||
{
|
||||
needsValveUpdate = true;
|
||||
}
|
||||
|
||||
data.prevActive = data.activeTicks > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(FluidContainerRegistry.isFilledContainer(structure.inventory[0]) && (structure.editMode == ContainerEditMode.BOTH || structure.editMode == ContainerEditMode.EMPTY))
|
||||
{
|
||||
FluidStack itemFluid = FluidContainerRegistry.getFluidForFilledItem(structure.inventory[0]);
|
||||
|
||||
if((structure.waterStored == null && itemFluid.amount <= max) || structure.waterStored.amount+itemFluid.amount <= max)
|
||||
{
|
||||
if(structure.waterStored != null && !structure.waterStored.isFluidEqual(itemFluid))
|
||||
|
||||
if(needsValveUpdate || structure.needsRenderUpdate())
|
||||
{
|
||||
return;
|
||||
sendPacketToRenderer();
|
||||
}
|
||||
|
||||
ItemStack containerItem = structure.inventory[0].getItem().getContainerItem(structure.inventory[0]);
|
||||
|
||||
boolean filled = false;
|
||||
|
||||
if(containerItem != null)
|
||||
{
|
||||
if(structure.inventory[1] == null || (structure.inventory[1].isItemEqual(containerItem) && structure.inventory[1].stackSize+1 <= containerItem.getMaxStackSize()))
|
||||
{
|
||||
structure.inventory[0] = null;
|
||||
|
||||
if(structure.inventory[1] == null)
|
||||
{
|
||||
structure.inventory[1] = containerItem;
|
||||
}
|
||||
else {
|
||||
structure.inventory[1].stackSize++;
|
||||
}
|
||||
|
||||
filled = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
structure.inventory[0].stackSize--;
|
||||
|
||||
if(structure.inventory[0].stackSize == 0)
|
||||
{
|
||||
structure.inventory[0] = null;
|
||||
}
|
||||
|
||||
filled = true;
|
||||
}
|
||||
|
||||
if(filled)
|
||||
{
|
||||
if(structure.waterStored == null)
|
||||
{
|
||||
structure.waterStored = itemFluid.copy();
|
||||
}
|
||||
else {
|
||||
structure.waterStored.amount += itemFluid.amount;
|
||||
}
|
||||
|
||||
markDirty();
|
||||
}
|
||||
|
||||
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(this)));
|
||||
|
||||
structure.prevWater = structure.waterStored;
|
||||
structure.prevSteam = structure.steamStored;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -307,38 +166,46 @@ public class TileEntityBoilerCasing extends TileEntityMultiblock<SynchronizedBoi
|
||||
data.add(structure.volume*BoilerUpdateProtocol.WATER_PER_TANK);
|
||||
data.add(structure.volume*BoilerUpdateProtocol.STEAM_PER_TANK);
|
||||
data.add(structure.editMode.ordinal());
|
||||
}
|
||||
|
||||
if(structure != null && structure.waterStored != null)
|
||||
{
|
||||
data.add(1);
|
||||
data.add(structure.waterStored.getFluidID());
|
||||
data.add(structure.waterStored.amount);
|
||||
}
|
||||
else {
|
||||
data.add(0);
|
||||
}
|
||||
|
||||
if(structure != null && structure.steamStored != null)
|
||||
{
|
||||
data.add(1);
|
||||
data.add(structure.steamStored.getFluidID());
|
||||
data.add(structure.steamStored.amount);
|
||||
}
|
||||
else {
|
||||
data.add(0);
|
||||
}
|
||||
|
||||
if(structure != null && isRendering)
|
||||
{
|
||||
data.add(structure.valves.size());
|
||||
|
||||
for(ValveData valveData : structure.valves)
|
||||
if(structure.waterStored != null)
|
||||
{
|
||||
valveData.location.write(data);
|
||||
data.add(1);
|
||||
data.add(structure.waterStored.getFluidID());
|
||||
data.add(structure.waterStored.amount);
|
||||
}
|
||||
else {
|
||||
data.add(0);
|
||||
}
|
||||
|
||||
data.add(valveData.side.ordinal());
|
||||
data.add(valveData.serverFluid);
|
||||
if(structure.steamStored != null)
|
||||
{
|
||||
data.add(1);
|
||||
data.add(structure.steamStored.getFluidID());
|
||||
data.add(structure.steamStored.amount);
|
||||
}
|
||||
else {
|
||||
data.add(0);
|
||||
}
|
||||
|
||||
if(isRendering)
|
||||
{
|
||||
Set<ValveData> toSend = new HashSet<ValveData>();
|
||||
|
||||
for(ValveData valveData : structure.valves)
|
||||
{
|
||||
if(valveData.activeTicks > 0)
|
||||
{
|
||||
toSend.add(valveData);
|
||||
}
|
||||
}
|
||||
|
||||
data.add(toSend.size());
|
||||
|
||||
for(ValveData valveData : toSend)
|
||||
{
|
||||
valveData.location.write(data);
|
||||
data.add(valveData.side.ordinal());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,56 +222,44 @@ public class TileEntityBoilerCasing extends TileEntityMultiblock<SynchronizedBoi
|
||||
clientWaterCapacity = dataStream.readInt();
|
||||
clientSteamCapacity = dataStream.readInt();
|
||||
structure.editMode = ContainerEditMode.values()[dataStream.readInt()];
|
||||
}
|
||||
|
||||
if(dataStream.readInt() == 1)
|
||||
{
|
||||
structure.waterStored = new FluidStack(dataStream.readInt(), dataStream.readInt());
|
||||
}
|
||||
else {
|
||||
structure.waterStored = null;
|
||||
}
|
||||
|
||||
if(dataStream.readInt() == 1)
|
||||
{
|
||||
structure.steamStored = new FluidStack(dataStream.readInt(), dataStream.readInt());
|
||||
}
|
||||
else {
|
||||
structure.steamStored = null;
|
||||
}
|
||||
|
||||
if(clientHasStructure && isRendering)
|
||||
{
|
||||
int size = dataStream.readInt();
|
||||
|
||||
for(int i = 0; i < size; i++)
|
||||
|
||||
if(dataStream.readInt() == 1)
|
||||
{
|
||||
ValveData data = new ValveData();
|
||||
data.location = Coord4D.read(dataStream);
|
||||
data.side = ForgeDirection.getOrientation(dataStream.readInt());
|
||||
int viewingTicks = 0;
|
||||
structure.waterStored = new FluidStack(FluidRegistry.getFluid(dataStream.readInt()), dataStream.readInt());
|
||||
}
|
||||
else {
|
||||
structure.waterStored = null;
|
||||
}
|
||||
|
||||
if(dataStream.readInt() == 1)
|
||||
{
|
||||
structure.steamStored = new FluidStack(FluidRegistry.getFluid(dataStream.readInt()), dataStream.readInt());
|
||||
}
|
||||
else {
|
||||
structure.steamStored = null;
|
||||
}
|
||||
|
||||
if(isRendering)
|
||||
{
|
||||
int size = dataStream.readInt();
|
||||
|
||||
valveViewing.clear();
|
||||
|
||||
if(dataStream.readBoolean())
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
viewingTicks = 30;
|
||||
}
|
||||
ValveData data = new ValveData();
|
||||
data.location = Coord4D.read(dataStream);
|
||||
data.side = ForgeDirection.getOrientation(dataStream.readInt());
|
||||
|
||||
valveViewing.add(data);
|
||||
|
||||
if(viewingTicks == 0)
|
||||
{
|
||||
if(valveViewing.containsKey(data) && valveViewing.get(data) > 0)
|
||||
TileEntityBoilerCasing tileEntity = (TileEntityBoilerCasing)data.location.getTileEntity(worldObj);
|
||||
|
||||
if(tileEntity != null)
|
||||
{
|
||||
continue;
|
||||
tileEntity.clientHasStructure = true;
|
||||
}
|
||||
}
|
||||
|
||||
valveViewing.put(data, viewingTicks);
|
||||
|
||||
TileEntityBoilerCasing tileEntity = (TileEntityBoilerCasing)data.location.getTileEntity(worldObj);
|
||||
|
||||
if(tileEntity != null)
|
||||
{
|
||||
tileEntity.clientHasStructure = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -515,6 +370,12 @@ public class TileEntityBoilerCasing extends TileEntityMultiblock<SynchronizedBoi
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return LangUtils.localize("gui.thermoelectricBoiler");
|
||||
}
|
||||
|
||||
public boolean isInnerSide(ForgeDirection side)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user