Pipes now render the average fluid instead of flickering

This commit is contained in:
Calclavia 2014-03-17 20:41:56 +08:00
parent 61deef795d
commit dc7474704f
18 changed files with 64 additions and 67 deletions

View file

@ -30,6 +30,7 @@ import universalelectricity.api.vector.Vector3;
import calclavia.lib.content.module.TileRender;
import calclavia.lib.content.module.prefab.TileInventory;
import calclavia.lib.gui.ContainerDummy;
import calclavia.lib.java.Pair;
import calclavia.lib.network.IPacketReceiver;
import calclavia.lib.network.PacketHandler;
import calclavia.lib.prefab.item.ItemBlockSaved;
@ -43,7 +44,6 @@ import calclavia.lib.utility.inventory.AutoCraftingManager.IAutoCrafter;
import calclavia.lib.utility.inventory.InventoryUtility;
import codechicken.multipart.ControlKeyModifer;
import com.builtbroken.common.Pair;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.relauncher.Side;

View file

@ -2,9 +2,7 @@ package resonantinduction.electrical.armbot;
import net.minecraft.item.ItemStack;
import resonantinduction.electrical.encoder.coding.IProcessTask;
import com.builtbroken.common.science.units.UnitHelper;
import calclavia.lib.science.units.UnitHelper;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;

View file

@ -20,6 +20,7 @@ import resonantinduction.electrical.encoder.coding.ProgramHelper;
import universalelectricity.api.energy.EnergyStorageHandler;
import universalelectricity.api.vector.Vector2;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.java.Pair;
import calclavia.lib.multiblock.fake.IMultiBlock;
import calclavia.lib.network.IPacketReceiverWithID;
import calclavia.lib.network.PacketHandler;
@ -27,7 +28,6 @@ import calclavia.lib.prefab.tile.TileElectrical;
import calclavia.lib.utility.MathUtility;
import calclavia.lib.utility.inventory.InventoryUtility;
import com.builtbroken.common.Pair;
import com.google.common.io.ByteArrayDataInput;
public class TileArmbot extends TileElectrical implements IMultiBlock, IArmbot, IPacketReceiverWithID

View file

@ -12,10 +12,9 @@ import resonantinduction.electrical.armbot.TaskBaseArmbot;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import resonantinduction.electrical.encoder.coding.ITask;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.java.Pair;
import calclavia.lib.utility.inventory.InventoryUtility;
import com.builtbroken.common.Pair;
/**
* Used by arms to break a specific block in a position.
*

View file

@ -14,9 +14,8 @@ import resonantinduction.electrical.armbot.TaskBaseArmbot;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import resonantinduction.electrical.encoder.coding.args.ArgumentFloatData;
import universalelectricity.api.vector.Vector3;
import com.builtbroken.common.Pair;
import com.builtbroken.common.science.units.UnitHelper;
import calclavia.lib.java.Pair;
import calclavia.lib.science.units.UnitHelper;
public class TaskFire extends TaskBaseArmbot
{

View file

@ -14,11 +14,10 @@ import resonantinduction.electrical.armbot.TaskBaseProcess;
import resonantinduction.electrical.encoder.coding.args.ArgumentIntData;
import universalelectricity.api.vector.Vector2;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.science.units.UnitHelper;
import calclavia.lib.utility.MathUtility;
import calclavia.lib.utility.inventory.InternalInventoryHandler;
import com.builtbroken.common.science.units.UnitHelper;
public class TaskGive extends TaskBaseArmbot
{

View file

@ -9,8 +9,7 @@ import net.minecraft.util.AxisAlignedBB;
import resonantinduction.electrical.armbot.IArmbot;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import resonantinduction.electrical.encoder.coding.args.ArgumentIntData;
import com.builtbroken.common.science.units.UnitHelper;
import calclavia.lib.science.units.UnitHelper;
public class TaskGrabItem extends TaskGrabPrefab
{

View file

@ -6,8 +6,7 @@ import net.minecraft.nbt.NBTTagCompound;
import resonantinduction.core.ArgumentData;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import resonantinduction.electrical.encoder.coding.IProgrammableMachine;
import com.builtbroken.common.science.units.UnitHelper;
import calclavia.lib.science.units.UnitHelper;
public class TaskIdle extends TaskBaseProcess
{

View file

@ -8,10 +8,9 @@ import resonantinduction.electrical.armbot.TaskBaseArmbot;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import resonantinduction.electrical.encoder.coding.args.ArgumentIntData;
import universalelectricity.api.vector.Vector2;
import calclavia.lib.science.units.UnitHelper;
import calclavia.lib.utility.MathUtility;
import com.builtbroken.common.science.units.UnitHelper;
/**
* Rotates an armbot by a set amount
*

View file

@ -8,10 +8,9 @@ import resonantinduction.electrical.armbot.TaskBaseArmbot;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import resonantinduction.electrical.encoder.coding.args.ArgumentIntData;
import universalelectricity.api.vector.Vector2;
import calclavia.lib.science.units.UnitHelper;
import calclavia.lib.utility.MathUtility;
import com.builtbroken.common.science.units.UnitHelper;
/**
* Rotates the armbot to a specific direction.
*

View file

@ -14,11 +14,10 @@ import resonantinduction.electrical.armbot.TaskBaseProcess;
import resonantinduction.electrical.encoder.coding.args.ArgumentIntData;
import universalelectricity.api.vector.Vector2;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.science.units.UnitHelper;
import calclavia.lib.utility.MathUtility;
import calclavia.lib.utility.inventory.InternalInventoryHandler;
import com.builtbroken.common.science.units.UnitHelper;
public class TaskTake extends TaskBaseArmbot
{

View file

@ -11,8 +11,7 @@ import resonantinduction.electrical.armbot.TaskBaseArmbot;
import resonantinduction.electrical.armbot.TaskBaseProcess;
import resonantinduction.electrical.encoder.coding.IProcessTask;
import resonantinduction.electrical.encoder.coding.args.ArgumentIntData;
import com.builtbroken.common.science.units.UnitHelper;
import calclavia.lib.science.units.UnitHelper;
public class TaskUse extends TaskBaseArmbot
{

View file

@ -2,8 +2,7 @@ package resonantinduction.electrical.encoder.coding;
import net.minecraft.world.World;
import universalelectricity.api.vector.Vector3;
import com.builtbroken.common.Pair;
import calclavia.lib.java.Pair;
/**
* Simple interface too say an object is programmable

View file

@ -1,9 +1,7 @@
package resonantinduction.electrical.multimeter;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import calclavia.lib.java.EvictingList;
/**
* Graph for the multimeter
@ -20,7 +18,7 @@ public abstract class Graph<V extends Comparable<V>>
/**
* Each point represents a tick.
*/
protected List<V> points = new ArrayList<V>();
protected final EvictingList<V> points;
private V peak = getDefault();
/**
@ -32,26 +30,18 @@ public abstract class Graph<V extends Comparable<V>>
{
this.name = name;
this.maxPoints = maxPoints;
points = new EvictingList<V>(maxPoints);
}
public void add(V y)
{
if (y.compareTo(peak) > 0)
{
peak = y;
}
points.add(y);
points.add(0, y);
peak = getDefault();
if (points.size() > maxPoints)
{
if (points.get(maxPoints) == peak)
{
peak = getDefault();
}
points.remove(maxPoints);
}
for (V point : points)
if (point.compareTo(peak) > 0)
peak = y;
}
public V getPeak()

View file

@ -5,10 +5,9 @@ import java.util.HashMap;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.mechanical.Mechanical;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.java.Pair;
import calclavia.lib.schematic.Schematic;
import com.builtbroken.common.Pair;
public class SchematicWaterTurbine extends Schematic
{
@Override

View file

@ -5,10 +5,9 @@ import java.util.HashMap;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.mechanical.Mechanical;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.java.Pair;
import calclavia.lib.schematic.Schematic;
import com.builtbroken.common.Pair;
public class SchematicWindTurbine extends Schematic
{
@Override

View file

@ -16,6 +16,7 @@ import resonantinduction.core.grid.fluid.FluidPressureNode;
import resonantinduction.core.grid.fluid.IPressureNodeProvider;
import resonantinduction.core.prefab.part.PartFramedNode;
import resonantinduction.mechanical.Mechanical;
import calclavia.lib.java.EvictingList;
import calclavia.lib.utility.WorldUtility;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.render.CCRenderState;
@ -31,6 +32,10 @@ import cpw.mods.fml.relauncher.SideOnly;
public class PartPipe extends PartFramedNode<EnumPipeMaterial, FluidPressureNode, IPressureNodeProvider> implements IPressureNodeProvider, TSlottedPart, JNormalOcclusion, IHollowConnect
{
protected FluidTank tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
/**
* Computes the average fluid for client to render.
*/
private EvictingList<Integer> averageTankData = new EvictingList<Integer>(20);
private boolean markPacket = true;
public PartPipe()
@ -90,24 +95,29 @@ public class PartPipe extends PartFramedNode<EnumPipeMaterial, FluidPressureNode
@Override
public boolean canConnect(ForgeDirection from, Object source)
{
if (source instanceof FluidPressureNode)
if (!isBlockedOnSide(from))
{
FluidPressureNode otherNode = (FluidPressureNode) source;
if (otherNode.parent instanceof PartPipe)
if (source instanceof FluidPressureNode)
{
PartPipe otherPipe = (PartPipe) otherNode.parent;
FluidPressureNode otherNode = (FluidPressureNode) source;
if (getMaterial() == otherPipe.getMaterial())
if (otherNode.parent instanceof PartPipe)
{
return getColor() == otherPipe.getColor() || (getColor() == DEFAULT_COLOR || otherPipe.getColor() == DEFAULT_COLOR);
}
PartPipe otherPipe = (PartPipe) otherNode.parent;
return false;
if (!otherPipe.isBlockedOnSide(from.getOpposite()) && getMaterial() == otherPipe.getMaterial())
{
return getColor() == otherPipe.getColor() || (getColor() == DEFAULT_COLOR || otherPipe.getColor() == DEFAULT_COLOR);
}
return false;
}
}
return super.canConnect(from, source);
}
return super.canConnect(from, source);
return false;
}
};
@ -126,6 +136,7 @@ public class PartPipe extends PartFramedNode<EnumPipeMaterial, FluidPressureNode
this.material = material;
node.maxFlowRate = getMaterial().maxFlowRate;
node.maxPressure = getMaterial().maxPressure;
tank.setCapacity(node.maxFlowRate);
}
@Override
@ -139,6 +150,8 @@ public class PartPipe extends PartFramedNode<EnumPipeMaterial, FluidPressureNode
{
super.update();
averageTankData.add(tank.getFluidAmount());
if (!world().isRemote && markPacket)
{
sendFluidUpdate();
@ -149,8 +162,22 @@ public class PartPipe extends PartFramedNode<EnumPipeMaterial, FluidPressureNode
public void sendFluidUpdate()
{
NBTTagCompound nbt = new NBTTagCompound();
tank.writeToNBT(nbt);
tile().getWriteStream(this).writeByte(3).writeNBTTagCompound(nbt);
int averageAmount = 0;
if (averageTankData.size() > 0)
{
for (int i = 0; i < averageTankData.size(); i++)
{
averageAmount += averageTankData.get(i);
}
averageAmount /= averageTankData.size();
}
FluidTank tempTank = tank.getFluid() != null ? new FluidTank(tank.getFluid().getFluid(), averageAmount, tank.getCapacity()) : new FluidTank(tank.getCapacity());
tempTank.writeToNBT(nbt);
tile().getWriteStream(this).writeByte(3).writeInt(tank.getCapacity()).writeNBTTagCompound(nbt);
}
@Override
@ -158,7 +185,7 @@ public class PartPipe extends PartFramedNode<EnumPipeMaterial, FluidPressureNode
{
if (packetID == 3)
{
tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
tank = new FluidTank(packet.readInt());
tank.readFromNBT(packet.readNBTTagCompound());
}
else
@ -237,11 +264,6 @@ public class PartPipe extends PartFramedNode<EnumPipeMaterial, FluidPressureNode
@Override
public FluidTank getPressureTank()
{
if (tank == null)
{
tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
}
return tank;
}

View file

@ -12,7 +12,6 @@ import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11;
import resonantinduction.archaic.fluid.tank.TileTank;
import resonantinduction.core.Reference;
import calclavia.lib.render.FluidRenderUtility;
import calclavia.lib.render.RenderUtility;