Fixed pipe connection for colors

Also change the name of a few classes in the process
This commit is contained in:
Rseifert 2013-03-26 19:47:35 -04:00
parent ef6e6fde06
commit 3dd19fc09d
11 changed files with 133 additions and 132 deletions

View file

@ -13,58 +13,72 @@ import fluidmech.common.machines.pipes.TileEntityPipe;
public class RenderNetworkPipe extends TileEntitySpecialRenderer
{
private ModelLargePipe SixPipe;
private boolean[] renderSide = new boolean[6];
private ModelLargePipe SixPipe;
private boolean[] renderSide = new boolean[6];
public RenderNetworkPipe()
{
SixPipe = new ModelLargePipe();
}
public RenderNetworkPipe()
{
SixPipe = new ModelLargePipe();
}
public void renderAModelAt(TileEntity te, double d, double d1, double d2, float f)
{
// Texture file
GL11.glPushMatrix();
GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
int meta = 0;
if (te instanceof TileEntityNetworkPipe)
{
meta = te.getBlockMetadata();
this.renderSide = ((TileEntityNetworkPipe) te).renderConnection;
}
this.render(meta);
GL11.glPopMatrix();
public void renderAModelAt(TileEntity te, double d, double d1, double d2, float f)
{
// Texture file
GL11.glPushMatrix();
GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
}
public static String getPipeTexture(int meta)
{
return FluidMech.MODEL_TEXTURE_DIRECTORY + "pipes/"+ColorCode.get(meta).getName()+"Pipe.png";
}
public void render(int meta)
{
bindTextureByName(this.getPipeTexture(meta));
if (renderSide[0])
SixPipe.renderBottom();
if (renderSide[1])
SixPipe.renderTop();
if (renderSide[3])
SixPipe.renderFront();
if (renderSide[2])
SixPipe.renderBack();
if (renderSide[5])
SixPipe.renderRight();
if (renderSide[4])
SixPipe.renderLeft();
SixPipe.renderMiddle();
}
int meta = 0;
@Override
public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8)
{
this.renderAModelAt(tileEntity, var2, var4, var6, var8);
}
if (te instanceof TileEntityNetworkPipe)
{
meta = te.getBlockMetadata();
this.renderSide = ((TileEntityNetworkPipe) te).renderConnection;
}
this.render(meta, renderSide);
GL11.glPopMatrix();
}
public static String getPipeTexture(int meta)
{
return FluidMech.MODEL_TEXTURE_DIRECTORY + "pipes/" + ColorCode.get(meta).getName() + "Pipe.png";
}
public void render(int meta, boolean[] side)
{
bindTextureByName(this.getPipeTexture(meta));
if (side[0])
{
SixPipe.renderBottom();
}
if (side[1])
{
SixPipe.renderTop();
}
if (side[3])
{
SixPipe.renderFront();
}
if (side[2])
{
SixPipe.renderBack();
}
if (side[5])
{
SixPipe.renderRight();
}
if (side[4])
{
SixPipe.renderLeft();
}
SixPipe.renderMiddle();
}
@Override
public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8)
{
this.renderAModelAt(tileEntity, var2, var4, var6, var8);
}
}

View file

@ -228,7 +228,7 @@ public class TileEntityMinorPump extends TileEntityElectricityRunnable implement
}
@Override
public boolean canConnect(ForgeDirection dir, LiquidStack... stacks)
public boolean canConnect(ForgeDirection dir,TileEntity entity, LiquidStack... stacks)
{
if (dir == this.pipeConnection.getOpposite())
{

View file

@ -213,7 +213,7 @@ public class TileEntityReleaseValve extends TileEntityAdvanced implements IPsiCr
}
@Override
public boolean canConnect(ForgeDirection dir, LiquidStack... stacks)
public boolean canConnect(ForgeDirection dir,TileEntity entity, LiquidStack... stacks)
{
for (int i = 0; i < stacks.length; i++)
{

View file

@ -220,7 +220,7 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
}
@Override
public boolean canConnect(ForgeDirection dir, LiquidStack... stacks)
public boolean canConnect(ForgeDirection dir, TileEntity entity, LiquidStack... stacks)
{
for (int i = 0; i < stacks.length; i++)
{

View file

@ -3,8 +3,8 @@ package fluidmech.common.machines.pipes;
import fluidmech.common.FluidMech;
import hydraulic.api.ColorCode;
import hydraulic.api.IColorCoded;
import hydraulic.api.IPipeConnection;
import hydraulic.api.IFluidNetworkPart;
import hydraulic.api.IPipeConnector;
import hydraulic.api.IReadOut;
import hydraulic.core.liquidNetwork.HydraulicNetwork;
@ -36,8 +36,6 @@ import cpw.mods.fml.relauncher.SideOnly;
public class TileEntityNetworkPipe extends TileEntityAdvanced implements ITankContainer, IReadOut, IColorCoded, IFluidNetworkPart, IPacketReceiver
{
/* COLOR CODE THIS PIPE USES FOR CONNECTION RULES */
private ColorCode color = ColorCode.NONE;
/* TANK TO FAKE OTHER TILES INTO BELIVING THIS HAS AN INTERNAL STORAGE */
private LiquidTank fakeTank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME);
/* CURRENTLY CONNECTED TILE ENTITIES TO THIS */
@ -61,7 +59,6 @@ public class TileEntityNetworkPipe extends TileEntityAdvanced implements ITankCo
@Override
public void initiate()
{
this.color = ColorCode.get(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
this.updateAdjacentConnections();
}
@ -103,7 +100,7 @@ public class TileEntityNetworkPipe extends TileEntityAdvanced implements ITankCo
@Override
public ColorCode getColor()
{
return this.color;
return ColorCode.get(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
}
/**
@ -112,37 +109,28 @@ public class TileEntityNetworkPipe extends TileEntityAdvanced implements ITankCo
@Override
public void setColor(Object cc)
{
this.color = ColorCode.get(cc);
}
/**
* sets the current color mark of the pipe
*/
public void setColor(int i)
{
if (i < ColorCode.values().length)
{
this.color = ColorCode.values()[i];
}
// TODO add stuff here to reset the pipe's metadata
}
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side)
{
/* DEBUG CODE */
boolean testConnections = false;
/* DEBUG CODE ACTIVATERS */
boolean testConnections = true;
boolean testNetwork = true;
/* NORMAL OUTPUT */
String string = this.getNetwork().pressureProduced + "p ";
/* DEBUG CODE */
if (testConnections)
{
for (int i = 0; i < 6; i++)
{
string += " " + this.renderConnection[i];
string.replaceAll("true", "T").replaceAll("false", "F");
string += ":" + (this.renderConnection[i] ? "T" : "F") + (this.getAdjacentConnections()[i] != null ? "T" : "F");
}
}
if(testNetwork)
if (testNetwork)
{
string += " " + this.getNetwork().toString();
}
@ -153,7 +141,7 @@ public class TileEntityNetworkPipe extends TileEntityAdvanced implements ITankCo
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
if (resource == null || !this.color.isValidLiquid(resource))
if (resource == null || !this.getColor().isValidLiquid(resource))
{
return 0;
}
@ -163,7 +151,7 @@ public class TileEntityNetworkPipe extends TileEntityAdvanced implements ITankCo
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill)
{
if (tankIndex != 0 || resource == null || !this.color.isValidLiquid(resource))
if (tankIndex != 0 || resource == null || !this.getColor().isValidLiquid(resource))
{
return 0;
}
@ -191,7 +179,7 @@ public class TileEntityNetworkPipe extends TileEntityAdvanced implements ITankCo
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
{
if (this.color.isValidLiquid(type))
if (this.getColor().isValidLiquid(type))
{
return this.fakeTank;
}
@ -199,26 +187,39 @@ public class TileEntityNetworkPipe extends TileEntityAdvanced implements ITankCo
}
/**
* validates that the tileEntity this pipe is connecting to is valid
* Checks to make sure the connection is valid to the tileEntity
*
* @param tileEntity - connection
* @param side - side connecting
* @param tileEntity - the tileEntity being checked
* @param side - side the connection is too
*/
public void validataConnectionSide(TileEntity tileEntity, ForgeDirection side)
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
{
if (!this.worldObj.isRemote && tileEntity != null)
{
if (tileEntity instanceof IPipeConnector && ((IPipeConnector) tileEntity).canConnect(side, color.getArrayLiquidStacks()))
if (tileEntity instanceof IPipeConnection)
{
if (tileEntity instanceof IFluidNetworkPart)
if (((IPipeConnection) tileEntity).canConnect(side, this, getColor().getArrayLiquidStacks()))
{
this.getNetwork().mergeNetworks(((IFluidNetworkPart) tileEntity).getNetwork());
if (tileEntity instanceof IFluidNetworkPart)
{
if (((IFluidNetworkPart) tileEntity).getColor() == this.getColor())
{
this.getNetwork().mergeNetworks(((IFluidNetworkPart) tileEntity).getNetwork());
connectedBlocks[side.ordinal()] = tileEntity;
}
}
else
{
connectedBlocks[side.ordinal()] = tileEntity;
}
}
connectedBlocks[side.ordinal()] = tileEntity;
}
else if (tileEntity instanceof IColorCoded && (this.color == ColorCode.NONE || this.color == ((IColorCoded) tileEntity).getColor()))
else if (tileEntity instanceof IColorCoded)
{
connectedBlocks[side.ordinal()] = tileEntity;
if (this.getColor() == ColorCode.NONE || this.getColor() == ((IColorCoded) tileEntity).getColor())
{
connectedBlocks[side.ordinal()] = tileEntity;
}
}
else if (tileEntity instanceof ITankContainer)
{
@ -239,9 +240,13 @@ public class TileEntityNetworkPipe extends TileEntityAdvanced implements ITankCo
for (int i = 0; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
this.validataConnectionSide(this.worldObj.getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ), dir);
this.validateConnectionSide(this.worldObj.getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ), dir);
this.renderConnection[i] = this.connectedBlocks[i] != null;
if (this.connectedBlocks[i] instanceof ITankContainer)
{
this.getNetwork().addEntity(this.connectedBlocks[i]);
}
}
/**
@ -255,16 +260,9 @@ public class TileEntityNetworkPipe extends TileEntityAdvanced implements ITankCo
}
@Override
public boolean canConnect(ForgeDirection dir, LiquidStack... stacks)
public boolean canConnect(ForgeDirection dir, TileEntity entity, LiquidStack... stacks)
{
for (int i = 0; i < stacks.length; i++)
{
if (this.color.isValidLiquid(stacks[i]))
{
return true;
}
}
return false;
return true;
}
@Override
@ -278,7 +276,7 @@ public class TileEntityNetworkPipe extends TileEntityAdvanced implements ITankCo
{
if (this.pipeNetwork == null)
{
this.setNetwork(new HydraulicNetwork(color,this));
this.setNetwork(new HydraulicNetwork(this.getColor(), this));
}
return this.pipeNetwork;
}
@ -319,9 +317,9 @@ public class TileEntityNetworkPipe extends TileEntityAdvanced implements ITankCo
}
@Override
public boolean canConnect(ForgeDirection direction)
public boolean canConnect(ForgeDirection dir)
{
return true;
return worldObj.getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetZ, zCoord + dir.offsetY) instanceof IFluidNetworkPart;
}
}

View file

@ -3,7 +3,7 @@ package fluidmech.common.machines.pipes;
import fluidmech.common.machines.TileEntityTank;
import hydraulic.api.ColorCode;
import hydraulic.api.IColorCoded;
import hydraulic.api.IPipeConnector;
import hydraulic.api.IPipeConnection;
import hydraulic.api.IPsiCreator;
import hydraulic.api.IReadOut;
import hydraulic.core.liquidNetwork.LiquidHandler;
@ -275,9 +275,9 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
connectedBlocks[side] = null;
}
}
else if (tileEntity instanceof IPipeConnector)
else if (tileEntity instanceof IPipeConnection)
{
if (!((IPipeConnector) tileEntity).canConnect(direction, color.getLiquidData().getStack()))
if (!((IPipeConnection) tileEntity).canConnect(direction,this, color.getLiquidData().getStack()))
{
connectedBlocks[side] = null;
}
@ -308,7 +308,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
highestPressure = ((TileEntityPipe) connectedBlocks[i]).getPressure();
}
}
if (connectedBlocks[i] instanceof IPsiCreator && ((IPipeConnector) connectedBlocks[i]).canConnect(dir, color.getArrayLiquidStacks()))
if (connectedBlocks[i] instanceof IPsiCreator && ((IPipeConnection) connectedBlocks[i]).canConnect(dir,this, color.getArrayLiquidStacks()))
{
int p = ((IPsiCreator) connectedBlocks[i]).getPressureOut(color.getLiquidData().getStack(), dir);

View file

@ -11,7 +11,7 @@ import net.minecraftforge.liquids.LiquidStack;
* that doesn't change the over all network pressure. So pipes, gauges, tubes, buffers, decor
* blocks.
*/
public interface IFluidNetworkPart extends IPipeConnector, IColorCoded, IConnectionProvider
public interface IFluidNetworkPart extends IPipeConnection, IColorCoded, IConnectionProvider
{
/**
* gets the devices pressure from a given side for input

View file

@ -4,7 +4,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.LiquidStack;
public interface IPipeConnector
public interface IPipeConnection
{
/**
*
@ -13,5 +13,5 @@ public interface IPipeConnector
* connecting machine has no specific stack requirement
* @return true if it can connect
*/
public boolean canConnect(ForgeDirection dir, LiquidStack... stacks);
public boolean canConnect(ForgeDirection dir,TileEntity entity, LiquidStack... stacks);
}

View file

@ -3,7 +3,7 @@ package hydraulic.api;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.LiquidStack;
public interface IPsiCreator extends IPipeConnector
public interface IPsiCreator extends IPipeConnection
{
/**
* gets the pressure produced from that side of the machine. Use canConnect method to allow a

View file

@ -11,7 +11,7 @@ import net.minecraftforge.liquids.LiquidStack;
* net.minecraftforge.liquids too make your machine work with other fluid mods that don't use
* pressure
*/
public interface IPsiReciever extends IPipeConnector
public interface IPsiReciever extends IPipeConnection
{
/**
* the load that this machine is handling, working, or moving

View file

@ -2,7 +2,7 @@ package hydraulic.core.liquidNetwork;
import hydraulic.api.ColorCode;
import hydraulic.api.IFluidNetworkPart;
import hydraulic.api.IPipeConnector;
import hydraulic.api.IPipeConnection;
import hydraulic.api.IPsiCreator;
import hydraulic.api.IPsiReciever;
import hydraulic.helpers.connectionHelper;
@ -50,29 +50,14 @@ public class HydraulicNetwork
this.color = color;
}
/**
* updates the pressure in the network
*
* @param ent
*/
public void updatePressure()
public void registerLoad(TileEntity entity)
{
this.pressureLoad = 0;
this.pressureProduced = 0;
for (TileEntity ent : receivers)
{
if (ent instanceof IPipeConnector && ((IPipeConnector) ent).canConnect(ForgeDirection.UNKNOWN, this.color.getArrayLiquidStacks()))
{
if (ent instanceof IPsiReciever)
{
pressureLoad += ((IPsiReciever) ent).getPressureLoad();
}
else if (ent instanceof IPsiCreator)
{
pressureProduced += ((IPsiCreator) ent).getPressureOut(color.getLiquidData().getStack(), ForgeDirection.UNKNOWN);
}
}
}
}
public void registerProducer(TileEntity entity)
{
}
/**
@ -293,6 +278,10 @@ public class HydraulicNetwork
{
it.remove();
}
else if (conductor.getColor() != this.color)
{
it.remove();
}
else
{
conductor.setNetwork(this);