diff --git a/src/main/java/mekanism/common/Mekanism.java b/src/main/java/mekanism/common/Mekanism.java index 5403697de..c9c8de4c2 100644 --- a/src/main/java/mekanism/common/Mekanism.java +++ b/src/main/java/mekanism/common/Mekanism.java @@ -33,6 +33,7 @@ import mekanism.common.Tier.FactoryTier; import mekanism.common.base.IFactory.RecipeType; import mekanism.common.base.IModule; import mekanism.common.content.boiler.BoilerCache; +import mekanism.common.content.boiler.BoilerManager; import mekanism.common.content.boiler.SynchronizedBoilerData; import mekanism.common.content.matrix.MatrixCache; import mekanism.common.content.matrix.SynchronizedMatrixData; @@ -162,7 +163,7 @@ public class Mekanism public static MultiblockManager tankManager = new MultiblockManager("dynamicTank", TankCache.class); public static MultiblockManager matrixManager = new MultiblockManager("energizedInductionMatrix", MatrixCache.class); public static MultiblockManager turbineManager = new MultiblockManager("industrialTurbine", TurbineCache.class); - public static MultiblockManager boilerManager = new MultiblockManager("thermoelectricBoiler", BoilerCache.class); + public static MultiblockManager boilerManager = new BoilerManager("thermoelectricBoiler"); /** Mekanism creative tab */ public static CreativeTabMekanism tabMekanism = new CreativeTabMekanism(); diff --git a/src/main/java/mekanism/common/content/boiler/BoilerCache.java b/src/main/java/mekanism/common/content/boiler/BoilerCache.java index 1f8ad6606..176bc9ab4 100644 --- a/src/main/java/mekanism/common/content/boiler/BoilerCache.java +++ b/src/main/java/mekanism/common/content/boiler/BoilerCache.java @@ -1,5 +1,6 @@ package mekanism.common.content.boiler; +import mekanism.api.Coord4D; import mekanism.common.content.tank.SynchronizedTankData; import mekanism.common.multiblock.MultiblockCache; import mekanism.common.util.FluidContainerUtils.ContainerEditMode; @@ -7,9 +8,12 @@ import mekanism.common.util.FluidContainerUtils.ContainerEditMode; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.Constants.NBT; import net.minecraftforge.fluids.FluidStack; +import java.util.HashMap; + public class BoilerCache extends MultiblockCache { public ItemStack[] inventory = new ItemStack[2]; diff --git a/src/main/java/mekanism/common/content/boiler/BoilerManager.java b/src/main/java/mekanism/common/content/boiler/BoilerManager.java new file mode 100644 index 000000000..5ca71930d --- /dev/null +++ b/src/main/java/mekanism/common/content/boiler/BoilerManager.java @@ -0,0 +1,96 @@ +package mekanism.common.content.boiler; + +import mekanism.api.Coord4D; +import mekanism.common.multiblock.MultiblockCache; +import mekanism.common.multiblock.MultiblockManager; +import mekanism.common.tile.TileEntityBoiler; +import mekanism.common.tile.TileEntityMultiblock; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; + +/** + * Created by ben on 09/01/15. + */ +public class BoilerManager extends MultiblockManager +{ + public BoilerManager(String s) + { + super(s, BoilerCache.class); + } + + public void tickSelf(World world) + { + ArrayList idsToKill = new ArrayList(); + HashMap> tilesToKill = new HashMap>(); + + for(Map.Entry> entry : inventories.entrySet()) + { + int inventoryID = entry.getKey(); + + HashSet boilers = new HashSet(); + + for(Coord4D obj : entry.getValue().locations) + { + if(obj.dimensionId == world.provider.dimensionId && obj.exists(world)) + { + TileEntity tileEntity = obj.getTileEntity(world); + + if(!(tileEntity instanceof TileEntityMultiblock) || ((TileEntityMultiblock)tileEntity).getManager() != this || (getStructureId(((TileEntityMultiblock)tileEntity)) != -1 && getStructureId(((TileEntityMultiblock)tileEntity)) != inventoryID)) + { + if(!tilesToKill.containsKey(inventoryID)) + { + tilesToKill.put(inventoryID, new HashSet()); + } + + tilesToKill.get(inventoryID).add(obj); + } + else if(tileEntity instanceof TileEntityBoiler) + { + ((TileEntityBoiler)tileEntity).simulateHeat(); + boilers.add((TileEntityBoiler) tileEntity); + } + } + } + + if(!boilers.isEmpty()) + { + SynchronizedBoilerData data = boilers.iterator().next().getSynchronizedData(); + + if(data != null) + { + boilers.iterator().next().getSynchronizedData().applyTemperatureChange(); + } + + for (TileEntityBoiler boiler : boilers) + { + boiler.applyTemperatureChange(); + } + } + + if(entry.getValue().locations.isEmpty()) + { + idsToKill.add(inventoryID); + } + } + + for(Map.Entry> entry : tilesToKill.entrySet()) + { + for(Coord4D obj : entry.getValue()) + { + inventories.get(entry.getKey()).locations.remove(obj); + dataHandler.markDirty(); + } + } + + for(int inventoryID : idsToKill) + { + inventories.remove(inventoryID); + dataHandler.markDirty(); + } + } +} diff --git a/src/main/java/mekanism/common/content/boiler/BoilerUpdateProtocol.java b/src/main/java/mekanism/common/content/boiler/BoilerUpdateProtocol.java index eeb0e1078..848b6b4cc 100644 --- a/src/main/java/mekanism/common/content/boiler/BoilerUpdateProtocol.java +++ b/src/main/java/mekanism/common/content/boiler/BoilerUpdateProtocol.java @@ -104,7 +104,7 @@ public class BoilerUpdateProtocol extends UpdateProtocol data.location = obj; data.side = getSide(obj, origX+xmin, origX+xmax, origY+ymin, origY+ymax, origZ+zmin, origZ+zmax); - ((SynchronizedBoilerData)structure).valves.add(data); + structure.valves.add(data); } } } diff --git a/src/main/java/mekanism/common/content/boiler/SynchronizedBoilerData.java b/src/main/java/mekanism/common/content/boiler/SynchronizedBoilerData.java index 61335983f..a5c4491d8 100644 --- a/src/main/java/mekanism/common/content/boiler/SynchronizedBoilerData.java +++ b/src/main/java/mekanism/common/content/boiler/SynchronizedBoilerData.java @@ -23,7 +23,7 @@ public class SynchronizedBoilerData extends SynchronizedData @Override protected void onFormed() { - if(((SynchronizedTankData)structureFound).fluidStored != null) + if(structureFound.fluidStored != null) { - ((SynchronizedTankData)structureFound).fluidStored.amount = Math.min(((SynchronizedTankData)structureFound).fluidStored.amount, structureFound.volume*FLUID_PER_TANK); + structureFound.fluidStored.amount = Math.min(structureFound.fluidStored.amount, structureFound.volume*FLUID_PER_TANK); } } @Override - protected void onStructureCreated(SynchronizedData structure, int origX, int origY, int origZ, int xmin, int xmax, int ymin, int ymax, int zmin, int zmax) + protected void onStructureCreated(SynchronizedTankData structure, int origX, int origY, int origZ, int xmin, int xmax, int ymin, int ymax, int zmin, int zmax) { for(Coord4D obj : structure.locations) { @@ -91,7 +90,7 @@ public class TankUpdateProtocol extends UpdateProtocol data.location = obj; data.side = getSide(obj, origX+xmin, origX+xmax, origY+ymin, origY+ymax, origZ+zmin, origZ+zmax); - ((SynchronizedTankData)structure).valves.add(data); + structure.valves.add(data); } } } diff --git a/src/main/java/mekanism/common/multiblock/MultiblockManager.java b/src/main/java/mekanism/common/multiblock/MultiblockManager.java index c94f2e2cf..f8d259ccf 100644 --- a/src/main/java/mekanism/common/multiblock/MultiblockManager.java +++ b/src/main/java/mekanism/common/multiblock/MultiblockManager.java @@ -141,52 +141,57 @@ public class MultiblockManager> for(MultiblockManager manager : managers) { - ArrayList idsToKill = new ArrayList(); - HashMap> tilesToKill = new HashMap>(); - - for(Map.Entry entry : ((Map)manager.inventories).entrySet()) + manager.tickSelf(world); + } + } + + public void tickSelf(World world) + { + ArrayList idsToKill = new ArrayList(); + HashMap> tilesToKill = new HashMap>(); + + for(Map.Entry> entry : inventories.entrySet()) + { + int inventoryID = entry.getKey(); + + for(Coord4D obj : entry.getValue().locations) { - int inventoryID = entry.getKey(); - - for(Coord4D obj : (Set)entry.getValue().locations) + if(obj.dimensionId == world.provider.dimensionId && obj.exists(world)) { - if(obj.dimensionId == world.provider.dimensionId && obj.exists(world)) + TileEntity tileEntity = obj.getTileEntity(world); + + if(!(tileEntity instanceof TileEntityMultiblock) || ((TileEntityMultiblock)tileEntity).getManager() != this || (getStructureId(((TileEntityMultiblock)tileEntity)) != -1 && getStructureId(((TileEntityMultiblock)tileEntity)) != inventoryID)) { - TileEntity tileEntity = obj.getTileEntity(world); - - if(!(tileEntity instanceof TileEntityMultiblock) || ((TileEntityMultiblock)tileEntity).getManager() != manager || (getStructureId(((TileEntityMultiblock)tileEntity)) != -1 && getStructureId(((TileEntityMultiblock)tileEntity)) != inventoryID)) + if(!tilesToKill.containsKey(inventoryID)) { - if(!tilesToKill.containsKey(inventoryID)) - { - tilesToKill.put(inventoryID, new HashSet()); - } - - tilesToKill.get(inventoryID).add(obj); + tilesToKill.put(inventoryID, new HashSet()); } + + tilesToKill.get(inventoryID).add(obj); } } - - if(entry.getValue().locations.isEmpty()) - { - idsToKill.add(inventoryID); - } } - - for(Map.Entry> entry : tilesToKill.entrySet()) + + if(entry.getValue().locations.isEmpty()) { - for(Coord4D obj : entry.getValue()) - { - ((Map)manager.inventories).get(entry.getKey()).locations.remove(obj); - manager.dataHandler.markDirty(); - } + idsToKill.add(inventoryID); } - - for(int inventoryID : idsToKill) + } + + for(Map.Entry> entry : tilesToKill.entrySet()) + { + for(Coord4D obj : entry.getValue()) { - manager.inventories.remove(inventoryID); - manager.dataHandler.markDirty(); + inventories.get(entry.getKey()).locations.remove(obj); + dataHandler.markDirty(); } } + + for(int inventoryID : idsToKill) + { + inventories.remove(inventoryID); + dataHandler.markDirty(); + } } public static int getStructureId(TileEntityMultiblock tile) diff --git a/src/main/java/mekanism/common/tile/TileEntityBoiler.java b/src/main/java/mekanism/common/tile/TileEntityBoiler.java index dd253d1f6..fa436c977 100644 --- a/src/main/java/mekanism/common/tile/TileEntityBoiler.java +++ b/src/main/java/mekanism/common/tile/TileEntityBoiler.java @@ -43,7 +43,7 @@ public class TileEntityBoiler extends TileEntityMultiblock