Work on boilers

This commit is contained in:
aidancbrady 2016-02-24 17:42:12 -05:00
parent 3c1496740c
commit 2d972edf45
8 changed files with 175 additions and 278 deletions

View file

@ -1,7 +1,6 @@
package mekanism.common.content.boiler;
import mekanism.common.tile.TileEntityBoilerCasing;
import net.minecraftforge.fluids.FluidStack;
public class BoilerSteamTank extends BoilerTank
@ -17,9 +16,15 @@ public class BoilerSteamTank extends BoilerTank
return steamBoiler.structure != null ? steamBoiler.structure.steamStored : null;
}
@Override
public void setFluid(FluidStack stack)
{
steamBoiler.structure.steamStored = stack;
}
@Override
public int getCapacity()
{
return steamBoiler.structure != null ? steamBoiler.structure.steamVolume*BoilerUpdateProtocol.STEAM_PER_TANK : 0;
}
}

View file

@ -4,7 +4,6 @@ import mekanism.api.Coord4D;
import mekanism.common.content.boiler.SynchronizedBoilerData.ValveData;
import mekanism.common.tile.TileEntityBoilerCasing;
import mekanism.common.util.MekanismUtils;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidTank;
@ -20,12 +19,6 @@ public abstract class BoilerTank implements IFluidTank
public abstract void setFluid(FluidStack stack);
@Override
public int getCapacity()
{
return steamBoiler.structure != null ? steamBoiler.structure.volume * BoilerUpdateProtocol.WATER_PER_TANK : 0;
}
@Override
public int fill(FluidStack resource, boolean doFill)
{
@ -48,9 +41,7 @@ public abstract class BoilerTank implements IFluidTank
if(resource.amount > 0 && doFill)
{
MekanismUtils.saveChunk(steamBoiler);
updateValveData(true);
steamBoiler.sendPacketToRenderer();
updateValveData(false);
updateValveData();
}
return resource.amount;
@ -65,9 +56,7 @@ public abstract class BoilerTank implements IFluidTank
if(getCapacity() > 0 && doFill)
{
MekanismUtils.saveChunk(steamBoiler);
updateValveData(true);
steamBoiler.sendPacketToRenderer();
updateValveData(false);
updateValveData();
}
return getCapacity();
@ -91,9 +80,7 @@ public abstract class BoilerTank implements IFluidTank
if(resource.amount > 0 && doFill)
{
MekanismUtils.saveChunk(steamBoiler);
updateValveData(true);
steamBoiler.sendPacketToRenderer();
updateValveData(false);
updateValveData();
}
return resource.amount;
@ -107,9 +94,7 @@ public abstract class BoilerTank implements IFluidTank
if(space > 0 && doFill)
{
MekanismUtils.saveChunk(steamBoiler);
updateValveData(true);
steamBoiler.sendPacketToRenderer();
updateValveData(false);
updateValveData();
}
return space;
@ -119,7 +104,7 @@ public abstract class BoilerTank implements IFluidTank
return 0;
}
public void updateValveData(boolean value)
public void updateValveData()
{
if(steamBoiler.structure != null)
{
@ -127,7 +112,7 @@ public abstract class BoilerTank implements IFluidTank
{
if(data.location.equals(Coord4D.get(steamBoiler)))
{
data.serverFluid = value;
data.onTransfer();
}
}
}

View file

@ -1,7 +1,6 @@
package mekanism.common.content.boiler;
import mekanism.common.tile.TileEntityBoilerCasing;
import net.minecraftforge.fluids.FluidStack;
public class BoilerWaterTank extends BoilerTank
@ -17,9 +16,15 @@ public class BoilerWaterTank extends BoilerTank
return steamBoiler.structure != null ? steamBoiler.structure.waterStored : null;
}
@Override
public void setFluid(FluidStack stack)
{
steamBoiler.structure.waterStored = stack;
}
@Override
public int getCapacity()
{
return steamBoiler.structure != null ? steamBoiler.structure.waterVolume*BoilerUpdateProtocol.WATER_PER_TANK : 0;
}
}

View file

@ -15,8 +15,10 @@ import net.minecraftforge.fluids.FluidStack;
public class SynchronizedBoilerData extends SynchronizedData<SynchronizedBoilerData> implements IHeatTransfer
{
public FluidStack waterStored;
public FluidStack prevWater;
public FluidStack steamStored;
public FluidStack prevSteam;
public double temperature;
@ -37,6 +39,37 @@ public class SynchronizedBoilerData extends SynchronizedData<SynchronizedBoilerD
public ItemStack[] inventory = new ItemStack[2];
public Set<ValveData> valves = new HashSet<ValveData>();
public boolean needsRenderUpdate()
{
if((waterStored == null && prevWater != null) || (waterStored != null && prevWater == null))
{
return true;
}
if(waterStored != null && prevWater != null)
{
if((waterStored.getFluid() != prevWater.getFluid()) || (waterStored.amount != prevWater.amount))
{
return true;
}
}
if((steamStored == null && prevSteam != null) || (steamStored != null && prevSteam == null))
{
return true;
}
if(steamStored != null && prevSteam != null)
{
if((steamStored.getFluid() != prevSteam.getFluid()) || (steamStored.amount != prevSteam.amount))
{
return true;
}
}
return false;
}
@Override
public ItemStack[] getInventory()
@ -124,7 +157,14 @@ public class SynchronizedBoilerData extends SynchronizedData<SynchronizedBoilerD
{
public ForgeDirection side;
public Coord4D location;
public boolean serverFluid;
public boolean prevActive;
public int activeTicks;
public void onTransfer()
{
activeTicks = 30;
}
@Override
public int hashCode()

View file

@ -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)
{

View file

@ -63,12 +63,12 @@ public class TileEntityBoilerValve extends TileEntityBoilerCasing implements IFl
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
{
return true;
return ((!worldObj.isRemote && structure != null) || (worldObj.isRemote && clientHasStructure));
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return true;
return ((!worldObj.isRemote && structure != null) || (worldObj.isRemote && clientHasStructure));
}
}

View file

@ -116,9 +116,9 @@ public class TileEntityDynamicTank extends TileEntityMultiblock<SynchronizedTank
}
structure.prevFluid = structure.fluidStored;
manageInventory();
}
manageInventory();
}
}
}

View file

@ -468,6 +468,7 @@ gui.providers=providers
gui.structure=Structure
gui.dynamicTank=Dynamic Tank
gui.industrialTurbine=Industrial Turbine
gui.thermoelectricBoiler=Thermoelectric Boiler
gui.visuals=Visuals
gui.noEject=Can't Eject
gui.undefined=Undefined