Finished pipe system and fixed tanks
This commit is contained in:
parent
8436dd5b41
commit
bd496c66bd
12 changed files with 180 additions and 564 deletions
|
@ -1,13 +1,23 @@
|
|||
package resonantinduction.api.fluid;
|
||||
|
||||
/** Applied to tiles that are pipes and support pressure
|
||||
/**
|
||||
* Applied to tiles that are pipes and support pressure
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
* @author DarkGuardsman
|
||||
*/
|
||||
public interface IFluidPipe extends IFluidConnector, IPressureInput
|
||||
{
|
||||
/** Max pressure this pipe can support */
|
||||
int getMaxPressure();
|
||||
/**
|
||||
* Max pressure this pipe can support.
|
||||
*
|
||||
* @return amount in pascals.
|
||||
*/
|
||||
int getMaxPressure();
|
||||
|
||||
/** Max flow rate of fluid this pipe can support */
|
||||
int getMaxFlowRate();
|
||||
/**
|
||||
* Max flow rate of fluid this pipe can support
|
||||
*
|
||||
* @return amount in liters.
|
||||
*/
|
||||
int getMaxFlowRate();
|
||||
}
|
||||
|
|
|
@ -3,34 +3,28 @@ package resonantinduction.mechanical.fluid.network;
|
|||
import java.util.Set;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
import net.minecraftforge.event.world.WorldEvent.Save;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import resonantinduction.api.fluid.IFluidConnector;
|
||||
import resonantinduction.api.fluid.IFluidNetwork;
|
||||
import resonantinduction.mechanical.fluid.tank.TileTank;
|
||||
import universalelectricity.api.net.IConnector;
|
||||
import universalelectricity.core.net.ConnectionPathfinder;
|
||||
import universalelectricity.core.net.Network;
|
||||
import universalelectricity.core.net.NetworkTickHandler;
|
||||
import calclavia.lib.utility.FluidUtility;
|
||||
|
||||
/**
|
||||
* The fluid network.
|
||||
*
|
||||
* @author DarkCow, Calclavia
|
||||
*
|
||||
*/
|
||||
public abstract class FluidNetwork extends Network<IFluidNetwork, IFluidConnector, IFluidHandler> implements IFluidNetwork
|
||||
{
|
||||
protected FluidTank tank = new FluidTank(0);
|
||||
protected final FluidTankInfo[] tankInfo = new FluidTankInfo[1];
|
||||
protected boolean reloadTanks = false;
|
||||
protected long ticks = 0;
|
||||
|
||||
public FluidNetwork()
|
||||
{
|
||||
NetworkTickHandler.addNetwork(this);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addConnector(IFluidConnector connector)
|
||||
|
@ -39,14 +33,29 @@ public abstract class FluidNetwork extends Network<IFluidNetwork, IFluidConnecto
|
|||
super.addConnector(connector);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean continueUpdate()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reconstruct()
|
||||
{
|
||||
if (this.reloadTanks)
|
||||
{
|
||||
this.reloadTanks();
|
||||
}
|
||||
this.tank = new FluidTank(0);
|
||||
|
||||
for (IFluidConnector part : this.getConnectors())
|
||||
{
|
||||
if (part.getNetwork() instanceof IFluidNetwork)
|
||||
|
@ -54,15 +63,17 @@ public abstract class FluidNetwork extends Network<IFluidNetwork, IFluidConnecto
|
|||
part.setNetwork(this);
|
||||
}
|
||||
|
||||
this.buildPart(part);
|
||||
this.reconstructConnector(part);
|
||||
}
|
||||
this.rebuildHandler();
|
||||
this.reloadTanks();
|
||||
|
||||
this.reconstructTankInfo();
|
||||
this.distributeConnectors();
|
||||
}
|
||||
|
||||
public void buildPart(IFluidConnector part)
|
||||
public void reconstructConnector(IFluidConnector connector)
|
||||
{
|
||||
FluidTank tank = part.getInternalTank();
|
||||
FluidTank tank = connector.getInternalTank();
|
||||
|
||||
if (tank != null)
|
||||
{
|
||||
this.tank.setCapacity(this.tank.getCapacity() + tank.getCapacity());
|
||||
|
@ -81,7 +92,7 @@ public abstract class FluidNetwork extends Network<IFluidNetwork, IFluidConnecto
|
|||
}
|
||||
}
|
||||
|
||||
public void rebuildHandler()
|
||||
public void reconstructTankInfo()
|
||||
{
|
||||
if (this.getTank() != null)
|
||||
{
|
||||
|
@ -91,7 +102,8 @@ public abstract class FluidNetwork extends Network<IFluidNetwork, IFluidConnecto
|
|||
{
|
||||
this.tankInfo[0] = null;
|
||||
}
|
||||
this.reloadTanks = true;
|
||||
|
||||
this.distributeConnectors();
|
||||
NetworkTickHandler.addNetwork(this);
|
||||
}
|
||||
|
||||
|
@ -100,9 +112,10 @@ public abstract class FluidNetwork extends Network<IFluidNetwork, IFluidConnecto
|
|||
{
|
||||
int prev = this.getTank().getFluidAmount();
|
||||
int fill = this.getTank().fill(resource, doFill);
|
||||
|
||||
if (prev != this.getTank().getFluidAmount())
|
||||
{
|
||||
this.rebuildHandler();
|
||||
this.reconstructTankInfo();
|
||||
}
|
||||
|
||||
return fill;
|
||||
|
@ -115,10 +128,10 @@ public abstract class FluidNetwork extends Network<IFluidNetwork, IFluidConnecto
|
|||
{
|
||||
FluidStack before = this.getTank().getFluid();
|
||||
FluidStack drain = this.getTank().drain(resource.amount, doDrain);
|
||||
|
||||
|
||||
if (before != this.getTank().getFluid() || this.getTank().getFluid() == null || this.getTank().getFluid().amount != before.amount)
|
||||
{
|
||||
this.rebuildHandler();
|
||||
this.reconstructTankInfo();
|
||||
}
|
||||
|
||||
return drain;
|
||||
|
@ -136,59 +149,28 @@ public abstract class FluidNetwork extends Network<IFluidNetwork, IFluidConnecto
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate()
|
||||
public void distributeConnectors()
|
||||
{
|
||||
return this.reloadTanks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean continueUpdate()
|
||||
{
|
||||
return this.reloadTanks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
this.ticks++;
|
||||
if (ticks >= Long.MAX_VALUE - 10)
|
||||
{
|
||||
ticks = 1;
|
||||
}
|
||||
if (this.reloadTanks && ticks % 10 == 0)
|
||||
{
|
||||
this.reloadTanks();
|
||||
}
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
public void onWorldSave(Save event)
|
||||
{
|
||||
this.reloadTanks();
|
||||
}
|
||||
|
||||
public void reloadTanks()
|
||||
{
|
||||
this.reloadTanks = false;
|
||||
FluidStack stack = this.getTank().getFluid();
|
||||
this.fillTankSet(stack != null ? stack.copy() : null, this.getConnectors());
|
||||
}
|
||||
|
||||
public void fillTankSet(FluidStack stack, Set<IFluidConnector> tankList)
|
||||
public void fillTankSet(FluidStack stack, Set<IFluidConnector> connectors)
|
||||
{
|
||||
int parts = tankList.size();
|
||||
for (IFluidConnector part : tankList)
|
||||
int parts = connectors.size();
|
||||
for (IFluidConnector part : connectors)
|
||||
{
|
||||
part.getInternalTank().setFluid(null);
|
||||
if (stack != null)
|
||||
{
|
||||
int fillPer = (stack.amount / parts) + (stack.amount % parts);
|
||||
stack.amount -= part.getInternalTank().fill(FluidUtility.getStack(stack, fillPer), true);
|
||||
part.onFluidChanged();
|
||||
|
||||
if (parts > 1)
|
||||
parts--;
|
||||
}
|
||||
|
||||
part.onFluidChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,11 @@ import resonantinduction.api.fluid.IFluidPipe;
|
|||
import universalelectricity.api.vector.Vector3;
|
||||
import calclavia.lib.utility.FluidUtility;
|
||||
|
||||
/** @author DarkGuardsman */
|
||||
/**
|
||||
* The network for pipe fluid transfer. getNodes() is NOT used.
|
||||
*
|
||||
* @author DarkGuardsman
|
||||
*/
|
||||
public class PipeNetwork extends FluidNetwork
|
||||
{
|
||||
public HashMap<IFluidHandler, EnumSet<ForgeDirection>> connectionMap = new HashMap<IFluidHandler, EnumSet<ForgeDirection>>();
|
||||
|
@ -21,60 +25,62 @@ public class PipeNetwork extends FluidNetwork
|
|||
@Override
|
||||
public void update()
|
||||
{
|
||||
super.update();
|
||||
|
||||
/*
|
||||
* Slight delay to allow visual effect to take place before draining the pipe's internal
|
||||
* tank
|
||||
*/
|
||||
if (this.getTank().getFluidAmount() > 0)
|
||||
FluidStack stack = this.getTank().getFluid().copy();
|
||||
int count = this.connectionMap.size();
|
||||
|
||||
for (Entry<IFluidHandler, EnumSet<ForgeDirection>> entry : this.connectionMap.entrySet())
|
||||
{
|
||||
FluidStack stack = this.getTank().getFluid().copy();
|
||||
int count = this.connectionMap.size();
|
||||
|
||||
for (Entry<IFluidHandler, EnumSet<ForgeDirection>> entry : this.connectionMap.entrySet())
|
||||
int sideCount = entry.getValue().size();
|
||||
for (ForgeDirection dir : entry.getValue())
|
||||
{
|
||||
int sideCount = entry.getValue().size();
|
||||
for (ForgeDirection dir : entry.getValue())
|
||||
int volPer = (stack.amount / count);
|
||||
int volPerSide = (volPer / sideCount);
|
||||
int maxFill = 1000;
|
||||
|
||||
TileEntity tile = new Vector3((TileEntity) entry.getKey()).modifyPositionFromSide(dir).getTileEntity(((TileEntity) entry.getKey()).worldObj);
|
||||
|
||||
if (tile instanceof IFluidPipe)
|
||||
{
|
||||
int volPer = (stack.amount / count) + (stack.amount % count);
|
||||
int volPerSide = (volPer / sideCount) + (volPer % count);
|
||||
int maxFill = 1000;
|
||||
TileEntity entity = new Vector3((TileEntity) entry.getKey()).modifyPositionFromSide(dir).getTileEntity(((TileEntity) entry.getKey()).worldObj);
|
||||
if (entity instanceof IFluidPipe)
|
||||
{
|
||||
maxFill = ((IFluidPipe) entity).getMaxFlowRate();
|
||||
}
|
||||
|
||||
stack.amount -= entry.getKey().fill(dir, FluidUtility.getStack(stack, Math.min(volPerSide, maxFill)), true);
|
||||
|
||||
if (sideCount > 1)
|
||||
--sideCount;
|
||||
if (volPer <= 0)
|
||||
break;
|
||||
maxFill = ((IFluidPipe) tile).getMaxFlowRate();
|
||||
}
|
||||
if (count > 1)
|
||||
count--;
|
||||
if (stack == null || stack.amount <= 0)
|
||||
|
||||
stack.amount -= entry.getKey().fill(dir, FluidUtility.getStack(stack, Math.min(volPerSide, maxFill)), true);
|
||||
|
||||
if (sideCount > 1)
|
||||
--sideCount;
|
||||
if (volPer <= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
this.getTank().setFluid(stack);
|
||||
// TODO check for change before rebuilding
|
||||
this.rebuildHandler();
|
||||
if (count > 1)
|
||||
count--;
|
||||
|
||||
if (stack == null || stack.amount <= 0)
|
||||
{
|
||||
stack = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.getTank().setFluid(stack);
|
||||
// TODO check for change before rebuilding
|
||||
this.reconstructTankInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate()
|
||||
{
|
||||
return true;
|
||||
return getTank().getFluidAmount() > 0 && connectionMap.size() > 0 && getConnectors().size() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean continueUpdate()
|
||||
{
|
||||
return this.getConnectors().size() > 0;
|
||||
return canUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,9 +91,9 @@ public class PipeNetwork extends FluidNetwork
|
|||
}
|
||||
|
||||
@Override
|
||||
public void buildPart(IFluidConnector part)
|
||||
public void reconstructConnector(IFluidConnector part)
|
||||
{
|
||||
super.buildPart(part);
|
||||
super.reconstructConnector(part);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (part.getConnections()[i] instanceof IFluidHandler && !(part.getConnections()[i] instanceof IFluidPipe))
|
||||
|
|
|
@ -5,18 +5,12 @@ import net.minecraftforge.client.IItemRenderer;
|
|||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import resonantinduction.mechanical.Mechanical;
|
||||
import resonantinduction.mechanical.fluid.valve.ModelReleaseValve;
|
||||
import resonantinduction.mechanical.fluid.valve.RenderReleaseValve;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ItemPipeRenderer implements IItemRenderer
|
||||
{
|
||||
private ModelReleaseValve valve = new ModelReleaseValve();
|
||||
|
||||
@Override
|
||||
public boolean handleRenderType(ItemStack item, ItemRenderType type)
|
||||
{
|
||||
|
|
|
@ -190,7 +190,7 @@ public class PartPipe extends PartFramedConnection<EnumPipeMaterial, IFluidPipe,
|
|||
@Override
|
||||
public int getMaxPressure()
|
||||
{
|
||||
return 0;
|
||||
return 1000;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -36,7 +36,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
*/
|
||||
public abstract class TileFluidNetwork extends TileAdvanced implements IFluidConnector, IPacketReceiverWithID, IReadOut
|
||||
{
|
||||
protected FluidTank tank = new FluidTank(1 * FluidContainerRegistry.BUCKET_VOLUME);
|
||||
protected FluidTank tank;
|
||||
protected Object[] connectedBlocks = new Object[6];
|
||||
protected int colorID = 0;
|
||||
|
||||
|
@ -53,9 +53,6 @@ public abstract class TileFluidNetwork extends TileAdvanced implements IFluidCon
|
|||
/** Bitmask that handles connections for the renderer **/
|
||||
public byte renderSides = 0b0;
|
||||
|
||||
/** Tells the tank that on next update to check if it should update the client render data */
|
||||
public boolean updateFluidRender = false;
|
||||
|
||||
@Override
|
||||
public void initiate()
|
||||
{
|
||||
|
@ -64,30 +61,18 @@ public abstract class TileFluidNetwork extends TileAdvanced implements IFluidCon
|
|||
getNetwork().reconstruct();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
if (this.updateFluidRender)
|
||||
{
|
||||
//if (!FluidUtility.matchExact(prevStack, this.getInternalTank().getFluid()))
|
||||
{
|
||||
this.sendTankUpdate();
|
||||
}
|
||||
|
||||
this.prevStack = this.tank.getFluid();
|
||||
this.updateFluidRender = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFluidChanged()
|
||||
{
|
||||
this.updateFluidRender = true;
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
if (!FluidUtility.matchExact(prevStack, this.getInternalTank().getFluid()))
|
||||
{
|
||||
this.sendTankUpdate();
|
||||
}
|
||||
|
||||
this.prevStack = this.tank.getFluid();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -253,8 +238,7 @@ public abstract class TileFluidNetwork extends TileAdvanced implements IFluidCon
|
|||
}
|
||||
else if (id == PACKET_TANK)
|
||||
{
|
||||
this.tank = new FluidTank(data.readInt());
|
||||
this.getInternalTank().readFromNBT(PacketHandler.readNBTTagCompound(data));
|
||||
this.tank = new FluidTank(data.readInt()).readFromNBT(PacketHandler.readNBTTagCompound(data));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -280,10 +264,8 @@ public abstract class TileFluidNetwork extends TileAdvanced implements IFluidCon
|
|||
|
||||
public void sendTankUpdate()
|
||||
{
|
||||
if (this.getInternalTank() != null)
|
||||
{
|
||||
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_TANK, this, this.getInternalTank().getCapacity(), this.getInternalTank().writeToNBT(new NBTTagCompound())), this.worldObj, new Vector3(this), 60);
|
||||
}
|
||||
System.out.println("Send Amount: " + this.getInternalTank().getFluidAmount());
|
||||
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_TANK, this, getInternalTank().getCapacity(), getInternalTank().writeToNBT(new NBTTagCompound())), this.worldObj, new Vector3(this), 60);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -59,7 +59,18 @@ public class BlockTank extends BlockFluidNetwork
|
|||
@Override
|
||||
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return FluidUtility.playerActivatedFluidItem(world, x, y, z, entityplayer, side);
|
||||
if (world.getBlockTileEntity(x, y, z) instanceof TileTank)
|
||||
{
|
||||
System.out.println(world.isRemote + " Amount: " + ((TileTank) world.getBlockTileEntity(x, y, z)).getInternalTank().getFluidAmount());
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
|
||||
if (!world.isRemote)
|
||||
{
|
||||
|
||||
return FluidUtility.playerActivatedFluidItem(world, x, y, z, entityplayer, side);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,60 +8,62 @@ import net.minecraftforge.fluids.FluidStack;
|
|||
import resonantinduction.api.fluid.IFluidConnector;
|
||||
import resonantinduction.mechanical.fluid.network.FluidNetwork;
|
||||
|
||||
/** Network that handles connected tanks
|
||||
/**
|
||||
* Network that handles connected tanks
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
* @author DarkGuardsman
|
||||
*/
|
||||
public class TankNetwork extends FluidNetwork
|
||||
{
|
||||
{
|
||||
@Override
|
||||
public void distributeConnectors()
|
||||
{
|
||||
FluidStack fillStack = this.getTank().getFluid();
|
||||
int lowestY = 255, highestY = 0;
|
||||
|
||||
@Override
|
||||
public void reloadTanks()
|
||||
{
|
||||
FluidStack fillStack = this.getTank().getFluid();
|
||||
int lowestY = 255, highestY = 0;
|
||||
if (fillStack == null || fillStack.getFluid().isGaseous())
|
||||
{
|
||||
super.distributeConnectors();
|
||||
}
|
||||
else if (this.getConnectors().size() > 0)
|
||||
{
|
||||
fillStack = fillStack.copy();
|
||||
for (IFluidConnector part : this.getConnectors())
|
||||
{
|
||||
part.getInternalTank().setFluid(null);
|
||||
if (part instanceof TileEntity && ((TileEntity) part).yCoord < lowestY)
|
||||
{
|
||||
lowestY = ((TileEntity) part).yCoord;
|
||||
}
|
||||
if (part instanceof TileEntity && ((TileEntity) part).yCoord > highestY)
|
||||
{
|
||||
highestY = ((TileEntity) part).yCoord;
|
||||
}
|
||||
}
|
||||
|
||||
if (fillStack == null || fillStack.getFluid().isGaseous())
|
||||
{
|
||||
super.reloadTanks();
|
||||
}
|
||||
else if (this.getConnectors().size() > 0)
|
||||
{
|
||||
fillStack = fillStack.copy();
|
||||
for (IFluidConnector part : this.getConnectors())
|
||||
{
|
||||
part.getInternalTank().setFluid(null);
|
||||
if (part instanceof TileEntity && ((TileEntity) part).yCoord < lowestY)
|
||||
{
|
||||
lowestY = ((TileEntity) part).yCoord;
|
||||
}
|
||||
if (part instanceof TileEntity && ((TileEntity) part).yCoord > highestY)
|
||||
{
|
||||
highestY = ((TileEntity) part).yCoord;
|
||||
}
|
||||
}
|
||||
// TODO Add path finder to prevent filling when tanks are only connected at the top
|
||||
for (int y = lowestY; y <= highestY; y++)
|
||||
{
|
||||
Set<IFluidConnector> parts = new LinkedHashSet<IFluidConnector>();
|
||||
|
||||
//TODO Add path finder to prevent filling when tanks are only connected at the top
|
||||
for (int y = lowestY; y <= highestY; y++)
|
||||
{
|
||||
Set<IFluidConnector> parts = new LinkedHashSet<IFluidConnector>();
|
||||
for (IFluidConnector part : this.getConnectors())
|
||||
{
|
||||
if (part instanceof IFluidConnector && ((TileEntity) part).yCoord == y)
|
||||
{
|
||||
parts.add((IFluidConnector) part);
|
||||
}
|
||||
}
|
||||
if (!parts.isEmpty())
|
||||
{
|
||||
this.fillTankSet(fillStack, parts);
|
||||
}
|
||||
|
||||
for (IFluidConnector part : this.getConnectors())
|
||||
{
|
||||
if (part instanceof IFluidConnector && ((TileEntity) part).yCoord == y)
|
||||
{
|
||||
parts.add((IFluidConnector) part);
|
||||
}
|
||||
}
|
||||
if (!parts.isEmpty())
|
||||
{
|
||||
this.fillTankSet(fillStack, parts);
|
||||
}
|
||||
if (fillStack == null || fillStack.amount <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fillStack == null || fillStack.amount <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
package resonantinduction.mechanical.fluid.valve;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import resonantinduction.core.prefab.block.BlockRI;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class BlockReleaseValve extends BlockRI
|
||||
{
|
||||
public BlockReleaseValve()
|
||||
{
|
||||
super("releaseValve");
|
||||
this.setHardness(1f);
|
||||
this.setResistance(5f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World var1)
|
||||
{
|
||||
return new TileReleaseValve();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@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 int damageDropped(int meta)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int quantityDropped(Random par1Random)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World par1World, int x, int y, int z, int side)
|
||||
{
|
||||
super.onNeighborBlockChange(par1World, x, y, z, side);
|
||||
|
||||
}
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
// Date: 1/7/2013 12:20:13 PM
|
||||
// Template version 1.1
|
||||
// Java generated by Techne
|
||||
// Keep in mind that you still need to fill in some blanks
|
||||
// - ZeuX
|
||||
|
||||
package resonantinduction.mechanical.fluid.valve;
|
||||
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.model.ModelRenderer;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ModelReleaseValve extends ModelBase
|
||||
{
|
||||
|
||||
// fields
|
||||
ModelRenderer ValveStem;
|
||||
ModelRenderer ValveWheelCenter;
|
||||
ModelRenderer ValveRest;
|
||||
ModelRenderer WheelBar3;
|
||||
ModelRenderer WheelBar4;
|
||||
ModelRenderer Wheel;
|
||||
ModelRenderer Wheel2;
|
||||
ModelRenderer Wheel3;
|
||||
ModelRenderer Wheel4;
|
||||
ModelRenderer WheelB;
|
||||
ModelRenderer WheelB2;
|
||||
ModelRenderer WheelB3;
|
||||
ModelRenderer WheelB4;
|
||||
ModelRenderer[] renders;
|
||||
|
||||
public ModelReleaseValve()
|
||||
{
|
||||
textureWidth = 128;
|
||||
textureHeight = 32;
|
||||
|
||||
ValveStem = new ModelRenderer(this, 50, 21);
|
||||
ValveStem.addBox(-1F, -6F, -1F, 2, 3, 2);
|
||||
ValveStem.setRotationPoint(0F, 16F, 0F);
|
||||
ValveStem.setTextureSize(128, 32);
|
||||
ValveStem.mirror = true;
|
||||
setRotation(ValveStem, 0F, 0F, 0F);
|
||||
ValveWheelCenter = new ModelRenderer(this, 50, 17);
|
||||
ValveWheelCenter.addBox(-0.5F, -7.5F, -0.5F, 1, 2, 1);
|
||||
ValveWheelCenter.setRotationPoint(0F, 16F, 0F);
|
||||
ValveWheelCenter.setTextureSize(128, 32);
|
||||
ValveWheelCenter.mirror = true;
|
||||
setRotation(ValveWheelCenter, 0F, 0F, 0F);
|
||||
ValveRest = new ModelRenderer(this, 50, 27);
|
||||
ValveRest.addBox(-1.5F, -4F, -1.5F, 3, 1, 3);
|
||||
ValveRest.setRotationPoint(0F, 16F, 0F);
|
||||
ValveRest.setTextureSize(128, 32);
|
||||
ValveRest.mirror = true;
|
||||
setRotation(ValveRest, 0F, 0F, 0F);
|
||||
WheelBar3 = new ModelRenderer(this, 85, 15);
|
||||
WheelBar3.addBox(-3F, -7F, -0.5F, 6, 1, 1);
|
||||
WheelBar3.setRotationPoint(0F, 16F, 0F);
|
||||
WheelBar3.setTextureSize(128, 32);
|
||||
WheelBar3.mirror = true;
|
||||
setRotation(WheelBar3, 0F, 0.7853982F, 0F);
|
||||
WheelBar4 = new ModelRenderer(this, 85, 18);
|
||||
WheelBar4.addBox(-3F, -7F, -0.5F, 6, 1, 1);
|
||||
WheelBar4.setRotationPoint(0F, 16F, 0F);
|
||||
WheelBar4.setTextureSize(128, 32);
|
||||
WheelBar4.mirror = true;
|
||||
setRotation(WheelBar4, 0F, -0.7853982F, 0F);
|
||||
Wheel = new ModelRenderer(this, 50, 13);
|
||||
Wheel.addBox(-1.5F, -7.5F, -3.5F, 3, 1, 1);
|
||||
Wheel.setRotationPoint(0F, 16F, 0F);
|
||||
Wheel.setTextureSize(128, 32);
|
||||
Wheel.mirror = true;
|
||||
setRotation(Wheel, 0F, -0.7853982F, 0F);
|
||||
Wheel2 = new ModelRenderer(this, 50, 13);
|
||||
Wheel2.addBox(-1.5F, -7.5F, -3.5F, 3, 1, 1);
|
||||
Wheel2.setRotationPoint(0F, 16F, 0F);
|
||||
Wheel2.setTextureSize(128, 32);
|
||||
Wheel2.mirror = true;
|
||||
setRotation(Wheel2, 0F, 2.356194F, 0F);
|
||||
Wheel3 = new ModelRenderer(this, 50, 13);
|
||||
Wheel3.addBox(-1.5F, -7.5F, -3.5F, 3, 1, 1);
|
||||
Wheel3.setRotationPoint(0F, 16F, 0F);
|
||||
Wheel3.setTextureSize(128, 32);
|
||||
Wheel3.mirror = true;
|
||||
setRotation(Wheel3, 0F, -2.356194F, 0F);
|
||||
Wheel4 = new ModelRenderer(this, 50, 13);
|
||||
Wheel4.addBox(-1.5F, -7.5F, -3.5F, 3, 1, 1);
|
||||
Wheel4.setRotationPoint(0F, 16F, 0F);
|
||||
Wheel4.setTextureSize(128, 32);
|
||||
Wheel4.mirror = true;
|
||||
setRotation(Wheel4, 0F, 0.7853982F, 0F);
|
||||
WheelB = new ModelRenderer(this, 50, 13);
|
||||
WheelB.addBox(-1.5F, -7.5F, 2.5F, 3, 1, 1);
|
||||
WheelB.setRotationPoint(0F, 16F, 0F);
|
||||
WheelB.setTextureSize(128, 32);
|
||||
WheelB.mirror = true;
|
||||
setRotation(WheelB, 0F, -3.141593F, 0F);
|
||||
WheelB2 = new ModelRenderer(this, 50, 13);
|
||||
WheelB2.addBox(-1.5F, -7.5F, 2.5F, 3, 1, 1);
|
||||
WheelB2.setRotationPoint(0F, 16F, 0F);
|
||||
WheelB2.setTextureSize(128, 32);
|
||||
WheelB2.mirror = true;
|
||||
setRotation(WheelB2, 0F, 0F, 0F);
|
||||
WheelB3 = new ModelRenderer(this, 50, 13);
|
||||
WheelB3.addBox(-1.5F, -7.5F, 2.5F, 3, 1, 1);
|
||||
WheelB3.setRotationPoint(0F, 16F, 0F);
|
||||
WheelB3.setTextureSize(128, 32);
|
||||
WheelB3.mirror = true;
|
||||
setRotation(WheelB3, 0F, 1.570796F, 0F);
|
||||
WheelB4 = new ModelRenderer(this, 50, 13);
|
||||
WheelB4.addBox(-1.5F, -7.5F, 2.5F, 3, 1, 1);
|
||||
WheelB4.setRotationPoint(0F, 16F, 0F);
|
||||
WheelB4.setTextureSize(128, 32);
|
||||
WheelB4.mirror = true;
|
||||
setRotation(WheelB4, 0F, -1.570796F, 0F);
|
||||
renders = new ModelRenderer[] { ValveStem, ValveWheelCenter, ValveRest, WheelBar3, WheelBar4, Wheel, Wheel2, Wheel3, Wheel4, WheelB, WheelB2, WheelB3, WheelB4 };
|
||||
|
||||
}
|
||||
|
||||
public void render()
|
||||
{
|
||||
ModelRenderer[] renderSet = renders;
|
||||
for (int i = 0; i < renders.length; i++)
|
||||
{
|
||||
renderSet[i].render(0.0625F);
|
||||
}
|
||||
}
|
||||
|
||||
private void setRotation(ModelRenderer model, float x, float y, float z)
|
||||
{
|
||||
model.rotateAngleX = x;
|
||||
model.rotateAngleY = y;
|
||||
model.rotateAngleZ = z;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
package resonantinduction.mechanical.fluid.valve;
|
||||
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import resonantinduction.core.Reference;
|
||||
import resonantinduction.mechanical.fluid.pipe.RenderPipe;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class RenderReleaseValve extends TileEntitySpecialRenderer
|
||||
{
|
||||
public static ModelReleaseValve valve = new ModelReleaseValve();
|
||||
private TileEntity[] ents = new TileEntity[6];
|
||||
|
||||
public static final ResourceLocation VALVE_TEXTURE = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "releaseValve.png");
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(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);
|
||||
if (te instanceof TileReleaseValve)
|
||||
{
|
||||
ents = ((TileReleaseValve) te).connected;
|
||||
}
|
||||
bindTexture(RenderPipe.TEXTURE);
|
||||
if (ents[0] != null)
|
||||
RenderPipe.MODEL_PIPE.renderBottom();
|
||||
if (ents[1] != null)
|
||||
RenderPipe.MODEL_PIPE.renderTop();
|
||||
if (ents[3] != null)
|
||||
RenderPipe.MODEL_PIPE.renderFront();
|
||||
if (ents[2] != null)
|
||||
RenderPipe.MODEL_PIPE.renderBack();
|
||||
if (ents[5] != null)
|
||||
RenderPipe.MODEL_PIPE.renderRight();
|
||||
if (ents[4] != null)
|
||||
RenderPipe.MODEL_PIPE.renderLeft();
|
||||
RenderPipe.MODEL_PIPE.renderMiddle();
|
||||
bindTexture(VALVE_TEXTURE);
|
||||
if (ents[1] == null)
|
||||
valve.render();
|
||||
GL11.glPopMatrix();
|
||||
|
||||
}
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
package resonantinduction.mechanical.fluid.valve;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import resonantinduction.api.IReadOut;
|
||||
import resonantinduction.api.fluid.IFluidPipe;
|
||||
import resonantinduction.core.tilenetwork.ITileConnector;
|
||||
import resonantinduction.mechanical.fluid.pipe.TilePipe;
|
||||
import calclavia.lib.utility.WorldUtility;
|
||||
|
||||
public class TileReleaseValve extends TilePipe implements ITileConnector, IReadOut
|
||||
{
|
||||
public TileEntity[] connected = new TileEntity[6];
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
if (this.ticks % 10 == 0)
|
||||
{
|
||||
this.refresh();
|
||||
if (!this.worldObj.isRemote && !worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))
|
||||
{
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (connected[dir.ordinal()] instanceof IFluidHandler && !(connected[dir.ordinal()] instanceof IFluidPipe))
|
||||
{
|
||||
IFluidHandler drainedTank = (IFluidHandler) connected[dir.ordinal()];
|
||||
FluidStack stack = drainedTank.drain(dir.getOpposite(), FluidContainerRegistry.BUCKET_VOLUME, false);
|
||||
if (stack != null && stack.amount > 0)
|
||||
{
|
||||
IFluidPipe inputPipe = this.findValidPipe(stack);
|
||||
if (inputPipe != null)
|
||||
{
|
||||
int ammountFilled = inputPipe.getNetwork().fill(inputPipe, dir, stack, true);
|
||||
drainedTank.drain(dir.getOpposite(), ammountFilled, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** used to find a valid pipe for filling of the liquid type */
|
||||
public IFluidPipe findValidPipe(FluidStack stack)
|
||||
{
|
||||
// find normal color selective pipe first
|
||||
for (int i = 0; i < connected.length; i++)
|
||||
{
|
||||
TileEntity tile = connected[i];
|
||||
if (tile instanceof IFluidPipe && ((IFluidPipe) tile).fill(ForgeDirection.getOrientation(i), stack, false) > 0)
|
||||
{
|
||||
return (IFluidPipe) tile;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Collects info about the surrounding 6 tiles and orders them into drain-able(ITankContainer)
|
||||
* and fill-able(TileEntityPipes) instances */
|
||||
public void refresh()
|
||||
{
|
||||
// cleanup
|
||||
this.connected = WorldUtility.getSurroundingTileEntities(this);
|
||||
// read surroundings
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tileEntity = connected[dir.ordinal()];
|
||||
if (tileEntity instanceof ITileConnector)
|
||||
{
|
||||
if (this.canTileConnect(Connection.FLUIDS, dir.getOpposite()))
|
||||
{
|
||||
this.connected[dir.ordinal()] = tileEntity;
|
||||
}
|
||||
}
|
||||
else if (tileEntity instanceof IFluidHandler)
|
||||
{
|
||||
this.connected[dir.ordinal()] = tileEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTileConnect(Connection type, ForgeDirection dir)
|
||||
{
|
||||
return type == Connection.FLUIDS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMeterReading(EntityPlayer user, ForgeDirection side, EnumTools tool)
|
||||
{
|
||||
// TODO maybe debug on # of connected units of input/output
|
||||
String output = "";
|
||||
if (!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))
|
||||
{
|
||||
output += "Open";
|
||||
}
|
||||
else
|
||||
{
|
||||
output += "Closed";
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue