Merged network pipe with old pipe

Now that the new network pipes function up to the same level as the old
pipes its time to retire the old pipe. Only thing left too do with the
new pipes after this is too refine the code, add PSI methods, and make
it more compatible with other mods. Though as far as i can tell it
should work with other mods. However, if a mod doesn't use some methods
right then the pipes will not fill them as fast.
This commit is contained in:
Rseifert 2013-03-29 16:43:59 -04:00
parent 6eaaa91849
commit 24e4f1f853
9 changed files with 339 additions and 825 deletions

View file

@ -7,7 +7,7 @@ import fluidmech.client.render.BlockRenderHelper;
import fluidmech.client.render.ItemRenderHelper;
import fluidmech.client.render.RenderGearRod;
import fluidmech.client.render.RenderGenerator;
import fluidmech.client.render.RenderNetworkPipe;
import fluidmech.client.render.RenderPipe;
import fluidmech.client.render.RenderPipe;
import fluidmech.client.render.RenderPump;
import fluidmech.client.render.RenderReleaseValve;
@ -21,7 +21,7 @@ import fluidmech.common.machines.TileEntitySink;
import fluidmech.common.machines.TileEntityTank;
import fluidmech.common.machines.mech.TileEntityGenerator;
import fluidmech.common.machines.mech.TileEntityRod;
import fluidmech.common.machines.pipes.TileEntityNetworkPipe;
import fluidmech.common.machines.pipes.TileEntityPipe;
import fluidmech.common.machines.pipes.TileEntityPipe;
public class ClientProxy extends CommonProxy
@ -36,7 +36,7 @@ public class ClientProxy extends CommonProxy
public void Init()
{
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityPipe.class, new RenderPipe());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityNetworkPipe.class, new RenderNetworkPipe());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityPipe.class, new RenderPipe());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMinorPump.class, new RenderPump());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityRod.class, new RenderGearRod());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityGenerator.class, new RenderGenerator());

View file

@ -1,84 +0,0 @@
package fluidmech.client.render;
import hydraulic.api.ColorCode;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11;
import fluidmech.client.model.ModelLargePipe;
import fluidmech.common.FluidMech;
import fluidmech.common.machines.pipes.TileEntityNetworkPipe;
import fluidmech.common.machines.pipes.TileEntityPipe;
public class RenderNetworkPipe extends TileEntitySpecialRenderer
{
private ModelLargePipe SixPipe;
private boolean[] renderSide = new boolean[6];
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, 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

@ -9,60 +9,76 @@ import org.lwjgl.opengl.GL11;
import fluidmech.client.model.ModelLargePipe;
import fluidmech.common.FluidMech;
import fluidmech.common.machines.pipes.TileEntityPipe;
import fluidmech.common.machines.pipes.TileEntityPipe;
public class RenderPipe extends TileEntitySpecialRenderer
{
private ModelLargePipe SixPipe;
private TileEntity[] ents = new TileEntity[6];
private ModelLargePipe SixPipe;
private boolean[] renderSide = new boolean[6];
public RenderPipe()
{
SixPipe = new ModelLargePipe();
}
public RenderPipe()
{
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 TileEntityPipe)
{
meta = te.getBlockMetadata();
ents = ((TileEntityPipe) te).connectedBlocks;
}
this.render(meta, ents);
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, TileEntity[] ents)
{
bindTextureByName(this.getPipeTexture(meta));
if (ents[0] != null)
SixPipe.renderBottom();
if (ents[1] != null)
SixPipe.renderTop();
if (ents[3] != null)
SixPipe.renderFront();
if (ents[2] != null)
SixPipe.renderBack();
if (ents[5] != null)
SixPipe.renderRight();
if (ents[4] != null)
SixPipe.renderLeft();
SixPipe.renderMiddle();
int meta = 0;
}
if (te instanceof TileEntityPipe)
{
meta = te.getBlockMetadata();
this.renderSide = ((TileEntityPipe) te).renderConnection;
}
this.render(meta, renderSide);
GL11.glPopMatrix();
@Override
public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8)
{
this.renderAModelAt((TileEntityPipe) tileEntity, var2, var4, var6, var8);
}
}
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

@ -20,9 +20,9 @@ import fluidmech.common.machines.mech.BlockGenerator;
import fluidmech.common.machines.mech.BlockRod;
import fluidmech.common.machines.mech.TileEntityGenerator;
import fluidmech.common.machines.mech.TileEntityRod;
import fluidmech.common.machines.pipes.BlockNetworkPipe;
import fluidmech.common.machines.pipes.BlockPipe;
import fluidmech.common.machines.pipes.TileEntityNetworkPipe;
import fluidmech.common.machines.pipes.BlockPipe;
import fluidmech.common.machines.pipes.TileEntityPipe;
import fluidmech.common.machines.pipes.TileEntityPipe;
import hydraulic.api.ColorCode;
import hydraulic.core.liquidNetwork.LiquidHandler;
@ -92,7 +92,6 @@ public class FluidMech extends DummyModContainer
public final static int ITEM_ID_PREFIX = 13200;
public static Block blockPipe;
public static Block blockNetPipe;
public static Block blockTank;
public static Block blockMachine;
public static Block blockRod;
@ -128,7 +127,6 @@ public class FluidMech extends DummyModContainer
// Blocks
blockPipe = new BlockPipe(this.CONFIGURATION.getBlock("Pipes", BLOCK_ID_PREFIX).getInt());
blockNetPipe = new BlockNetworkPipe(this.CONFIGURATION.getBlock("HydraPipes", BLOCK_ID_PREFIX+9).getInt());
blockMachine = new BlockPumpMachine(this.CONFIGURATION.getBlock("Machines", BLOCK_ID_PREFIX + 1).getInt());
blockRod = new BlockRod(this.CONFIGURATION.getBlock("Mechanical Rod", BLOCK_ID_PREFIX + 3).getInt());
blockGenerator = new BlockGenerator((this.CONFIGURATION.getBlock("Generator", BLOCK_ID_PREFIX + 4).getInt()));
@ -149,7 +147,6 @@ public class FluidMech extends DummyModContainer
// block registry
GameRegistry.registerBlock(blockPipe, ItemBlockPipe.class, "lmPipe");
GameRegistry.registerBlock(blockNetPipe, ItemBlockPipe.class, "lmNPipe");
GameRegistry.registerBlock(blockReleaseValve, ItemBlockReleaseValve.class, "eValve");
GameRegistry.registerBlock(blockRod, "mechRod");
GameRegistry.registerBlock(blockGenerator, "lmGen");
@ -166,7 +163,6 @@ public class FluidMech extends DummyModContainer
proxy.Init();
// TileEntities
GameRegistry.registerTileEntity(TileEntityPipe.class, "lmPipeTile");
GameRegistry.registerTileEntity(TileEntityNetworkPipe.class, "lmNPipeTile");
GameRegistry.registerTileEntity(TileEntityMinorPump.class, "lmPumpTile");
GameRegistry.registerTileEntity(TileEntityRod.class, "lmRodTile");
GameRegistry.registerTileEntity(TileEntityReleaseValve.class, "lmeValve");

View file

@ -18,6 +18,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.ITankContainer;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidStack;
import universalelectricity.prefab.tile.TileEntityAdvanced;
@ -65,7 +66,7 @@ public class TileEntityReleaseValve extends TileEntityAdvanced implements IPsiCr
{
for (ITankContainer drainedTank : input)
{
LiquidStack stack = drainedTank.drain(ForgeDirection.UNKNOWN, TileEntityPipe.maxVolume, false);
LiquidStack stack = drainedTank.drain(ForgeDirection.UNKNOWN, LiquidContainerRegistry.BUCKET_VOLUME, false);
if (stack != null && stack.amount > 0)
{
TileEntityPipe inputPipe = this.findValidPipe(stack);

View file

@ -1,100 +0,0 @@
package fluidmech.common.machines.pipes;
import hydraulic.api.IFluidNetworkPart;
import java.util.List;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import universalelectricity.core.block.IConductor;
import universalelectricity.prefab.block.BlockAdvanced;
import fluidmech.common.FluidMech;
import fluidmech.common.TabFluidMech;
public class BlockNetworkPipe extends BlockAdvanced
{
public BlockNetworkPipe(int id)
{
super(id, Material.iron);
this.setBlockBounds(0.30F, 0.30F, 0.30F, 0.70F, 0.70F, 0.70F);
this.setHardness(1f);
this.setCreativeTab(TabFluidMech.INSTANCE);
this.setUnlocalizedName("lmNPipe");
this.setResistance(3f);
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public int damageDropped(int par1)
{
return par1;
}
@Override
public int getRenderType()
{
return -1;
}
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
super.onBlockAdded(world, x, y, z);
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof IFluidNetworkPart)
{
((IFluidNetworkPart) tileEntity).updateAdjacentConnections();
}
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int blockID)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof IFluidNetworkPart)
{
((IFluidNetworkPart) tileEntity).updateAdjacentConnections();
}
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityNetworkPipe();
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{
int meta = world.getBlockMetadata(x, y, z);
return new ItemStack(FluidMech.blockNetPipe, 1, meta);
}
@Override
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (int i = 0; i < 16; i++)
{
par3List.add(new ItemStack(par1, 1, i));
}
}
}

View file

@ -1,5 +1,7 @@
package fluidmech.common.machines.pipes;
import hydraulic.api.IFluidNetworkPart;
import java.util.List;
import net.minecraft.block.material.Material;
@ -8,78 +10,91 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import universalelectricity.core.block.IConductor;
import universalelectricity.prefab.block.BlockAdvanced;
import fluidmech.common.FluidMech;
import fluidmech.common.TabFluidMech;
public class BlockPipe extends BlockAdvanced
{
public BlockPipe(int id)
{
super(id, Material.iron);
this.setBlockBounds(0.30F, 0.30F, 0.30F, 0.70F, 0.70F, 0.70F);
this.setHardness(1f);
this.setCreativeTab(TabFluidMech.INSTANCE);
this.setUnlocalizedName("lmPipe");
this.setResistance(3f);
}
public BlockPipe(int id)
{
super(id, Material.iron);
this.setBlockBounds(0.30F, 0.30F, 0.30F, 0.70F, 0.70F, 0.70F);
this.setHardness(1f);
this.setCreativeTab(TabFluidMech.INSTANCE);
this.setUnlocalizedName("lmPipe");
this.setResistance(3f);
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public int damageDropped(int par1)
{
return par1;
}
@Override
public int damageDropped(int par1)
{
return par1;
}
@Override
public int getRenderType()
{
return -1;
}
@Override
public int getRenderType()
{
return -1;
}
@Override
public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
{
int var5 = par1World.getBlockId(par2, par3, par4);
return var5 == 0 || blocksList[var5].blockMaterial.isReplaceable();
}
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
super.onBlockAdded(world, x, y, z);
@Override
public boolean canPlaceBlockOnSide(World par1World, int par2, int par3, int par4, int par5)
{
return true;
}
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityPipe();
}
if (tileEntity instanceof IFluidNetworkPart)
{
((IFluidNetworkPart) tileEntity).updateAdjacentConnections();
}
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{
int meta = world.getBlockMetadata(x, y, z);
return new ItemStack(FluidMech.blockPipe, 1, meta);
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int blockID)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
@Override
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (int i = 0; i < 16; i++)
{
par3List.add(new ItemStack(par1, 1, i));
}
}
if (tileEntity instanceof IFluidNetworkPart)
{
((IFluidNetworkPart) tileEntity).updateAdjacentConnections();
}
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityPipe();
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{
int meta = world.getBlockMetadata(x, y, z);
return new ItemStack(FluidMech.blockPipe, 1, meta);
}
@Override
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (int i = 0; i < 16; i++)
{
par3List.add(new ItemStack(par1, 1, i));
}
}
}

View file

@ -1,329 +0,0 @@
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.IReadOut;
import hydraulic.core.liquidNetwork.HydraulicNetwork;
import java.util.Random;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.ITankContainer;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidStack;
import net.minecraftforge.liquids.LiquidTank;
import org.bouncycastle.util.Arrays;
import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.network.PacketManager;
import universalelectricity.prefab.tile.TileEntityAdvanced;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class TileEntityNetworkPipe extends TileEntityAdvanced implements ITankContainer, IReadOut, IColorCoded, IFluidNetworkPart, IPacketReceiver
{
/* 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 */
private TileEntity[] connectedBlocks = new TileEntity[6];
public boolean[] renderConnection = new boolean[6];
/* RANDOM INSTANCE USED BY THE UPDATE TICK */
private Random random = new Random();
/* NETWORK INSTANCE THAT THIS PIPE USES */
private HydraulicNetwork pipeNetwork;
@Override
public void updateEntity()
{
super.updateEntity();
if (!worldObj.isRemote && ticks % ((int) random.nextInt(10) * 80 + 20) == 0)
{
this.updateAdjacentConnections();
}
}
@Override
public void initiate()
{
this.updateAdjacentConnections();
}
@Override
public void invalidate()
{
if (!this.worldObj.isRemote)
{
this.getNetwork().splitNetwork(this);
}
super.invalidate();
}
@Override
public void handlePacketData(INetworkManager network, int type, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
if (this.worldObj.isRemote)
{
System.out.print("packet");
this.renderConnection[0] = dataStream.readBoolean();
this.renderConnection[1] = dataStream.readBoolean();
this.renderConnection[2] = dataStream.readBoolean();
this.renderConnection[3] = dataStream.readBoolean();
this.renderConnection[4] = dataStream.readBoolean();
this.renderConnection[5] = dataStream.readBoolean();
}
}
@Override
public Packet getDescriptionPacket()
{
return PacketManager.getPacket(FluidMech.CHANNEL, this, this.renderConnection[0], this.renderConnection[1], this.renderConnection[2], this.renderConnection[3], this.renderConnection[4], this.renderConnection[5]);
}
/**
* gets the current color mark of the pipe
*/
@Override
public ColorCode getColor()
{
return ColorCode.get(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
}
/**
* sets the current color mark of the pipe
*/
@Override
public void setColor(Object cc)
{
ColorCode code = ColorCode.get(cc);
if (!worldObj.isRemote && code != this.getColor())
{
this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, code.ordinal() & 15, 3);
}
}
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side)
{
/* DEBUG CODE ACTIVATERS */
boolean testConnections = false;
boolean testNetwork = false;
/* NORMAL OUTPUT */
String string = this.getNetwork().pressureProduced + "p ";
/* DEBUG CODE */
if (testConnections)
{
for (int i = 0; i < 6; i++)
{
string += ":" + (this.renderConnection[i] ? "T" : "F") + (this.getAdjacentConnections()[i] != null ? "T" : "F");
}
}
if (testNetwork)
{
string += " " + this.getNetwork().toString();
}
return string;
}
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
if (resource == null || !this.getColor().isValidLiquid(resource))
{
return 0;
}
return this.fill(0, resource, doFill);
}
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill)
{
if (tankIndex != 0 || resource == null || !this.getColor().isValidLiquid(resource))
{
return 0;
}
return this.getNetwork().addFluidToNetwork(resource, 0, doFill);
}
@Override
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return null;
}
@Override
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain)
{
return null;
}
@Override
public ILiquidTank[] getTanks(ForgeDirection direction)
{
return new ILiquidTank[] { this.fakeTank };
}
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
{
if (this.getColor().isValidLiquid(type))
{
return this.fakeTank;
}
return null;
}
/**
* Checks to make sure the connection is valid to the tileEntity
*
* @param tileEntity - the tileEntity being checked
* @param side - side the connection is too
*/
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
{
if (!this.worldObj.isRemote && tileEntity != null)
{
if (tileEntity instanceof IPipeConnection)
{
if (((IPipeConnection) tileEntity).canConnect(this, side))
{
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;
}
}
}
else if (tileEntity instanceof IColorCoded)
{
if (this.getColor() == ColorCode.NONE || this.getColor() == ((IColorCoded) tileEntity).getColor())
{
connectedBlocks[side.ordinal()] = tileEntity;
}
}
else if (tileEntity instanceof ITankContainer)
{
connectedBlocks[side.ordinal()] = tileEntity;
}
}
}
@Override
public void updateAdjacentConnections()
{
if (this.worldObj != null && !this.worldObj.isRemote)
{
boolean[] previousConnections = this.renderConnection.clone();
this.connectedBlocks = new TileEntity[6];
for (int i = 0; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
this.validateConnectionSide(this.worldObj.getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ), dir);
this.renderConnection[i] = this.connectedBlocks[i] != null;
if (this.renderConnection[i] && this.connectedBlocks[i] instanceof ITankContainer && !(this.connectedBlocks[i] instanceof IFluidNetworkPart))
{
this.getNetwork().addEntity((ITankContainer) this.connectedBlocks[i]);
}
}
/**
* Only send packet updates if visuallyConnected changed.
*/
if (!Arrays.areEqual(previousConnections, this.renderConnection))
{
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
}
}
@Override
public boolean canConnect(TileEntity entity, ForgeDirection dir)
{
return true;
}
@Override
public double getMaxPressure(ForgeDirection side)
{
return 350;
}
@Override
public HydraulicNetwork getNetwork()
{
if (this.pipeNetwork == null)
{
this.setNetwork(new HydraulicNetwork(this.getColor(), this));
}
return this.pipeNetwork;
}
@Override
public void setNetwork(HydraulicNetwork network)
{
this.pipeNetwork = network;
}
@Override
public int getMaxFlowRate(LiquidStack stack, ForgeDirection side)
{
return LiquidContainerRegistry.BUCKET_VOLUME * 2;
}
@Override
public boolean onOverPressure(Boolean damageAllowed)
{
if (damageAllowed)
{
worldObj.setBlockAndMetadataWithNotify(xCoord, yCoord, yCoord, 0, 0, 3);
return true;
}
return false;
}
@SideOnly(Side.CLIENT)
public AxisAlignedBB getRenderBoundingBox()
{
return AxisAlignedBB.getAABBPool().getAABB(this.xCoord, this.yCoord, this.zCoord, this.xCoord + 1, this.yCoord + 1, this.zCoord + 1);
}
@Override
public TileEntity[] getAdjacentConnections()
{
return this.connectedBlocks;
}
@Override
public boolean canConnect(ForgeDirection dir)
{
return worldObj.getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetZ, zCoord + dir.offsetY) instanceof IFluidNetworkPart;
}
}

View file

@ -1,123 +1,96 @@
package fluidmech.common.machines.pipes;
import fluidmech.common.machines.TileEntityTank;
import fluidmech.common.FluidMech;
import hydraulic.api.ColorCode;
import hydraulic.api.IColorCoded;
import hydraulic.api.IPipeConnection;
import hydraulic.api.IPsiCreator;
import hydraulic.api.IFluidNetworkPart;
import hydraulic.api.IReadOut;
import hydraulic.core.liquidNetwork.LiquidHandler;
import hydraulic.helpers.connectionHelper;
import hydraulic.core.liquidNetwork.HydraulicNetwork;
import java.util.Random;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.ITankContainer;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidStack;
import net.minecraftforge.liquids.LiquidTank;
import org.bouncycastle.util.Arrays;
import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.network.PacketManager;
import universalelectricity.prefab.tile.TileEntityAdvanced;
public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer, IReadOut, IColorCoded
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer, IReadOut, IColorCoded, IFluidNetworkPart, IPacketReceiver
{
private ColorCode color = ColorCode.NONE;
private int presure = 0;
public boolean converted = false;
public boolean isUniversal = false;
public TileEntity[] connectedBlocks = new TileEntity[6];
public static final int maxVolume = LiquidContainerRegistry.BUCKET_VOLUME * 2;
private LiquidTank tank = new LiquidTank(maxVolume);
/* 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 */
private TileEntity[] connectedBlocks = new TileEntity[6];
public boolean[] renderConnection = new boolean[6];
/* RANDOM INSTANCE USED BY THE UPDATE TICK */
private Random random = new Random();
/* NETWORK INSTANCE THAT THIS PIPE USES */
private HydraulicNetwork pipeNetwork;
@Override
public void updateEntity()
{
this.validataConnections();
this.color = ColorCode.get(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
if (ticks % 20 == 0)
super.updateEntity();
if (!worldObj.isRemote && ticks % ((int) random.nextInt(10) * 80 + 20) == 0)
{
this.updatePressure();
LiquidStack stack = tank.getLiquid();
if (!worldObj.isRemote && stack != null && stack.amount >= 0)
{
for (int i = 0; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
if (connectedBlocks[i] instanceof ITankContainer)
{
if (connectedBlocks[i] instanceof TileEntityPipe)
{
if (((TileEntityPipe) connectedBlocks[i]).presure < this.presure)
{
tank.drain(((TileEntityPipe) connectedBlocks[i]).fill(dir, stack, true), true);
}
}
else if (connectedBlocks[i] instanceof TileEntityTank && ((TileEntityTank) connectedBlocks[i]).getColor() == this.color)
{
if (dir == ForgeDirection.UP && !color.getLiquidData().getCanFloat())
{
/* do nothing */
}
else if (dir == ForgeDirection.DOWN && color.getLiquidData().getCanFloat())
{
/* do nothing */
}
else
{
tank.drain(((ITankContainer) connectedBlocks[i]).fill(dir.getOpposite(), stack, true), true);
}
}
else
{
tank.drain(((ITankContainer) connectedBlocks[i]).fill(dir.getOpposite(), stack, true), true);
}
}
if (stack == null || stack.amount <= 0)
{
break;
}
}
}
this.updateAdjacentConnections();
}
}
public void randomDisplayTick()
@Override
public void initiate()
{
Random random = new Random();
LiquidStack stack = tank.getLiquid();
if (stack != null && random.nextInt(10) == 0)
{
// TODO align this with the pipe model so not to drip where there is
// no pipe
double xx = (double) ((float) xCoord + random.nextDouble());
double zz = (double) yCoord + .3D;
double yy = (double) ((float) zCoord + random.nextDouble());
this.updateAdjacentConnections();
}
if (ColorCode.get(stack) != ColorCode.RED)
{
worldObj.spawnParticle("dripWater", xx, zz, yy, 0.0D, 0.0D, 0.0D);
}
else
{
worldObj.spawnParticle("dripLava", xx, zz, yy, 0.0D, 0.0D, 0.0D);
}
@Override
public void invalidate()
{
if (!this.worldObj.isRemote)
{
this.getNetwork().splitNetwork(this);
}
super.invalidate();
}
@Override
public void handlePacketData(INetworkManager network, int type, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
if (this.worldObj.isRemote)
{
this.renderConnection[0] = dataStream.readBoolean();
this.renderConnection[1] = dataStream.readBoolean();
this.renderConnection[2] = dataStream.readBoolean();
this.renderConnection[3] = dataStream.readBoolean();
this.renderConnection[4] = dataStream.readBoolean();
this.renderConnection[5] = dataStream.readBoolean();
}
}
@Override
public Packet getDescriptionPacket()
{
return PacketManager.getPacket(FluidMech.CHANNEL, this, this.renderConnection[0], this.renderConnection[1], this.renderConnection[2], this.renderConnection[3], this.renderConnection[4], this.renderConnection[5]);
}
/**
@ -126,7 +99,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
@Override
public ColorCode getColor()
{
return this.color;
return ColorCode.get(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
}
/**
@ -135,92 +108,57 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
@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)
ColorCode code = ColorCode.get(cc);
if (!worldObj.isRemote && code != this.getColor())
{
this.color = ColorCode.values()[i];
}
}
/**
* Reads a tile entity from NBT.
*/
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
LiquidStack liquid = new LiquidStack(0, 0, 0);
liquid.readFromNBT(nbt.getCompoundTag("stored"));
if (Item.itemsList[liquid.itemID] != null && liquid.amount > 0)
{
this.tank.setLiquid(liquid);
}
}
/**
* Writes a tile entity to NBT.
*/
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
if (tank.getLiquid() != null)
{
nbt.setTag("stored", tank.getLiquid().writeToNBT(new NBTTagCompound()));
this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, code.ordinal() & 15, 3);
}
}
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side)
{
LiquidStack stack = this.tank.getLiquid();
if (stack != null)
/* DEBUG CODE ACTIVATERS */
boolean testConnections = false;
boolean testNetwork = false;
/* NORMAL OUTPUT */
String string = this.getNetwork().pressureProduced + "p ";
/* DEBUG CODE */
if (testConnections)
{
return (stack.amount / LiquidContainerRegistry.BUCKET_VOLUME) + "/" + (this.tank.getCapacity() / LiquidContainerRegistry.BUCKET_VOLUME) + " " + LiquidHandler.get(stack).getName() + " @ " + this.presure + "p";
for (int i = 0; i < 6; i++)
{
string += ":" + (this.renderConnection[i] ? "T" : "F") + (this.getAdjacentConnections()[i] != null ? "T" : "F");
}
}
if (testNetwork)
{
string += " " + this.getNetwork().toString();
}
return "Empty" + " @ " + this.presure + "p";
return string;
}
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
if (resource == null)
if (resource == null || !this.getColor().isValidLiquid(resource))
{
return 0;
}
LiquidStack stack = tank.getLiquid();
if (this.color.isValidLiquid(resource))
{
if (stack == null || (stack != null && stack.isLiquidEqual(resource)))
{
return this.fill(0, resource, doFill);
}
else
{
// return this.causeMix(stack, resource);
}
}
return 0;
return this.fill(0, resource, doFill);
}
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill)
{
if (tankIndex != 0 || resource == null)
if (tankIndex != 0 || resource == null || !this.getColor().isValidLiquid(resource))
{
return 0;
}
return tank.fill(resource, doFill);
return this.getNetwork().addFluidToNetwork(resource, 0, doFill);
}
@Override
@ -238,92 +176,153 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
@Override
public ILiquidTank[] getTanks(ForgeDirection direction)
{
return new ILiquidTank[] { this.tank };
return new ILiquidTank[] { this.fakeTank };
}
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
{
if (this.color.isValidLiquid(type))
if (this.getColor().isValidLiquid(type))
{
return this.tank;
return this.fakeTank;
}
return null;
}
/**
* collects and sorts the surrounding TE for valid connections
* Checks to make sure the connection is valid to the tileEntity
*
* @param tileEntity - the tileEntity being checked
* @param side - side the connection is too
*/
public void validataConnections()
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
{
this.connectedBlocks = connectionHelper.getSurroundingTileEntities(worldObj, xCoord, yCoord, zCoord);
for (int side = 0; side < 6; side++)
if (!this.worldObj.isRemote && tileEntity != null)
{
ForgeDirection direction = ForgeDirection.getOrientation(side);
TileEntity tileEntity = connectedBlocks[side];
if (tileEntity instanceof ITankContainer)
if (tileEntity instanceof IPipeConnection)
{
if (tileEntity instanceof TileEntityPipe && this.color != ((TileEntityPipe) tileEntity).getColor())
if (((IPipeConnection) tileEntity).canConnect(this, side))
{
connectedBlocks[side] = null;
}
// TODO switch side catch for IPressure
if (this.color != ColorCode.NONE && tileEntity instanceof TileEntityTank && ((TileEntityTank) tileEntity).getColor() != ColorCode.NONE && color != ((TileEntityTank) tileEntity).getColor())
{
connectedBlocks[side] = null;
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;
}
}
}
else if (tileEntity instanceof IPipeConnection)
else if (tileEntity instanceof IColorCoded)
{
if (!((IPipeConnection) tileEntity).canConnect(this, direction))
if (this.getColor() == ColorCode.NONE || this.getColor() == ((IColorCoded) tileEntity).getColor())
{
connectedBlocks[side] = null;
connectedBlocks[side.ordinal()] = tileEntity;
}
}
else
else if (tileEntity instanceof ITankContainer)
{
connectedBlocks[side] = null;
connectedBlocks[side.ordinal()] = tileEntity;
}
}
}
/**
* updates this units pressure level using the pipe/machines around it
*/
public void updatePressure()
@Override
public void updateAdjacentConnections()
{
int highestPressure = 0;
this.presure = 0;
for (int i = 0; i < 6; i++)
if (this.worldObj != null && !this.worldObj.isRemote)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
boolean[] previousConnections = this.renderConnection.clone();
this.connectedBlocks = new TileEntity[6];
if (connectedBlocks[i] instanceof TileEntityPipe)
for (int i = 0; i < 6; i++)
{
if (((TileEntityPipe) connectedBlocks[i]).getPressure() > highestPressure)
ForgeDirection dir = ForgeDirection.getOrientation(i);
this.validateConnectionSide(this.worldObj.getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ), dir);
this.renderConnection[i] = this.connectedBlocks[i] != null;
if (this.renderConnection[i] && this.connectedBlocks[i] instanceof ITankContainer && !(this.connectedBlocks[i] instanceof IFluidNetworkPart))
{
highestPressure = ((TileEntityPipe) connectedBlocks[i]).getPressure();
this.getNetwork().addEntity((ITankContainer) this.connectedBlocks[i]);
}
}
if (connectedBlocks[i] instanceof IPsiCreator && ((IPipeConnection) connectedBlocks[i]).canConnect(this, dir))
/**
* Only send packet updates if visuallyConnected changed.
*/
if (!Arrays.areEqual(previousConnections, this.renderConnection))
{
int p = ((IPsiCreator) connectedBlocks[i]).getPressureOut(color.getLiquidData().getStack(), dir);
if (p > highestPressure)
{
highestPressure = p;
}
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
}
this.presure = highestPressure - 1;
}
public int getPressure()
@Override
public boolean canConnect(TileEntity entity, ForgeDirection dir)
{
return this.presure;
return true;
}
@Override
public double getMaxPressure(ForgeDirection side)
{
return 350;
}
@Override
public HydraulicNetwork getNetwork()
{
if (this.pipeNetwork == null)
{
this.setNetwork(new HydraulicNetwork(this.getColor(), this));
}
return this.pipeNetwork;
}
@Override
public void setNetwork(HydraulicNetwork network)
{
this.pipeNetwork = network;
}
@Override
public int getMaxFlowRate(LiquidStack stack, ForgeDirection side)
{
return LiquidContainerRegistry.BUCKET_VOLUME * 2;
}
@Override
public boolean onOverPressure(Boolean damageAllowed)
{
if (damageAllowed)
{
worldObj.setBlockAndMetadataWithNotify(xCoord, yCoord, yCoord, 0, 0, 3);
return true;
}
return false;
}
@SideOnly(Side.CLIENT)
public AxisAlignedBB getRenderBoundingBox()
{
return AxisAlignedBB.getAABBPool().getAABB(this.xCoord, this.yCoord, this.zCoord, this.xCoord + 1, this.yCoord + 1, this.zCoord + 1);
}
@Override
public TileEntity[] getAdjacentConnections()
{
return this.connectedBlocks;
}
@Override
public boolean canConnect(ForgeDirection dir)
{
return worldObj.getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetZ, zCoord + dir.offsetY) instanceof IFluidNetworkPart;
}
}