Massive fixes and improvements on the multimeter
This commit is contained in:
parent
6a5d2fe37b
commit
d95cd7d710
9 changed files with 73 additions and 78 deletions
|
@ -85,4 +85,5 @@ public abstract class Graph<V extends Comparable<V>>
|
|||
|
||||
public abstract NBTTagCompound save();
|
||||
|
||||
public abstract double getDouble();
|
||||
}
|
||||
|
|
|
@ -60,4 +60,10 @@ public class GraphF extends Graph<Float>
|
|||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDouble()
|
||||
{
|
||||
return get();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ import net.minecraft.nbt.NBTTagList;
|
|||
|
||||
public class GraphI extends Graph<Integer>
|
||||
{
|
||||
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<Integer>
|
|||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDouble()
|
||||
{
|
||||
return get();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ import net.minecraft.nbt.NBTTagList;
|
|||
|
||||
public class GraphL extends Graph<Long>
|
||||
{
|
||||
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<Long>
|
|||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDouble()
|
||||
{
|
||||
return get();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -26,7 +26,7 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
|
|||
* Energy Related
|
||||
*/
|
||||
public final GraphL energyGraph = new GraphL("Energy", maxData);
|
||||
public final GraphL energyCapacityGraph = new GraphL("Max", 1);
|
||||
public final GraphL energyCapacityGraph = new GraphL("Capacity", 1);
|
||||
public final GraphL voltageGraph = new GraphL("Voltage", maxData);
|
||||
public final GraphL torqueGraph = new GraphL("Torque", maxData);
|
||||
public final GraphF angularVelocityGraph = new GraphF("Speed", maxData);
|
||||
|
@ -41,8 +41,8 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
|
|||
/**
|
||||
* The relative bound sizes.
|
||||
*/
|
||||
private Vector3 upperBound = new Vector3();
|
||||
private Vector3 lowerBound = new Vector3();
|
||||
public Vector3 upperBound = new Vector3();
|
||||
public Vector3 lowerBound = new Vector3();
|
||||
|
||||
/**
|
||||
* The overall size of the multimeter
|
||||
|
@ -89,13 +89,13 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
|
|||
graphValue = UnitDisplay.getDisplayShort(torqueGraph.get(), Unit.NEWTON_METER);
|
||||
|
||||
if (graph == angularVelocityGraph)
|
||||
graphValue = UnitDisplay.roundDecimals(angularVelocityGraph.get()) + "";
|
||||
graphValue = UnitDisplay.roundDecimals(angularVelocityGraph.get()) + " rad/s";
|
||||
|
||||
if (graph == fluidGraph)
|
||||
graphValue = UnitDisplay.getDisplay(fluidGraph.get(), Unit.LITER);
|
||||
|
||||
if (graph == thermalGraph)
|
||||
graphValue = UnitDisplay.roundDecimals(thermalGraph.get()) + "";
|
||||
graphValue = UnitDisplay.roundDecimals(thermalGraph.get() - 273) + " C";
|
||||
|
||||
return graph.name + ": " + graphValue;
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public class PartMultimeter extends PartFace implements IConnector<MultimeterNet
|
|||
public enum DetectMode
|
||||
{
|
||||
NONE("none"), LESS_THAN("lessThan"), LESS_THAN_EQUAL("lessThanOrEqual"), EQUAL("equal"),
|
||||
GREATER_THAN("greaterThanOrEqual"), GREATER_THAN_EQUAL("greaterThan");
|
||||
GREATER_THAN_EQUAL("greaterThanOrEqual"), GREATER_THAN("greaterThan");
|
||||
|
||||
public String display;
|
||||
|
||||
|
@ -59,15 +59,16 @@ public class PartMultimeter extends PartFace implements IConnector<MultimeterNet
|
|||
|
||||
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
|
||||
|
||||
/**
|
||||
* 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<MultimeterNet
|
|||
if (!world().isRemote)
|
||||
{
|
||||
updateDetections();
|
||||
long detectedEnergy = getNetwork().energyGraph.get(0);
|
||||
double detectedValue = getNetwork().graphs.get(detectType).getDouble();
|
||||
|
||||
boolean outputRedstone = false;
|
||||
|
||||
|
@ -176,19 +177,19 @@ public class PartMultimeter extends PartFace implements IConnector<MultimeterNet
|
|||
default:
|
||||
break;
|
||||
case EQUAL:
|
||||
outputRedstone = detectedEnergy == redstoneTriggerLimit;
|
||||
outputRedstone = detectedValue == redstoneTriggerLimit;
|
||||
break;
|
||||
case GREATER_THAN:
|
||||
outputRedstone = detectedEnergy > 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<MultimeterNet
|
|||
placementSide = ForgeDirection.getOrientation(packet.readByte());
|
||||
facing = packet.readByte();
|
||||
detectMode = DetectMode.values()[packet.readByte()];
|
||||
detectType = packet.readByte();
|
||||
graphType = packet.readByte();
|
||||
getNetwork().center = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound());
|
||||
getNetwork().size = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound());
|
||||
getNetwork().isEnabled = packet.readBoolean();
|
||||
|
@ -316,6 +319,8 @@ public class PartMultimeter extends PartFace implements IConnector<MultimeterNet
|
|||
packet.writeByte(placementSide.ordinal());
|
||||
packet.writeByte(facing);
|
||||
packet.writeByte(detectMode.ordinal());
|
||||
packet.writeByte(detectType);
|
||||
packet.writeByte(graphType);
|
||||
packet.writeNBTTagCompound(getNetwork().center.writeToNBT(new NBTTagCompound()));
|
||||
packet.writeNBTTagCompound(getNetwork().size.writeToNBT(new NBTTagCompound()));
|
||||
packet.writeBoolean(getNetwork().isEnabled);
|
||||
|
@ -344,6 +349,8 @@ public class PartMultimeter extends PartFace implements IConnector<MultimeterNet
|
|||
placementSide = ForgeDirection.getOrientation(packet.readByte());
|
||||
facing = packet.readByte();
|
||||
detectMode = DetectMode.values()[packet.readByte()];
|
||||
detectType = packet.readByte();
|
||||
graphType = packet.readByte();
|
||||
getNetwork().center = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound());
|
||||
getNetwork().size = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound());
|
||||
getNetwork().isEnabled = packet.readBoolean();
|
||||
|
@ -365,8 +372,9 @@ public class PartMultimeter extends PartFace implements IConnector<MultimeterNet
|
|||
@Override
|
||||
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra)
|
||||
{
|
||||
detectMode = DetectMode.values()[data.readInt()];
|
||||
detectionValueType = data.readInt();
|
||||
detectMode = DetectMode.values()[data.readByte()];
|
||||
detectType = data.readByte();
|
||||
graphType = data.readByte();
|
||||
redstoneTriggerLimit = data.readDouble();
|
||||
}
|
||||
|
||||
|
@ -381,37 +389,10 @@ public class PartMultimeter extends PartFace implements IConnector<MultimeterNet
|
|||
return ForgeDirection.getOrientation(this.placementSide.ordinal());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static long getDetectedEnergy(ForgeDirection side, TileEntity tileEntity)
|
||||
public void toggleGraphType()
|
||||
{
|
||||
if (tileEntity instanceof IConductor)
|
||||
{
|
||||
IConnector<IEnergyNetwork> 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<MultimeterNet
|
|||
|
||||
public void toggleDetectionValue()
|
||||
{
|
||||
detectionValueType = (detectionValueType + 1) % getNetwork().graphs.size();
|
||||
detectType = (byte) ((detectType + 1) % getNetwork().graphs.size());
|
||||
updateServer();
|
||||
}
|
||||
|
||||
public void updateServer()
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer(ResonantInduction.PACKET_MULTIPART.getPacket(new universalelectricity.api.vector.Vector3(x(), y(), z()), placementSide.ordinal(), detectMode.ordinal(), detectionValueType, redstoneTriggerLimit));
|
||||
PacketDispatcher.sendPacketToServer(ResonantInduction.PACKET_MULTIPART.getPacket(new universalelectricity.api.vector.Vector3(x(), y(), z()), placementSide.ordinal(), (byte) detectMode.ordinal(), detectType, graphType, redstoneTriggerLimit));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -437,6 +418,8 @@ public class PartMultimeter extends PartFace implements IConnector<MultimeterNet
|
|||
super.load(nbt);
|
||||
placementSide = ForgeDirection.getOrientation(nbt.getByte("side"));
|
||||
detectMode = DetectMode.values()[nbt.getByte("detectMode")];
|
||||
detectType = nbt.getByte("detectionType");
|
||||
graphType = nbt.getByte("graphType");
|
||||
redstoneTriggerLimit = nbt.getDouble("triggerLimit");
|
||||
}
|
||||
|
||||
|
@ -446,6 +429,8 @@ public class PartMultimeter extends PartFace implements IConnector<MultimeterNet
|
|||
super.save(nbt);
|
||||
nbt.setByte("side", (byte) placementSide.ordinal());
|
||||
nbt.setByte("detectMode", (byte) detectMode.ordinal());
|
||||
nbt.setByte("detectionType", detectType);
|
||||
nbt.setByte("graphType", graphType);
|
||||
nbt.setDouble("triggerLimit", redstoneTriggerLimit);
|
||||
}
|
||||
|
||||
|
@ -566,8 +551,8 @@ public class PartMultimeter extends PartFace implements IConnector<MultimeterNet
|
|||
public Cuboid6 getRenderBounds()
|
||||
{
|
||||
if (isPrimary)
|
||||
return Cuboid6.full.copy().expand(Double.POSITIVE_INFINITY);
|
||||
|
||||
return Cuboid6.full.copy().expand(new Vector3(getNetwork().size.x, getNetwork().size.y, getNetwork().size.z));
|
||||
return Cuboid6.full;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -185,7 +185,7 @@ public class RenderMultimeter implements ISimpleItemRenderer
|
|||
RenderUtility.rotateBlockBasedOnDirection(part.getFacing());
|
||||
}
|
||||
|
||||
GL11.glTranslated(0, 0.07, 0);
|
||||
GL11.glTranslated(0, 0.05, 0);
|
||||
|
||||
List<String> information = new ArrayList<String>();
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue