More work on EIM. Found some inconsistency/incomplete mechanics in the new multiblock system, no longer should be an issue

This commit is contained in:
Aidan C. Brady 2015-03-03 00:15:18 -05:00
parent 1c0fe96fed
commit 978e0801fa
9 changed files with 70 additions and 35 deletions

View file

@ -162,7 +162,7 @@ public class Mekanism
/** MultiblockManagers for various structrures */
public static MultiblockManager<SynchronizedTankData> tankManager = new MultiblockManager<SynchronizedTankData>("dynamicTank", TankCache.class);
public static MultiblockManager<SynchronizedMatrixData> matrixManager = new MultiblockManager<SynchronizedMatrixData>("energizedInductionMatrix", MatrixCache.class);
public static MultiblockManager<SynchronizedMatrixData> matrixManager = new MultiblockManager<SynchronizedMatrixData>("inductionMatrix", MatrixCache.class);
public static MultiblockManager<SynchronizedTurbineData> turbineManager = new MultiblockManager<SynchronizedTurbineData>("industrialTurbine", TurbineCache.class);
public static MultiblockManager<SynchronizedBoilerData> boilerManager = new BoilerManager("thermoelectricBoiler");

View file

@ -29,6 +29,7 @@ import mekanism.common.tile.TileEntityInductionCasing;
import mekanism.common.tile.TileEntityInductionCell;
import mekanism.common.tile.TileEntityInductionPort;
import mekanism.common.tile.TileEntityInductionProvider;
import mekanism.common.tile.TileEntityMultiblock;
import mekanism.common.tile.TileEntitySolarEvaporationBlock;
import mekanism.common.tile.TileEntitySolarEvaporationController;
import mekanism.common.tile.TileEntitySolarEvaporationValve;
@ -123,9 +124,9 @@ public class BlockBasic extends Block implements IBlockCTM, ICustomBlockIcon
{
TileEntity tileEntity = world.getTileEntity(x, y, z);
if(block == this && tileEntity instanceof TileEntityDynamicTank)
if(block == this && tileEntity instanceof TileEntityMultiblock)
{
((TileEntityDynamicTank)tileEntity).update();
((TileEntityMultiblock)tileEntity).update();
}
if(tileEntity instanceof TileEntityBasicBlock)
@ -851,9 +852,9 @@ public class BlockBasic extends Block implements IBlockCTM, ICustomBlockIcon
{
TileEntity tileEntity = world.getTileEntity(x, y, z);
if(tileEntity instanceof TileEntityDynamicTank)
if(tileEntity instanceof TileEntityMultiblock)
{
((TileEntityDynamicTank)tileEntity).update();
((TileEntityMultiblock)tileEntity).update();
}
}
}

View file

@ -3,15 +3,19 @@ package mekanism.common.content.matrix;
import java.util.List;
import mekanism.common.Mekanism;
import mekanism.common.MekanismBlocks;
import mekanism.common.multiblock.MultiblockCache;
import mekanism.common.multiblock.MultiblockManager;
import mekanism.common.multiblock.UpdateProtocol;
import mekanism.common.tile.TileEntityMultiblock;
import mekanism.common.tile.TileEntityInductionCasing;
import mekanism.common.tile.TileEntityInductionCell;
import mekanism.common.tile.TileEntityInductionProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
public class MatrixUpdateProtocol extends UpdateProtocol<SynchronizedMatrixData>
{
public MatrixUpdateProtocol(TileEntityMultiblock<SynchronizedMatrixData> tileEntity)
public MatrixUpdateProtocol(TileEntityInductionCasing tileEntity)
{
super(tileEntity);
}
@ -19,7 +23,20 @@ public class MatrixUpdateProtocol extends UpdateProtocol<SynchronizedMatrixData>
@Override
protected boolean isValidFrame(int x, int y, int z)
{
return false;
return pointer.getWorldObj().getBlock(x, y, z) == MekanismBlocks.BasicBlock2 && pointer.getWorldObj().getBlockMetadata(x, y, z) == 1;
}
@Override
public boolean isValidInnerNode(int x, int y, int z)
{
TileEntity tile = pointer.getWorldObj().getTileEntity(x, y, z);
if(tile != null && (tile instanceof TileEntityInductionCell || tile instanceof TileEntityInductionProvider))
{
return true;
}
return isAir(x, y, z);
}
@Override

View file

@ -9,9 +9,9 @@ public class SynchronizedMatrixData extends SynchronizedData<SynchronizedMatrixD
public double electricityStored;
public double heat;
public int capacitors;
public int outputters;
@Override
public ItemStack[] getInventory()
{
return inventory;
}
}

View file

@ -28,7 +28,7 @@ public class MultiblockManager<T extends SynchronizedData<T>>
public String name;
/** A map containing references to all dynamic tank inventory caches. */
/** A map containing references to all multiblock inventory caches. */
public Map<Integer, MultiblockCache<T>> inventories = new HashMap<Integer, MultiblockCache<T>>();
public MultiblockManager(String s, Class<? extends MultiblockCache<T>> cache)
@ -61,7 +61,7 @@ public class MultiblockManager<T extends SynchronizedData<T>>
* Grabs an inventory from the world's caches, and removes all the world's references to it.
* @param world - world the cache is stored in
* @param id - inventory ID to pull
* @return correct Dynamic Tank inventory cache
* @return correct multiblock inventory cache
*/
public MultiblockCache<T> pullInventory(World world, int id)
{
@ -79,8 +79,8 @@ public class MultiblockManager<T extends SynchronizedData<T>>
}
/**
* Updates a dynamic tank cache with the defined inventory ID with the parameterized values.
* @param multiblock - dynamic tank TileEntity
* Updates a multiblock cache with the defined inventory ID with the parameterized values.
* @param multiblock - multiblock TileEntity
*/
public void updateCache(IMultiblock<T> multiblock)
{
@ -110,7 +110,7 @@ public class MultiblockManager<T extends SynchronizedData<T>>
}
/**
* Grabs a unique inventory ID for a dynamic tank.
* Grabs a unique inventory ID for a multiblock.
* @return unique inventory ID
*/
public int getUniqueInventoryID()

View file

@ -8,7 +8,6 @@ import java.util.Set;
import mekanism.api.Coord4D;
import mekanism.common.Mekanism;
import mekanism.common.tile.TileEntityMultiblock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
@ -18,6 +17,8 @@ public abstract class UpdateProtocol<T extends SynchronizedData<T>>
{
/** The multiblock nodes that have already been iterated over. */
public Set<TileEntityMultiblock<T>> iteratedNodes = new HashSet<TileEntityMultiblock<T>>();
public Set<Coord4D> innerNodes = new HashSet<Coord4D>();
/** The structures found, all connected by some nodes to the pointer. */
public T structureFound = null;
@ -151,20 +152,25 @@ public abstract class UpdateProtocol<T extends SynchronizedData<T>>
}
}
else {
if(!isAir(origX+x, origY+y, origZ+z))
if(!isValidInnerNode(origX+x, origY+y, origZ+z))
{
isHollow = false;
break;
}
else {
innerNodes.add(new Coord4D(origX+x, origY+y, origZ+z, pointer.getWorldObj().provider.dimensionId));
}
volume++;
}
}
if(!isHollow || !rightBlocks || !rightFrame)
{
break;
}
}
if(!isHollow || !rightBlocks || !rightFrame)
{
break;
@ -251,13 +257,18 @@ public abstract class UpdateProtocol<T extends SynchronizedData<T>>
* @param z - z coordinate
* @return
*/
private boolean isAir(int x, int y, int z)
protected boolean isAir(int x, int y, int z)
{
return pointer.getWorldObj().isAirBlock(x, y, z);
}
protected boolean isValidInnerNode(int x, int y, int z)
{
return isAir(x, y, z);
}
/**
* Whether or not the block at the specified location is a viable node for a dynamic tank.
* Whether or not the block at the specified location is a viable node for a multiblock structure.
* @param x - x coordinate
* @param y - y coordinate
* @param z - z coordinate
@ -276,7 +287,7 @@ public abstract class UpdateProtocol<T extends SynchronizedData<T>>
}
/**
* If the block at the specified location is on the minimum of all angles of this dynamic tank, and the one to use for the
* If the block at the specified location is on the minimum of all angles of this multiblock structure, and the one to use for the
* actual calculation.
* @param obj - location to check
* @param xmin - minimum x value
@ -295,7 +306,7 @@ public abstract class UpdateProtocol<T extends SynchronizedData<T>>
}
/**
* Whether or not the block at the specified location is considered a frame on the dynamic tank.
* Whether or not the block at the specified location is considered a frame on the multiblock structure.
* @param obj - location to check
* @param xmin - minimum x value
* @param xmax - maximum x value
@ -338,7 +349,7 @@ public abstract class UpdateProtocol<T extends SynchronizedData<T>>
}
/**
* Whether or not the block at the specified location serves as a frame for a dynamic tank.
* Whether or not the block at the specified location serves as a frame for a multiblock structure.
* @param x - x coordinate
* @param y - y coordinate
* @param z - z coordinate
@ -359,7 +370,7 @@ public abstract class UpdateProtocol<T extends SynchronizedData<T>>
protected void onStructureCreated(T structure, int origX, int origY, int origZ, int xmin, int xmax, int ymin, int ymax, int zmin, int zmax) {}
/**
* Runs the protocol and updates all tanks that make a part of the dynamic tank.
* Runs the protocol and updates all nodes that make a part of the multiblock.
*/
public void doUpdate()
{
@ -401,11 +412,11 @@ public abstract class UpdateProtocol<T extends SynchronizedData<T>>
{
for(int id : idsFound)
{
if(Mekanism.tankManager.inventories.get(id) != null)
if(getManager().inventories.get(id) != null)
{
if(cache == null)
{
cache = (MultiblockCache<T>)Mekanism.tankManager.pullInventory(pointer.getWorldObj(), id);
cache = getManager().pullInventory(pointer.getWorldObj(), id);
}
else {
mergeCaches(rejectedItems, cache, getManager().pullInventory(pointer.getWorldObj(), id));
@ -416,10 +427,11 @@ public abstract class UpdateProtocol<T extends SynchronizedData<T>>
}
}
else {
idToUse = Mekanism.tankManager.getUniqueInventoryID();
idToUse = getManager().getUniqueInventoryID();
}
//TODO someday: drop all items in rejectedItems
//TODO seriously this needs to happen soon
cache.apply((T)structureFound);

View file

@ -4,6 +4,7 @@ import mekanism.common.Mekanism;
import mekanism.common.content.matrix.MatrixUpdateProtocol;
import mekanism.common.content.matrix.SynchronizedMatrixData;
import mekanism.common.multiblock.MultiblockManager;
import net.minecraft.item.ItemStack;
public class TileEntityInductionCasing extends TileEntityMultiblock<SynchronizedMatrixData>
{
@ -15,6 +16,7 @@ public class TileEntityInductionCasing extends TileEntityMultiblock<Synchronized
public TileEntityInductionCasing(String name)
{
super(name);
inventory = new ItemStack[2];
}
@Override

View file

@ -2,5 +2,8 @@ package mekanism.common.tile;
public class TileEntityInductionPort extends TileEntityInductionCasing
{
public TileEntityInductionPort()
{
super("InductionPort");
}
}

View file

@ -22,19 +22,19 @@ import io.netty.buffer.ByteBuf;
public abstract class TileEntityMultiblock<T extends SynchronizedData<T>> extends TileEntityContainerBlock implements IMultiblock<T>
{
/** The tank data for this structure. */
/** The multiblock data for this structure. */
public T structure;
/** Whether or not to send this tank's structure in the next update packet. */
/** Whether or not to send this multiblock's structure in the next update packet. */
public boolean sendStructure;
/** This tank's previous "has structure" state. */
/** This multiblockblock's previous "has structure" state. */
public boolean prevStructure;
/** Whether or not this tank has it's structure, for the client side mechanics. */
/** Whether or not this multiblock has it's structure, for the client side mechanics. */
public boolean clientHasStructure;
/** Whether or not this tank segment is rendering the structure. */
/** Whether or not this multiblock segment is rendering the structure. */
public boolean isRendering;
public TileEntityMultiblock(String name)