From 2d972edf453e38fff627e8558e4a2f48ec7726c4 Mon Sep 17 00:00:00 2001 From: aidancbrady Date: Wed, 24 Feb 2016 17:42:12 -0500 Subject: [PATCH] Work on boilers --- .../content/boiler/BoilerSteamTank.java | 9 +- .../common/content/boiler/BoilerTank.java | 27 +- .../content/boiler/BoilerWaterTank.java | 9 +- .../boiler/SynchronizedBoilerData.java | 42 ++- .../common/tile/TileEntityBoilerCasing.java | 357 ++++++------------ .../common/tile/TileEntityBoilerValve.java | 4 +- .../common/tile/TileEntityDynamicTank.java | 4 +- .../resources/assets/mekanism/lang/en_US.lang | 1 + 8 files changed, 175 insertions(+), 278 deletions(-) diff --git a/src/main/java/mekanism/common/content/boiler/BoilerSteamTank.java b/src/main/java/mekanism/common/content/boiler/BoilerSteamTank.java index 3e99ab2a0..32086fd6f 100644 --- a/src/main/java/mekanism/common/content/boiler/BoilerSteamTank.java +++ b/src/main/java/mekanism/common/content/boiler/BoilerSteamTank.java @@ -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; + } } diff --git a/src/main/java/mekanism/common/content/boiler/BoilerTank.java b/src/main/java/mekanism/common/content/boiler/BoilerTank.java index 33a7cdc5d..d313536cc 100644 --- a/src/main/java/mekanism/common/content/boiler/BoilerTank.java +++ b/src/main/java/mekanism/common/content/boiler/BoilerTank.java @@ -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(); } } } diff --git a/src/main/java/mekanism/common/content/boiler/BoilerWaterTank.java b/src/main/java/mekanism/common/content/boiler/BoilerWaterTank.java index 78f8757da..ec1aab932 100644 --- a/src/main/java/mekanism/common/content/boiler/BoilerWaterTank.java +++ b/src/main/java/mekanism/common/content/boiler/BoilerWaterTank.java @@ -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; + } } diff --git a/src/main/java/mekanism/common/content/boiler/SynchronizedBoilerData.java b/src/main/java/mekanism/common/content/boiler/SynchronizedBoilerData.java index 74ee6d8e9..f44ffc3a2 100644 --- a/src/main/java/mekanism/common/content/boiler/SynchronizedBoilerData.java +++ b/src/main/java/mekanism/common/content/boiler/SynchronizedBoilerData.java @@ -15,8 +15,10 @@ import net.minecraftforge.fluids.FluidStack; public class SynchronizedBoilerData extends SynchronizedData 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 valves = new HashSet(); + + 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 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 valveViewing = new HashMap(); + /** A client-sided set of valves on this tank's structure that are currently active, used on the client for rendering fluids. */ + public Set valveViewing = new HashSet(); /** 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 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= 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 toSend = new HashSet(); + + 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 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