Unfinished errored work on nodes

This commit is contained in:
Calclavia 2014-03-08 00:40:02 -08:00
parent 07d4883a9e
commit c029993500
13 changed files with 415 additions and 352 deletions

View file

@ -17,8 +17,7 @@ public class MultipartMechanical implements IPartFactory
public MultipartMechanical()
{
MultiPartRegistry.registerParts(this, PART_TYPES);
MultipartGenerator.registerPassThroughInterface("resonantinduction.core.fluid.IPressurizedNode");
MultipartGenerator.registerPassThroughInterface("resonantinduction.api.mechanical.fluid.IPressure");
MultipartGenerator.registerPassThroughInterface("resonantinduction.core.grid.fluid.IPressureNodeProvider");
MultipartGenerator.registerTrait("resonantinduction.mechanical.energy.network.IMechanicalNodeProvider", "resonantinduction.mechanical.trait.TraitMechanical");
}

View file

@ -2,7 +2,7 @@ package resonantinduction.mechanical.energy.network;
import resonantinduction.core.grid.INodeProvider;
public interface IMechanicalNodeProvider extends INodeProvider<MechanicalNode>
public interface IMechanicalNodeProvider extends INodeProvider
{
}

View file

@ -4,6 +4,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.core.ResonantInduction;
import resonantinduction.core.grid.Node;
import resonantinduction.mechanical.Mechanical;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.network.IPacketReceiver;
@ -68,7 +69,7 @@ public abstract class TileMechanical extends TileAdvanced implements IMechanical
}
@Override
public MechanicalNode getNode(ForgeDirection dir)
public MechanicalNode getNode(Class<? extends Node> clazz, ForgeDirection dir)
{
return mechanicalNode;
}

View file

