Rewrote multiblock data saving, changed simple side names
This commit is contained in:
parent
99d6684425
commit
f83d481fd6
11 changed files with 103 additions and 207 deletions
|
@ -67,7 +67,7 @@ public class MekanismRenderer
|
||||||
|
|
||||||
public static RenderConfigurableMachine machineRenderer = new RenderConfigurableMachine();
|
public static RenderConfigurableMachine machineRenderer = new RenderConfigurableMachine();
|
||||||
|
|
||||||
private static String[] simpleSides = new String[] {"Down", "Up", "Front", "Back", "Left", "Right"};
|
private static String[] simpleSides = new String[] {"Bottom", "Top", "Front", "Back", "Left", "Right"};
|
||||||
|
|
||||||
public static void init()
|
public static void init()
|
||||||
{
|
{
|
||||||
|
|
|
@ -69,11 +69,6 @@ public class CommonWorldTickHandler
|
||||||
{
|
{
|
||||||
if(!world.isRemote)
|
if(!world.isRemote)
|
||||||
{
|
{
|
||||||
if(!MultiblockManager.loaded)
|
|
||||||
{
|
|
||||||
MultiblockManager.load(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!FrequencyManager.loaded)
|
if(!FrequencyManager.loaded)
|
||||||
{
|
{
|
||||||
FrequencyManager.load(world);
|
FrequencyManager.load(world);
|
||||||
|
|
|
@ -40,14 +40,11 @@ import mekanism.common.block.BlockMachine.MachineType;
|
||||||
import mekanism.common.chunkloading.ChunkManager;
|
import mekanism.common.chunkloading.ChunkManager;
|
||||||
import mekanism.common.content.boiler.BoilerManager;
|
import mekanism.common.content.boiler.BoilerManager;
|
||||||
import mekanism.common.content.boiler.SynchronizedBoilerData;
|
import mekanism.common.content.boiler.SynchronizedBoilerData;
|
||||||
import mekanism.common.content.matrix.MatrixCache;
|
|
||||||
import mekanism.common.content.matrix.SynchronizedMatrixData;
|
import mekanism.common.content.matrix.SynchronizedMatrixData;
|
||||||
import mekanism.common.content.tank.SynchronizedTankData;
|
import mekanism.common.content.tank.SynchronizedTankData;
|
||||||
import mekanism.common.content.tank.TankCache;
|
|
||||||
import mekanism.common.content.transporter.PathfinderCache;
|
import mekanism.common.content.transporter.PathfinderCache;
|
||||||
import mekanism.common.content.transporter.TransporterManager;
|
import mekanism.common.content.transporter.TransporterManager;
|
||||||
import mekanism.common.content.turbine.SynchronizedTurbineData;
|
import mekanism.common.content.turbine.SynchronizedTurbineData;
|
||||||
import mekanism.common.content.turbine.TurbineCache;
|
|
||||||
import mekanism.common.entity.EntityBabySkeleton;
|
import mekanism.common.entity.EntityBabySkeleton;
|
||||||
import mekanism.common.entity.EntityBalloon;
|
import mekanism.common.entity.EntityBalloon;
|
||||||
import mekanism.common.entity.EntityFlame;
|
import mekanism.common.entity.EntityFlame;
|
||||||
|
@ -168,9 +165,9 @@ public class Mekanism
|
||||||
public static Version versionNumber = new Version(8, 0, 2);
|
public static Version versionNumber = new Version(8, 0, 2);
|
||||||
|
|
||||||
/** MultiblockManagers for various structrures */
|
/** MultiblockManagers for various structrures */
|
||||||
public static MultiblockManager<SynchronizedTankData> tankManager = new MultiblockManager<SynchronizedTankData>("dynamicTank", TankCache.class);
|
public static MultiblockManager<SynchronizedTankData> tankManager = new MultiblockManager<SynchronizedTankData>("dynamicTank");
|
||||||
public static MultiblockManager<SynchronizedMatrixData> matrixManager = new MultiblockManager<SynchronizedMatrixData>("inductionMatrix", MatrixCache.class);
|
public static MultiblockManager<SynchronizedMatrixData> matrixManager = new MultiblockManager<SynchronizedMatrixData>("inductionMatrix");
|
||||||
public static MultiblockManager<SynchronizedTurbineData> turbineManager = new MultiblockManager<SynchronizedTurbineData>("industrialTurbine", TurbineCache.class);
|
public static MultiblockManager<SynchronizedTurbineData> turbineManager = new MultiblockManager<SynchronizedTurbineData>("industrialTurbine");
|
||||||
public static MultiblockManager<SynchronizedBoilerData> boilerManager = new BoilerManager("thermoelectricBoiler");
|
public static MultiblockManager<SynchronizedBoilerData> boilerManager = new BoilerManager("thermoelectricBoiler");
|
||||||
|
|
||||||
/** FrequencyManagers for various networks */
|
/** FrequencyManagers for various networks */
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
package mekanism.common.content.boiler;
|
package mekanism.common.content.boiler;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import mekanism.api.Coord4D;
|
import mekanism.api.Coord4D;
|
||||||
import mekanism.common.multiblock.MultiblockCache;
|
import mekanism.common.multiblock.MultiblockCache;
|
||||||
import mekanism.common.multiblock.MultiblockManager;
|
import mekanism.common.multiblock.MultiblockManager;
|
||||||
|
@ -8,11 +13,6 @@ import mekanism.common.tile.TileEntityMultiblock;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
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.
|
* Created by ben on 09/01/15.
|
||||||
*/
|
*/
|
||||||
|
@ -20,7 +20,7 @@ public class BoilerManager extends MultiblockManager<SynchronizedBoilerData>
|
||||||
{
|
{
|
||||||
public BoilerManager(String s)
|
public BoilerManager(String s)
|
||||||
{
|
{
|
||||||
super(s, BoilerCache.class);
|
super(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tickSelf(World world)
|
public void tickSelf(World world)
|
||||||
|
@ -83,14 +83,12 @@ public class BoilerManager extends MultiblockManager<SynchronizedBoilerData>
|
||||||
for(Coord4D obj : entry.getValue())
|
for(Coord4D obj : entry.getValue())
|
||||||
{
|
{
|
||||||
inventories.get(entry.getKey()).locations.remove(obj);
|
inventories.get(entry.getKey()).locations.remove(obj);
|
||||||
dataHandler.markDirty();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int inventoryID : idsToKill)
|
for(int inventoryID : idsToKill)
|
||||||
{
|
{
|
||||||
inventories.remove(inventoryID);
|
inventories.remove(inventoryID);
|
||||||
dataHandler.markDirty();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,53 +8,22 @@ import java.util.Set;
|
||||||
|
|
||||||
import mekanism.api.Coord4D;
|
import mekanism.api.Coord4D;
|
||||||
import mekanism.common.tile.TileEntityMultiblock;
|
import mekanism.common.tile.TileEntityMultiblock;
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.WorldSavedData;
|
|
||||||
import net.minecraftforge.common.util.Constants.NBT;
|
|
||||||
|
|
||||||
public class MultiblockManager<T extends SynchronizedData<T>>
|
public class MultiblockManager<T extends SynchronizedData<T>>
|
||||||
{
|
{
|
||||||
private static Set<MultiblockManager> managers = new HashSet<MultiblockManager>();
|
private static Set<MultiblockManager> managers = new HashSet<MultiblockManager>();
|
||||||
|
|
||||||
public static boolean loaded;
|
|
||||||
|
|
||||||
public Class<? extends MultiblockCache<T>> cacheClass;
|
|
||||||
|
|
||||||
public DataHandler dataHandler;
|
|
||||||
|
|
||||||
public String name;
|
public String name;
|
||||||
|
|
||||||
/** A map containing references to all multiblock inventory caches. */
|
/** A map containing references to all multiblock inventory caches. */
|
||||||
public Map<Integer, MultiblockCache<T>> inventories = new HashMap<Integer, MultiblockCache<T>>();
|
public Map<Integer, MultiblockCache<T>> inventories = new HashMap<Integer, MultiblockCache<T>>();
|
||||||
|
|
||||||
public MultiblockManager(String s, Class<? extends MultiblockCache<T>> cache)
|
public MultiblockManager(String s)
|
||||||
{
|
{
|
||||||
name = s;
|
name = s;
|
||||||
managers.add(this);
|
managers.add(this);
|
||||||
cacheClass = cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createOrLoad(World world)
|
|
||||||
{
|
|
||||||
if(dataHandler == null)
|
|
||||||
{
|
|
||||||
dataHandler = (DataHandler)world.perWorldStorage.loadData(DataHandler.class, name);
|
|
||||||
|
|
||||||
if(dataHandler == null)
|
|
||||||
{
|
|
||||||
dataHandler = new DataHandler(name);
|
|
||||||
dataHandler.setManager(this);
|
|
||||||
world.perWorldStorage.setData(name, dataHandler);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
dataHandler.setManager(this);
|
|
||||||
dataHandler.syncManager();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,50 +34,25 @@ public class MultiblockManager<T extends SynchronizedData<T>>
|
||||||
*/
|
*/
|
||||||
public MultiblockCache<T> pullInventory(World world, int id)
|
public MultiblockCache<T> pullInventory(World world, int id)
|
||||||
{
|
{
|
||||||
if(!loaded)
|
|
||||||
{
|
|
||||||
load(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
MultiblockCache<T> toReturn = inventories.get(id);
|
MultiblockCache<T> toReturn = inventories.get(id);
|
||||||
|
|
||||||
|
for(Coord4D obj : inventories.get(id).locations)
|
||||||
|
{
|
||||||
|
TileEntityMultiblock<T> tileEntity = (TileEntityMultiblock<T>)obj.getTileEntity(world);
|
||||||
|
|
||||||
|
if(tileEntity != null)
|
||||||
|
{
|
||||||
|
System.out.println("RESET " + Coord4D.get(tileEntity));
|
||||||
|
tileEntity.cachedData = tileEntity.getNewCache();
|
||||||
|
tileEntity.cachedID = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inventories.remove(id);
|
inventories.remove(id);
|
||||||
dataHandler.markDirty();
|
|
||||||
|
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates a multiblock cache with the defined inventory ID with the parameterized values.
|
|
||||||
* @param multiblock - multiblock TileEntity
|
|
||||||
*/
|
|
||||||
public void updateCache(IMultiblock<T> multiblock)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
if(!loaded)
|
|
||||||
{
|
|
||||||
load(((TileEntity)multiblock).getWorldObj());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!inventories.containsKey(multiblock.getSynchronizedData().inventoryID))
|
|
||||||
{
|
|
||||||
MultiblockCache<T> cache = cacheClass.newInstance();
|
|
||||||
cache.sync((T)multiblock.getSynchronizedData());
|
|
||||||
cache.locations.add(Coord4D.get((TileEntity)multiblock));
|
|
||||||
|
|
||||||
inventories.put(multiblock.getSynchronizedData().inventoryID, cache);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
inventories.get(multiblock.getSynchronizedData().inventoryID).sync((T)multiblock.getSynchronizedData());
|
|
||||||
inventories.get(multiblock.getSynchronizedData().inventoryID).locations.add(Coord4D.get((TileEntity)multiblock));
|
|
||||||
dataHandler.markDirty();
|
|
||||||
} catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grabs a unique inventory ID for a multiblock.
|
* Grabs a unique inventory ID for a multiblock.
|
||||||
* @return unique inventory ID
|
* @return unique inventory ID
|
||||||
|
@ -134,11 +78,6 @@ public class MultiblockManager<T extends SynchronizedData<T>>
|
||||||
|
|
||||||
public static void tick(World world)
|
public static void tick(World world)
|
||||||
{
|
{
|
||||||
if(!loaded)
|
|
||||||
{
|
|
||||||
load(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(MultiblockManager manager : managers)
|
for(MultiblockManager manager : managers)
|
||||||
{
|
{
|
||||||
manager.tickSelf(world);
|
manager.tickSelf(world);
|
||||||
|
@ -183,14 +122,12 @@ public class MultiblockManager<T extends SynchronizedData<T>>
|
||||||
for(Coord4D obj : entry.getValue())
|
for(Coord4D obj : entry.getValue())
|
||||||
{
|
{
|
||||||
inventories.get(entry.getKey()).locations.remove(obj);
|
inventories.get(entry.getKey()).locations.remove(obj);
|
||||||
dataHandler.markDirty();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int inventoryID : idsToKill)
|
for(int inventoryID : idsToKill)
|
||||||
{
|
{
|
||||||
inventories.remove(inventoryID);
|
inventories.remove(inventoryID);
|
||||||
dataHandler.markDirty();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,29 +146,17 @@ public class MultiblockManager<T extends SynchronizedData<T>>
|
||||||
return ((TileEntityMultiblock)tile1).getManager() == ((TileEntityMultiblock)tile2).getManager();
|
return ((TileEntityMultiblock)tile1).getManager() == ((TileEntityMultiblock)tile2).getManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getInventoryId(TileEntityMultiblock<T> tile)
|
public void updateCache(TileEntityMultiblock<T> tile)
|
||||||
{
|
{
|
||||||
Coord4D coord = Coord4D.get(tile);
|
if(!inventories.containsKey(tile.cachedID))
|
||||||
|
|
||||||
for(Map.Entry<Integer, MultiblockCache<T>> entry : inventories.entrySet())
|
|
||||||
{
|
{
|
||||||
if(entry.getValue().locations.contains(coord))
|
tile.cachedData.locations.add(Coord4D.get(tile));
|
||||||
{
|
inventories.put(tile.cachedID, tile.cachedData);
|
||||||
return entry.getKey();
|
|
||||||
}
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void load(World world)
|
|
||||||
{
|
|
||||||
loaded = true;
|
|
||||||
|
|
||||||
for(MultiblockManager manager : managers)
|
|
||||||
{
|
|
||||||
manager.createOrLoad(world);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inventories.get(tile.cachedID).locations.add(Coord4D.get(tile));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reset()
|
public static void reset()
|
||||||
|
@ -239,91 +164,6 @@ public class MultiblockManager<T extends SynchronizedData<T>>
|
||||||
for(MultiblockManager manager : managers)
|
for(MultiblockManager manager : managers)
|
||||||
{
|
{
|
||||||
manager.inventories.clear();
|
manager.inventories.clear();
|
||||||
manager.dataHandler = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
loaded = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class DataHandler extends WorldSavedData
|
|
||||||
{
|
|
||||||
public MultiblockManager manager;
|
|
||||||
|
|
||||||
public Map<Integer, MultiblockCache> loadedInventories;
|
|
||||||
|
|
||||||
public DataHandler(String tagName)
|
|
||||||
{
|
|
||||||
super(tagName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setManager(MultiblockManager m)
|
|
||||||
{
|
|
||||||
manager = m;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void syncManager()
|
|
||||||
{
|
|
||||||
if(loadedInventories != null)
|
|
||||||
{
|
|
||||||
manager.inventories = loadedInventories;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readFromNBT(NBTTagCompound nbtTags)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
String cacheClass = nbtTags.getString("cacheClass");
|
|
||||||
|
|
||||||
NBTTagList list = nbtTags.getTagList("invList", NBT.TAG_COMPOUND);
|
|
||||||
|
|
||||||
loadedInventories = new HashMap<Integer, MultiblockCache>();
|
|
||||||
|
|
||||||
for(int i = 0; i < list.tagCount(); i++)
|
|
||||||
{
|
|
||||||
NBTTagCompound compound = list.getCompoundTagAt(i);
|
|
||||||
MultiblockCache cache = (MultiblockCache)Class.forName(cacheClass).newInstance();
|
|
||||||
cache.load(compound);
|
|
||||||
|
|
||||||
NBTTagList coordsList = compound.getTagList("coordsList", NBT.TAG_COMPOUND);
|
|
||||||
|
|
||||||
for(int j = 0; j < coordsList.tagCount(); j++)
|
|
||||||
{
|
|
||||||
cache.locations.add(Coord4D.read(coordsList.getCompoundTagAt(j)));
|
|
||||||
}
|
|
||||||
|
|
||||||
loadedInventories.put(compound.getInteger("id"), cache);
|
|
||||||
}
|
|
||||||
} catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToNBT(NBTTagCompound nbtTags)
|
|
||||||
{
|
|
||||||
nbtTags.setString("cacheClass", manager.cacheClass.getName());
|
|
||||||
|
|
||||||
NBTTagList list = new NBTTagList();
|
|
||||||
|
|
||||||
for(Map.Entry<Integer, MultiblockCache> entry : ((Map<Integer, MultiblockCache>)manager.inventories).entrySet())
|
|
||||||
{
|
|
||||||
NBTTagCompound compound = new NBTTagCompound();
|
|
||||||
compound.setInteger("id", entry.getKey());
|
|
||||||
entry.getValue().save(compound);
|
|
||||||
|
|
||||||
NBTTagList coordsList = new NBTTagList();
|
|
||||||
|
|
||||||
for(Coord4D coord : (Set<Coord4D>)entry.getValue().locations)
|
|
||||||
{
|
|
||||||
coordsList.appendTag(coord.write(new NBTTagCompound()));
|
|
||||||
}
|
|
||||||
|
|
||||||
compound.setTag("coordsList", coordsList);
|
|
||||||
list.appendTag(compound);
|
|
||||||
}
|
|
||||||
|
|
||||||
nbtTags.setTag("invList", list);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -402,11 +402,10 @@ public abstract class UpdateProtocol<T extends SynchronizedData<T>>
|
||||||
for(Coord4D obj : structureFound.locations)
|
for(Coord4D obj : structureFound.locations)
|
||||||
{
|
{
|
||||||
TileEntityMultiblock<T> tileEntity = (TileEntityMultiblock<T>)obj.getTileEntity(pointer.getWorldObj());
|
TileEntityMultiblock<T> tileEntity = (TileEntityMultiblock<T>)obj.getTileEntity(pointer.getWorldObj());
|
||||||
int id = getManager().getInventoryId(tileEntity);
|
|
||||||
|
|
||||||
if(id != -1)
|
if(tileEntity.cachedID != -1)
|
||||||
{
|
{
|
||||||
idsFound.add(id);
|
idsFound.add(tileEntity.cachedID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,7 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
|
||||||
{
|
{
|
||||||
toDraw -= getTransmitterNetwork().emit(received, true);
|
toDraw -= getTransmitterNetwork().emit(received, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
((IStrictEnergyStorage)outputter).setEnergy(((IStrictEnergyStorage)outputter).getEnergy() - toDraw);
|
((IStrictEnergyStorage)outputter).setEnergy(((IStrictEnergyStorage)outputter).getEnergy() - toDraw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package mekanism.common.tile;
|
package mekanism.common.tile;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -9,6 +11,7 @@ import mekanism.api.IHeatTransfer;
|
||||||
import mekanism.api.Range4D;
|
import mekanism.api.Range4D;
|
||||||
import mekanism.common.Mekanism;
|
import mekanism.common.Mekanism;
|
||||||
import mekanism.common.base.IFluidContainerManager;
|
import mekanism.common.base.IFluidContainerManager;
|
||||||
|
import mekanism.common.content.boiler.BoilerCache;
|
||||||
import mekanism.common.content.boiler.BoilerUpdateProtocol;
|
import mekanism.common.content.boiler.BoilerUpdateProtocol;
|
||||||
import mekanism.common.content.boiler.SynchronizedBoilerData;
|
import mekanism.common.content.boiler.SynchronizedBoilerData;
|
||||||
import mekanism.common.content.boiler.SynchronizedBoilerData.ValveData;
|
import mekanism.common.content.boiler.SynchronizedBoilerData.ValveData;
|
||||||
|
@ -17,7 +20,6 @@ import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||||
import mekanism.common.util.FluidContainerUtils;
|
import mekanism.common.util.FluidContainerUtils;
|
||||||
import mekanism.common.util.FluidContainerUtils.ContainerEditMode;
|
import mekanism.common.util.FluidContainerUtils.ContainerEditMode;
|
||||||
import mekanism.common.util.HeatUtils;
|
import mekanism.common.util.HeatUtils;
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
@ -25,8 +27,6 @@ import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
|
|
||||||
public class TileEntityBoiler extends TileEntityMultiblock<SynchronizedBoilerData> implements IFluidContainerManager, IHeatTransfer
|
public class TileEntityBoiler 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. */
|
/** A client-sided and server-sided map of valves on this tank's structure, used on the client for rendering fluids. */
|
||||||
|
@ -278,6 +278,12 @@ public class TileEntityBoiler extends TileEntityMultiblock<SynchronizedBoilerDat
|
||||||
{
|
{
|
||||||
return new SynchronizedBoilerData();
|
return new SynchronizedBoilerData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BoilerCache getNewCache()
|
||||||
|
{
|
||||||
|
return new BoilerCache();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BoilerUpdateProtocol getProtocol()
|
protected BoilerUpdateProtocol getProtocol()
|
||||||
|
|
|
@ -12,6 +12,7 @@ import mekanism.common.Mekanism;
|
||||||
import mekanism.common.base.IFluidContainerManager;
|
import mekanism.common.base.IFluidContainerManager;
|
||||||
import mekanism.common.content.tank.SynchronizedTankData;
|
import mekanism.common.content.tank.SynchronizedTankData;
|
||||||
import mekanism.common.content.tank.SynchronizedTankData.ValveData;
|
import mekanism.common.content.tank.SynchronizedTankData.ValveData;
|
||||||
|
import mekanism.common.content.tank.TankCache;
|
||||||
import mekanism.common.content.tank.TankUpdateProtocol;
|
import mekanism.common.content.tank.TankUpdateProtocol;
|
||||||
import mekanism.common.multiblock.MultiblockManager;
|
import mekanism.common.multiblock.MultiblockManager;
|
||||||
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||||
|
@ -265,6 +266,12 @@ public class TileEntityDynamicTank extends TileEntityMultiblock<SynchronizedTank
|
||||||
return new SynchronizedTankData();
|
return new SynchronizedTankData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TankCache getNewCache()
|
||||||
|
{
|
||||||
|
return new TankCache();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TankUpdateProtocol getProtocol()
|
protected TankUpdateProtocol getProtocol()
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
import mekanism.api.energy.IStrictEnergyStorage;
|
import mekanism.api.energy.IStrictEnergyStorage;
|
||||||
import mekanism.common.Mekanism;
|
import mekanism.common.Mekanism;
|
||||||
|
import mekanism.common.content.matrix.MatrixCache;
|
||||||
import mekanism.common.content.matrix.MatrixUpdateProtocol;
|
import mekanism.common.content.matrix.MatrixUpdateProtocol;
|
||||||
import mekanism.common.content.matrix.SynchronizedMatrixData;
|
import mekanism.common.content.matrix.SynchronizedMatrixData;
|
||||||
import mekanism.common.multiblock.MultiblockManager;
|
import mekanism.common.multiblock.MultiblockManager;
|
||||||
|
@ -96,6 +97,12 @@ public class TileEntityInductionCasing extends TileEntityMultiblock<Synchronized
|
||||||
{
|
{
|
||||||
return new SynchronizedMatrixData();
|
return new SynchronizedMatrixData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MatrixCache getNewCache()
|
||||||
|
{
|
||||||
|
return new MatrixCache();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected MatrixUpdateProtocol getProtocol()
|
protected MatrixUpdateProtocol getProtocol()
|
||||||
|
|
|
@ -8,12 +8,14 @@ import mekanism.api.Coord4D;
|
||||||
import mekanism.api.Range4D;
|
import mekanism.api.Range4D;
|
||||||
import mekanism.common.Mekanism;
|
import mekanism.common.Mekanism;
|
||||||
import mekanism.common.multiblock.IMultiblock;
|
import mekanism.common.multiblock.IMultiblock;
|
||||||
|
import mekanism.common.multiblock.MultiblockCache;
|
||||||
import mekanism.common.multiblock.MultiblockManager;
|
import mekanism.common.multiblock.MultiblockManager;
|
||||||
import mekanism.common.multiblock.SynchronizedData;
|
import mekanism.common.multiblock.SynchronizedData;
|
||||||
import mekanism.common.multiblock.UpdateProtocol;
|
import mekanism.common.multiblock.UpdateProtocol;
|
||||||
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.AxisAlignedBB;
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
@ -36,6 +38,12 @@ public abstract class TileEntityMultiblock<T extends SynchronizedData<T>> extend
|
||||||
/** Whether or not this multiblock segment is rendering the structure. */
|
/** Whether or not this multiblock segment is rendering the structure. */
|
||||||
public boolean isRendering;
|
public boolean isRendering;
|
||||||
|
|
||||||
|
/** This multiblock segment's cached data */
|
||||||
|
public MultiblockCache cachedData = getNewCache();
|
||||||
|
|
||||||
|
/** This multiblock segment's cached inventory ID */
|
||||||
|
public int cachedID = -1;
|
||||||
|
|
||||||
public TileEntityMultiblock(String name)
|
public TileEntityMultiblock(String name)
|
||||||
{
|
{
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -75,6 +83,11 @@ public abstract class TileEntityMultiblock<T extends SynchronizedData<T>> extend
|
||||||
if(structure == null)
|
if(structure == null)
|
||||||
{
|
{
|
||||||
isRendering = false;
|
isRendering = false;
|
||||||
|
|
||||||
|
if(cachedID != -1)
|
||||||
|
{
|
||||||
|
getManager().updateCache(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(structure == null && ticker == 5)
|
if(structure == null && ticker == 5)
|
||||||
|
@ -112,6 +125,8 @@ public abstract class TileEntityMultiblock<T extends SynchronizedData<T>> extend
|
||||||
|
|
||||||
if(getSynchronizedData().inventoryID != -1)
|
if(getSynchronizedData().inventoryID != -1)
|
||||||
{
|
{
|
||||||
|
cachedData.sync(getSynchronizedData());
|
||||||
|
cachedID = getSynchronizedData().inventoryID;
|
||||||
getManager().updateCache(this);
|
getManager().updateCache(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,6 +164,8 @@ public abstract class TileEntityMultiblock<T extends SynchronizedData<T>> extend
|
||||||
|
|
||||||
protected abstract T getNewStructure();
|
protected abstract T getNewStructure();
|
||||||
|
|
||||||
|
public abstract MultiblockCache<T> getNewCache();
|
||||||
|
|
||||||
protected abstract UpdateProtocol<T> getProtocol();
|
protected abstract UpdateProtocol<T> getProtocol();
|
||||||
|
|
||||||
public abstract MultiblockManager<T> getManager();
|
public abstract MultiblockManager<T> getManager();
|
||||||
|
@ -209,6 +226,35 @@ public abstract class TileEntityMultiblock<T extends SynchronizedData<T>> extend
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFromNBT(NBTTagCompound nbtTags)
|
||||||
|
{
|
||||||
|
super.readFromNBT(nbtTags);
|
||||||
|
|
||||||
|
if(structure == null)
|
||||||
|
{
|
||||||
|
cachedID = nbtTags.getInteger("cachedID");
|
||||||
|
|
||||||
|
if(cachedID != -1)
|
||||||
|
{
|
||||||
|
cachedData.load(nbtTags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToNBT(NBTTagCompound nbtTags)
|
||||||
|
{
|
||||||
|
super.writeToNBT(nbtTags);
|
||||||
|
|
||||||
|
nbtTags.setInteger("cachedID", cachedID);
|
||||||
|
|
||||||
|
if(cachedID != -1)
|
||||||
|
{
|
||||||
|
cachedData.save(nbtTags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getStackInSlot(int slotID)
|
public ItemStack getStackInSlot(int slotID)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue