Created a GUI window to debug gears outside of MC GUI
This commit is contained in:
parent
055bbf4b82
commit
5572a27736
|
@ -37,7 +37,7 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj
|
|||
private double power = 0;
|
||||
private INodeProvider parent;
|
||||
|
||||
protected final AbstractMap<MechanicalNode, ForgeDirection> connections = new WeakHashMap<MechanicalNode, ForgeDirection>();
|
||||
private final AbstractMap<MechanicalNode, ForgeDirection> connections = new WeakHashMap<MechanicalNode, ForgeDirection>();
|
||||
|
||||
public MechanicalNode(INodeProvider parent)
|
||||
{
|
||||
|
@ -132,9 +132,9 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj
|
|||
power = getEnergy() / deltaTime;
|
||||
|
||||
debug("Node->Connections");
|
||||
synchronized (connections)
|
||||
synchronized (getConnections())
|
||||
{
|
||||
Iterator<Entry<MechanicalNode, ForgeDirection>> it = connections.entrySet().iterator();
|
||||
Iterator<Entry<MechanicalNode, ForgeDirection>> it = getConnections().entrySet().iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
|
@ -280,26 +280,30 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj
|
|||
@Override
|
||||
public void reconstruct()
|
||||
{
|
||||
debug("reconstruct");
|
||||
recache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deconstruct()
|
||||
{
|
||||
for (Entry<MechanicalNode, ForgeDirection> entry : connections.entrySet())
|
||||
debug("deconstruct");
|
||||
for (Entry<MechanicalNode, ForgeDirection> entry : getConnections().entrySet())
|
||||
{
|
||||
entry.getKey().recache();
|
||||
}
|
||||
connections.clear();
|
||||
getConnections().clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recache()
|
||||
{
|
||||
connections.clear();
|
||||
debug("Node->Recahce");
|
||||
getConnections().clear();
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
debug("\tDir: " + dir);
|
||||
TileEntity tile = position().translate(dir).getTileEntity(world());
|
||||
|
||||
if (tile instanceof INodeProvider)
|
||||
|
@ -308,17 +312,19 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj
|
|||
|
||||
if (check != null && canConnect(dir, check) && check.canConnect(dir.getOpposite(), this))
|
||||
{
|
||||
connections.put(check, dir);
|
||||
getConnections().put(check, dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the node provider for this node */
|
||||
public INodeProvider getParent()
|
||||
{
|
||||
return parent;
|
||||
}
|
||||
|
||||
/** Sets the node provider for the node */
|
||||
public void setParent(INodeProvider parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
|
@ -329,4 +335,9 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj
|
|||
{
|
||||
return this.getClass().getName() + this.hashCode();
|
||||
}
|
||||
|
||||
public AbstractMap<MechanicalNode, ForgeDirection> getConnections()
|
||||
{
|
||||
return connections;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import net.minecraftforge.common.ForgeDirection;
|
|||
import resonant.api.grid.INode;
|
||||
import resonant.api.grid.INodeProvider;
|
||||
import resonant.core.ResonantEngine;
|
||||
import resonantinduction.mechanical.gear.GearDebugFrame;
|
||||
import codechicken.lib.data.MCDataInput;
|
||||
import codechicken.lib.data.MCDataOutput;
|
||||
import codechicken.multipart.ControlKeyModifer;
|
||||
|
@ -53,10 +54,15 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
|
|||
node.debug("Part: " + this + " Node: " + this.node);
|
||||
this.node.update(0.05f);
|
||||
}
|
||||
|
||||
if (frame != null)
|
||||
{
|
||||
frame.update();
|
||||
}
|
||||
super.update();
|
||||
}
|
||||
|
||||
GearDebugFrame frame = null;
|
||||
|
||||
@Override
|
||||
public boolean activate(EntityPlayer player, MovingObjectPosition hit, ItemStack itemStack)
|
||||
{
|
||||
|
@ -64,10 +70,26 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
|
|||
{
|
||||
if (itemStack != null && itemStack.getItem().itemID == Item.stick.itemID)
|
||||
{
|
||||
if (!world().isRemote && ControlKeyModifer.isControlDown(player))
|
||||
if (!world().isRemote)
|
||||
{
|
||||
this.node.doDebug = !this.node.doDebug;
|
||||
player.addChatMessage("[Debug] PartMechanical debug mode is now " + (this.node.doDebug ? "on" : "off"));
|
||||
if (!ControlKeyModifer.isControlDown(player))
|
||||
{
|
||||
this.node.doDebug = !this.node.doDebug;
|
||||
player.addChatMessage("[Debug] PartMechanical debug mode is now " + (this.node.doDebug ? "on" : "off"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (frame == null)
|
||||
{
|
||||
frame = new GearDebugFrame(this);
|
||||
frame.showDebugFrame();
|
||||
}
|
||||
else
|
||||
{
|
||||
frame.closeDebugFrame();
|
||||
frame = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -107,6 +129,10 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
|
|||
public void onWorldSeparate()
|
||||
{
|
||||
node.deconstruct();
|
||||
if (frame != null)
|
||||
{
|
||||
frame.closeDebugFrame();
|
||||
}
|
||||
}
|
||||
|
||||
/** Packet Code. */
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package resonantinduction.mechanical.gear;
|
||||
|
||||
import java.awt.Label;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class DataLabel extends Label
|
||||
{
|
||||
public void update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,179 @@
|
|||
package resonantinduction.mechanical.gear;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Label;
|
||||
import java.awt.Panel;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonantinduction.mechanical.energy.grid.MechanicalNode;
|
||||
import resonantinduction.mechanical.energy.grid.PartMechanical;
|
||||
|
||||
/** Java GUI used to help debug gear information
|
||||
*
|
||||
* @author Darkguardsman */
|
||||
@SuppressWarnings("serial")
|
||||
public class GearDebugFrame extends Frame implements ActionListener
|
||||
{
|
||||
List<DataLabel> dataLabels = new ArrayList<DataLabel>();
|
||||
Label[] connections = new Label[20];
|
||||
|
||||
long tick = 0;
|
||||
PartMechanical part = null;
|
||||
|
||||
public GearDebugFrame(PartMechanical part)
|
||||
{
|
||||
this.part = part;
|
||||
setLayout(new BorderLayout());
|
||||
setBackground(Color.DARK_GRAY);
|
||||
|
||||
//Top bar
|
||||
Panel topPanel = new Panel(new GridLayout(1, 4, 0, 0));
|
||||
|
||||
DataLabel tickLabel = new DataLabel()
|
||||
{
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
setText("Tick: " + tick);
|
||||
}
|
||||
};
|
||||
topPanel.add(tickLabel);
|
||||
|
||||
DataLabel xLabel = new DataLabel()
|
||||
{
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
setText("X: " + GearDebugFrame.this.part.x());
|
||||
}
|
||||
};
|
||||
topPanel.add(xLabel);
|
||||
DataLabel yLabel = new DataLabel()
|
||||
{
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
setText("Y: " + GearDebugFrame.this.part.y());
|
||||
}
|
||||
};
|
||||
topPanel.add(yLabel);
|
||||
DataLabel zLabel = new DataLabel()
|
||||
{
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
setText("Z: " + GearDebugFrame.this.part.z());
|
||||
}
|
||||
};
|
||||
topPanel.add(zLabel);
|
||||
add(topPanel, BorderLayout.NORTH);
|
||||
|
||||
//Middle bar
|
||||
Panel middlePanel = new Panel(new GridLayout(8, 1, 0, 0));
|
||||
|
||||
DataLabel velLabel = new DataLabel()
|
||||
{
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
setText("Vel: " + GearDebugFrame.this.part.node.angularVelocity);
|
||||
}
|
||||
};
|
||||
middlePanel.add(velLabel);
|
||||
|
||||
DataLabel angleLabel = new DataLabel()
|
||||
{
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
setText("Angle: " + GearDebugFrame.this.part.node.renderAngle);
|
||||
}
|
||||
};
|
||||
middlePanel.add(angleLabel);
|
||||
|
||||
DataLabel torqueLabel = new DataLabel()
|
||||
{
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
setText("Torque: " + GearDebugFrame.this.part.node.torque);
|
||||
}
|
||||
};
|
||||
middlePanel.add(torqueLabel);
|
||||
|
||||
add(middlePanel, BorderLayout.EAST);
|
||||
|
||||
Panel connectionPanel = new Panel(new GridLayout(this.connections.length / 4, 4, 0, 0));
|
||||
for (int i = 0; i < connections.length; i++)
|
||||
{
|
||||
this.connections[i] = new Label("Connection" + i + ": null");
|
||||
connectionPanel.add(connections[i]);
|
||||
}
|
||||
add(connectionPanel, BorderLayout.WEST);
|
||||
|
||||
//exit icon handler
|
||||
addWindowListener(new WindowAdapter()
|
||||
{
|
||||
public void windowClosing(WindowEvent e)
|
||||
{
|
||||
Frame f = (Frame) e.getSource();
|
||||
f.setVisible(false);
|
||||
f.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** Called each cpu cycle */
|
||||
public void update()
|
||||
{
|
||||
tick++;
|
||||
if (this.part != null)
|
||||
{
|
||||
for (DataLabel label : dataLabels)
|
||||
{
|
||||
label.update();
|
||||
}
|
||||
int c = 0;
|
||||
for (Entry<MechanicalNode, ForgeDirection> entry : part.node.getConnections().entrySet())
|
||||
{
|
||||
this.connections[c].setText("Connection" + c + ": " + entry.getKey());
|
||||
c++;
|
||||
}
|
||||
for (int i = c; i < connections.length; i++)
|
||||
{
|
||||
this.connections[c].setText("Connection" + c + ": NONE");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Shows the frame */
|
||||
public void showDebugFrame()
|
||||
{
|
||||
setTitle("Resonant Engine Debug Window");
|
||||
setBounds(200, 200, 450, 600);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
/** Hides the frame and tells it to die off */
|
||||
public void closeDebugFrame()
|
||||
{
|
||||
dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
|
@ -82,7 +82,7 @@ public class GearNode extends MechanicalNode
|
|||
public void recache()
|
||||
{
|
||||
debug("doRecache: " + this);
|
||||
connections.clear();
|
||||
getConnections().clear();
|
||||
|
||||
/** Only call refresh if this is the main block of a multiblock gear or a single gear block. */
|
||||
if (!gear().getMultiBlock().isPrimary() || world() == null)
|
||||
|
@ -99,7 +99,7 @@ public class GearNode extends MechanicalNode
|
|||
|
||||
if (instance != null && instance != this && !(instance.getParent() instanceof PartGearShaft) && instance.canConnect(gear().placementSide.getOpposite(), this))
|
||||
{
|
||||
connections.put(instance, gear().placementSide);
|
||||
getConnections().put(instance, gear().placementSide);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,9 +122,9 @@ public class GearNode extends MechanicalNode
|
|||
* (the center), then we try to look for a gear shaft in the center. */
|
||||
MechanicalNode instance = (MechanicalNode) ((INodeProvider) tile).getNode(MechanicalNode.class, checkDir == gear().placementSide.getOpposite() ? ForgeDirection.UNKNOWN : checkDir);
|
||||
|
||||
if (!connections.containsValue(checkDir) && instance != this && checkDir != gear().placementSide && instance != null && instance.canConnect(checkDir.getOpposite(), this))
|
||||
if (!getConnections().containsValue(checkDir) && instance != this && checkDir != gear().placementSide && instance != null && instance.canConnect(checkDir.getOpposite(), this))
|
||||
{
|
||||
connections.put(instance, checkDir);
|
||||
getConnections().put(instance, checkDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -142,13 +142,13 @@ public class GearNode extends MechanicalNode
|
|||
ForgeDirection checkDir = ForgeDirection.getOrientation(Rotation.rotateSide(gear().placementSide.ordinal(), i));
|
||||
TileEntity checkTile = new universalelectricity.api.vector.Vector3(gear().tile()).translate(checkDir, displaceCheck).getTileEntity(world());
|
||||
|
||||
if (!connections.containsValue(checkDir) && checkTile instanceof INodeProvider)
|
||||
if (!getConnections().containsValue(checkDir) && checkTile instanceof INodeProvider)
|
||||
{
|
||||
MechanicalNode instance = (MechanicalNode) ((INodeProvider) checkTile).getNode(MechanicalNode.class, gear().placementSide);
|
||||
|
||||
if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite(), this) && !(instance.getParent() instanceof PartGearShaft))
|
||||
{
|
||||
connections.put(instance, checkDir);
|
||||
getConnections().put(instance, checkDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class GearShaftNode extends MechanicalNode
|
|||
@Override
|
||||
public void recache()
|
||||
{
|
||||
connections.clear();
|
||||
getConnections().clear();
|
||||
List<ForgeDirection> dirs = new ArrayList<ForgeDirection>();
|
||||
dirs.add(shaft().placementSide);
|
||||
dirs.add(shaft().placementSide.getOpposite());
|
||||
|
@ -59,7 +59,7 @@ public class GearShaftNode extends MechanicalNode
|
|||
|
||||
if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite(), this))
|
||||
{
|
||||
connections.put(instance, checkDir);
|
||||
getConnections().put(instance, checkDir);
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public class GearShaftNode extends MechanicalNode
|
|||
if (!dirs.isEmpty())
|
||||
for (ForgeDirection checkDir : dirs)
|
||||
{
|
||||
if (!connections.containsValue(checkDir) && (checkDir == shaft().placementSide || checkDir == shaft().placementSide.getOpposite()))
|
||||
if (!getConnections().containsValue(checkDir) && (checkDir == shaft().placementSide || checkDir == shaft().placementSide.getOpposite()))
|
||||
{
|
||||
TileEntity checkTile = new universalelectricity.api.vector.Vector3(shaft().tile()).translate(checkDir).getTileEntity(world());
|
||||
|
||||
|
@ -81,7 +81,7 @@ public class GearShaftNode extends MechanicalNode
|
|||
// Only connect to shafts outside of this block space.
|
||||
if (instance != null && instance != this && instance.getParent() instanceof PartGearShaft && instance.canConnect(checkDir.getOpposite(), this))
|
||||
{
|
||||
connections.put(instance, checkDir);
|
||||
getConnections().put(instance, checkDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue