Connected texture logic now working
This commit is contained in:
parent
5189633823
commit
a6c5eb6d72
5 changed files with 155 additions and 69 deletions
|
@ -3,6 +3,16 @@ package resonantinduction.electrical.multimeter;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
/**
|
||||
* Graph for the multimeter
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class Graph
|
||||
{
|
||||
private final int maxPoints;
|
||||
|
@ -33,7 +43,6 @@ public class Graph
|
|||
{
|
||||
peak = 0;
|
||||
}
|
||||
|
||||
points.remove(maxPoints);
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +54,34 @@ public class Graph
|
|||
|
||||
public long get(int x)
|
||||
{
|
||||
return points.get(x);
|
||||
return points.size() > x ? points.get(x) : 0;
|
||||
}
|
||||
|
||||
public void load(NBTTagCompound nbt)
|
||||
{
|
||||
NBTTagList nbtList = nbt.getTagList("DataPoints");
|
||||
|
||||
for (int i = 0; i < nbtList.tagCount(); ++i)
|
||||
{
|
||||
NBTTagCompound nbtPoint = (NBTTagCompound) nbtList.tagAt(i);
|
||||
add(nbtPoint.getLong("data"));
|
||||
}
|
||||
}
|
||||
|
||||
public NBTTagCompound save()
|
||||
{
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
NBTTagList data = new NBTTagList();
|
||||
|
||||
for (long value : points)
|
||||
{
|
||||
NBTTagCompound nbtPoint = new NBTTagCompound();
|
||||
nbtPoint.setLong("data", value);
|
||||
|
||||
data.appendTag(nbtPoint);
|
||||
}
|
||||
|
||||
nbt.setTag("DataPoints", data);
|
||||
return nbt;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,10 +73,10 @@ public class GuiMultimeter extends GuiContainerBase
|
|||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
String s = LanguageUtility.getLocal("tile.resonantinduction:multimeter.name");
|
||||
this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 15, 4210752);
|
||||
this.fontRenderer.drawString(EnumColor.INDIGO + LanguageUtility.getLocal("gui.resonantinduction.multimeter.averageEnergy"), 35, 15, 4210752);
|
||||
this.renderUniversalDisplay(35, 25, this.multimeter.getAverageDetectedEnergy(), mouseX, mouseY, Unit.JOULES);
|
||||
this.fontRenderer.drawString(EnumColor.INDIGO + LanguageUtility.getLocal("gui.resonantinduction.multimeter.energy"), 35, 15, 4210752);
|
||||
this.renderUniversalDisplay(35, 25, this.multimeter.getNetwork().graph.get(0), mouseX, mouseY, Unit.JOULES);
|
||||
this.fontRenderer.drawString(EnumColor.INDIGO + LanguageUtility.getLocal("gui.resonantinduction.multimeter.energy"), 35, 35, 4210752);
|
||||
this.renderUniversalDisplay(35, 45, this.multimeter.getDetectedEnergy(), mouseX, mouseY, Unit.JOULES);
|
||||
this.renderUniversalDisplay(35, 45, this.multimeter.getNetwork().graph.get(0), mouseX, mouseY, Unit.JOULES);
|
||||
this.fontRenderer.drawString(EnumColor.ORANGE + LanguageUtility.getLocal("gui.resonantinduction.multimeter.redstone"), 35, 58, 4210752);
|
||||
this.fontRenderer.drawString(EnumColor.RED + LanguageUtility.getLocal("gui.resonantinduction.multimeter." + this.multimeter.getMode().display), 35, 68, 4210752);
|
||||
this.fontRenderer.drawString(Unit.JOULES.name + "(s)", 35, 100, 4210752);
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
package resonantinduction.electrical.multimeter;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import java.util.List;
|
||||
|
||||
import universalelectricity.api.net.IUpdate;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import universalelectricity.core.net.Network;
|
||||
import universalelectricity.core.net.NetworkTickHandler;
|
||||
|
||||
public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter>
|
||||
public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter> implements IUpdate
|
||||
{
|
||||
public List<String> displayInformation;
|
||||
public Graph graph = new Graph(20 * 10);
|
||||
|
||||
/**
|
||||
* The absolute center of the multimeter screens.
|
||||
*/
|
||||
|
@ -14,8 +20,15 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
|
|||
/**
|
||||
* The relative bound sizes.
|
||||
*/
|
||||
public Vector3 upperBound = new Vector3();
|
||||
public Vector3 lowerBound = new Vector3();
|
||||
private Vector3 upperBound = new Vector3();
|
||||
private Vector3 lowerBound = new Vector3();
|
||||
|
||||
/**
|
||||
* The overall size of the multimeter
|
||||
*/
|
||||
public Vector3 size = new Vector3();
|
||||
|
||||
private long queueGraphValue = 0;
|
||||
|
||||
@Override
|
||||
public void reconstruct()
|
||||
|
@ -26,6 +39,35 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
|
|||
center = upperBound.midPoint(lowerBound);
|
||||
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));
|
||||
NetworkTickHandler.addNetwork(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
if (queueGraphValue > 0)
|
||||
{
|
||||
graph.add(queueGraphValue);
|
||||
queueGraphValue = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate()
|
||||
{
|
||||
return getConnectors().size() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean continueUpdate()
|
||||
{
|
||||
return canUpdate();
|
||||
}
|
||||
|
||||
public void updateGraph(long detectedValue)
|
||||
{
|
||||
queueGraphValue += detectedValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -58,4 +100,5 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
|
|||
{
|
||||
return new MultimeterNetwork();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -82,20 +82,14 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
|
||||
|
||||
private DetectMode detectMode = DetectMode.NONE;
|
||||
private long redstoneTriggerLimit;
|
||||
|
||||
private long peakDetection;
|
||||
private long energyLimit;
|
||||
private long detectedEnergy;
|
||||
private long detectedAverageEnergy;
|
||||
public boolean redstoneOn;
|
||||
private byte side;
|
||||
private int ticks;
|
||||
|
||||
private MultimeterNetwork network;
|
||||
|
||||
public List<String> displayInformation;
|
||||
public Graph graph;
|
||||
|
||||
public void preparePlacement(int side, int itemDamage)
|
||||
{
|
||||
this.side = (byte) (side ^ 1);
|
||||
|
@ -177,10 +171,9 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
|
||||
if (!world().isRemote)
|
||||
{
|
||||
if (ticks % 20 == 0)
|
||||
if (ticks % 10 == 0)
|
||||
{
|
||||
long prevDetectedEnergy = detectedEnergy;
|
||||
updateDetection(doGetDetectedEnergy());
|
||||
long detectedEnergy = doGetDetectedEnergy();
|
||||
|
||||
boolean outputRedstone = false;
|
||||
|
||||
|
@ -189,31 +182,34 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
default:
|
||||
break;
|
||||
case EQUAL:
|
||||
outputRedstone = detectedEnergy == energyLimit;
|
||||
outputRedstone = detectedEnergy == redstoneTriggerLimit;
|
||||
break;
|
||||
case GREATER_THAN:
|
||||
outputRedstone = detectedEnergy > energyLimit;
|
||||
outputRedstone = detectedEnergy > redstoneTriggerLimit;
|
||||
break;
|
||||
case GREATER_THAN_EQUAL:
|
||||
outputRedstone = detectedEnergy >= energyLimit;
|
||||
outputRedstone = detectedEnergy >= redstoneTriggerLimit;
|
||||
break;
|
||||
case LESS_THAN:
|
||||
outputRedstone = detectedEnergy < energyLimit;
|
||||
outputRedstone = detectedEnergy < redstoneTriggerLimit;
|
||||
break;
|
||||
case LESS_THAN_EQUAL:
|
||||
outputRedstone = detectedEnergy <= energyLimit;
|
||||
outputRedstone = detectedEnergy <= redstoneTriggerLimit;
|
||||
break;
|
||||
}
|
||||
|
||||
getNetwork().updateGraph(detectedEnergy);
|
||||
|
||||
if (outputRedstone != redstoneOn)
|
||||
{
|
||||
redstoneOn = outputRedstone;
|
||||
tile().notifyPartChange(this);
|
||||
}
|
||||
|
||||
if (prevDetectedEnergy != detectedEnergy)
|
||||
if (getNetwork().graph.get(1) != detectedEnergy)
|
||||
{
|
||||
writeDesc(getWriteStream());
|
||||
// writeDesc(getWriteStream());
|
||||
writeGraph(getWriteStream());
|
||||
// this.getWriteStream().writeByte(3).writeByte((byte)
|
||||
// detectMode.ordinal()).writeLong(detectedEnergy).writeLong(detectedAverageEnergy).writeLong(energyLimit);
|
||||
}
|
||||
|
@ -239,8 +235,7 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
detectMode = DetectMode.values()[packet.readByte()];
|
||||
refresh();
|
||||
getNetwork().center = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound());
|
||||
getNetwork().upperBound = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound());
|
||||
getNetwork().lowerBound = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound());
|
||||
getNetwork().size = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -250,8 +245,13 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
packet.writeByte(this.side);
|
||||
packet.writeByte((byte) detectMode.ordinal());
|
||||
packet.writeNBTTagCompound(getNetwork().center.writeToNBT(new NBTTagCompound()));
|
||||
packet.writeNBTTagCompound(getNetwork().upperBound.writeToNBT(new NBTTagCompound()));
|
||||
packet.writeNBTTagCompound(getNetwork().lowerBound.writeToNBT(new NBTTagCompound()));
|
||||
packet.writeNBTTagCompound(getNetwork().size.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
public void writeGraph(MCDataOutput packet)
|
||||
{
|
||||
packet.writeByte(2);
|
||||
packet.writeNBTTagCompound(getNetwork().graph.save());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -268,19 +268,15 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
detectMode = DetectMode.values()[packet.readByte()];
|
||||
refresh();
|
||||
getNetwork().center = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound());
|
||||
getNetwork().upperBound = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound());
|
||||
getNetwork().lowerBound = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound());
|
||||
getNetwork().size = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound());
|
||||
}
|
||||
else if (packetID == 1)
|
||||
{
|
||||
energyLimit = packet.readLong();
|
||||
redstoneTriggerLimit = packet.readLong();
|
||||
}
|
||||
else if (packetID == 3)
|
||||
else if (packetID == 2)
|
||||
{
|
||||
this.detectMode = DetectMode.values()[packet.readByte()];
|
||||
this.detectedEnergy = packet.readLong();
|
||||
this.detectedAverageEnergy = packet.readLong();
|
||||
this.energyLimit = packet.readLong();
|
||||
getNetwork().graph.load(packet.readNBTTagCompound());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -328,23 +324,6 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
return CompatibilityModule.getEnergy(tileEntity, side);
|
||||
}
|
||||
|
||||
public void updateDetection(long detected)
|
||||
{
|
||||
detectedEnergy = detected;
|
||||
detectedAverageEnergy = (detectedAverageEnergy + detectedEnergy) / 2;
|
||||
peakDetection = Math.max(peakDetection, detectedEnergy);
|
||||
}
|
||||
|
||||
public long getDetectedEnergy()
|
||||
{
|
||||
return detectedEnergy;
|
||||
}
|
||||
|
||||
public long getAverageDetectedEnergy()
|
||||
{
|
||||
return detectedAverageEnergy;
|
||||
}
|
||||
|
||||
public void toggleMode()
|
||||
{
|
||||
if (!this.world().isRemote)
|
||||
|
@ -363,7 +342,7 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
super.load(nbt);
|
||||
side = nbt.getByte("side");
|
||||
detectMode = DetectMode.values()[nbt.getByte("detectMode")];
|
||||
energyLimit = nbt.getLong("energyLimit");
|
||||
redstoneTriggerLimit = nbt.getLong("energyLimit");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -372,7 +351,7 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
super.save(nbt);
|
||||
nbt.setByte("side", this.side);
|
||||
nbt.setByte("detectMode", (byte) detectMode.ordinal());
|
||||
nbt.setLong("energyLimit", energyLimit);
|
||||
nbt.setLong("energyLimit", redstoneTriggerLimit);
|
||||
}
|
||||
|
||||
public DetectMode getMode()
|
||||
|
@ -382,12 +361,7 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
|
||||
public float getLimit()
|
||||
{
|
||||
return energyLimit;
|
||||
}
|
||||
|
||||
public float getPeak()
|
||||
{
|
||||
return peakDetection;
|
||||
return redstoneTriggerLimit;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,6 +9,8 @@ import org.lwjgl.opengl.GL11;
|
|||
import resonantinduction.archaic.Archaic;
|
||||
import resonantinduction.core.Reference;
|
||||
import resonantinduction.core.ResonantInduction;
|
||||
import universalelectricity.api.energy.UnitDisplay;
|
||||
import universalelectricity.api.energy.UnitDisplay.Unit;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import calclavia.lib.render.RenderUtility;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
@ -46,11 +48,37 @@ public class RenderMultimeter
|
|||
if (!part.hasMultimeter(part.x(), part.y() - 1, part.z()))
|
||||
RenderUtility.renderCube(-0.501, -0.0501, 0.44, 0.501, 0.0501, 0.501, Archaic.blockMachinePart, null, metadata);
|
||||
// LEFT
|
||||
if (((dir == ForgeDirection.WEST || dir == ForgeDirection.EAST) && !part.hasMultimeter(part.x(), part.y(), part.z() - 1)) || ((dir == ForgeDirection.SOUTH || dir == ForgeDirection.NORTH) && !part.hasMultimeter(part.x() + 1, part.y(), part.z())))
|
||||
RenderUtility.renderCube(-0.501, -0.0501, -0.501, -0.44, 0.0501, 0.501, Archaic.blockMachinePart, null, metadata);
|
||||
// RIGHT
|
||||
if (((dir == ForgeDirection.WEST || dir == ForgeDirection.EAST) && !part.hasMultimeter(part.x(), part.y(), part.z() + 1)) || ((dir == ForgeDirection.SOUTH || dir == ForgeDirection.NORTH) && !part.hasMultimeter(part.x() - 1, part.y(), part.z())))
|
||||
RenderUtility.renderCube(0.44, -0.0501, -0.501, 0.501, 0.0501, 0.501, Archaic.blockMachinePart, null, metadata);
|
||||
for (int i = 2; i < 6; i++)
|
||||
{
|
||||
ForgeDirection check = ForgeDirection.getOrientation(i);
|
||||
|
||||
if (!part.hasMultimeter(part.x() + check.offsetX, part.y() + check.offsetY, part.z() + check.offsetZ))
|
||||
{
|
||||
if (dir.offsetX != 0 && check.offsetZ != 0)
|
||||
{
|
||||
if (dir.offsetX != check.offsetZ)
|
||||
{
|
||||
RenderUtility.renderCube(-0.501, -0.0501, -0.501, -0.44, 0.0501, 0.501, Archaic.blockMachinePart, null, metadata);
|
||||
}
|
||||
else if (dir.offsetX == check.offsetZ)
|
||||
{
|
||||
RenderUtility.renderCube(0.44, -0.0501, -0.501, 0.501, 0.0501, 0.501, Archaic.blockMachinePart, null, metadata);
|
||||
}
|
||||
}
|
||||
if (dir.offsetZ != 0 && check.offsetX != 0)
|
||||
{
|
||||
if (dir.offsetZ == check.offsetX)
|
||||
{
|
||||
RenderUtility.renderCube(-0.501, -0.0501, -0.501, -0.44, 0.0501, 0.501, Archaic.blockMachinePart, null, metadata);
|
||||
}
|
||||
else if (dir.offsetZ != check.offsetX)
|
||||
{
|
||||
RenderUtility.renderCube(0.44, -0.0501, -0.501, 0.501, 0.0501, 0.501, Archaic.blockMachinePart, null, metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
|
||||
/**
|
||||
|
@ -65,7 +93,11 @@ public class RenderMultimeter
|
|||
GL11.glTranslated(centerTranslation.x, centerTranslation.y, centerTranslation.z);
|
||||
RenderUtility.rotateFaceBlockToSideOutwards(part.getDirection().getOpposite());
|
||||
GL11.glTranslated(0, 0.05, 0);
|
||||
RenderUtility.renderText("" + part.getDetectedEnergy(), 0.8f, 0.8f);
|
||||
String display = UnitDisplay.getDisplay(part.getNetwork().graph.get(0), Unit.JOULES);
|
||||
if (dir.offsetX == 0)
|
||||
RenderUtility.renderText(display, (float) (part.getNetwork().size.x * 0.9f), 0.5f);
|
||||
if (dir.offsetZ == 0)
|
||||
RenderUtility.renderText(display, (float) (part.getNetwork().size.z * 0.9f), 0.5f);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue