From d95cd7d71048bdea43bdc5b349357ab91f6c7646 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sat, 22 Feb 2014 21:03:09 +0800 Subject: [PATCH] Massive fixes and improvements on the multimeter --- .../electrical/multimeter/Graph.java | 1 + .../electrical/multimeter/GraphF.java | 6 ++ .../electrical/multimeter/GraphI.java | 10 ++- .../electrical/multimeter/GraphL.java | 10 ++- .../electrical/multimeter/GuiMultimeter.java | 8 +- .../electrical/multimeter/ItemMultimeter.java | 16 ---- .../multimeter/MultimeterNetwork.java | 10 +-- .../electrical/multimeter/PartMultimeter.java | 79 ++++++++----------- .../multimeter/RenderMultimeter.java | 11 ++- 9 files changed, 73 insertions(+), 78 deletions(-) diff --git a/electrical/src/main/java/resonantinduction/electrical/multimeter/Graph.java b/electrical/src/main/java/resonantinduction/electrical/multimeter/Graph.java index 8ac0d6aa9..9292356f6 100644 --- a/electrical/src/main/java/resonantinduction/electrical/multimeter/Graph.java +++ b/electrical/src/main/java/resonantinduction/electrical/multimeter/Graph.java @@ -85,4 +85,5 @@ public abstract class Graph> public abstract NBTTagCompound save(); + public abstract double getDouble(); } diff --git a/electrical/src/main/java/resonantinduction/electrical/multimeter/GraphF.java b/electrical/src/main/java/resonantinduction/electrical/multimeter/GraphF.java index eeedd53c6..3d8838467 100644 --- a/electrical/src/main/java/resonantinduction/electrical/multimeter/GraphF.java +++ b/electrical/src/main/java/resonantinduction/electrical/multimeter/GraphF.java @@ -60,4 +60,10 @@ public class GraphF extends Graph return nbt; } + @Override + public double getDouble() + { + return get(); + } + } diff --git a/electrical/src/main/java/resonantinduction/electrical/multimeter/GraphI.java b/electrical/src/main/java/resonantinduction/electrical/multimeter/GraphI.java index 6ae41dd46..fb4ecc8fb 100644 --- a/electrical/src/main/java/resonantinduction/electrical/multimeter/GraphI.java +++ b/electrical/src/main/java/resonantinduction/electrical/multimeter/GraphI.java @@ -5,9 +5,9 @@ import net.minecraft.nbt.NBTTagList; public class GraphI extends Graph { - public GraphI(String name,int maxPoints) + public GraphI(String name, int maxPoints) { - super(name,maxPoints); + super(name, maxPoints); } @Override @@ -59,4 +59,10 @@ public class GraphI extends Graph return nbt; } + @Override + public double getDouble() + { + return get(); + } + } diff --git a/electrical/src/main/java/resonantinduction/electrical/multimeter/GraphL.java b/electrical/src/main/java/resonantinduction/electrical/multimeter/GraphL.java index c611b1e06..0b6cb0b13 100644 --- a/electrical/src/main/java/resonantinduction/electrical/multimeter/GraphL.java +++ b/electrical/src/main/java/resonantinduction/electrical/multimeter/GraphL.java @@ -5,9 +5,9 @@ import net.minecraft.nbt.NBTTagList; public class GraphL extends Graph { - public GraphL(String name,int maxPoints) + public GraphL(String name, int maxPoints) { - super(name,maxPoints); + super(name, maxPoints); } @Override @@ -59,4 +59,10 @@ public class GraphL extends Graph return nbt; } + @Override + public double getDouble() + { + return get(); + } + } diff --git a/electrical/src/main/java/resonantinduction/electrical/multimeter/GuiMultimeter.java b/electrical/src/main/java/resonantinduction/electrical/multimeter/GuiMultimeter.java index 7ec6deced..cb1da7141 100644 --- a/electrical/src/main/java/resonantinduction/electrical/multimeter/GuiMultimeter.java +++ b/electrical/src/main/java/resonantinduction/electrical/multimeter/GuiMultimeter.java @@ -54,7 +54,7 @@ public class GuiMultimeter extends GuiContainerBase try { - multimeter.redstoneTriggerLimit = Integer.parseInt(this.textFieldLimit.getText()); + multimeter.redstoneTriggerLimit = Double.parseDouble(textFieldLimit.getText()); multimeter.updateServer(); } catch (Exception e) @@ -80,6 +80,9 @@ public class GuiMultimeter extends GuiContainerBase case 1: multimeter.toggleDetectionValue(); break; + case 2: + multimeter.toggleGraphType(); + break; } } @@ -90,8 +93,9 @@ public class GuiMultimeter extends GuiContainerBase String s = LanguageUtility.getLocal("item.resonantinduction:multimeter.name"); this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 6, 4210752); this.fontRenderer.drawString(EnumColor.INDIGO + "Detection Type", 9, 20, 4210752); - this.fontRenderer.drawString(multimeter.getNetwork().getDisplay(multimeter.detectionValueType), 9, 60, 4210752); + this.fontRenderer.drawString(multimeter.getNetwork().getDisplay(multimeter.detectType), 9, 60, 4210752); this.fontRenderer.drawString("Logic: " + EnumColor.RED + LanguageUtility.getLocal("gui.resonantinduction.multimeter." + this.multimeter.getMode().display), 9, 75, 4210752); + this.fontRenderer.drawString(multimeter.getNetwork().graphs.get(multimeter.graphType).name, 95, 115, 4210752); this.textFieldLimit.drawTextBox(); } diff --git a/electrical/src/main/java/resonantinduction/electrical/multimeter/ItemMultimeter.java b/electrical/src/main/java/resonantinduction/electrical/multimeter/ItemMultimeter.java index f6e923803..e9c77cf4e 100644 --- a/electrical/src/main/java/resonantinduction/electrical/multimeter/ItemMultimeter.java +++ b/electrical/src/main/java/resonantinduction/electrical/multimeter/ItemMultimeter.java @@ -64,22 +64,6 @@ public class ItemMultimeter extends JItemMultiPart implements IHighlight } } - @Override - public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer entityPlayer, World world, int x, int y, int z, int par7, float par8, float par9, float par10) - { - if (ControlKeyModifer.isControlDown(entityPlayer)) - { - if (!world.isRemote) - { - entityPlayer.addChatMessage(LanguageUtility.getLocal("message.multimeter.onUse").replace("%v", "" + PartMultimeter.getDetectedEnergy(ForgeDirection.getOrientation(par7), world.getBlockTileEntity(x, y, z)))); - } - - return true; - } - - return super.onItemUse(par1ItemStack, entityPlayer, world, x, y, z, par7, par8, par9, par10); - } - public float getDetection(ItemStack itemStack) { if (itemStack.stackTagCompound == null || !itemStack.getTagCompound().hasKey("detection")) diff --git a/electrical/src/main/java/resonantinduction/electrical/multimeter/MultimeterNetwork.java b/electrical/src/main/java/resonantinduction/electrical/multimeter/MultimeterNetwork.java index 04d0170ae..8b882923c 100644 --- a/electrical/src/main/java/resonantinduction/electrical/multimeter/MultimeterNetwork.java +++ b/electrical/src/main/java/resonantinduction/electrical/multimeter/MultimeterNetwork.java @@ -26,7 +26,7 @@ public class MultimeterNetwork extends Network playersUsing = new HashSet(); + /** + * Detection + */ public double redstoneTriggerLimit; - public int detectionValueType = 0; + public byte detectType = 0; + public byte graphType = 0; private DetectMode detectMode = DetectMode.NONE; - - // TODO: Move warn settings over. public boolean redstoneOn; public boolean isPrimary; - private MultimeterNetwork network; public boolean hasMultimeter(int x, int y, int z) @@ -167,7 +168,7 @@ public class PartMultimeter extends PartFace implements IConnector redstoneTriggerLimit; + outputRedstone = detectedValue > redstoneTriggerLimit; break; case GREATER_THAN_EQUAL: - outputRedstone = detectedEnergy >= redstoneTriggerLimit; + outputRedstone = detectedValue >= redstoneTriggerLimit; break; case LESS_THAN: - outputRedstone = detectedEnergy < redstoneTriggerLimit; + outputRedstone = detectedValue < redstoneTriggerLimit; break; case LESS_THAN_EQUAL: - outputRedstone = detectedEnergy <= redstoneTriggerLimit; + outputRedstone = detectedValue <= redstoneTriggerLimit; break; } @@ -304,6 +305,8 @@ public class PartMultimeter extends PartFace implements IConnector conductor = ((IConductor) tileEntity).getInstance(side.getOpposite()); - - if (conductor == null) - { - conductor = ((IConductor) tileEntity).getInstance(ForgeDirection.UNKNOWN); - } - - if (conductor != null) - { - // TODO: Conductor may always return null in some cases. - IEnergyNetwork network = conductor.getNetwork(); - return network.getLastBuffer(); - } - } - - if (tileEntity instanceof IMechanical) - { - IMechanical instance = ((IMechanical) tileEntity).getInstance(side); - - if (instance != null) - { - return (long) (instance.getTorque() * instance.getAngularVelocity()); - } - } - - return CompatibilityModule.getEnergy(tileEntity, side); + graphType = (byte) ((graphType + 1) % getNetwork().graphs.size()); + updateServer(); } public void toggleMode() @@ -422,13 +403,13 @@ public class PartMultimeter extends PartFace implements IConnector information = new ArrayList(); @@ -228,10 +228,13 @@ public class RenderMultimeter implements ISimpleItemRenderer GL11.glPushMatrix(); GL11.glTranslatef(0, 0, displacement * i); - if (dir.offsetX == 0) - RenderUtility.renderText(info, (float) (part.getNetwork().size.x * 0.9f), maxScale); - if (dir.offsetZ == 0) + + if (dir.offsetX != 0) RenderUtility.renderText(info, (float) (part.getNetwork().size.z * 0.9f), maxScale); + else if (dir.offsetY != 0) + RenderUtility.renderText(info, (float) ((part.getNetwork().size.x + part.getNetwork().size.z) / 2 * 0.9f), maxScale); + else if (dir.offsetZ != 0) + RenderUtility.renderText(info, (float) (part.getNetwork().size.x * 0.9f), maxScale); GL11.glPopMatrix(); }