Multimeter screens now render
This commit is contained in:
parent
8b8d2b9ee7
commit
5189633823
3 changed files with 69 additions and 69 deletions
|
@ -1,6 +1,7 @@
|
|||
package resonantinduction.electrical.multimeter;
|
||||
|
||||
import universalelectricity.api.vector.Vector2;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import universalelectricity.core.net.Network;
|
||||
|
||||
public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter>
|
||||
|
@ -8,75 +9,48 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
|
|||
/**
|
||||
* The absolute center of the multimeter screens.
|
||||
*/
|
||||
public Vector2 center = new Vector2();
|
||||
public Vector3 center = new Vector3();
|
||||
|
||||
/**
|
||||
* The relative bound sizes.
|
||||
*/
|
||||
public Vector2 upperBound = new Vector2();
|
||||
public Vector2 lowerBound = new Vector2();
|
||||
public Vector3 upperBound = new Vector3();
|
||||
public Vector3 lowerBound = new Vector3();
|
||||
|
||||
@Override
|
||||
public void reconstruct()
|
||||
{
|
||||
upperBound = null;
|
||||
lowerBound = null;
|
||||
super.reconstruct();
|
||||
center = upperBound.midPoint(lowerBound);
|
||||
upperBound.subtract(center);
|
||||
lowerBound.subtract(center);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidConnector(PartMultimeter node)
|
||||
{
|
||||
return node.world() != null && node.tile() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reconstructConnector(PartMultimeter node)
|
||||
{
|
||||
node.setNetwork(this);
|
||||
|
||||
/**
|
||||
* Computer upper bound
|
||||
*/
|
||||
if (node.getPosition().y > upperBound.x)
|
||||
if (upperBound == null)
|
||||
{
|
||||
upperBound.x = node.getPosition().y;
|
||||
upperBound = node.getPosition().translate(0.5);
|
||||
}
|
||||
|
||||
if (node.getDirection().offsetX == 0)
|
||||
if (lowerBound == null)
|
||||
{
|
||||
if (node.getPosition().x > upperBound.y)
|
||||
{
|
||||
upperBound.y = node.getPosition().x;
|
||||
}
|
||||
lowerBound = node.getPosition().translate(0.5);
|
||||
}
|
||||
|
||||
if (node.getDirection().offsetZ == 0)
|
||||
{
|
||||
if (node.getPosition().z > upperBound.y)
|
||||
{
|
||||
upperBound.y = node.getPosition().z;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Computer lower bound
|
||||
*/
|
||||
if (node.getPosition().y < lowerBound.x)
|
||||
{
|
||||
lowerBound.x = node.getPosition().y;
|
||||
}
|
||||
|
||||
if (node.getDirection().offsetX == 0)
|
||||
{
|
||||
if (node.getPosition().x < lowerBound.y)
|
||||
{
|
||||
lowerBound.y = node.getPosition().x;
|
||||
}
|
||||
}
|
||||
|
||||
if (node.getDirection().offsetZ == 0)
|
||||
{
|
||||
if (node.getPosition().z < lowerBound.y)
|
||||
{
|
||||
lowerBound.y = node.getPosition().z;
|
||||
}
|
||||
}
|
||||
upperBound = upperBound.max(node.getPosition().translate(0.5));
|
||||
lowerBound = lowerBound.min(node.getPosition().translate(0.5));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -82,6 +82,7 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
|
||||
|
||||
private DetectMode detectMode = DetectMode.NONE;
|
||||
|
||||
private long peakDetection;
|
||||
private long energyLimit;
|
||||
private long detectedEnergy;
|
||||
|
@ -107,15 +108,18 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
|
||||
public void refresh()
|
||||
{
|
||||
if (!world().isRemote)
|
||||
if (world() != null && !world().isRemote)
|
||||
{
|
||||
for (Object obj : getConnections())
|
||||
{
|
||||
if (obj instanceof PartMultimeter)
|
||||
{
|
||||
this.getNetwork().merge(((PartMultimeter) obj).getNetwork());
|
||||
getNetwork().merge(((PartMultimeter) obj).getNetwork());
|
||||
}
|
||||
}
|
||||
|
||||
getNetwork().reconstruct();
|
||||
writeDesc(getWriteStream());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,7 +213,9 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
|
||||
if (prevDetectedEnergy != detectedEnergy)
|
||||
{
|
||||
this.getWriteStream().writeByte(3).writeByte((byte) detectMode.ordinal()).writeLong(detectedEnergy).writeLong(detectedAverageEnergy).writeLong(energyLimit);
|
||||
writeDesc(getWriteStream());
|
||||
// this.getWriteStream().writeByte(3).writeByte((byte)
|
||||
// detectMode.ordinal()).writeLong(detectedEnergy).writeLong(detectedAverageEnergy).writeLong(energyLimit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -218,7 +224,9 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
{
|
||||
for (EntityPlayer player : playersUsing)
|
||||
{
|
||||
this.getWriteStream().writeByte(3).writeByte((byte) detectMode.ordinal()).writeLong(detectedEnergy).writeLong(detectedAverageEnergy).writeLong(energyLimit);
|
||||
writeDesc(getWriteStream());
|
||||
// this.getWriteStream().writeByte(3).writeByte((byte)
|
||||
// detectMode.ordinal()).writeLong(detectedEnergy).writeLong(detectedAverageEnergy).writeLong(energyLimit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -226,21 +234,24 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
@Override
|
||||
public void readDesc(MCDataInput packet)
|
||||
{
|
||||
packet.readByte();
|
||||
this.side = packet.readByte();
|
||||
detectMode = DetectMode.values()[packet.readByte()];
|
||||
detectedEnergy = packet.readLong();
|
||||
detectedAverageEnergy = packet.readLong();
|
||||
energyLimit = packet.readLong();
|
||||
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());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDesc(MCDataOutput packet)
|
||||
{
|
||||
packet.writeByte(0);
|
||||
packet.writeByte(this.side);
|
||||
packet.writeByte((byte) detectMode.ordinal());
|
||||
packet.writeLong(detectedEnergy);
|
||||
packet.writeLong(detectedAverageEnergy);
|
||||
packet.writeLong(energyLimit);
|
||||
packet.writeNBTTagCompound(getNetwork().center.writeToNBT(new NBTTagCompound()));
|
||||
packet.writeNBTTagCompound(getNetwork().upperBound.writeToNBT(new NBTTagCompound()));
|
||||
packet.writeNBTTagCompound(getNetwork().lowerBound.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -251,7 +262,16 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
|
||||
public void read(MCDataInput packet, int packetID)
|
||||
{
|
||||
if (packetID == 1)
|
||||
if (packetID == 0)
|
||||
{
|
||||
this.side = packet.readByte();
|
||||
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());
|
||||
}
|
||||
else if (packetID == 1)
|
||||
{
|
||||
energyLimit = packet.readLong();
|
||||
}
|
||||
|
|
|
@ -1,21 +1,16 @@
|
|||
package resonantinduction.electrical.multimeter;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import calclavia.lib.render.RenderUtility;
|
||||
import resonantinduction.archaic.Archaic;
|
||||
import resonantinduction.core.Reference;
|
||||
import resonantinduction.core.ResonantInduction;
|
||||
import resonantinduction.mechanical.Mechanical;
|
||||
import universalelectricity.api.energy.UnitDisplay;
|
||||
import universalelectricity.api.energy.UnitDisplay.Unit;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import calclavia.lib.render.RenderUtility;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
|
@ -38,7 +33,6 @@ public class RenderMultimeter
|
|||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
|
||||
RenderUtility.rotateFaceBlockToSideOutwards(part.getDirection().getOpposite());
|
||||
GL11.glPushMatrix();
|
||||
RenderUtility.bind(TextureMap.locationBlocksTexture);
|
||||
// Render the main panel
|
||||
RenderUtility.renderCube(-0.5, -0.05, -0.5, 0.5, 0.05, 0.5, Archaic.blockMachinePart, ResonantInduction.loadedIconMap.get(Reference.PREFIX + "multimeter_screen"));
|
||||
|
@ -58,10 +52,22 @@ public class RenderMultimeter
|
|||
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);
|
||||
GL11.glPopMatrix();
|
||||
GL11.glTranslated(0, 0.05, 0);
|
||||
// Render all the multimeter text
|
||||
RenderUtility.renderText("" + part.getDetectedEnergy(), 0.8f);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
/**
|
||||
* Only one block renders this text.
|
||||
* Render all the multimeter text
|
||||
*/
|
||||
if (part.getNetwork().center.distance(new Vector3(part.x(), part.y(), part.z()).translate(0.5)) < 0.8)
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
|
||||
Vector3 centerTranslation = part.getNetwork().center.clone().subtract(part.x(), part.y(), part.z()).add(-0.5);
|
||||
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);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue