Multimeter now works with fluids

This commit is contained in:
Calclavia 2014-02-15 23:52:01 +08:00
parent a8a547265e
commit 466f5b0839
6 changed files with 128 additions and 34 deletions

View file

@ -0,0 +1,62 @@
package resonantinduction.electrical.multimeter;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
public class GraphI extends Graph<Integer>
{
public GraphI(int maxPoints)
{
super(maxPoints);
}
@Override
public void queue(Integer value)
{
queue += value;
}
@Override
public void doneQueue()
{
super.doneQueue();
queue = 0;
}
@Override
public Integer getDefault()
{
return 0;
}
@Override
public void load(NBTTagCompound nbt)
{
super.load(nbt);
NBTTagList nbtList = nbt.getTagList("DataPoints");
for (int i = 0; i < nbtList.tagCount(); ++i)
{
NBTTagCompound nbtPoint = (NBTTagCompound) nbtList.tagAt(i);
points.add(nbtPoint.getInteger("data"));
}
}
@Override
public NBTTagCompound save()
{
NBTTagCompound nbt = new NBTTagCompound();
NBTTagList data = new NBTTagList();
for (Integer value : points)
{
NBTTagCompound nbtPoint = new NBTTagCompound();
nbtPoint.setInteger("data", value);
data.appendTag(nbtPoint);
}
nbt.setTag("DataPoints", data);
return nbt;
}
}

View file

@ -20,11 +20,16 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
*/
private int maxData = 20 * 10;
private final List<Graph> graphs = new ArrayList<Graph>();
/**
* Energy Related
*/
public final GraphL energyGraph = new GraphL(maxData);
public final GraphL energyCapacityGraph = new GraphL(1);
public final GraphL torqueGraph = new GraphL(maxData);
public final GraphF angularVelocityGraph = new GraphF(maxData);
public final GraphI fluidGraph = new GraphI(maxData);
/**
* The absolute center of the multimeter screens.
*/
@ -57,6 +62,7 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
graphs.add(energyCapacityGraph);
graphs.add(torqueGraph);
graphs.add(angularVelocityGraph);
graphs.add(fluidGraph);
}
@Override
@ -103,33 +109,36 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
@Override
public void reconstruct()
{
upperBound = null;
lowerBound = null;
super.reconstruct();
center = upperBound.midPoint(lowerBound);
/**
* Make bounds relative.
*/
upperBound.subtract(center);
lowerBound.subtract(center);
size = new Vector3(Math.abs(upperBound.x) + Math.abs(lowerBound.x), Math.abs(upperBound.y) + Math.abs(lowerBound.y), Math.abs(upperBound.z) + Math.abs(lowerBound.z));
double area = (size.x != 0 ? size.x : 1) * (size.y != 0 ? size.y : 1) * (size.z != 0 ? size.z : 1);
isEnabled = area == getConnectors().size();
NetworkTickHandler.addNetwork(this);
Iterator<PartMultimeter> it = this.getConnectors().iterator();
while (it.hasNext())
if (getConnectors().size() > 0)
{
PartMultimeter connector = it.next();
connector.updateDesc();
connector.updateGraph();
}
upperBound = null;
lowerBound = null;
super.reconstruct();
center = upperBound.midPoint(lowerBound);
doUpdate = true;
/**
* Make bounds relative.
*/
upperBound.subtract(center);
lowerBound.subtract(center);
size = new Vector3(Math.abs(upperBound.x) + Math.abs(lowerBound.x), Math.abs(upperBound.y) + Math.abs(lowerBound.y), Math.abs(upperBound.z) + Math.abs(lowerBound.z));
double area = (size.x != 0 ? size.x : 1) * (size.y != 0 ? size.y : 1) * (size.z != 0 ? size.z : 1);
isEnabled = area == getConnectors().size();
NetworkTickHandler.addNetwork(this);
Iterator<PartMultimeter> it = this.getConnectors().iterator();
while (it.hasNext())
{
PartMultimeter connector = it.next();
connector.updateDesc();
connector.updateGraph();
}
doUpdate = true;
}
}
@Override

View file

@ -15,6 +15,8 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import resonantinduction.api.mechanical.IMechanical;
import resonantinduction.core.ResonantInduction;
import resonantinduction.electrical.Electrical;
@ -100,6 +102,13 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
return getMultimeter(x, y, z) != null;
}
@Override
public void preRemove()
{
if (!world().isRemote)
getNetwork().split(this);
}
public void refresh()
{
if (world() != null)
@ -291,6 +300,17 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
}
}
if (tileEntity instanceof IFluidHandler)
{
FluidTankInfo[] fluidInfo = ((IFluidHandler) tileEntity).getTankInfo(receivingSide);
for(FluidTankInfo info : fluidInfo)
{
if(info.fluid != null)
getNetwork().fluidGraph.queue(info.fluid.amount);
}
}
getNetwork().energyGraph.queue(CompatibilityModule.getEnergy(tileEntity, receivingSide));
/**

View file

@ -156,21 +156,24 @@ public class RenderMultimeter implements ISimpleItemRenderer
// TODO: Add other dispaly info support.
List<String> information = new ArrayList<String>();
information.add(UnitDisplay.getDisplay(part.getNetwork().energyGraph.get(0), Unit.JOULES));
if (part.getNetwork().energyGraph.get(0) > 0)
information.add(UnitDisplay.getDisplay(part.getNetwork().energyGraph.get(0), Unit.JOULES));
if (part.getNetwork().energyCapacityGraph.get(0) > 0)
{
information.add("Max: " + UnitDisplay.getDisplay(part.getNetwork().energyCapacityGraph.get(0), Unit.JOULES));
}
if (part.getNetwork().torqueGraph.get(0) != 0)
{
information.add("Torque: " + UnitDisplay.getDisplayShort(part.getNetwork().torqueGraph.get(0), Unit.NEWTON_METER));
}
if (part.getNetwork().angularVelocityGraph.get(0) != 0)
{
information.add("Speed: " + UnitDisplay.roundDecimals(part.getNetwork().angularVelocityGraph.get(0)));
}
if (part.getNetwork().fluidGraph.get(0) != 0)
information.add("Fluid: " + UnitDisplay.getDisplay(part.getNetwork().fluidGraph.get(0), Unit.LITER));
if (information.size() <= 0)
information.add("No information");
float displacement = information.size() / 5f;
float maxScale = (float) (part.getNetwork().size.x + part.getNetwork().size.z) * 0.005f;

View file

@ -26,7 +26,7 @@ public class BlockTesla extends BlockSidedIO implements ITileEntityProvider
public BlockTesla(int id)
{
super(id, UniversalElectricity.machine);
setTextureName(Reference.PREFIX + "machine");
setTextureName(Reference.PREFIX + "material_metal_side");
}
@Override

View file

@ -141,7 +141,7 @@ tooltip.wire.helpText=Higher voltages will increase transfer rate and decrease e
tooltip.noShift=Hold %0shift %1for more information"
# %0 is the color for the charge level, %1 is grey to reset it back to normal (optional), %v0 is the current charge, %v1 is the max charge
tooltip.battery.energy=Energy: %0%v0 / %v1
tooltip.multimeter.line1=Right click click to place,
tooltip.multimeter.line1=Right click to place,
tooltip.multimeter.line2=Control right click to scan data.
tooltip.multimeter.noSave=No detection saved.
tooltip.multimeter.lastSave=Last Detection: %v KJ