@ -1,5 +1,6 @@
package resonantinduction.mechanical.fluid.pipe;
import calclavia.lib.utility.WorldUtility;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -12,9 +13,9 @@ import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import resonantinduction.core.ResonantInduction;
import resonantinduction.core.fluid.IPressurizedNode;
import resonantinduction.core.fluid.PressureNetwork;
import resonantinduction.core.prefab.part.PartFramedConnection;
import resonantinduction.core.grid.fluid.IPressureNodeProvider;
import resonantinduction.core.grid.fluid.PressureNode;
import resonantinduction.core.prefab.part.PartFramedNode;
import resonantinduction.mechanical.Mechanical;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.render.CCRenderState;
@ -28,10 +29,9 @@ import codechicken.multipart.TileMultipart;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PartPipe extends PartFramedConnection<EnumPipeMaterial, IPressurizedNode, PressureNetwork> implements IPressurizedNode, TSlottedPart, JNormalOcclusion, IHollowConnect
public class PartPipe extends PartFramedNode<EnumPipeMaterial, PressureNode, IPressureNodeProvider> implements IPressureNodeProvider, TSlottedPart, JNormalOcclusion, IHollowConnect
{
protected FluidTank tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
private int pressure;
private boolean markPacket = true;
public PartPipe(int typeID)
@ -39,6 +39,76 @@ public class PartPipe extends PartFramedConnection<EnumPipeMaterial, IPressurize
super();
material = EnumPipeMaterial.values()[typeID];
requiresInsulation = false;
node = new PressureNode(this)
{
@Override
public void recache()
{
synchronized (connections)
{
connections.clear();
byte previousConnections = getAllCurrentConnections();
currentConnections = 0;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tile = position().translate(dir).getTileEntity(world());
if (tile instanceof IFluidHandler)
{
if (tile instanceof IPressureNodeProvider)
{
PressureNode check = ((IPressureNodeProvider) tile).getNode(dir.getOpposite());
if (check != null && canConnect(dir, check) && check.canConnect(dir.getOpposite(), this))
{
currentConnections = WorldUtility.setEnableSide(currentConnections, dir, true);
connections.put(check, dir);
}
}
else
{
currentConnections = WorldUtility.setEnableSide(currentConnections, dir, true);
connections.put(tile, dir);
}
}
}
/** Only send packet updates if visuallyConnected changed. */
if (previousConnections != currentConnections)
{
sendConnectionUpdate();
}
}
}
@Override
public boolean canConnect(ForgeDirection from, Object source)
{return
super.canConnect(from, source);
/*Object obj = tile instanceof TileMultipart ? ((TileMultipart) tile).partMap(ForgeDirection.UNKNOWN.ordinal()) : tile;
if (obj instanceof PartPipe)
{
if (this.getMaterial() == ((PartPipe) obj).getMaterial())
{
return getColor() == ((PartPipe) obj).getColor() || (getColor() == DEFAULT_COLOR || ((PartPipe) obj).getColor() == DEFAULT_COLOR);
}
return false;
}
return tile instanceof IFluidHandler;*/
}
@Override
public int getMaxFlowRate()
{
return 100;
}
};
}
public PartPipe()
@ -104,19 +174,6 @@ public class PartPipe extends PartFramedConnection<EnumPipeMaterial, IPressurize
return new ItemStack(Mechanical.itemPipe);
}
/** Fluid network methods. */
@Override
public PressureNetwork getNetwork()
{
if (this.network == null)
{
this.network = new PressureNetwork();
this.network.addConnector(this);
}
return this.network;
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
@ -172,12 +229,7 @@ public class PartPipe extends PartFramedConnection<EnumPipeMaterial, IPressurize
}
@Override
public void onFluidChanged()
{
}
@Override
public FluidTank getInternalTank()
public FluidTank getPressureTank()
{
if (this.tank == null)
{
@ -187,51 +239,7 @@ public class PartPipe extends PartFramedConnection<EnumPipeMaterial, IPressurize
return this.tank;
}
@Override
protected boolean canConnectTo(TileEntity tile, ForgeDirection dir)
{
Object obj = tile instanceof TileMultipart ? ((TileMultipart) tile).partMap(ForgeDirection.UNKNOWN.ordinal()) : tile;
if (obj instanceof PartPipe)
{
if (this.getMaterial() == ((PartPipe) obj).getMaterial())
{
return getColor() == ((PartPipe) obj).getColor() || (getColor() == DEFAULT_COLOR || ((PartPipe) obj).getColor() == DEFAULT_COLOR);
}
return false;
}
return tile instanceof IFluidHandler;
}
@Override
protected IPressurizedNode getConnector(TileEntity tile)
{
if (tile instanceof IPressurizedNode)
if (((IPressurizedNode) tile).getInstance(ForgeDirection.UNKNOWN) instanceof IPressurizedNode)
return (IPressurizedNode) ((IPressurizedNode) tile).getInstance(ForgeDirection.UNKNOWN);
return null;
}
@Override
public int getPressure(ForgeDirection dir)
{
return pressure;
}
@Override
public void setPressure(int amount)
{
pressure = amount;
}
@Override
public int getMaxFlowRate()
{
return 100;
}
@Override
public void drawBreaking(RenderBlocks renderBlocks)
@ -253,11 +261,4 @@ public class PartPipe extends PartFramedConnection<EnumPipeMaterial, IPressurize
super.load(nbt);
tank.readFromNBT(nbt);
}
@Override
public boolean canFlow()
{
return true;
}
}

View file

@ -4,17 +4,43 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import resonantinduction.api.mechanical.fluid.IPressure;
import resonantinduction.core.fluid.IPressurizedNode;
import resonantinduction.core.grid.fluid.IPressureNodeProvider;
import resonantinduction.core.grid.fluid.PressureNode;
import resonantinduction.mechanical.energy.network.TileMechanical;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.prefab.tile.IRotatable;
public class TilePump extends TileMechanical implements IFluidHandler, IRotatable, IPressure
public class TilePump extends TileMechanical implements IPressureNodeProvider, IRotatable
{
private final long maximumPower = 100000;
private final PressureNode pressureNode;
public TilePump()
{
pressureNode = new PressureNode(this)
{
@Override
public int getPressure(ForgeDirection dir)
{
if (mechanicalNode.getPower() > 0)
{
if (dir == getDirection())
{
return (int) Math.max((((double) mechanicalNode.getPower() / (double) maximumPower) * 100), 2);
}
else if (dir == getDirection().getOpposite())
{
return (int) -Math.max((((double) mechanicalNode.getPower() / (double) maximumPower) * 100), 2);
}
}
return 0;
}
}
}
@Override
public void updateEntity()
@ -28,7 +54,7 @@ public class TilePump extends TileMechanical implements IFluidHandler, IRotatabl
*/
TileEntity tileIn = new Vector3(this).translate(getDirection().getOpposite()).getTileEntity(this.worldObj);
if (tileIn instanceof IFluidHandler && !(tileIn instanceof IPressurizedNode))
if (tileIn instanceof IFluidHandler && !(tileIn instanceof IPressureNodeProvider))
{
int flowRate = (int) (((double) mechanicalNode.getPower() / (double) maximumPower) * 500);
FluidStack drain = ((IFluidHandler) tileIn).drain(getDirection(), flowRate, false);
@ -98,26 +124,9 @@ public class TilePump extends TileMechanical implements IFluidHandler, IRotatabl
}
@Override
public void setPressure(int amount)
public FluidTank getPressureTank()
{
}
@Override
public int getPressure(ForgeDirection dir)
{
if (mechanicalNode.getPower() > 0)
{
if (dir == getDirection())
{
return (int) Math.max((((double) mechanicalNode.getPower() / (double) maximumPower) * 100), 2);
}
else if (dir == getDirection().getOpposite())
{
return (int) -Math.max((((double) mechanicalNode.getPower() / (double) maximumPower) * 100), 2);
}
}
return 0;
return null;
}
}

View file

@ -1,10 +0,0 @@
package resonantinduction.api.mechanical.fluid;
import net.minecraftforge.common.ForgeDirection;
public interface IPressure
{
public void setPressure(int amount);
public int getPressure(ForgeDirection dir);
}

View file

@ -1,27 +0,0 @@
package resonantinduction.core.fluid;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.IFluidHandler;
import resonantinduction.api.mechanical.fluid.IPressure;
import universalelectricity.api.net.IConnector;
/**
* Applied to tiles that are pipes and support pressure
*
* @author DarkGuardsman
*/
public interface IPressurizedNode extends IConnector<PressureNetwork>, IFluidHandler, IPressure
{
public FluidTank getInternalTank();
public void onFluidChanged();
public boolean canFlow();
/**
* Max flow rate of fluid this pipe can support
*
* @return amount in liters.
*/
public int getMaxFlowRate();
}

View file

@ -1,206 +0,0 @@
package resonantinduction.core.fluid;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.IFluidHandler;
import resonantinduction.api.mechanical.fluid.IPressure;
import universalelectricity.api.net.IUpdate;
import universalelectricity.core.net.NetworkTickHandler;
import universalelectricity.core.net.NodeNetwork;
/**
* The network for pipe fluid transfer. getNodes() is NOT used.
*
* @author Calclavia
*/
public class PressureNetwork extends NodeNetwork<PressureNetwork, IPressurizedNode, IFluidHandler> implements IUpdate
{
public PressureNetwork()
{
super(IPressurizedNode.class);
}
@Override
public void update()
{
for (IPressurizedNode connector : getConnectors())
{
calculatePressure((IPressurizedNode) connector);
distribute((IPressurizedNode) connector);
}
}
@Override
public boolean canUpdate()
{
return getConnectors().size() > 0;
}
@Override
public boolean continueUpdate()
{
return canUpdate();
}
/**
* Calculate pressure in this pipe.
*/
public void calculatePressure(IPressurizedNode sourcePipe)
{
int totalPressure = 0;
int findCount = 0;
int minPressure = 0;
int maxPressure = 0;
Object[] connections = sourcePipe.getConnections();
if (connections != null)
{
for (int i = 0; i < connections.length; i++)
{
Object obj = connections[i];
if (obj instanceof IPressure)
{
int pressure = ((IPressure) obj).getPressure(ForgeDirection.getOrientation(i).getOpposite());
minPressure = Math.min(pressure, minPressure);
maxPressure = Math.max(pressure, maxPressure);
totalPressure += pressure;
findCount++;
}
}
}
if (findCount == 0)
{
sourcePipe.setPressure(0);
}
else
{
/**
* Create pressure loss.
*/
if (minPressure < 0)
minPressure += 1;
if (maxPressure > 0)
maxPressure -= 1;
sourcePipe.setPressure(Math.max(minPressure, Math.min(maxPressure, totalPressure / findCount + Integer.signum(totalPressure))));
}
}
/**
* Distribute fluid in this pipe based on pressure.
*/
public void distribute(IPressurizedNode sourcePipe)
{
Object[] connections = sourcePipe.getConnections();
for (int i = 0; i < connections.length; i++)
{
Object obj = connections[i];
if (obj instanceof IPressurizedNode)
{
IPressurizedNode otherPipe = (IPressurizedNode) obj;
/**
* Move fluid from higher pressure to lower. In this case, move from tankA to tankB.
*/
ForgeDirection dir = ForgeDirection.getOrientation(i);
int pressureA = sourcePipe.getPressure(dir);
int pressureB = otherPipe.getPressure(dir.getOpposite());
if (pressureA >= pressureB)
{
FluidTank tankA = sourcePipe.getInternalTank();
FluidStack fluidA = tankA.getFluid();
if (tankA != null && fluidA != null)
{
int amountA = fluidA.amount;
if (amountA > 0)
{
FluidTank tankB = otherPipe.getInternalTank();
if (tankB != null)
{
int amountB = tankB.getFluidAmount();
int quantity = Math.max(pressureA > pressureB ? (pressureA - pressureB) * sourcePipe.getMaxFlowRate() : 0, Math.min((amountA - amountB) / 2, sourcePipe.getMaxFlowRate()));
quantity = Math.min(Math.min(quantity, tankB.getCapacity() - amountB), amountA);
if (quantity > 0)
{
FluidStack drainStack = sourcePipe.drain(dir.getOpposite(), quantity, false);
if (drainStack != null && drainStack.amount > 0)
sourcePipe.drain(dir.getOpposite(), otherPipe.fill(dir, drainStack, true), true);
}
}
}
}
}
}
else if (obj instanceof IFluidHandler)
{
IFluidHandler fluidHandler = (IFluidHandler) obj;
ForgeDirection dir = ForgeDirection.getOrientation(i);
int pressure = sourcePipe.getPressure(dir);
int tankPressure = fluidHandler instanceof IPressure ? ((IPressure) fluidHandler).getPressure(dir.getOpposite()) : 0;
FluidTank sourceTank = sourcePipe.getInternalTank();
int transferAmount = (Math.max(pressure, tankPressure) - Math.min(pressure, tankPressure)) * sourcePipe.getMaxFlowRate();
if (pressure > tankPressure)
{
if (sourceTank.getFluidAmount() > 0 && transferAmount > 0)
{
FluidStack drainStack = sourcePipe.drain(dir.getOpposite(), transferAmount, false);
sourcePipe.drain(dir.getOpposite(), fluidHandler.fill(dir.getOpposite(), drainStack, true), true);
}
}
else if (pressure < tankPressure)
{
if (transferAmount > 0)
{
FluidStack drainStack = fluidHandler.drain(dir.getOpposite(), transferAmount, false);
if (drainStack != null)
{
fluidHandler.drain(dir.getOpposite(), sourcePipe.fill(dir.getOpposite(), drainStack, true), true);
}
}
}
}
}
}
@Override
public Class getConnectorClass()
{
return IPressurizedNode.class;
}
@Override
public PressureNetwork newInstance()
{
return new PressureNetwork();
}
@Override
public void reconstructConnector(IPressurizedNode connector)
{
connector.setNetwork(this);
}
@Override
public void reconstruct()
{
NetworkTickHandler.addNetwork(this);
super.reconstruct();
}
}

View file

@ -2,7 +2,19 @@ package resonantinduction.core.grid;
import net.minecraftforge.common.ForgeDirection;
public interface INodeProvider<N extends Node>
/**
* Any inheritance of INodeProvider should have a method "getNode()"
*
* @author Calclavia
*
* @param <N> - Node type.
*/
public interface INodeProvider
{
public N getNode(ForgeDirection from);
/**
* @param nodeType - The type of node we are looking for.
* @param from - The direction.
* @return Returns the node object.
*/
public Object getNode(Class<? extends Node> nodeType, ForgeDirection from);
}

View file

@ -95,6 +95,11 @@ public abstract class Node<P extends INodeProvider, G extends Grid, N>
return connections;
}
public boolean canConnect(ForgeDirection from, Object source)
{
return false;
}
/**
* Must be called to load the node's data.
*/

View file

@ -4,7 +4,7 @@ import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.IFluidHandler;
import resonantinduction.core.grid.INodeProvider;
public interface IPressureNodeProvider extends INodeProvider<PressureNode>, IFluidHandler
public interface IPressureNodeProvider extends INodeProvider, IFluidHandler
{
FluidTank getPressureTank();
}

View file

@ -10,7 +10,6 @@ import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.IFluidHandler;
import resonantinduction.api.mechanical.fluid.IPressure;
import resonantinduction.core.grid.Node;
import resonantinduction.core.grid.TickingGrid;
import universalelectricity.api.vector.Vector3;
@ -53,9 +52,9 @@ public class PressureNode extends Node<IPressureNodeProvider, TickingGrid, Objec
Entry<Object, ForgeDirection> entry = it.next();
Object obj = entry.getKey();
if (obj instanceof IPressure)
if (obj instanceof PressureNode)
{
int pressure = ((IPressure) obj).getPressure(entry.getValue().getOpposite());
int pressure = ((PressureNode) obj).getPressure(entry.getValue().getOpposite());
minPressure = Math.min(pressure, minPressure);
maxPressure = Math.max(pressure, maxPressure);
@ -138,7 +137,7 @@ public class PressureNode extends Node<IPressureNodeProvider, TickingGrid, Objec
{
IFluidHandler fluidHandler = (IFluidHandler) obj;
int pressure = getPressure(dir);
int tankPressure = fluidHandler instanceof IPressure ? ((IPressure) fluidHandler).getPressure(dir.getOpposite()) : 0;
int tankPressure = fluidHandler instanceof IPressureNodeProvider ? ((IPressureNodeProvider) fluidHandler).getNode(getClass(),dir.getOpposite()).getPressure(dir.getOpposite()) : 0;
FluidTank sourceTank = parent.getPressureTank();
int transferAmount = (Math.max(pressure, tankPressure) - Math.min(pressure, tankPressure)) * getMaxFlowRate();

View file

@ -0,0 +1,280 @@
package resonantinduction.core.prefab.part;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.core.grid.INodeProvider;
import resonantinduction.core.grid.Node;
import universalelectricity.api.vector.Vector3;
import universalelectricity.api.vector.VectorHelper;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
import codechicken.lib.raytracer.IndexedCuboid6;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.IconTransformation;
import codechicken.lib.render.RenderUtils;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Translation;
import codechicken.microblock.IHollowConnect;
import codechicken.multipart.IconHitEffects;
import codechicken.multipart.JIconHitEffects;
import codechicken.multipart.JNormalOcclusion;
import codechicken.multipart.NormalOcclusionTest;
import codechicken.multipart.PartMap;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TSlottedPart;
import codechicken.multipart.TileMultipart;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public abstract class PartFramedNode<M extends Enum, N extends Node, T extends INodeProvider> extends PartColorableMaterial<M> implements INodeProvider, TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects
{
public static IndexedCuboid6[] sides = new IndexedCuboid6[7];
public static IndexedCuboid6[] insulatedSides = new IndexedCuboid6[7];
static
{
sides[0] = new IndexedCuboid6(0, new Cuboid6(0.36, 0.000, 0.36, 0.64, 0.36, 0.64));
sides[1] = new IndexedCuboid6(1, new Cuboid6(0.36, 0.64, 0.36, 0.64, 1.000, 0.64));
sides[2] = new IndexedCuboid6(2, new Cuboid6(0.36, 0.36, 0.000, 0.64, 0.64, 0.36));
sides[3] = new IndexedCuboid6(3, new Cuboid6(0.36, 0.36, 0.64, 0.64, 0.64, 1.000));
sides[4] = new IndexedCuboid6(4, new Cuboid6(0.000, 0.36, 0.36, 0.36, 0.64, 0.64));
sides[5] = new IndexedCuboid6(5, new Cuboid6(0.64, 0.36, 0.36, 1.000, 0.64, 0.64));
sides[6] = new IndexedCuboid6(6, new Cuboid6(0.36, 0.36, 0.36, 0.64, 0.64, 0.64));
insulatedSides[0] = new IndexedCuboid6(0, new Cuboid6(0.3, 0.0, 0.3, 0.7, 0.3, 0.7));
insulatedSides[1] = new IndexedCuboid6(1, new Cuboid6(0.3, 0.7, 0.3, 0.7, 1.0, 0.7));
insulatedSides[2] = new IndexedCuboid6(2, new Cuboid6(0.3, 0.3, 0.0, 0.7, 0.7, 0.3));
insulatedSides[3] = new IndexedCuboid6(3, new Cuboid6(0.3, 0.3, 0.7, 0.7, 0.7, 1.0));
insulatedSides[4] = new IndexedCuboid6(4, new Cuboid6(0.0, 0.3, 0.3, 0.3, 0.7, 0.7));
insulatedSides[5] = new IndexedCuboid6(5, new Cuboid6(0.7, 0.3, 0.3, 1.0, 0.7, 0.7));
insulatedSides[6] = new IndexedCuboid6(6, new Cuboid6(0.3, 0.3, 0.3, 0.7, 0.7, 0.7));
}
protected Object[] connections = new Object[6];
protected N node;
/**
* Bitmask connections
*/
public byte currentConnections = 0x00;
/** Client Side */
private ForgeDirection testingSide;
@SideOnly(Side.CLIENT)
protected Icon breakIcon;
public void preparePlacement(int meta)
{
this.setMaterial(meta);
}
@Override
public boolean occlusionTest(TMultiPart other)
{
return NormalOcclusionTest.apply(this, other);
}
@Override
public Iterable<IndexedCuboid6> getSubParts()
{
Set<IndexedCuboid6> subParts = new HashSet<IndexedCuboid6>();
IndexedCuboid6[] currentSides = isInsulated() ? insulatedSides : sides;
if (tile() != null)
{
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
int ord = side.ordinal();
if (connectionMapContainsSide(getAllCurrentConnections(), side) || side == testingSide)
subParts.add(currentSides[ord]);
}
}
subParts.add(currentSides[6]);
return subParts;
}
/**
* Rendering and block bounds.
*/
@Override
public Iterable<Cuboid6> getCollisionBoxes()
{
Set<Cuboid6> collisionBoxes = new HashSet<Cuboid6>();
collisionBoxes.addAll((Collection<? extends Cuboid6>) getSubParts());
return collisionBoxes;
}
@Override
public float getStrength(MovingObjectPosition hit, EntityPlayer player)
{
return 10F;
}
@Override
public void drawBreaking(RenderBlocks renderBlocks)
{
if (breakIcon != null)
{
CCRenderState.reset();
RenderUtils.renderBlock(sides[6], 0, new Translation(x(), y(), z()), new IconTransformation(breakIcon), null);
}
}
@Override
public Cuboid6 getBounds()
{
return new Cuboid6(0.375, 0.375, 0.375, 0.625, 0.625, 0.625);
}
@Override
public Icon getBreakingIcon(Object subPart, int side)
{
return breakIcon;
}
@Override
public Icon getBrokenIcon(int side)
{
return breakIcon;
}
@Override
public Iterable<Cuboid6> getOcclusionBoxes()
{
return getCollisionBoxes();
}
@Override
public int getSlotMask()
{
return PartMap.CENTER.mask;
}
@Override
public int getHollowSize()
{
return isInsulated ? 8 : 6;
}
@Override
public void addHitEffects(MovingObjectPosition hit, EffectRenderer effectRenderer)
{
IconHitEffects.addHitEffects(this, hit, effectRenderer);
}
@Override
public void addDestroyEffects(EffectRenderer effectRenderer)
{
IconHitEffects.addDestroyEffects(this, effectRenderer, false);
}
public boolean isBlockedOnSide(ForgeDirection side)
{
TMultiPart blocker = tile().partMap(side.ordinal());
testingSide = side;
boolean expandable = NormalOcclusionTest.apply(this, blocker);
testingSide = null;
return !expandable;
}
public byte getAllCurrentConnections()
{
return (byte) (currentConnections);
}
public static boolean connectionMapContainsSide(byte connections, ForgeDirection side)
{
byte tester = (byte) (1 << side.ordinal());
return ((connections & tester) > 0);
}
@Override
public void bind(TileMultipart t)
{
node.deconstruct();
super.bind(t);
node.reconstruct();
}
public boolean isCurrentlyConnected(ForgeDirection side)
{
return connectionMapContainsSide(getAllCurrentConnections(), side);
}
@Override
public void onWorldJoin()
{
node.reconstruct();
}
@Override
public void onWorldSeparate()
{
node.deconstruct();
}
public void copyFrom(PartFramedNode<M, N, T> other)
{
this.isInsulated = other.isInsulated;
this.color = other.color;
this.connections = other.connections;
this.material = other.material;
}
/** Packet Methods */
public void sendConnectionUpdate()
{
tile().getWriteStream(this).writeByte(0).writeByte(currentConnections);
}
@Override
public void readDesc(MCDataInput packet)
{
super.readDesc(packet);
currentConnections = packet.readByte();
}
@Override
public void writeDesc(MCDataOutput packet)
{
super.writeDesc(packet);
packet.writeByte(currentConnections);
}
@Override
public void read(MCDataInput packet)
{
read(packet, packet.readUByte());
}
@Override
public void read(MCDataInput packet, int packetID)
{
if (packetID == 0)
{
currentConnections= packet.readByte();
tile().markRender();
}
else
{
super.read(packet, packetID);
}
}
public N getNode(ForgeDirection from)
{
return node;
}
}