Rewrote a lot of the network parts and a bit of code

Created a prefab that both pipe and tank extend so they share the same
network code. This should decrease issues with errors that arise between
the two. As well i reworked a few things in the network fluid tile class
to prevent issues.
This commit is contained in:
DarkGuardsman 2013-10-30 11:26:46 -04:00
parent a526333551
commit 679809db34
22 changed files with 857 additions and 1274 deletions

View file

@ -13,7 +13,7 @@ import dark.api.parts.INetworkPart;
* the parts in a set way to function correctly
*
* @author DarkGuardsman */
public interface INetworkFluidPart extends IColorCoded, IFluidHandler, INetworkPart
public interface INetworkFluidPart extends IFluidHandler, INetworkPart
{
/** Gets information about the tanks internal storage that the network has access to. */

View file

@ -36,16 +36,16 @@ public class NetworkFluidContainers extends NetworkFluidTiles
{
this.cleanUpMembers();
if (this.combinedStorage() == null || this.combinedStorage().getFluid() == null)
if (this.getNetworkTank() == null || this.getNetworkTank().getFluid() == null)
{
super.writeDataToTiles();
return;
}
FluidStack fillStack = this.combinedStorage().getFluid().copy();
FluidStack fillStack = this.getNetworkTank().getFluid().copy();
int lowestY = 255, highestY = 0;
if (this.combinedStorage().getFluid() != null && this.getNetworkMemebers().size() > 0)
if (this.getNetworkTank().getFluid() != null && this.getNetworkMemebers().size() > 0)
{
for (INetworkPart part : this.getNetworkMemebers())
{

View file

@ -8,6 +8,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import dark.api.ColorCode;
import dark.api.fluid.INetworkFluidPart;
@ -17,11 +18,11 @@ import dark.core.prefab.tilenetwork.NetworkTileEntities;
public class NetworkFluidTiles extends NetworkTileEntities
{
/** Fluid Tanks that are connected to the network but not part of it ** */
/** Fluid Tanks that are connected to the network but not part of the network's main body */
public final Set<IFluidHandler> connectedTanks = new HashSet<IFluidHandler>();
/** Collective storage of all fluid tiles */
public FluidTank sharedTank;
/** Collective storage tank of all fluid tile that make up this networks main body */
protected FluidTank sharedTank;
protected FluidTankInfo sharedTankInfo;
/** Has the collective tank been loaded yet */
protected boolean loadedLiquids = false;
@ -38,70 +39,65 @@ public class NetworkFluidTiles extends NetworkTileEntities
}
/** Gets the collective tank of the network */
public FluidTank combinedStorage()
public FluidTank getNetworkTank()
{
if (this.sharedTank == null)
{
this.sharedTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
this.readDataFromTiles();
}
return this.sharedTank;
}
/** Stores Fluid in this network's collective tank */
public int storeFluidInSystem(FluidStack stack, boolean doFill)
{
if (stack == null || this.combinedStorage() == null)
{
return 0;
}
int prevVolume = this.combinedStorage().getFluidAmount();
if (!loadedLiquids)
{
this.readDataFromTiles();
}
return this.sharedTank;
}
int filled = this.combinedStorage().fill(stack, doFill);
if (doFill)
public FluidTankInfo getNetworkTankInfo()
{
if (this.sharedTankInfo == null)
{
this.writeDataToTiles();
return filled;
this.sharedTankInfo = this.getNetworkTank().getInfo();
}
return this.sharedTankInfo;
}
public int fillNetworkTank(FluidStack stack, boolean doFill)
{
if (this.getNetworkTank() != null)
{
int p = this.getNetworkTank().getFluid() != null ? this.getNetworkTank().getFluid().amount : 0;
int r = this.getNetworkTank().fill(stack, doFill);
if (doFill)
{
if (p != r)
{
this.sharedTankInfo = this.getNetworkTank().getInfo();
this.writeDataToTiles();
}
}
return r;
}
return 0;
}
/** Drains the network's collective tank */
public FluidStack drainFluidFromSystem(int maxDrain, boolean doDrain)
public FluidStack drainNetworkTank(int volume, boolean doDrain)
{
int prevVolume = this.combinedStorage().getFluidAmount();
if (!loadedLiquids)
if (this.getNetworkTank() != null)
{
this.readDataFromTiles();
}
FluidStack stack = this.combinedStorage().getFluid();
if (stack != null)
{
stack = this.combinedStorage().getFluid().copy();
if (maxDrain < stack.amount)
{
stack = FluidHelper.getStack(stack, maxDrain);
}
stack = this.combinedStorage().drain(maxDrain, doDrain);
FluidStack p = this.getNetworkTank().getFluid();
FluidStack r = this.getNetworkTank().drain(volume, doDrain);
if (doDrain)
{
this.writeDataToTiles();
//Has the tank changed any. If yes then update all info and do a client update
if (!p.isFluidEqual(r) && (p == null || r == null || p.amount != r.amount))
{
this.sharedTankInfo = this.getNetworkTank().getInfo();
this.writeDataToTiles();
//TODO do a client update from the network rather than each pipe updating itself.
}
}
}
return stack;
}
public FluidStack drainFluidFromSystem(FluidStack stack, boolean doDrain)
{
if (stack != null && this.combinedStorage().getFluid() != null && stack.isFluidEqual(this.combinedStorage().getFluid()))
{
return this.drainFluidFromSystem(stack.amount, doDrain);
return r;
}
return null;
}
@ -110,9 +106,9 @@ public class NetworkFluidTiles extends NetworkTileEntities
public void writeDataToTiles()
{
this.cleanUpMembers();
if (this.combinedStorage().getFluid() != null && this.networkMember.size() > 0)
if (this.getNetworkTank().getFluid() != null && this.networkMember.size() > 0)
{
FluidStack stack = this.combinedStorage().getFluid() == null ? null : this.combinedStorage().getFluid().copy();
FluidStack stack = this.getNetworkTank().getFluid() == null ? null : this.getNetworkTank().getFluid().copy();
int membersFilled = 0;
for (INetworkPart par : this.networkMember)
@ -160,11 +156,11 @@ public class NetworkFluidTiles extends NetworkTileEntities
}
if (stack != null && stack.amount > 0)
{
this.combinedStorage().setFluid(stack);
this.getNetworkTank().setFluid(stack);
}
else
{
this.combinedStorage().setFluid(null);
this.getNetworkTank().setFluid(null);
}
this.loadedLiquids = true;
}
@ -221,17 +217,18 @@ public class NetworkFluidTiles extends NetworkTileEntities
protected void mergeDo(NetworkTileEntities network)
{
NetworkFluidTiles newNetwork = (NetworkFluidTiles) this.newInstance();
FluidStack one = this.combinedStorage().getFluid();
FluidStack two = ((NetworkFluidTiles) network).combinedStorage().getFluid();
FluidStack one = this.getNetworkTank().getFluid();
FluidStack two = ((NetworkFluidTiles) network).getNetworkTank().getFluid();
this.combinedStorage().setFluid(null);
((NetworkFluidTiles) network).combinedStorage().setFluid(null);
this.getNetworkTank().setFluid(null);
((NetworkFluidTiles) network).getNetworkTank().setFluid(null);
newNetwork.getNetworkMemebers().addAll(this.getNetworkMemebers());
newNetwork.getNetworkMemebers().addAll(network.getNetworkMemebers());
newNetwork.cleanUpMembers();
newNetwork.combinedStorage().setFluid(FluidCraftingHandler.mergeFluidStacks(one, two));
newNetwork.getNetworkTank().setFluid(FluidCraftingHandler.mergeFluidStacks(one, two));
newNetwork.sharedTankInfo = newNetwork.getNetworkTank().getInfo();
newNetwork.writeDataToTiles();
}
@ -256,7 +253,8 @@ public class NetworkFluidTiles extends NetworkTileEntities
}
}
}
this.combinedStorage().setCapacity(capacity);
this.getNetworkTank().setCapacity(capacity);
this.sharedTankInfo = this.getNetworkTank().getInfo();
}
@Override
@ -273,11 +271,11 @@ public class NetworkFluidTiles extends NetworkTileEntities
public String getNetworkFluid()
{
if (combinedStorage() != null && combinedStorage().getFluid() != null && combinedStorage().getFluid().getFluid() != null)
if (this.getNetworkTank() != null && this.getNetworkTank().getFluid() != null && this.getNetworkTank().getFluid().getFluid() != null)
{
int cap = combinedStorage().getCapacity() / FluidContainerRegistry.BUCKET_VOLUME;
int vol = combinedStorage().getFluid() != null ? (combinedStorage().getFluid().amount / FluidContainerRegistry.BUCKET_VOLUME) : 0;
String name = combinedStorage().getFluid().getFluid().getLocalizedName();
int cap = this.getNetworkTank().getCapacity() / FluidContainerRegistry.BUCKET_VOLUME;
int vol = this.getNetworkTank().getFluid() != null ? (this.getNetworkTank().getFluid().amount / FluidContainerRegistry.BUCKET_VOLUME) : 0;
String name = this.getNetworkTank().getFluid().getFluid().getLocalizedName();
return String.format("%d/%d %S Stored", vol, cap, name);
}
return ("Empty");

View file

@ -64,14 +64,14 @@ public class NetworkPipes extends NetworkFluidTiles
public int addFluidToNetwork(TileEntity source, FluidStack sta, boolean doFill, boolean allowStore)
{
int used = 0;
FluidStack prevCombined = this.combinedStorage().getFluid();
FluidStack prevCombined = this.getNetworkTank().getFluid();
FluidStack stack = sta.copy();
if (!this.processingRequest && stack != null)
{
this.processingRequest = true;
if (this.combinedStorage().getFluid() != null && !stack.isFluidEqual(this.combinedStorage().getFluid()))
if (this.getNetworkTank().getFluid() != null && !stack.isFluidEqual(this.getNetworkTank().getFluid()))
{
//this.causingMixing(null, this.combinedStorage().getFluid(), stack);
}
@ -156,33 +156,33 @@ public class NetworkPipes extends NetworkFluidTiles
}
else if (allowStore)
{
used = this.storeFluidInSystem(stack, doFill);
used = this.fillNetworkTank(stack, doFill);
// System.out.println("Network Target filled for " + used + doFill);
filledMain = true;
}
/* IF THE COMBINED STORAGE OF THE PIPES HAS LIQUID MOVE IT FIRST */
if (!filledMain && used > 0 && this.combinedStorage().getFluid() != null && this.combinedStorage().getFluid().amount > 0)
if (!filledMain && used > 0 && this.getNetworkTank().getFluid() != null && this.getNetworkTank().getFluid().amount > 0)
{
FluidStack drainStack = new FluidStack(0, 0);
if (this.combinedStorage().getFluid().amount >= used)
if (this.getNetworkTank().getFluid().amount >= used)
{
drainStack = this.combinedStorage().drain(used, doFill);
drainStack = this.drainNetworkTank(used, doFill);
used = 0;
}
else
{
int pUsed = used;
used = Math.min(used, Math.max(used - this.combinedStorage().getFluid().amount, 0));
drainStack = this.combinedStorage().drain(pUsed - used, doFill);
used = Math.min(used, Math.max(used - this.getNetworkTank().getFluid().amount, 0));
drainStack = this.drainNetworkTank(pUsed - used, doFill);
}
// System.out.println("Pulling " + (drainStack != null ? drainStack.amount : 0) +
// " from combined leaving " + (this.combinedStorage.getLiquid() != null ?
// this.combinedStorage.getLiquid().amount : 0));
}
if (prevCombined != null && this.combinedStorage().getFluid() != null && prevCombined.amount != this.combinedStorage().getFluid().amount)
if (prevCombined != null && this.getNetworkTank().getFluid() != null && prevCombined.amount != this.getNetworkTank().getFluid().amount)
{
this.writeDataToTiles();
}

View file

@ -359,7 +359,7 @@ public class ModelLiquidTank extends ModelBase
public void renderMeter(TileEntity tee, float f5)
{
int[] conenctedTiles = new int[6];
byte[] conenctedTiles = new byte[6];
if (tee instanceof TileEntityTank)
{
conenctedTiles = ((TileEntityTank) tee).renderConnection;

View file

@ -14,7 +14,7 @@ import dark.core.prefab.ModPrefab;
import dark.fluid.client.model.ModelReleaseValve;
import dark.fluid.common.FMRecipeLoader;
import dark.fluid.common.FluidMech;
import dark.fluid.common.pipes.PipeMaterial;
import dark.fluid.common.PipeMaterial;
@SideOnly(Side.CLIENT)
public class ItemRenderHelper implements IItemRenderer

View file

@ -1,85 +0,0 @@
package dark.fluid.client.render;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.core.client.renders.RenderTileMachine;
import dark.core.prefab.ModPrefab;
import dark.core.prefab.helpers.ConnectionHelper;
import dark.fluid.client.model.ModelCenterTank;
import dark.fluid.client.model.ModelCornerTank;
import dark.fluid.client.model.ModelTank;
import dark.fluid.common.FluidMech;
import dark.fluid.common.machines.TileEntityBoiler;
@SideOnly(Side.CLIENT)
public class RenderBoiler extends RenderTileMachine
{
int type = 0;
private ModelTank model;
private ModelCenterTank model2;
private ModelCornerTank model3;
public RenderBoiler(float par1)
{
model = new ModelTank(par1);
model2 = new ModelCenterTank(par1);
model3 = new ModelCornerTank(par1);
}
@Override
public void renderModel(TileEntity tileEntity, double d, double d1, double d2, float d3)
{
GL11.glPushMatrix();
GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
TileEntity[] connected = ((TileEntityBoiler) tileEntity).connectedBlocks;
int meta = 0;
if (connected[5] == null && connected[3] == null && connected[4] == null && connected[2] == null || ((TileEntityBoiler) tileEntity).tankCount < 2)
{
bindTextureByName(FluidMech.instance.PREFIX, ModPrefab.MODEL_DIRECTORY + "tankTexture.png");
model.generalRender(0.0625F);
}
else if (ConnectionHelper.corner(tileEntity) == 0 || ((TileEntityBoiler) tileEntity).tankCount > 2)
{
bindTextureByName(FluidMech.instance.PREFIX, ModPrefab.MODEL_DIRECTORY + "tankBlock.png");
model2.renderBlock(0.0625F);
}
else
{
int corner = ConnectionHelper.corner(tileEntity);
bindTextureByName(FluidMech.instance.PREFIX, ModPrefab.MODEL_DIRECTORY + "CornerTank.png");
switch (corner)
{
case 1:
GL11.glRotatef(270f, 0f, 1f, 0f);
break;
case 2:
GL11.glRotatef(0f, 0f, 1f, 0f);
break;
case 3:
GL11.glRotatef(90f, 0f, 1f, 0f);
break;
case 4:
GL11.glRotatef(180f, 0f, 1f, 0f);
break;
}
model3.renderCorner(0.0625f);
}
GL11.glPopMatrix();
}
@Override
public ResourceLocation getTexture(int block, int meta)
{
// TODO Auto-generated method stub
return null;
}
}

View file

@ -11,8 +11,8 @@ import dark.core.client.renders.RenderTileMachine;
import dark.core.prefab.ModPrefab;
import dark.fluid.client.model.ModelLargePipe;
import dark.fluid.common.FluidMech;
import dark.fluid.common.PipeMaterial;
import dark.fluid.common.pipes.EnumPipeType;
import dark.fluid.common.pipes.PipeMaterial;
import dark.fluid.common.pipes.TileEntityPipe;
@SideOnly(Side.CLIENT)
@ -45,7 +45,7 @@ public class RenderPipe extends RenderTileMachine
}
else
{
this.render(PipeMaterial.STONE, 0, new boolean[6]);
this.render(PipeMaterial.STONE, 0, new byte[6]);
}
GL11.glPopMatrix();
@ -71,30 +71,30 @@ public class RenderPipe extends RenderTileMachine
return new ResourceLocation(FluidMech.instance.DOMAIN, ModPrefab.MODEL_DIRECTORY + "pipes/Pipe.png");
}
public void render(PipeMaterial mat, int pipeID, boolean[] side)
public void render(PipeMaterial mat, int pipeID, byte[] side)
{
bindTexture(RenderPipe.getTexture(mat, pipeID));
if (side[0])
if (side[0] != 0 && side[0] != 3)
{
SixPipe.renderBottom();
}
if (side[1])
if (side[1] != 0 && side[1] != 3)
{
SixPipe.renderTop();
}
if (side[3])
if (side[3] != 0 && side[3] != 3)
{
SixPipe.renderFront();
}
if (side[2])
if (side[2] != 0 && side[2] != 3)
{
SixPipe.renderBack();
}
if (side[5])
if (side[5] != 0 && side[05] != 3)
{
SixPipe.renderRight();
}
if (side[4])
if (side[4] != 0 && side[4] != 3)
{
SixPipe.renderLeft();
}

View file

@ -29,13 +29,13 @@ public class RenderTank extends RenderTileMachine
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float var8)
{
FluidStack liquid = tileEntity instanceof TileEntityTank ? ((TileEntityTank) tileEntity).getTank().getFluid() : null;
FluidStack liquid = tileEntity instanceof TileEntityTank ? ((TileEntityTank) tileEntity).getTankInfo()[0].fluid : null;
this.renderTank(tileEntity, x, y, z, 0, liquid);
}
public void renderTank(TileEntity tileEntity, double x, double y, double z, int meta, FluidStack liquid)
{
int[] render = new int[6];
byte[] render = new byte[6];
if (tileEntity instanceof TileEntityTank)
{
render = ((TileEntityTank) tileEntity).renderConnection;
@ -56,7 +56,7 @@ public class RenderTank extends RenderTileMachine
GL11.glTranslatef((float) x, (float) y, (float) z);
GL11.glScalef(1.01F, 1.01F, 1.01F);
int cap = tileEntity instanceof TileEntityTank ? ((TileEntityTank) tileEntity).getTankSize() : liquid.amount;
int cap = tileEntity instanceof TileEntityTank ? ((TileEntityTank) tileEntity).getTankInfo()[0].capacity : liquid.amount;
GL11.glCallList(displayList[(int) ((float) liquid.amount / (float) (cap) * (RenderBlockFluid.DISPLAY_STAGES - 1))]);
GL11.glPopAttrib();

View file

@ -10,7 +10,6 @@ import dark.api.ColorCode;
import dark.core.common.CoreRecipeLoader;
import dark.core.common.RecipeLoader;
import dark.core.common.items.ItemParts.Parts;
import dark.fluid.common.pipes.PipeMaterial;
public class FMRecipeLoader extends RecipeLoader
{

View file

@ -31,7 +31,6 @@ import dark.fluid.common.machines.BlockSink;
import dark.fluid.common.machines.BlockTank;
import dark.fluid.common.pipes.BlockPipe;
import dark.fluid.common.pipes.ItemBlockPipe;
import dark.fluid.common.pipes.PipeMaterial;
import dark.fluid.common.pump.BlockConstructionPump;
import dark.fluid.common.pump.BlockDrain;
import dark.fluid.common.pump.BlockPumpMachine;

View file

@ -1,4 +1,4 @@
package dark.fluid.common.pipes;
package dark.fluid.common;
import java.util.ArrayList;
import java.util.List;
@ -8,7 +8,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import dark.api.ColorCode;
import dark.fluid.common.FMRecipeLoader;
import dark.fluid.common.prefab.TileEntityFluidNetworkTile;
/** Enum to hold info about each pipe material. Values are by default and some can change with pipe
* upgrades.
@ -131,30 +131,16 @@ public enum PipeMaterial
return new ItemStack(FMRecipeLoader.blockPipe, s, (this.ordinal() * spacing) + color.ordinal() + 1);
}
public static ItemStack getDropItem(World world, int x, int y, int z)
public static int getDropItemMeta(World world, int x, int y, int z)
{
int meta = world.getBlockMetadata(x, y, z);
TileEntity ent = world.getBlockTileEntity(x, y, z);
meta *= spacing;
if (ent instanceof TileEntityPipe)
if (ent instanceof TileEntityFluidNetworkTile)
{
meta += ((TileEntityPipe) ent).getPipeID();
meta += ((TileEntityFluidNetworkTile) ent).getSubID();
}
return new ItemStack(FMRecipeLoader.blockPipe, 1, meta);
}
public static ColorCode getColor(int pipeID)
{
return EnumPipeType.getColorCode(pipeID % spacing);
}
public static int updateColor(Object cc, int pipeID)
{
if (EnumPipeType.canColor(pipeID))
{
return EnumPipeType.getUpdatedID(pipeID, ColorCode.get(cc));
}
return pipeID;
return meta;
}
public boolean canSupport(FluidStack fluid)

View file

@ -1,73 +0,0 @@
package dark.fluid.common.machines;
import java.util.List;
import java.util.Set;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import com.builtbroken.common.Pair;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.fluid.common.BlockFM;
public class BlockBoiler extends BlockFM
{
public BlockBoiler()
{
super(BlockBoiler.class, "Boilers", Material.iron);
this.setCreativeTab(CreativeTabs.tabBlock);
this.setHardness(1f);
this.setResistance(3f);
}
@Override
public int damageDropped(int metadata)
{
return 0;
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityBoiler();
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
@SideOnly(Side.CLIENT)
public boolean renderAsNormalBlock()
{
return false;
}
@Override
@SideOnly(Side.CLIENT)
public int getRenderType()
{
return -1;
}
@Override
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(new ItemStack(par1, 1, 0));
}
@Override
public void getTileEntities(int blockID, Set<Pair<String, Class<? extends TileEntity>>> list)
{
list.add(new Pair<String, Class<? extends TileEntity>>("FMSteamBoiler", TileEntityBoiler.class));
}
}

View file

@ -1,5 +1,6 @@
package dark.fluid.common.machines;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@ -20,6 +21,8 @@ import dark.api.ColorCode.IColorCoded;
import dark.core.prefab.helpers.FluidHelper;
import dark.fluid.client.render.BlockRenderHelper;
import dark.fluid.common.BlockFM;
import dark.fluid.common.PipeMaterial;
import dark.fluid.common.pipes.TileEntityPipe;
public class BlockTank extends BlockFM
{
@ -74,9 +77,9 @@ public class BlockTank extends BlockFM
public int getComparatorInputOverride(World world, int x, int y, int z, int par5)
{
TileEntityTank tileEntity = (TileEntityTank) world.getBlockTileEntity(x, y, z);
if (tileEntity != null)
if (tileEntity != null && tileEntity.getTileNetwork().getNetworkTankInfo().fluid != null)
{
return tileEntity.getRedstoneLevel();
return 15 * (tileEntity.getTileNetwork().getNetworkTankInfo().fluid.amount / tileEntity.getTileNetwork().getNetworkTankInfo().capacity);
}
return 0;
}
@ -84,13 +87,19 @@ public class BlockTank extends BlockFM
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{
int meta = world.getBlockMetadata(x, y, z);
if (world.getBlockTileEntity(x, y, z) instanceof TileEntityTank)
{
meta = ((TileEntityTank) world.getBlockTileEntity(x, y, z)).getColor().ordinal() & 15;
}
return new ItemStack(this, 1, meta);
return new ItemStack(this, 1, PipeMaterial.getDropItemMeta(world, x, y, z));
}
@Override
public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int metadata, int fortune)
{
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
TileEntity entity = world.getBlockTileEntity(x, y, z);
if (entity instanceof TileEntityPipe)
{
ret.add(new ItemStack(this, 1, PipeMaterial.getDropItemMeta(world, x, y, z)));
}
return ret;
}
@Override

View file

@ -1,186 +0,0 @@
package dark.fluid.common.machines;
import java.util.List;
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 net.minecraftforge.fluids.IFluidTank;
import dark.api.ColorCode;
import dark.api.fluid.INetworkFluidPart;
import dark.core.prefab.tilenetwork.NetworkTileEntities;
import dark.fluid.common.prefab.TileEntityFluidDevice;
public class TileEntityBoiler extends TileEntityFluidDevice implements IFluidHandler, INetworkFluidPart
{
public TileEntity[] connectedBlocks = new TileEntity[6];
public int tankCount;
FluidTank outputTank = new FluidTank(4);
FluidTank inputTank = new FluidTank(4);
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
{
if (fluid != null)
{
if (inputTank.getFluid() == null || inputTank.getFluid().getFluid().equals(fluid))
{
return true;
}
}
return false;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
if (fluid != null)
{
if (from == ForgeDirection.DOWN)
{
//Bottom side is reserved for draining boiler of liquid when moving it
if (inputTank.getFluid() != null && inputTank.getFluid().getFluid().equals(fluid))
{
return true;
}
}
else if (outputTank.getFluid() != null && fluid.equals(outputTank.getFluid().getFluid()))
{
return true;
}
}
return false;
}
@Override
public boolean canTileConnect(Connection type, ForgeDirection dir)
{
return true;
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
// TODO Auto-generated method stub
return 0;
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
if (from == ForgeDirection.DOWN)
{
}
else
{
}
return null;
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{
// TODO Auto-generated method stub
return null;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from)
{
// TODO Auto-generated method stub
return null;
}
@Override
public ColorCode getColor()
{
// TODO Auto-generated method stub
return null;
}
@Override
public boolean setColor(Object obj)
{
return false;
}
@Override
public List<TileEntity> getNetworkConnections()
{
// TODO Auto-generated method stub
return null;
}
@Override
public void refresh()
{
// TODO Auto-generated method stub
}
@Override
public NetworkTileEntities getTileNetwork()
{
// TODO Auto-generated method stub
return null;
}
@Override
public void setTileNetwork(NetworkTileEntities fluidNetwok)
{
// TODO Auto-generated method stub
}
@Override
public boolean mergeDamage(String result)
{
// TODO Auto-generated method stub
return false;
}
@Override
public FluidTankInfo[] getTankInfo()
{
// TODO Auto-generated method stub
return null;
}
@Override
public int fillTankContent(int index, FluidStack stack, boolean doFill)
{
// TODO Auto-generated method stub
return 0;
}
@Override
public FluidStack drainTankContent(int index, int volume, boolean doDrain)
{
// TODO Auto-generated method stub
return null;
}
@Override
public boolean canPassThrew(FluidStack fluid, ForgeDirection from, ForgeDirection to)
{
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onPassThrew(FluidStack fluid, ForgeDirection from, ForgeDirection to)
{
// TODO Auto-generated method stub
return false;
}
}

View file

@ -106,7 +106,7 @@ public class TileEntityReleaseValve extends TileEntityFluidDevice implements ITi
}
/** if any of allowed list is true
*
*
* @return true */
public boolean isRestricted()
{
@ -135,7 +135,7 @@ public class TileEntityReleaseValve extends TileEntityFluidDevice implements ITi
if (tileEntity instanceof INetworkPipe)
{
INetworkPipe pipe = (INetworkPipe) tileEntity;
if (this.canConnect(pipe.getColor()))
if (this.canTileConnect(Connection.FLUIDS, dir.getOpposite()))
{
this.output.add(pipe);
}

View file

@ -1,429 +1,7 @@
package dark.fluid.common.machines;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import dark.fluid.common.prefab.TileEntityFluidNetworkTile;
import net.minecraft.entity.player.EntityPlayer;
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.tileentity.TileEntityComparator;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import net.minecraftforge.fluids.IFluidTank;
import org.bouncycastle.util.Arrays;
import universalelectricity.prefab.network.IPacketReceiver;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.api.ColorCode;
import dark.api.ColorCode.IColorCoded;
import dark.api.IToolReadOut;
import dark.api.fluid.FluidMasterList;
import dark.api.fluid.INetworkFluidPart;
import dark.api.fluid.INetworkPipe;
import dark.core.common.DarkMain;
import dark.core.network.PacketHandler;
import dark.core.prefab.helpers.FluidHelper;
import dark.core.prefab.tilenetwork.NetworkTileEntities;
import dark.core.prefab.tilenetwork.fluid.NetworkFluidContainers;
import dark.core.prefab.tilenetwork.fluid.NetworkFluidTiles;
import dark.fluid.common.pipes.PipeMaterial;
import dark.fluid.common.prefab.TileEntityFluidStorage;
public class TileEntityTank extends TileEntityFluidStorage implements IFluidHandler, IToolReadOut, IColorCoded, INetworkFluidPart, IPacketReceiver
public class TileEntityTank extends TileEntityFluidNetworkTile
{
/* CURRENTLY CONNECTED TILE ENTITIES TO THIS */
private List<TileEntity> connectedBlocks = new ArrayList<TileEntity>();
public int[] renderConnection = new int[6];
/* NETWORK INSTANCE THAT THIS PIPE USES */
private NetworkFluidContainers fluidNetwork;
private int refreshRate = 1;
protected ColorCode colorCode = ColorCode.UNKOWN;
protected boolean flagForColorCodeUpdate = false;
@Override
public void updateEntity()
{
super.updateEntity();
if (!worldObj.isRemote)
{
if (ticks % refreshRate == 0)
{
this.refreshRate = (random.nextInt(5) * 40) + 20;
this.refresh();
}
}
}
@Override
public void initiate()
{
this.refresh();
}
@Override
public void invalidate()
{
if (!this.worldObj.isRemote)
{
this.getTileNetwork().splitNetwork(this.worldObj, this);
}
super.invalidate();
}
@Override
public void handlePacketData(INetworkManager network, int type, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
try
{
if (this.worldObj.isRemote)
{
int id = dataStream.readInt();
if (id == 0 || id == 1)
{
if (id == 0)
{
this.getTank().setFluid(FluidStack.loadFluidStackFromNBT(PacketHandler.instance().readNBTTagCompound(dataStream)));
//System.out.println("Received Fluid Packet Fluid = " + this.getTank().getFluid().getFluid().getName() + "@" + this.getTank().getFluid().amount);
}
else
{
this.getTank().setFluid(null);
dataStream.readInt();
}
this.colorCode = ColorCode.get(dataStream.readInt());
this.renderConnection[0] = dataStream.readInt();
this.renderConnection[1] = dataStream.readInt();
this.renderConnection[2] = dataStream.readInt();
this.renderConnection[3] = dataStream.readInt();
this.renderConnection[4] = dataStream.readInt();
this.renderConnection[5] = dataStream.readInt();
}
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public Packet getDescriptionPacket()
{
FluidStack stack = null;
if (this.getTank().getFluid() != null && this.getTank().getFluid().getFluid() != null)
{
stack = this.getTank().getFluid();
}
return PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, stack != null ? 0 : 1, stack != null ? stack.writeToNBT(new NBTTagCompound()) : 1, this.colorCode.ordinal(), 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()
{
if (this.flagForColorCodeUpdate)
{
int meta = this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
if (meta == 15)
{
this.colorCode = ColorCode.UNKOWN;
}
else
{
this.colorCode = ColorCode.get(meta);
}
this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 3);
this.flagForColorCodeUpdate = false;
}
return this.colorCode;
}
/** sets the current color mark of the pipe */
@Override
public boolean setColor(Object cc)
{
if (!worldObj.isRemote)
{
this.colorCode = ColorCode.get(cc);
return true;
}
return false;
}
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side, EnumTools tool)
{
/* DEBUG CODE ACTIVATERS */
boolean testNetwork = true;
/* NORMAL OUTPUT */
String string = "Fluid>" + (this.getTileNetwork() instanceof NetworkFluidTiles ? ((NetworkFluidTiles) this.getTileNetwork()).getNetworkFluid() : "Error");
if (testNetwork)
{
string += "\nNetID>" + this.getTileNetwork().toString();
}
return string;
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
if (resource == null || this.worldObj.isRemote)
{
return 0;
}
return ((NetworkFluidContainers) this.getTileNetwork()).storeFluidInSystem(resource, doFill);
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack stack, boolean doDrain)
{
if (this.worldObj.isRemote)
{
return null;
}
return ((NetworkFluidContainers) this.getTileNetwork()).drainFluidFromSystem(stack, doDrain);
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
if (this.worldObj.isRemote)
{
return null;
}
return ((NetworkFluidContainers) this.getTileNetwork()).drainFluidFromSystem(maxDrain, doDrain);
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection direction)
{
return new FluidTankInfo[] { new FluidTankInfo(((NetworkFluidContainers) this.getTileNetwork()).combinedStorage()) };
}
/** 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)
{
this.renderConnection[side.ordinal()] = tileEntity instanceof TileEntityTank && ((TileEntityTank) tileEntity).getColor() == this.getColor() ? 2 : (tileEntity instanceof INetworkPipe ? 1 : tileEntity != null ? 3 : 0);
if (tileEntity != null)
{
if (tileEntity instanceof TileEntityTank)
{
if (((TileEntityTank) tileEntity).getColor() == this.getColor())
{
this.getTileNetwork().merge(((TileEntityTank) tileEntity).getTileNetwork(), this);
connectedBlocks.add(tileEntity);
}
}
if (tileEntity instanceof TileEntityComparator)
{
this.worldObj.markBlockForUpdate(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
}
}
}
}
@Override
public void refresh()
{
if (this.worldObj != null && !this.worldObj.isRemote)
{
int[] previousConnections = this.renderConnection.clone();
this.connectedBlocks.clear();
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);
}
/** Only send packet updates if visuallyConnected changed. */
if (!Arrays.areEqual(previousConnections, this.renderConnection))
{
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
}
}
@Override
public NetworkTileEntities getTileNetwork()
{
if (this.fluidNetwork == null)
{
this.setTileNetwork(new NetworkFluidContainers(this));
}
return this.fluidNetwork;
}
@Override
public void setTileNetwork(NetworkTileEntities network)
{
if (network instanceof NetworkFluidContainers)
{
this.fluidNetwork = ((NetworkFluidContainers) network);
}
}
@Override
@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 List<TileEntity> getNetworkConnections()
{
return this.connectedBlocks;
}
@Override
public int getTankSize()
{
return FluidContainerRegistry.BUCKET_VOLUME * (BlockTank.tankVolume > 0 ? BlockTank.tankVolume : 1);
}
@Override
public int fillTankContent(int index, FluidStack stack, boolean doFill)
{
if (index == 0)
{
return this.getTank().fill(stack, doFill);
}
return 0;
}
@Override
public FluidStack drainTankContent(int index, int volume, boolean doDrain)
{
if (index == 0)
{
return this.getTank().drain(volume, doDrain);
}
return null;
}
public int getRedstoneLevel()
{
if (this.getTileNetwork() != null && this.getTileNetwork() instanceof NetworkFluidTiles)
{
IFluidTank tank = ((NetworkFluidTiles) this.getTileNetwork()).combinedStorage();
if (tank != null && tank.getFluid() != null)
{
int max = tank.getCapacity();
int current = tank.getFluid().amount;
double percent = current / max;
return ((int) (15 * percent));
}
}
return 0;
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
{
return fluid != null;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return fluid != null;
}
@Override
public boolean mergeDamage(String result)
{
return false;
}
@Override
public FluidTankInfo[] getTankInfo()
{
return new FluidTankInfo[] { this.getTank().getInfo() };
}
/** Reads a tile entity from NBT. */
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
//Load color code from nbt
if (nbt.hasKey("ColorCode"))
{
this.colorCode = ColorCode.get(nbt.getInteger("ColorCode"));
}
else
{
this.flagForColorCodeUpdate = true;
}
}
/** Writes a tile entity to NBT. */
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("ColorCode", this.colorCode.ordinal());
}
@Override
public boolean canPassThrew(FluidStack fluid, ForgeDirection from, ForgeDirection to)
{
return this.connectedBlocks.get(from.ordinal()) != null && this.connectedBlocks.get(to.ordinal()) != null;
}
@Override
public boolean onPassThrew(FluidStack fluid, ForgeDirection from, ForgeDirection to)
{
PipeMaterial mat = PipeMaterial.get(this.getBlockMetadata());
if (fluid != null && fluid.getFluid() != null && mat != null)
{
if (fluid.getFluid().isGaseous(fluid) && !mat.canSupportGas)
{
//TODO lose 25% of the gas, and render the lost
}
else if (FluidMasterList.isMolten(fluid.getFluid()) && !mat.canSupportMoltenFluids)
{
//TODO start to heat up the pipe to melting point. When it hits melting point turn the pipe to its molten metal equal
//TODO also once it reaches a set heat level start burning up blocks around the pipe. Eg wood
}
else if (!fluid.getFluid().isGaseous(fluid) && !mat.canSupportFluids)
{
//Slowly start damaging the pipe as its can support the fluid due to how the pipe is made
}
}
return false;
}
}

View file

@ -27,6 +27,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import dark.api.ColorCode;
import dark.api.ColorCode.IColorCoded;
import dark.fluid.common.BlockFM;
import dark.fluid.common.PipeMaterial;
public class BlockPipe extends BlockFM
{
@ -59,7 +60,7 @@ public class BlockPipe extends BlockFM
TileEntity entity = world.getBlockTileEntity(x, y, z);
if (entity instanceof TileEntityPipe)
{
ret.add(new ItemStack(this, 1, (world.getBlockMetadata(x, y, z) * PipeMaterial.spacing) + ((TileEntityPipe) entity).getPipeID()));
ret.add(new ItemStack(this, 1, PipeMaterial.getDropItemMeta(world, x, y, z)));
}
return ret;
}
@ -92,7 +93,7 @@ public class BlockPipe extends BlockFM
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{
return PipeMaterial.getDropItem(world, x, y, z);
return new ItemStack(this, 1, PipeMaterial.getDropItemMeta(world, x, y, z));
}
@Override

View file

@ -0,0 +1,111 @@
package dark.fluid.common.pipes;
import dark.api.ColorCode;
import dark.api.ColorCode.IColoredId;
public enum EnumTankTypes implements IColoredId
{
Base(0, 0, true),
COLOR(new IPipeType()
{
@Override
public ColorCode getColor(int meta)
{
return ColorCode.get(meta);
}
@Override
public String getName(int pipeID)
{
if (pipeID < 16 && pipeID > 0)
{
return ColorCode.get(pipeID - 1).name;
}
return "";
}
}, 1, 16, true);
private IPipeType type;
public int metaStart = 1;
public int metaEnd = 16;
public boolean canColor = false;
private EnumTankTypes()
{
this.metaStart = this.ordinal() * 16;
this.metaEnd = this.metaStart + 15;
}
private EnumTankTypes(int metaStart, int metaEnd, boolean canColor)
{
}
private EnumTankTypes(IPipeType type, int metaStart, int metaEnd, boolean canColor)
{
this.type = type;
this.metaStart = metaStart;
this.metaEnd = metaEnd;
this.canColor = canColor;
}
public static EnumPipeType get(int meta)
{
for (EnumPipeType type : EnumPipeType.values())
{
if (meta >= type.metaStart && meta <= type.metaEnd)
{
return type;
}
}
return null;
}
public static boolean canColor(int meta)
{
EnumPipeType type = get(meta);
if (type != null)
{
return type.canColor;
}
return false;
}
public static int getUpdatedID(int pipeID, ColorCode newColor)
{
if (pipeID == 0)
{
return 1 + newColor.ordinal();
}
return pipeID;
}
public static ColorCode getColorCode(int meta)
{
EnumPipeType type = get(meta);
if (type != null)
{
return type.getColor(meta);
}
return ColorCode.UNKOWN;
}
@Override
public ColorCode getColor(int meta)
{
if (type != null)
{
return type.getColor(meta);
}
return ColorCode.UNKOWN;
}
public String getName(int pipeID)
{
if (type != null)
{
return type.getName(pipeID);
}
return "";
}
}

View file

@ -7,6 +7,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import dark.api.ColorCode.IColorCoded;
import dark.fluid.common.PipeMaterial;
public class ItemBlockPipe extends ItemBlock
{

View file

@ -41,91 +41,16 @@ import dark.core.network.PacketHandler;
import dark.core.prefab.helpers.FluidHelper;
import dark.core.prefab.tilenetwork.NetworkTileEntities;
import dark.core.prefab.tilenetwork.fluid.NetworkPipes;
import dark.fluid.common.PipeMaterial;
import dark.fluid.common.prefab.TileEntityFluidNetworkTile;
public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler, IToolReadOut, IColorCoded, INetworkPipe, IPacketReceiver
public class TileEntityPipe extends TileEntityFluidNetworkTile implements IColorCoded, INetworkPipe
{
/** Pipe temp tank storage, main storage is thought of as the collective network tank */
protected FluidTank tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
/** TileEntities that this pipe has connections too */
private List<TileEntity> connectedBlocks = new ArrayList<TileEntity>();
/** Should render connections on side */
public boolean[] renderConnection = new boolean[6];
/** Network that links the collective pipes together to work */
private NetworkPipes pipeNetwork;
protected int updateTick = 1;
protected int pipeID = 0;
String refClassID = "";
public enum PipePacketID
{
PIPE_CONNECTIONS,
EXTENTION_CREATE,
EXTENTION_UPDATE;
}
@Override
public void updateEntity()
{
super.updateEntity();
if (!worldObj.isRemote)
{
if (ticks % this.updateTick == 0)
{
this.updateTick = this.worldObj.rand.nextInt(5) * 40 + 20;
this.refresh();
}
}
}
@Override
public void invalidate()
{
super.invalidate();
if (!this.worldObj.isRemote)
{
this.getTileNetwork().splitNetwork(this.worldObj, this);
}
}
@Override
public void handlePacketData(INetworkManager network, int type, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
try
{
if (this.worldObj.isRemote)
{
this.pipeID = dataStream.readInt();
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();
}
}
catch (Exception e)
{
System.out.print("Error with reading packet for TileEntityPipe");
e.printStackTrace();
}
}
@Override
public Packet getDescriptionPacket()
{
return PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, this.pipeID, 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 PipeMaterial.getColor(this.pipeID);
return EnumPipeType.getColorCode(this.subID);
}
/** sets the current color mark of the pipe */
@ -134,218 +59,60 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler,
{
if (!worldObj.isRemote)
{
int p = this.pipeID;
this.pipeID = PipeMaterial.updateColor(cc, pipeID);
return p != this.pipeID;
int p = this.subID;
this.subID = EnumPipeType.getUpdatedID(subID, ColorCode.get(cc));
return p != this.subID;
}
return false;
}
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side, EnumTools tool)
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
{
if (tool == EnumTools.PIPE_GUAGE)
super.validateConnectionSide(tileEntity, side);
if (tileEntity instanceof TileEntityPipe)
{
/* DEBUG CODE ACTIVATERS */
boolean testConnections = true;
/* NORMAL OUTPUT */
String string = ((NetworkPipes) this.getTileNetwork()).pressureProduced + "p " + ((NetworkPipes) this.getTileNetwork()).getNetworkFluid();
/* DEBUG CODE */
if (testConnections)
int meta = new Vector3(this).getBlockMetadata(this.worldObj);
int metaOther = new Vector3(tileEntity).getBlockMetadata(this.worldObj);
if (meta < PipeMaterial.values().length && metaOther < PipeMaterial.values().length)
{
for (int i = 0; i < 6; i++)
PipeMaterial pipeMat = PipeMaterial.values()[meta];
PipeMaterial pipeMatOther = PipeMaterial.values()[metaOther];
//Same pipe types can connect
if (pipeMat == pipeMatOther)
{
string += "||" + (this.renderConnection[i] ? "T" : "F");
this.getTileNetwork().merge(((INetworkPipe) tileEntity).getTileNetwork(), this);
connectedBlocks.add(tileEntity);
this.renderConnection[side.ordinal()] = TileEntityFluidNetworkTile.NETWORK_CONNECTION;
return;
}//Wood and stone pipes can connect to each other but not other pipe types since they are more like a trough than a pipe
else if ((pipeMat == PipeMaterial.WOOD || pipeMat == PipeMaterial.STONE) && (pipeMatOther == PipeMaterial.WOOD || pipeMatOther == PipeMaterial.STONE))
{
this.getTileNetwork().merge(((INetworkPipe) tileEntity).getTileNetwork(), this);
connectedBlocks.add(tileEntity);
this.renderConnection[side.ordinal()] = TileEntityFluidNetworkTile.NETWORK_CONNECTION;
return;
}//Any other pipe can connect to each other as long as the color matches except for glass which only works with itself at the moment
else if (pipeMat != PipeMaterial.WOOD && pipeMat != PipeMaterial.STONE && pipeMatOther != PipeMaterial.WOOD && pipeMatOther != PipeMaterial.STONE && pipeMat != PipeMaterial.GLASS && pipeMatOther != PipeMaterial.GLASS)
{
this.getTileNetwork().merge(((INetworkPipe) tileEntity).getTileNetwork(), this);
connectedBlocks.add(tileEntity);
this.renderConnection[side.ordinal()] = TileEntityFluidNetworkTile.NETWORK_CONNECTION;
return;
}
}
string += " " + this.getTileNetwork().toString();
return string;
this.connectedBlocks.remove(tileEntity);
this.renderConnection[side.ordinal()] = TileEntityFluidNetworkTile.NO_CONENCTION;
}
return null;
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
if (resource == null)
{
return 0;
}
return ((NetworkPipes) this.getTileNetwork()).addFluidToNetwork(VectorHelper.getTileEntityFromSide(this.worldObj, new Vector3(this), from), resource, doFill);
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return null;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection direction)
{
if (this.getTileNetwork() instanceof NetworkPipes)
{
return new FluidTankInfo[] { ((NetworkPipes) this.getTileNetwork()).combinedStorage().getInfo() };
}
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
* @return */
public boolean validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
{
if (!this.worldObj.isRemote && tileEntity != null)
{
if (tileEntity instanceof ITileConnector)
{
if (((ITileConnector) tileEntity).canTileConnect(Connection.FLUIDS, side.getOpposite()))
{
if (tileEntity instanceof INetworkPipe)
{
if (tileEntity instanceof TileEntityPipe)
{
int meta = new Vector3(this).getBlockMetadata(this.worldObj);
int metaOther = new Vector3(tileEntity).getBlockMetadata(this.worldObj);
if (meta < PipeMaterial.values().length && metaOther < PipeMaterial.values().length)
{
PipeMaterial pipeMat = PipeMaterial.values()[meta];
PipeMaterial pipeMatOther = PipeMaterial.values()[metaOther];
//Same pipe types can connect
if (pipeMat == pipeMatOther)
{
this.getTileNetwork().merge(((INetworkPipe) tileEntity).getTileNetwork(), this);
return connectedBlocks.add(tileEntity);
}//Wood and stone pipes can connect to each other but not other pipe types since they are more like a trough than a pipe
else if ((pipeMat == PipeMaterial.WOOD || pipeMat == PipeMaterial.STONE) && (pipeMatOther == PipeMaterial.WOOD || pipeMatOther == PipeMaterial.STONE))
{
this.getTileNetwork().merge(((INetworkPipe) tileEntity).getTileNetwork(), this);
return connectedBlocks.add(tileEntity);
}//Any other pipe can connect to each other as long as the color matches except for glass which only works with itself at the moment
else if (pipeMat != PipeMaterial.WOOD && pipeMat != PipeMaterial.STONE && pipeMatOther != PipeMaterial.WOOD && pipeMatOther != PipeMaterial.STONE && pipeMat != PipeMaterial.GLASS && pipeMatOther != PipeMaterial.GLASS)
{
this.getTileNetwork().merge(((INetworkPipe) tileEntity).getTileNetwork(), this);
return connectedBlocks.add(tileEntity);
}
}
return false;
}
else
{
this.getTileNetwork().merge(((INetworkPipe) tileEntity).getTileNetwork(), this);
return connectedBlocks.add(tileEntity);
}
}
else
{
return connectedBlocks.add(tileEntity);
}
}
}
else if (tileEntity instanceof IColorCoded)
{
if (this.getColor() == ColorCode.UNKOWN || this.getColor() == ((IColorCoded) tileEntity).getColor())
{
return connectedBlocks.add(tileEntity);
}
}
else if (tileEntity instanceof IFluidHandler)
{
return connectedBlocks.add(tileEntity);
}
}
return false;
}
@Override
public boolean canTileConnect(Connection type, ForgeDirection dir)
{
Vector3 connection = new Vector3(this).modifyPositionFromSide(dir.getOpposite());
TileEntity entity = connection.getTileEntity(this.worldObj);
//Unknown color codes can connect to any color, however two different colors can connect to support better pipe layouts
if (entity instanceof IColorCoded && ((IColorCoded) entity).getColor() != this.getColor() && ((IColorCoded) entity).getColor() != ColorCode.UNKOWN)
{
return false;
}//All Fluid connections are supported
else if (type == Connection.FLUIDS)
{
return true;
}
return false;
}
@Override
public boolean canPassThrew(FluidStack fluid, ForgeDirection from, ForgeDirection to)
{
return this.renderConnection[from.ordinal()] && this.renderConnection[to.ordinal()];
}
@Override
public boolean onPassThrew(FluidStack fluid, ForgeDirection from, ForgeDirection to)
{
PipeMaterial mat = PipeMaterial.get(this.getBlockMetadata());
if (fluid != null && fluid.getFluid() != null && mat != null)
{
if (fluid.getFluid().isGaseous(fluid) && !mat.canSupportGas)
{
//TODO lose 25% of the gas, and render the lost
}
else if (FluidMasterList.isMolten(fluid.getFluid()) && !mat.canSupportMoltenFluids)
{
//TODO start to heat up the pipe to melting point. When it hits melting point turn the pipe to its molten metal equal
//TODO also once it reaches a set heat level start burning up blocks around the pipe. Eg wood
}
else if (!fluid.getFluid().isGaseous(fluid) && !mat.canSupportFluids)
{
//Slowly start damaging the pipe as its can support the fluid due to how the pipe is made
}
}
return false;
}
@Override
public void refresh()
{
if (this.worldObj != null && !this.worldObj.isRemote)
{
boolean[] previousConnections = this.renderConnection.clone();
this.connectedBlocks.clear();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity ent = new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj);
this.renderConnection[dir.ordinal()] = this.validateConnectionSide(ent, dir);
if (this.renderConnection[dir.ordinal()] && ent instanceof IFluidHandler && !(ent instanceof INetworkPipe))
{
IFluidHandler tankContainer = (IFluidHandler) ent;
this.getTileNetwork().addTile(ent, false);
/* LITTLE TRICK TO AUTO DRAIN TANKS ON EACH CONNECTION UPDATE */
FluidStack stack = tankContainer.drain(dir, FluidContainerRegistry.BUCKET_VOLUME, false);
if (stack != null && stack.amount > 0)
{
//TODO change this to be turned off or leave it as is for not using valves
int fill = ((NetworkPipes) this.getTileNetwork()).addFluidToNetwork((TileEntity) tankContainer, stack, true);
tankContainer.drain(dir, fill, true);
}
}
}
/** Only send packet updates if visuallyConnected changed. */
if (!Arrays.areEqual(previousConnections, this.renderConnection))
{
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
}
//TODO do checks for molten pipe so that fluids like water turn into steam, oils and fuels burn
return super.onPassThrew(fluid, from, to);
}
@Override
@ -360,13 +127,13 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler,
}
@Override
public NetworkTileEntities getTileNetwork()
public NetworkPipes getTileNetwork()
{
if (this.pipeNetwork == null)
if (this.network == null || !(this.network instanceof NetworkPipes))
{
this.setTileNetwork(new NetworkPipes(this));
}
return this.pipeNetwork;
return (NetworkPipes) this.network;
}
@Override
@ -374,7 +141,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler,
{
if (network instanceof NetworkPipes)
{
this.pipeNetwork = (NetworkPipes) network;
this.network = (NetworkPipes) network;
}
}
@ -417,119 +184,14 @@ public class TileEntityPipe extends TileEntityAdvanced implements IFluidHandler,
return false;
}
@Override
@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 List<TileEntity> getNetworkConnections()
{
return this.connectedBlocks;
}
@Override
public FluidTankInfo[] getTankInfo()
{
return new FluidTankInfo[] { this.tank.getInfo() };
}
@Override
public int fillTankContent(int index, FluidStack stack, boolean doFill)
{
if (index == 0)
{
return this.tank.fill(stack, doFill);
}
return 0;
}
@Override
public FluidStack drainTankContent(int index, int volume, boolean doDrain)
{
if (index == 0)
{
return this.tank.drain(volume, doDrain);
}
return null;
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{
// TODO Auto-generated method stub
return null;
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
{
return this.canTileConnect(Connection.FLUIDS, from);
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return this.canTileConnect(Connection.FLUIDS, from);
}
@Override
public boolean mergeDamage(String result)
{
return false;
}
/** Reads a tile entity from NBT. */
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
//Load color code from nbt
this.refClassID = nbt.getString("id");
this.pipeID = nbt.getInteger("PipeItemId");
//Load fluid tank
FluidStack liquid = FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag("FluidTank"));
if (nbt.hasKey("stored"))
{
NBTTagCompound tag = nbt.getCompoundTag("stored");
String name = tag.getString("LiquidName");
int amount = nbt.getInteger("Amount");
Fluid fluid = FluidRegistry.getFluid(name);
if (fluid != null)
{
liquid = new FluidStack(fluid, amount);
}
}
if (liquid != null)
{
this.tank.setFluid(liquid);
}
}
/** Writes a tile entity to NBT. */
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("PipeItemId", this.pipeID);
if (this.tank != null && this.tank.getFluid() != null)
{
nbt.setTag("FluidTank", this.tank.getFluid().writeToNBT(new NBTTagCompound()));
}
}
public void setPipeID(int itemDamage)
{
this.pipeID = itemDamage;
this.subID = itemDamage;
}
public int getPipeID()
{
return this.pipeID;
return this.subID;
}
}

View file

@ -0,0 +1,583 @@
package dark.fluid.common.prefab;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
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.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import org.bouncycastle.util.Arrays;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.Player;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import universalelectricity.core.vector.Vector3;
import dark.api.ColorCode;
import dark.api.ColorCode.IColorCoded;
import dark.api.fluid.FluidMasterList;
import dark.api.fluid.INetworkFluidPart;
import dark.api.parts.INetworkPart;
import dark.api.parts.ITileConnector;
import dark.core.common.DarkMain;
import dark.core.network.ISimplePacketReceiver;
import dark.core.network.PacketHandler;
import dark.core.prefab.tilenetwork.NetworkTileEntities;
import dark.core.prefab.tilenetwork.fluid.NetworkFluidTiles;
import dark.core.prefab.tilenetwork.fluid.NetworkPipes;
import dark.fluid.common.PipeMaterial;
import dark.fluid.common.machines.TileEntityTank;
public class TileEntityFluidNetworkTile extends TileEntityFluidDevice implements INetworkFluidPart, ISimplePacketReceiver
{
private int updateTick = 1;
protected static final byte NO_CONENCTION = 0, PIPE_CONENCTION = 1, NETWORK_CONNECTION = 2, TILE_ENTITY_CONENCTION = 3;
protected FluidTank[] internalTanks = new FluidTank[] { new FluidTank(FluidContainerRegistry.BUCKET_VOLUME) };
protected FluidTankInfo[] internalTanksInfo = new FluidTankInfo[] { new FluidTankInfo(null, FluidContainerRegistry.BUCKET_VOLUME) };
protected List<TileEntity> connectedBlocks = new ArrayList<TileEntity>();
public byte[] renderConnection = new byte[6];
public boolean[] canConnectSide = new boolean[] { true, true, true, true, true, true };
protected int heat = 0;
protected int maxHeat = 20000;
protected int damage = 0;
protected int maxDamage = 1000;
protected int subID = 0;
protected NetworkFluidTiles network;
@Override
public void updateEntity()
{
super.updateEntity();
if (!worldObj.isRemote)
{
if (ticks % this.updateTick == 0)
{
this.updateTick = this.worldObj.rand.nextInt(5) * 40 + 20;
this.refresh();
}
}
}
@Override
public void invalidate()
{
super.invalidate();
if (!this.worldObj.isRemote)
{
this.getTileNetwork().splitNetwork(this.worldObj, this);
}
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
if (this.getTileNetwork() != null && this.canConnectSide[from.ordinal()] && resource != null)
{
return this.getTileNetwork().fillNetworkTank(resource, doFill);
}
return 0;
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{
if (this.getTileNetwork() != null && this.canConnectSide[from.ordinal()] && resource != null)
{
if (this.getTileNetwork().getNetworkTank() != null && this.getTileNetwork().getNetworkTank().getFluid() != null && this.getTileNetwork().getNetworkTank().getFluid().isFluidEqual(resource))
{
this.getTileNetwork().drainNetworkTank(resource.amount, doDrain);
}
}
return null;
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
if (this.getTileNetwork() != null && this.canConnectSide[from.ordinal()])
{
this.getTileNetwork().drainNetworkTank(maxDrain, doDrain);
}
return null;
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
{
return this.canConnectSide[from.ordinal()] && this.damage < this.maxDamage;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return this.canConnectSide[from.ordinal()] && this.damage < this.maxDamage;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from)
{
return new FluidTankInfo[] { this.getTileNetwork().getNetworkTankInfo() };
}
@Override
public List<TileEntity> getNetworkConnections()
{
return this.connectedBlocks;
}
@Override
public void refresh()
{
if (this.worldObj != null && !this.worldObj.isRemote)
{
byte[] previousConnections = this.renderConnection.clone();
this.connectedBlocks.clear();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
this.validateConnectionSide(new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj), dir);
}
/** Only send packet updates if visuallyConnected changed. */
if (!Arrays.areEqual(previousConnections, this.renderConnection))
{
this.sendRenderUpdate();
}
}
}
/** 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)
{
this.renderConnection[side.ordinal()] = TileEntityFluidNetworkTile.NO_CONENCTION;
if (tileEntity != null)
{
this.renderConnection[side.ordinal()] = TileEntityFluidNetworkTile.TILE_ENTITY_CONENCTION;
if (tileEntity instanceof ITileConnector && !((ITileConnector) tileEntity).canTileConnect(Connection.FLUIDS, side.getOpposite()))
{
this.renderConnection[side.ordinal()] = TileEntityFluidNetworkTile.NO_CONENCTION;
}
else if (tileEntity instanceof INetworkFluidPart)
{
if (this.canTileConnect(Connection.NETWORK, side.getOpposite()))
{
this.getTileNetwork().merge(((INetworkFluidPart) tileEntity).getTileNetwork(), (INetworkPart) tileEntity);
this.renderConnection[side.ordinal()] = TileEntityFluidNetworkTile.NETWORK_CONNECTION;
connectedBlocks.add(tileEntity);
}
}
else if (tileEntity instanceof IFluidHandler)
{
this.getTileNetwork().merge(((TileEntityTank) tileEntity).getTileNetwork(), this);
connectedBlocks.add(tileEntity);
if (this.getTileNetwork() instanceof NetworkPipes)
{
((NetworkPipes) this.getTileNetwork()).addTile(tileEntity, false);
}
}
else
{
this.renderConnection[side.ordinal()] = TileEntityFluidNetworkTile.TILE_ENTITY_CONENCTION;
}
}
}
}
@Override
public NetworkFluidTiles getTileNetwork()
{
if (this.network == null)
{
this.network = new NetworkFluidTiles(this);
}
return this.network;
}
@Override
public void setTileNetwork(NetworkTileEntities fluidNetwork)
{
if (fluidNetwork instanceof NetworkFluidTiles)
{
this.network = (NetworkFluidTiles) fluidNetwork;
}
}
@Override
public boolean mergeDamage(String result)
{
return false;
}
@Override
public FluidTankInfo[] getTankInfo()
{
if (this.internalTanksInfo == null)
{
this.internalTanksInfo = new FluidTankInfo[this.internalTanks.length];
for (int i = 0; i < this.internalTanks.length; i++)
{
this.internalTanksInfo[i] = this.internalTanks[i].getInfo();
}
}
return this.internalTanksInfo;
}
@Override
public int fillTankContent(int index, FluidStack stack, boolean doFill)
{
if (index < this.internalTanks.length)
{
if (this.internalTanks[index] == null)
{
this.internalTanks[index] = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
this.internalTanksInfo[index] = this.internalTanks[index].getInfo();
}
int p = this.internalTanks[index].getFluid() != null ? this.internalTanks[index].getFluid().amount : 0;
int fill = this.internalTanks[index].fill(stack, doFill);
if (p != fill)
{
//TODO add a catch to this so we don't send a dozen packets for one updates
this.sendTankUpdate(index);
}
return fill;
}
return 0;
}
@Override
public FluidStack drainTankContent(int index, int volume, boolean doDrain)
{
if (index < this.internalTanks.length)
{
if (this.internalTanks[index] == null)
{
this.internalTanks[index] = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
this.internalTanksInfo[index] = this.internalTanks[index].getInfo();
}
FluidStack prev = this.internalTanks[index].getFluid();
FluidStack stack = this.internalTanks[index].drain(volume, doDrain);
if (prev != null && (stack == null || prev.amount != stack.amount))
{
//TODO add a catch to this so we don't send a dozen packets for one updates
this.sendTankUpdate(index);
}
return stack;
}
return null;
}
@Override
public boolean canTileConnect(Connection type, ForgeDirection dir)
{
if (this.damage >= this.maxDamage)
{
return false;
}
Vector3 connection = new Vector3(this).modifyPositionFromSide(dir.getOpposite());
TileEntity entity = connection.getTileEntity(this.worldObj);
//Unknown color codes can connect to any color, however two different colors can connect to support better pipe layouts
if (entity instanceof IColorCoded && this instanceof IColorCoded && ((IColorCoded) entity).getColor() != ((IColorCoded) this).getColor() && ((IColorCoded) this).getColor() != ColorCode.UNKOWN && ((IColorCoded) entity).getColor() != ColorCode.UNKOWN)
{
return false;
}//All Fluid connections are supported
else if (type == Connection.FLUIDS)
{
return true;
}
return false;
}
@Override
public boolean canPassThrew(FluidStack fluid, ForgeDirection from, ForgeDirection to)
{
return this.connectedBlocks.get(from.ordinal()) != null && this.connectedBlocks.get(to.ordinal()) != null && this.damage < this.maxDamage;
}
@Override
public boolean onPassThrew(FluidStack fluid, ForgeDirection from, ForgeDirection to)
{
PipeMaterial mat = PipeMaterial.get(this.getBlockMetadata());
if (fluid != null && fluid.getFluid() != null && mat != null)
{
if (fluid.getFluid().isGaseous(fluid) && !mat.canSupportGas)
{
//TODO lose 25% of the gas, and render the lost
}
else if (FluidMasterList.isMolten(fluid.getFluid()) && !mat.canSupportMoltenFluids)
{
//TODO start to heat up the pipe to melting point. When it hits melting point turn the pipe to its molten metal equal
//TODO also once it reaches a set heat level start burning up blocks around the pipe. Eg wood
this.heat += FluidMasterList.getHeatPerPass(fluid.getFluid());
if (heat >= this.maxHeat)
{
this.worldObj.setBlock(xCoord, yCoord, zCoord, Block.lavaStill.blockID);
return true;
}
}
else if (!fluid.getFluid().isGaseous(fluid) && !mat.canSupportFluids)
{
this.damage += 1;
if (this.damage >= this.maxDamage)
{
//TODO test this and make sure its right, as well black fluid block in some cases
this.getBlockType().dropBlockAsItem(worldObj, xCoord, yCoord, zCoord, 0, 0);
this.worldObj.setBlock(xCoord, yCoord, zCoord, 0);
return true;
}
}
}
return false;
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.damage = nbt.getInteger("damage");
this.heat = nbt.getInteger("heat");
this.subID = nbt.getInteger("subID");
if (nbt.hasKey("stored"))
{
NBTTagCompound tag = nbt.getCompoundTag("stored");
String name = tag.getString("LiquidName");
int amount = nbt.getInteger("Amount");
Fluid fluid = FluidRegistry.getFluid(name);
if (fluid != null)
{
FluidStack liquid = new FluidStack(fluid, amount);
internalTanks[0].setFluid(liquid);
internalTanksInfo[0] = internalTanks[0].getInfo();
}
}
else if (nbt.hasKey("FluidTank"))
{
internalTanks[0].readFromNBT(nbt.getCompoundTag("FluidTank"));
internalTanksInfo[0] = internalTanks[0].getInfo();
}
else
{
int tankCount = nbt.getByte("InternalTanks");
if (tankCount > 0)
{
this.internalTanks = new FluidTank[tankCount];
for (int i = 0; i < this.internalTanks.length; i++)
{
FluidTank tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
if (this.internalTanksInfo != null && i < this.internalTanksInfo.length && this.internalTanksInfo[i] != null)
{
tank = new FluidTank(this.internalTanksInfo[i].capacity);
}
tank.readFromNBT(nbt.getCompoundTag("FluidTank" + i));
}
this.internalTanksInfo = new FluidTankInfo[tankCount];
for (int i = 0; i < this.internalTanksInfo.length; i++)
{
this.internalTanksInfo[i] = this.internalTanks[i].getInfo();
}
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("damage", this.damage);
nbt.setInteger("heat", this.heat);
nbt.setInteger("subID", this.subID);
if (this.internalTanks != null)
{
nbt.setByte("InternalTanks", (byte) this.internalTanks.length);
for (byte i = 0; i < this.internalTanks.length; i++)
{
if (this.internalTanks[i] != null)
{
nbt.setCompoundTag("FluidTank" + i, this.internalTanks[i].writeToNBT(new NBTTagCompound()));
}
}
}
}
@Override
public boolean simplePacket(String id, ByteArrayDataInput data, Player player)
{
try
{
if (this.worldObj.isRemote)
{
if (id == "DescriptionPacket")
{
this.subID = data.readInt();
this.renderConnection[0] = data.readByte();
this.renderConnection[1] = data.readByte();
this.renderConnection[2] = data.readByte();
this.renderConnection[3] = data.readByte();
this.renderConnection[4] = data.readByte();
this.renderConnection[5] = data.readByte();
int tanks = data.readInt();
this.internalTanks = new FluidTank[tanks];
for (int i = 0; i < tanks; i++)
{
this.internalTanks[i] = new FluidTank(data.readInt());
this.internalTanks[i].readFromNBT(PacketHandler.instance().readNBTTagCompound(data));
}
return true;
}
else if (id == "TankPacket")
{
this.subID = data.readInt();
this.renderConnection[0] = data.readByte();
this.renderConnection[1] = data.readByte();
this.renderConnection[2] = data.readByte();
this.renderConnection[3] = data.readByte();
this.renderConnection[4] = data.readByte();
this.renderConnection[5] = data.readByte();
return true;
}
else if (id == "RenderPacket")
{
int tanks = data.readInt();
this.internalTanks = new FluidTank[tanks];
for (int i = 0; i < tanks; i++)
{
this.internalTanks[i] = new FluidTank(data.readInt());
this.internalTanks[i].readFromNBT(PacketHandler.instance().readNBTTagCompound(data));
}
return true;
}
else if (id == "SingleTank")
{
int index = data.readInt();
this.internalTanks[index] = new FluidTank(data.readInt());
this.internalTanks[index].readFromNBT(PacketHandler.instance().readNBTTagCompound(data));
return true;
}
}
}
catch (IOException e)
{
System.out.println("// Fluid Mechanics Tank packet read error");
e.printStackTrace();
return true;
}
return false;
}
@Override
public Packet getDescriptionPacket()
{
Object[] data = new Object[(this.internalTanks != null ? (this.internalTanks.length * 2) : 2) + 7];
data[0] = "DescriptionPacket";
data[1] = this.subID;
data[2] = this.renderConnection[0];
data[3] = this.renderConnection[1];
data[4] = this.renderConnection[2];
data[5] = this.renderConnection[3];
data[6] = this.renderConnection[4];
data[7] = this.renderConnection[5];
data[8] = (this.internalTanks != null ? (this.internalTanks.length) : 1);
int place = 9;
for (int i = 0; i < this.internalTanks.length; i++)
{
if (this.internalTanks[i] == null)
{
this.internalTanks[i] = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
}
data[place] = this.internalTanks[i].getCapacity();
data[place + 1] = this.internalTanks[i].writeToNBT(new NBTTagCompound());
place += 2;
}
return PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, data);
}
public void sendRenderUpdate()
{
Object[] data = new Object[7];
data[0] = "renderPacket";
data[1] = this.subID;
data[2] = this.renderConnection[0];
data[3] = this.renderConnection[1];
data[4] = this.renderConnection[2];
data[5] = this.renderConnection[3];
data[6] = this.renderConnection[4];
data[7] = this.renderConnection[5];
PacketHandler.instance().sendPacketToClients(PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, data));
}
public void sendTankUpdate()
{
if (this.internalTanks != null)
{
Object[] data = new Object[(this.internalTanks != null ? (this.internalTanks.length * 2) : 2) + 2];
data[0] = "TankPacket";
data[1] = this.internalTanks.length;
int place = 2;
for (int i = 0; i < this.internalTanks.length; i++)
{
if (this.internalTanks[i] == null)
{
this.internalTanks[i] = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
}
data[place] = this.internalTanks[i].getCapacity();
data[place + 1] = this.internalTanks[i].writeToNBT(new NBTTagCompound());
place += 2;
}
PacketHandler.instance().sendPacketToClients(PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, data));
}
}
public void sendTankUpdate(int index)
{
if (this.internalTanks != null && index < this.internalTanks.length)
{
if (this.internalTanks[index] == null)
{
this.internalTanks[index] = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
}
PacketHandler.instance().sendPacketToClients(PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, "SingleTank", index, this.internalTanks[index].getCapacity(), this.internalTanks[index].writeToNBT(new NBTTagCompound())));
}
}
@Override
@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);
}
public int getSubID()
{
return this.subID;
}
}