Converted some multimeter classes to Scala

This commit is contained in:
Calclavia 2014-09-30 09:49:57 +08:00
parent 92603a456d
commit feac01af4a
10 changed files with 379 additions and 581 deletions

View file

@ -1,54 +0,0 @@
/**
*
*/
package resonantinduction.electrical.multimeter;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
/**
* @author Calclavia
*
*/
public class ContainerMultimeter extends Container
{
private final int yDisplacement = 51;
private PartMultimeter tileEntity;
public ContainerMultimeter(InventoryPlayer inventoryPlayer, PartMultimeter tileEntity)
{
this.tileEntity = tileEntity;
int i;
for (i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18 + yDisplacement));
}
}
for (i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142 + yDisplacement));
}
this.tileEntity.playersUsing.add(inventoryPlayer.player);
}
@Override
public void onContainerClosed(EntityPlayer entityPlayer)
{
this.tileEntity.playersUsing.remove(entityPlayer);
super.onContainerClosed(entityPlayer);
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer)
{
return true;
}
}

View file

@ -0,0 +1,32 @@
/**
*
*/
package resonantinduction.electrical.multimeter
import net.minecraft.entity.player.{EntityPlayer, InventoryPlayer}
import net.minecraft.inventory.{Container, Slot}
/**
* @author Calclavia
*
*/
class ContainerMultimeter(inventoryPlayer: InventoryPlayer, tileEntity: PartMultimeter) extends Container
{
private final val yDisplacement: Int = 51
for (i <- 0 until 3; j <- 0 until 9)
addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18 + yDisplacement))
for (i <- 0 until 9)
this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142 + yDisplacement))
tileEntity.playersUsing.add(inventoryPlayer.player)
override def onContainerClosed(entityPlayer: EntityPlayer)
{
this.tileEntity.playersUsing.remove(entityPlayer)
super.onContainerClosed(entityPlayer)
}
def canInteractWith(entityplayer: EntityPlayer): Boolean = true;
}

View file

@ -1,106 +0,0 @@
/**
*
*/
package resonantinduction.electrical.multimeter;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.InventoryPlayer;
import resonant.lib.gui.GuiContainerBase;
import resonant.lib.render.EnumColor;
import resonant.lib.utility.LanguageUtility;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Multimeter GUI
*
* @author Calclavia
*
*/
@SideOnly(Side.CLIENT)
public class GuiMultimeter extends GuiContainerBase
{
PartMultimeter multimeter;
private GuiTextField textFieldLimit;
public GuiMultimeter(InventoryPlayer inventoryPlayer, PartMultimeter tileEntity)
{
super(new ContainerMultimeter(inventoryPlayer, tileEntity));
this.multimeter = tileEntity;
this.ySize = 217;
}
@Override
public void initGui()
{
super.initGui();
this.buttonList.add(new GuiButton(0, this.width / 2 + 20, this.height / 2 - 23, 50, 20, LanguageUtility.getLocal("gui.resonantinduction.multimeter.toggle")));
this.buttonList.add(new GuiButton(1, this.width / 2 - 80, this.height / 2 - 75, 100, 20, LanguageUtility.getLocal("gui.resonantinduction.multimeter.toggleDetection")));
this.buttonList.add(new GuiButton(2, this.width / 2 - 80, this.height / 2 + 0, 80, 20, LanguageUtility.getLocal("gui.resonantinduction.multimeter.toggleGraph")));
this.textFieldLimit = new GuiTextField(fontRendererObj, 9, 90, 90, 12);
this.textFieldLimit.setMaxStringLength(8);
this.textFieldLimit.setText("" + this.multimeter.redstoneTriggerLimit);
}
@Override
protected void keyTyped(char par1, int par2)
{
super.keyTyped(par1, par2);
this.textFieldLimit.textboxKeyTyped(par1, par2);
try
{
multimeter.redstoneTriggerLimit = Double.parseDouble(textFieldLimit.getText());
multimeter.updateServer();
}
catch (Exception e)
{
}
}
@Override
protected void mouseClicked(int par1, int par2, int par3)
{
super.mouseClicked(par1, par2, par3);
this.textFieldLimit.mouseClicked(par1 - this.containerWidth, par2 - this.containerHeight, par3);
}
@Override
protected void actionPerformed(GuiButton button)
{
switch (button.id)
{
case 0:
multimeter.toggleMode();
break;
case 1:
multimeter.toggleDetectionValue();
break;
case 2:
multimeter.toggleGraphType();
break;
}
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
String graphName = multimeter.getNetwork().getLocalized(multimeter.getNetwork().graphs.get(multimeter.graphType));
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
String s = LanguageUtility.getLocal("item.resonantinduction:multimeter.name");
this.fontRendererObj.drawString(s, this.xSize / 2 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752);
this.fontRendererObj.drawString(EnumColor.INDIGO + "Detection Type", 9, 20, 4210752);
this.fontRendererObj.drawString(multimeter.getNetwork().getDisplay(multimeter.detectType), 9, 60, 4210752);
this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.resonantinduction.multimeter.logic")+" " + EnumColor.RED + LanguageUtility.getLocal("gui.resonantinduction.multimeter." + this.multimeter.getMode().display), 9, 75, 4210752);
this.fontRendererObj.drawString(graphName, 95, 115, 4210752);
this.textFieldLimit.drawTextBox();
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y)
{
super.drawGuiContainerBackgroundLayer(f, x, y);
}
}

View file

@ -0,0 +1,86 @@
/**
*
*/
package resonantinduction.electrical.multimeter
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraft.client.gui.{GuiButton, GuiTextField}
import net.minecraft.entity.player.InventoryPlayer
import resonant.lib.gui.GuiContainerBase
import resonant.lib.render.EnumColor
import resonant.lib.utility.LanguageUtility
import resonant.lib.wrapper.WrapList._
/**
* Multimeter GUI
*
* @author Calclavia
*
*/
@SideOnly(Side.CLIENT)
class GuiMultimeter(inventoryPlayer: InventoryPlayer, multimeter: PartMultimeter) extends GuiContainerBase(new ContainerMultimeter(inventoryPlayer, multimeter))
{
private var textFieldLimit: GuiTextField = null
this.ySize = 217
override def initGui
{
super.initGui
this.buttonList.add(new GuiButton(0, this.width / 2 + 20, this.height / 2 - 23, 50, 20, LanguageUtility.getLocal("gui.resonantinduction.multimeter.toggle")))
this.buttonList.add(new GuiButton(1, this.width / 2 - 80, this.height / 2 - 75, 100, 20, LanguageUtility.getLocal("gui.resonantinduction.multimeter.toggleDetection")))
this.buttonList.add(new GuiButton(2, this.width / 2 - 80, this.height / 2 + 0, 80, 20, LanguageUtility.getLocal("gui.resonantinduction.multimeter.toggleGraph")))
this.textFieldLimit = new GuiTextField(fontRendererObj, 9, 90, 90, 12)
this.textFieldLimit.setMaxStringLength(8)
this.textFieldLimit.setText("" + this.multimeter.redstoneTriggerLimit)
}
protected override def keyTyped(par1: Char, par2: Int)
{
super.keyTyped(par1, par2)
this.textFieldLimit.textboxKeyTyped(par1, par2)
try
{
multimeter.redstoneTriggerLimit = textFieldLimit.getText.toDouble
multimeter.updateServer()
}
catch
{
case e: Exception =>
{
}
}
}
protected override def mouseClicked(par1: Int, par2: Int, par3: Int)
{
super.mouseClicked(par1, par2, par3)
this.textFieldLimit.mouseClicked(par1 - this.containerWidth, par2 - this.containerHeight, par3)
}
protected override def actionPerformed(button: GuiButton)
{
button.id match
{
case 0 =>
multimeter.toggleMode()
case 1 =>
multimeter.toggleDetectionValue()
case 2 =>
multimeter.toggleGraphType()
}
}
protected override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int)
{
val graphName: String = multimeter.getNetwork.getLocalized(multimeter.getNetwork.graphs(multimeter.graphType))
super.drawGuiContainerForegroundLayer(mouseX, mouseY)
val s: String = LanguageUtility.getLocal("item.resonantinduction:multimeter.name")
this.fontRendererObj.drawString(s, this.xSize / 2 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752)
this.fontRendererObj.drawString(EnumColor.INDIGO + "Detection Type", 9, 20, 4210752)
this.fontRendererObj.drawString(multimeter.getNetwork.getDisplay(multimeter.detectType), 9, 60, 4210752)
this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.resonantinduction.multimeter.logic") + " " + EnumColor.RED + LanguageUtility.getLocal("gui.resonantinduction.multimeter." + this.multimeter.getMode.display), 9, 75, 4210752)
this.fontRendererObj.drawString(graphName, 95, 115, 4210752)
this.textFieldLimit.drawTextBox()
}
}

View file

@ -1,101 +0,0 @@
package resonantinduction.electrical.multimeter;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import org.lwjgl.input.Keyboard;
import resonant.lib.render.EnumColor;
import resonant.lib.utility.LanguageUtility;
import resonantinduction.core.ResonantPartFactory;
import resonantinduction.core.ResonantPartFactory$;
import resonantinduction.core.prefab.part.IHighlight;
import resonantinduction.electrical.wire.base.WireMaterial;
import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Vector3;
import codechicken.microblock.FacePlacementGrid$;
import codechicken.multipart.JItemMultiPart;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.PartMap;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
public class ItemMultimeter extends JItemMultiPart implements IHighlight
{
private IIcon[] icons = new IIcon[WireMaterial.values().length];
@Override
public TMultiPart newPart(ItemStack itemStack, EntityPlayer player, World world, BlockCoord pos, int side, Vector3 hit)
{
side = FacePlacementGrid$.MODULE$.getHitSlot(hit, side);
TileEntity tile = world.getTileEntity(pos.x, pos.y, pos.z);
if (tile instanceof TileMultipart)
{
TMultiPart centerPart = ((TileMultipart) tile).partMap(PartMap.CENTER.ordinal());
if (centerPart != null && !player.isSneaking())
{
pos.offset(side ^ 1);
}
}
PartMultimeter part = ResonantPartFactory$.MODULE$.create(PartMultimeter.class);
if (part != null)
{
int l = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
int facing = l == 0 ? 2 : (l == 1 ? 5 : (l == 2 ? 3 : (l == 3 ? 4 : 0)));
part.preparePlacement(side, facing);
}
return part;
}
@Override
public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List list, boolean par4)
{
if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
{
list.add(LanguageUtility.getLocal("tooltip.noShift").replace("%0", EnumColor.AQUA.toString()).replace("%1", EnumColor.GREY.toString()));
}
else
{
list.addAll(LanguageUtility.splitStringPerWord(LanguageUtility.getLocal("item.resonantinduction:multimeter.tooltip"), 5));
}
}
public float getDetection(ItemStack itemStack)
{
if (itemStack.stackTagCompound == null || !itemStack.getTagCompound().hasKey("detection"))
{
return -1;
}
return itemStack.stackTagCompound.getFloat("detection");
}
public void setDetection(ItemStack itemStack, float detection)
{
if (itemStack.stackTagCompound == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
itemStack.stackTagCompound.setFloat("detection", detection);
}
@Override
public int getHighlightType()
{
return 0;
}
}

View file

@ -0,0 +1,80 @@
package resonantinduction.electrical.multimeter
import java.util.List
import codechicken.lib.vec.{BlockCoord, Vector3}
import codechicken.microblock.FacePlacementGrid
import codechicken.multipart.{JItemMultiPart, PartMap, TMultiPart, TileMultipart}
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.MathHelper
import net.minecraft.world.World
import org.lwjgl.input.Keyboard
import resonant.lib.render.EnumColor
import resonant.lib.utility.LanguageUtility
import resonant.lib.wrapper.WrapList._
import resonantinduction.core.ResonantPartFactory
import resonantinduction.core.prefab.part.IHighlight
class ItemMultimeter extends JItemMultiPart with IHighlight
{
def newPart(itemStack: ItemStack, player: EntityPlayer, world: World, pos: BlockCoord, vSide: Int, hit: Vector3): TMultiPart =
{
val side = FacePlacementGrid.getHitSlot(hit, vSide)
val tile: TileEntity = world.getTileEntity(pos.x, pos.y, pos.z)
if (tile.isInstanceOf[TileMultipart])
{
val centerPart: TMultiPart = tile.asInstanceOf[TileMultipart].partMap(PartMap.CENTER.ordinal)
if (centerPart != null && !player.isSneaking)
{
pos.offset(side ^ 1)
}
}
val part = ResonantPartFactory.create(classOf[PartMultimeter])
if (part != null)
{
val l = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3
val facing = if (l == 0) 2 else (if (l == 1) 5 else (if (l == 2) 3 else (if (l == 3) 4 else 0)))
part.preparePlacement(side, facing)
}
return part
}
override def addInformation(itemStack: ItemStack, par2EntityPlayer: EntityPlayer, list: List[_], par4: Boolean)
{
if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
{
list.add(LanguageUtility.getLocal("tooltip.noShift").replace("%0", EnumColor.AQUA.toString).replace("%1", EnumColor.GREY.toString))
}
else
{
list.addAll(LanguageUtility.splitStringPerWord(LanguageUtility.getLocal("item.resonantinduction:multimeter.tooltip"), 5))
}
}
def getDetection(itemStack: ItemStack): Float =
{
if (itemStack.stackTagCompound == null || !itemStack.getTagCompound.hasKey("detection"))
{
return -1
}
return itemStack.stackTagCompound.getFloat("detection")
}
def setDetection(itemStack: ItemStack, detection: Float)
{
if (itemStack.stackTagCompound == null)
{
itemStack.setTagCompound(new NBTTagCompound)
}
itemStack.stackTagCompound.setFloat("detection", detection)
}
def getHighlightType: Int = 0
}

View file

@ -1,75 +0,0 @@
package resonantinduction.electrical.multimeter;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
public class ModelMultimeter extends ModelBase
{
// fields
ModelRenderer Base;
ModelRenderer secPanel;
ModelRenderer arm;
ModelRenderer button;
ModelRenderer arm2;
ModelRenderer infopanel;
public ModelMultimeter()
{
textureWidth = 128;
textureHeight = 128;
Base = new ModelRenderer(this, 0, 0);
Base.addBox(0F, 0F, 0F, 14, 14, 1);
Base.setRotationPoint(-7F, 9F, 7F);
Base.setTextureSize(128, 128);
Base.mirror = true;
setRotation(Base, 0F, 0F, 0F);
secPanel = new ModelRenderer(this, 0, 18);
secPanel.addBox(0F, 0F, 0F, 4, 8, 1);
secPanel.setRotationPoint(-6F, 10F, 6F);
secPanel.setTextureSize(128, 128);
secPanel.mirror = true;
setRotation(secPanel, 0F, 0F, 0F);
arm = new ModelRenderer(this, 0, 29);
arm.addBox(0F, 0F, 0F, 1, 9, 2);
arm.setRotationPoint(-3.5F, 13F, 5.5F);
arm.setTextureSize(128, 128);
arm.mirror = true;
setRotation(arm, 0F, 0F, 0F);
button = new ModelRenderer(this, 0, 43);
button.addBox(0F, 0F, 0F, 2, 1, 1);
button.setRotationPoint(-5F, 11F, 5.5F);
button.setTextureSize(128, 128);
button.mirror = true;
setRotation(button, 0F, 0F, 0F);
arm2 = new ModelRenderer(this, 10, 29);
arm2.addBox(0F, 0F, 0F, 1, 9, 2);
arm2.setRotationPoint(-5.5F, 13F, 5.5F);
arm2.setTextureSize(128, 128);
arm2.mirror = true;
setRotation(arm2, 0F, 0F, 0F);
infopanel = new ModelRenderer(this, 33, 0);
infopanel.addBox(0F, 0F, 0F, 7, 12, 1);
infopanel.setRotationPoint(-1F, 10F, 6.5F);
infopanel.setTextureSize(128, 128);
infopanel.mirror = true;
setRotation(infopanel, 0F, 0F, 0F);
}
public void render(float f5)
{
Base.render(f5);
secPanel.render(f5);
arm.render(f5);
button.render(f5);
arm2.render(f5);
infopanel.render(f5);
}
private void setRotation(ModelRenderer model, float x, float y, float z)
{
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
}

View file

@ -1,244 +0,0 @@
package resonantinduction.electrical.multimeter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import resonant.lib.utility.LanguageUtility;
import resonantinduction.electrical.multimeter.graph.*;
import universalelectricity.api.UnitDisplay;
import universalelectricity.api.core.grid.IUpdate;
import universalelectricity.core.grid.Grid;
import universalelectricity.core.grid.UpdateTicker;
import universalelectricity.core.transform.vector.Vector3;
public class MultimeterGrid extends Grid<PartMultimeter> implements IUpdate
{
public final List<String> displayInformation = new ArrayList<String>();
/**
* Maximum data points a graph can store.
*/
private int maxData = 1;
/**
* The available graphs to be handled.
*/
public final List<Graph> graphs = new ArrayList<Graph>();
public final GraphL energyGraph = new GraphL("energy", maxData);
public final GraphL powerGraph = new GraphL("power", maxData);
public final GraphL energyCapacityGraph = new GraphL("capacity", 1);
public final GraphL voltageGraph = new GraphL("voltage", maxData);
public final GraphD torqueGraph = new GraphD("torque", maxData);
public final GraphD angularVelocityGraph = new GraphD("speed", maxData);
public final GraphI fluidGraph = new GraphI("fluid", maxData);
public final GraphF thermalGraph = new GraphF("temperature", maxData);
public final GraphI pressureGraph = new GraphI("pressure", maxData);
/**
* The absolute center of the multimeter screens.
*/
public Vector3 center = new Vector3();
/**
* The relative bound sizes.
*/
public Vector3 upperBound = new Vector3();
public Vector3 lowerBound = new Vector3();
/**
* The overall size of the multimeter
*/
public Vector3 size = new Vector3();
private long queueGraphValue = 0;
private long queueGraphCapacity = 0;
private boolean doUpdate = false;
/**
* If the screen is not a perfect rectangle, don't render.
*/
public boolean isEnabled = true;
public PartMultimeter primaryMultimeter = null;
public MultimeterGrid()
{
super(PartMultimeter.class);
graphs.add(energyGraph);
graphs.add(powerGraph);
graphs.add(energyCapacityGraph);
graphs.add(voltageGraph);
graphs.add(torqueGraph);
graphs.add(angularVelocityGraph);
graphs.add(fluidGraph);
graphs.add(thermalGraph);
graphs.add(pressureGraph);
}
public String getDisplay(int graphID)
{
Graph graph = graphs.get(graphID);
String graphValue = "";
if (graph == energyGraph)
graphValue = new UnitDisplay(UnitDisplay.Unit.JOULES, energyGraph.get()).toString();
if (graph == powerGraph)
graphValue = new UnitDisplay(UnitDisplay.Unit.WATT, powerGraph.get()).toString();
if (graph == energyCapacityGraph)
graphValue = new UnitDisplay(UnitDisplay.Unit.JOULES, energyCapacityGraph.get()).toString();
if (graph == voltageGraph)
graphValue = new UnitDisplay(UnitDisplay.Unit.VOLTAGE, voltageGraph.get()).toString();
if (graph == torqueGraph)
graphValue = new UnitDisplay(UnitDisplay.Unit.NEWTON_METER, torqueGraph.get(), true).toString();
if (graph == angularVelocityGraph)
graphValue = UnitDisplay.roundDecimals(angularVelocityGraph.get()) + " rad/s";
if (graph == fluidGraph)
graphValue = new UnitDisplay(UnitDisplay.Unit.LITER, fluidGraph.get()).toString();
if (graph == thermalGraph)
graphValue = UnitDisplay.roundDecimals(thermalGraph.get()) + " K";
if (graph == pressureGraph)
graphValue = UnitDisplay.roundDecimals(pressureGraph.get()) + " Pa";
return getLocalized(graph) + ": " + graphValue;
}
public String getLocalized(Graph graph)
{
return LanguageUtility.getLocal("tooltip.graph." + graph.name);
}
public boolean isPrimary(PartMultimeter check)
{
return primaryMultimeter == check;
}
@Override
public void update(double delta)
{
for (Graph graph : graphs)
{
graph.doneQueue();
}
doUpdate = false;
}
public void markUpdate()
{
doUpdate = true;
}
@Override
public boolean canUpdate()
{
return doUpdate && continueUpdate();
}
@Override
public boolean continueUpdate()
{
return getNodes().size() > 0;
}
@Override
public boolean isValidNode(Object node)
{
return node instanceof PartMultimeter && ((PartMultimeter) node).world() != null && ((PartMultimeter) node).tile() != null;
}
@Override
public void reconstruct()
{
if (getNodes().size() > 0)
{
primaryMultimeter = null;
upperBound = null;
lowerBound = null;
super.reconstruct();
center = upperBound.midPoint(lowerBound);
/**
* 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 == getNodes().size();
UpdateTicker.addUpdater(this);
Iterator<PartMultimeter> it = this.getNodes().iterator();
while (it.hasNext())
{
PartMultimeter connector = it.next();
connector.updateDesc();
connector.updateGraph();
}
doUpdate = true;
}
}
@Override
protected void reconstructNode(PartMultimeter node)
{
node.setNetwork(this);
if (primaryMultimeter == null)
primaryMultimeter = node;
if (upperBound == null)
{
upperBound = node.getPosition().add(1);
}
if (lowerBound == null)
{
lowerBound = node.getPosition();
}
upperBound = upperBound.max(node.getPosition().add(1));
lowerBound = lowerBound.min(node.getPosition());
}
public void load(NBTTagCompound nbt)
{
NBTTagList nbtList = nbt.getTagList("graphs", 0);
for (int i = 0; i < nbtList.tagCount(); ++i)
{
NBTTagCompound nbtCompound = (NBTTagCompound) nbtList.getCompoundTagAt(i);
graphs.get(i).load(nbtCompound);
}
}
public NBTTagCompound save()
{
NBTTagCompound nbt = new NBTTagCompound();
NBTTagList data = new NBTTagList();
for (Graph graph : graphs)
{
data.appendTag(graph.save());
}
nbt.setTag("graphs", data);
return nbt;
}
}

View file

@ -0,0 +1,180 @@
package resonantinduction.electrical.multimeter
import net.minecraft.nbt.{NBTTagCompound, NBTTagList}
import resonant.lib.utility.LanguageUtility
import resonantinduction.electrical.multimeter.graph._
import universalelectricity.api.UnitDisplay
import universalelectricity.api.core.grid.IUpdate
import universalelectricity.core.grid.{Grid, UpdateTicker}
import universalelectricity.core.transform.vector.Vector3
import scala.collection.convert.wrapAll._
import scala.collection.mutable.ArrayBuffer
class MultimeterGrid extends Grid[PartMultimeter](classOf[PartMultimeter]) with IUpdate
{
final val displayInformation = new ArrayBuffer[String]
/**
* Maximum data points a graph can store.
*/
private val maxData: Int = 1
/**
* The available graphs to be handled.
*/
final val graphs = new ArrayBuffer[Graph[_]]
final val energyGraph: GraphL = new GraphL("energy", maxData)
final val powerGraph: GraphL = new GraphL("power", maxData)
final val energyCapacityGraph: GraphL = new GraphL("capacity", 1)
final val voltageGraph: GraphL = new GraphL("voltage", maxData)
final val torqueGraph: GraphD = new GraphD("torque", maxData)
final val angularVelocityGraph: GraphD = new GraphD("speed", maxData)
final val fluidGraph: GraphI = new GraphI("fluid", maxData)
final val thermalGraph: GraphF = new GraphF("temperature", maxData)
final val pressureGraph: GraphI = new GraphI("pressure", maxData)
/**
* The absolute center of the multimeter screens.
*/
var center: Vector3 = new Vector3
/**
* The relative bound sizes.
*/
var upperBound: Vector3 = new Vector3
var lowerBound: Vector3 = new Vector3
/**
* The overall size of the multimeter
*/
var size: Vector3 = new Vector3
private var doUpdate: Boolean = false
/**
* If the screen is not a perfect rectangle, don't render.
*/
var isEnabled: Boolean = true
var primaryMultimeter: PartMultimeter = null
graphs += energyGraph
graphs += powerGraph
graphs += energyCapacityGraph
graphs += voltageGraph
graphs += torqueGraph
graphs += angularVelocityGraph
graphs += fluidGraph
graphs += thermalGraph
graphs += pressureGraph
def getDisplay(graphID: Int): String =
{
val graph = graphs(graphID)
var graphValue: String = ""
if (graph == energyGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.JOULES, energyGraph.get).toString
if (graph == powerGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.WATT, powerGraph.get).toString
if (graph == energyCapacityGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.JOULES, energyCapacityGraph.get).toString
if (graph == voltageGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.VOLTAGE, voltageGraph.get).toString
if (graph == torqueGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.NEWTON_METER, torqueGraph.get, true).toString
if (graph == angularVelocityGraph) graphValue = UnitDisplay.roundDecimals(angularVelocityGraph.get) + " rad/s"
if (graph == fluidGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.LITER, fluidGraph.get.toInt).toString
if (graph == thermalGraph) graphValue = UnitDisplay.roundDecimals(thermalGraph.get.toFloat) + " K"
if (graph == pressureGraph) graphValue = UnitDisplay.roundDecimals(pressureGraph.get.toInt) + " Pa"
return getLocalized(graph) + ": " + graphValue
}
def getLocalized(graph: Graph[_]): String =
{
return LanguageUtility.getLocal("tooltip.graph." + graph.name)
}
def isPrimary(check: PartMultimeter): Boolean =
{
return primaryMultimeter == check
}
def update(delta: Double)
{
graphs.foreach(_.doneQueue())
doUpdate = false
}
def markUpdate
{
doUpdate = true
}
def canUpdate: Boolean =
{
return doUpdate && continueUpdate
}
def continueUpdate: Boolean =
{
return getNodes.size > 0
}
override def isValidNode(node: AnyRef): Boolean =
{
return node.isInstanceOf[PartMultimeter] && node.asInstanceOf[PartMultimeter].world != null && node.asInstanceOf[PartMultimeter].tile != null
}
override def reconstruct
{
if (getNodes.size > 0)
{
primaryMultimeter = null
upperBound = null
lowerBound = null
super.reconstruct
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))
val area: Double = (if (size.x != 0) size.x else 1) * (if (size.y != 0) size.y else 1) * (if (size.z != 0) size.z else 1)
isEnabled = area == getNodes.size
UpdateTicker.addUpdater(this)
getNodes foreach (c =>
{
c.updateDesc()
c.updateGraph()
})
doUpdate = true
}
}
protected override def reconstructNode(node: PartMultimeter)
{
node.setNetwork(this)
if (primaryMultimeter == null) primaryMultimeter = node
if (upperBound == null)
{
upperBound = node.getPosition.add(1)
}
if (lowerBound == null)
{
lowerBound = node.getPosition
}
upperBound = upperBound.max(node.getPosition.add(1))
lowerBound = lowerBound.min(node.getPosition)
}
def load(nbt: NBTTagCompound)
{
val nbtList: NBTTagList = nbt.getTagList("graphs", 0)
for (i <- 0 until nbtList.tagCount)
{
val nbtCompound: NBTTagCompound = nbtList.getCompoundTagAt(i)
graphs.get(i).load(nbtCompound)
}
}
def save: NBTTagCompound =
{
val nbt: NBTTagCompound = new NBTTagCompound
val data: NBTTagList = new NBTTagList
graphs.foreach(g => data.appendTag(g.save()))
nbt.setTag("graphs", data)
return nbt
}
}

View file

@ -66,7 +66,7 @@ public abstract class Graph<V extends Comparable<V>>
add(queue);
}
protected abstract V getDefault();
public abstract V getDefault();
public void load(NBTTagCompound nbt)
{