From 466f5b083952b1a1b8b1b130ec435b7ccf42d373 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sat, 15 Feb 2014 23:52:01 +0800 Subject: [PATCH] Multimeter now works with fluids --- .../electrical/multimeter/GraphI.java | 62 +++++++++++++++++++ .../multimeter/MultimeterNetwork.java | 59 ++++++++++-------- .../electrical/multimeter/PartMultimeter.java | 20 ++++++ .../multimeter/RenderMultimeter.java | 17 ++--- .../electrical/tesla/BlockTesla.java | 2 +- .../languages/en_US.properties | 2 +- 6 files changed, 128 insertions(+), 34 deletions(-) create mode 100644 electrical/src/main/java/resonantinduction/electrical/multimeter/GraphI.java diff --git a/electrical/src/main/java/resonantinduction/electrical/multimeter/GraphI.java b/electrical/src/main/java/resonantinduction/electrical/multimeter/GraphI.java new file mode 100644 index 00000000..ae3af713 --- /dev/null +++ b/electrical/src/main/java/resonantinduction/electrical/multimeter/GraphI.java @@ -0,0 +1,62 @@ +package resonantinduction.electrical.multimeter; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + +public class GraphI extends Graph +{ + 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; + } + +} diff --git a/electrical/src/main/java/resonantinduction/electrical/multimeter/MultimeterNetwork.java b/electrical/src/main/java/resonantinduction/electrical/multimeter/MultimeterNetwork.java index 61ce1be2..4afc538c 100644 --- a/electrical/src/main/java/resonantinduction/electrical/multimeter/MultimeterNetwork.java +++ b/electrical/src/main/java/resonantinduction/electrical/multimeter/MultimeterNetwork.java @@ -20,11 +20,16 @@ public class MultimeterNetwork extends Network graphs = new ArrayList(); + /** + * 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 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 it = this.getConnectors().iterator(); + + while (it.hasNext()) + { + PartMultimeter connector = it.next(); + connector.updateDesc(); + connector.updateGraph(); + } + + doUpdate = true; + } } @Override diff --git a/electrical/src/main/java/resonantinduction/electrical/multimeter/PartMultimeter.java b/electrical/src/main/java/resonantinduction/electrical/multimeter/PartMultimeter.java index decf94a0..d3c4934d 100644 --- a/electrical/src/main/java/resonantinduction/electrical/multimeter/PartMultimeter.java +++ b/electrical/src/main/java/resonantinduction/electrical/multimeter/PartMultimeter.java @@ -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 information = new ArrayList(); - 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; diff --git a/electrical/src/main/java/resonantinduction/electrical/tesla/BlockTesla.java b/electrical/src/main/java/resonantinduction/electrical/tesla/BlockTesla.java index dbbc6561..1c37629c 100644 --- a/electrical/src/main/java/resonantinduction/electrical/tesla/BlockTesla.java +++ b/electrical/src/main/java/resonantinduction/electrical/tesla/BlockTesla.java @@ -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 diff --git a/src/main/resources/assets/resonantinduction/languages/en_US.properties b/src/main/resources/assets/resonantinduction/languages/en_US.properties index c4a7ccca..18125514 100644 --- a/src/main/resources/assets/resonantinduction/languages/en_US.properties +++ b/src/main/resources/assets/resonantinduction/languages/en_US.properties @@ -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