From 58715f9f07dcd18717f12c16a51dc672819df4ed Mon Sep 17 00:00:00 2001 From: Robert S Date: Thu, 25 Sep 2014 18:26:42 -0400 Subject: [PATCH] Moved some things to RE, and converted a few classes --- .../scala/resonantinduction/core/Timer.java | 50 ---- .../core/debug/FrameDebug.java | 233 ------------------ .../core/debug/FrameNodeDebug.java | 109 -------- .../resonantinduction/core/debug/IDebug.java | 9 - .../resonantinduction/core/debug/IUpdate.java | 9 - .../core/debug/UpdatePanel.java | 33 --- .../core/debug/UpdatedLabel.java | 30 --- .../core/handler/TextureHookHandler.java | 32 --- .../core/handler/TextureHookHandler.scala | 31 +++ .../core/interfaces/ICmdMachine.java | 21 -- .../core/interfaces/IMechanicalNode.java | 56 ----- .../core/interfaces/IMechanicalNode.scala | 54 ++++ .../mechanical/mech/DebugFrameMechanical.java | 6 +- .../process/grinder/TileGrindingWheel.java | 2 +- .../mech/process/mixer/TileMixer.java | 2 +- 15 files changed, 90 insertions(+), 587 deletions(-) delete mode 100644 src/main/scala/resonantinduction/core/Timer.java delete mode 100644 src/main/scala/resonantinduction/core/debug/FrameDebug.java delete mode 100644 src/main/scala/resonantinduction/core/debug/FrameNodeDebug.java delete mode 100644 src/main/scala/resonantinduction/core/debug/IDebug.java delete mode 100644 src/main/scala/resonantinduction/core/debug/IUpdate.java delete mode 100644 src/main/scala/resonantinduction/core/debug/UpdatePanel.java delete mode 100644 src/main/scala/resonantinduction/core/debug/UpdatedLabel.java delete mode 100644 src/main/scala/resonantinduction/core/handler/TextureHookHandler.java create mode 100644 src/main/scala/resonantinduction/core/handler/TextureHookHandler.scala delete mode 100644 src/main/scala/resonantinduction/core/interfaces/ICmdMachine.java delete mode 100644 src/main/scala/resonantinduction/core/interfaces/IMechanicalNode.java create mode 100644 src/main/scala/resonantinduction/core/interfaces/IMechanicalNode.scala diff --git a/src/main/scala/resonantinduction/core/Timer.java b/src/main/scala/resonantinduction/core/Timer.java deleted file mode 100644 index 0ac645a86..000000000 --- a/src/main/scala/resonantinduction/core/Timer.java +++ /dev/null @@ -1,50 +0,0 @@ -package resonantinduction.core; - -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.relauncher.Side; - -import java.util.HashMap; - -public class Timer -{ - private final HashMap clientTimer = new HashMap(); - private final HashMap serverTimer = new HashMap(); - - public void put(K key, int defaultTime) - { - getTimeMap().put(key, defaultTime); - } - - public boolean containsKey(K key) - { - return getTimeMap().containsKey(key); - } - - public void remove(K key) - { - getTimeMap().remove(key); - } - - public int decrease(K key) - { - return decrease(key, 1); - } - - public int decrease(K key, int amount) - { - int timeLeft = getTimeMap().get(key) - amount; - getTimeMap().put(key, timeLeft); - return timeLeft; - } - - public HashMap getTimeMap() - { - if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) - { - return serverTimer; - } - - return clientTimer; - } - -} diff --git a/src/main/scala/resonantinduction/core/debug/FrameDebug.java b/src/main/scala/resonantinduction/core/debug/FrameDebug.java deleted file mode 100644 index 13631bec7..000000000 --- a/src/main/scala/resonantinduction/core/debug/FrameDebug.java +++ /dev/null @@ -1,233 +0,0 @@ -package resonantinduction.core.debug; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Frame; -import java.awt.GridLayout; -import java.awt.LayoutManager; -import java.awt.Panel; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - -import javax.swing.BorderFactory; -import javax.swing.border.Border; -import javax.swing.border.EtchedBorder; - -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import universalelectricity.core.transform.vector.IVectorWorld; - -/** @author Darkguardsman */ -@SuppressWarnings("serial") -public class FrameDebug extends Frame implements IVectorWorld -{ - /** Linked tile */ - TileEntity tile = null; - - boolean debugNode = false; - protected long tick = 0; - - public FrameDebug(TileEntity tile) - { - this(); - this.tile = tile; - } - - protected FrameDebug() - { - buildGUI(); - } - - /** Called to build the base of the GUI */ - protected void buildGUI() - { - Border loweredetched = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED); - UpdatePanel topPanel = new UpdatePanel(); - UpdatePanel botPanel = new UpdatePanel(); - UpdatePanel rightPanel = new UpdatePanel(); - - topPanel.setBorder(loweredetched); - botPanel.setBorder(loweredetched); - rightPanel.setBorder(loweredetched); - - buildTop(topPanel); - buildBottom(botPanel); - buildCenter(rightPanel); - - this.add(topPanel, BorderLayout.NORTH); - this.add(botPanel, BorderLayout.SOUTH); - this.add(rightPanel, BorderLayout.CENTER); - - //exit icon handler - addWindowListener(new WindowAdapter() - { - public void windowClosing(WindowEvent e) - { - Frame f = (Frame) e.getSource(); - f.setVisible(false); - f.dispose(); - } - }); - } - - /** Top are of the Frame */ - public void buildTop(UpdatePanel panel) - { - panel.setLayout(new GridLayout(1, 2, 0, 0)); - UpdatedLabel tickLabel = new UpdatedLabel("Tile: ") - { - @Override - public String buildLabel() - { - return super.buildLabel() + tile; - } - }; - panel.add(tickLabel); - } - - /** Bottom are of the Frame */ - public void buildBottom(UpdatePanel panel) - { - panel.setLayout(new GridLayout(1, 4, 0, 0)); - UpdatedLabel tickLabel = new UpdatedLabel("Tick: ") - { - @Override - public String buildLabel() - { - return super.buildLabel() + tick; - } - }; - panel.add(tickLabel); - - UpdatedLabel xLabel = new UpdatedLabel("X: ") - { - @Override - public String buildLabel() - { - return super.buildLabel() + x(); - } - }; - panel.add(xLabel); - - UpdatedLabel yLabel = new UpdatedLabel("Y: ") - { - @Override - public String buildLabel() - { - return super.buildLabel() + y(); - } - }; - panel.add(yLabel); - - UpdatedLabel zLabel = new UpdatedLabel("Z: ") - { - @Override - public String buildLabel() - { - return super.buildLabel() + z(); - } - }; - panel.add(zLabel); - } - - /** Left are of the Frame */ - public void buildCenter(UpdatePanel panel) - { - panel.setLayout(new GridLayout(1, 4, 0, 0)); - UpdatedLabel tickLabel = new UpdatedLabel("Valid: ") - { - @Override - public String buildLabel() - { - return super.buildLabel() + (tile != null ? tile.isInvalid() : "null"); - } - }; - panel.add(tickLabel); - UpdatedLabel block_label = new UpdatedLabel("BLOCK: ") - { - @Override - public String buildLabel() - { - return super.buildLabel() + (tile != null ? tile.getBlockType() : "null"); - } - }; - panel.add(block_label); - - UpdatedLabel meta_label = new UpdatedLabel("META: ") - { - @Override - public String buildLabel() - { - return super.buildLabel() + (tile != null && tile.getBlockType() != null ? tile.getBlockMetadata() : "-"); - } - }; - panel.add(meta_label); - - UpdatedLabel id_label = new UpdatedLabel("BLOCK: ") - { - @Override - public String buildLabel() - { - return super.buildLabel() + (tile != null && tile.getBlockType() != null ? tile.getBlockType() : "-"); - } - }; - panel.add(id_label); - - } - - /** Called each tick by the host of this GUI */ - public void update() - { - tick++; - if (tick >= Long.MAX_VALUE) - { - tick = 0; - } - - for (Component component : getComponents()) - { - if (component instanceof IUpdate) - { - ((IUpdate) component).update(); - } - } - } - - /** 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 double z() - { - return tile != null ? tile.zCoord : 0; - } - - @Override - public double x() - { - return tile != null ? tile.xCoord : 0; - } - - @Override - public double y() - { - return tile != null ? tile.yCoord : 0; - } - - @Override - public World world() - { - return tile != null ? tile.getWorldObj() : null; - } -} diff --git a/src/main/scala/resonantinduction/core/debug/FrameNodeDebug.java b/src/main/scala/resonantinduction/core/debug/FrameNodeDebug.java deleted file mode 100644 index 83aa2e035..000000000 --- a/src/main/scala/resonantinduction/core/debug/FrameNodeDebug.java +++ /dev/null @@ -1,109 +0,0 @@ -package resonantinduction.core.debug; - -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import codechicken.multipart.TMultiPart; -import universalelectricity.api.core.grid.INode; -import universalelectricity.api.core.grid.INodeProvider; - -/** @author Darkguardsman */ -@SuppressWarnings("serial") -public class FrameNodeDebug extends FrameDebug -{ - protected INodeProvider nodeProvider = null; - /** Linked node */ - protected INode node = null; - protected Class nodeClazz = null; - - /** Are we debugging a node */ - - public FrameNodeDebug(TileEntity tile, Class nodeClazz) - { - super(tile); - this.nodeClazz = nodeClazz; - } - - public FrameNodeDebug(INodeProvider node, Class nodeClazz) - { - super(); - this.nodeProvider = node; - this.nodeClazz = nodeClazz; - } - - public FrameNodeDebug(INode node) - { - super(); - this.node = node; - } - - /** Gets the node used for debug */ - public INode getNode() - { - if (tile instanceof INodeProvider && nodeClazz != null) - { - return ((INodeProvider) tile).getNode(nodeClazz, ForgeDirection.UNKNOWN); - } - else if (nodeProvider != null && nodeClazz != null) - { - return nodeProvider.getNode(nodeClazz, ForgeDirection.UNKNOWN); - } - return node; - } - - @Override - public double z() - { - if (nodeProvider instanceof TileEntity) - { - return ((TileEntity) nodeProvider).zCoord; - } - else if (nodeProvider instanceof TMultiPart) - { - return ((TMultiPart) nodeProvider).z(); - } - return super.z(); - } - - @Override - public double x() - { - if (nodeProvider instanceof TileEntity) - { - return ((TileEntity) nodeProvider).xCoord; - } - else if (nodeProvider instanceof TMultiPart) - { - return ((TMultiPart) nodeProvider).x(); - } - return super.x(); - } - - @Override - public double y() - { - if (nodeProvider instanceof TileEntity) - { - return ((TileEntity) nodeProvider).yCoord; - } - else if (nodeProvider instanceof TMultiPart) - { - return ((TMultiPart) nodeProvider).y(); - } - return super.y(); - } - - @Override - public World world() - { - if (nodeProvider instanceof TileEntity) - { - return ((TileEntity) nodeProvider).getWorldObj(); - } - else if (nodeProvider instanceof TMultiPart) - { - return ((TMultiPart) nodeProvider).world(); - } - return super.world(); - } -} diff --git a/src/main/scala/resonantinduction/core/debug/IDebug.java b/src/main/scala/resonantinduction/core/debug/IDebug.java deleted file mode 100644 index 839d85b0a..000000000 --- a/src/main/scala/resonantinduction/core/debug/IDebug.java +++ /dev/null @@ -1,9 +0,0 @@ -package resonantinduction.core.debug; - -/** Used to pass info to the debug GUI - * - * @author Darkguardsman */ -public interface IDebug -{ - -} diff --git a/src/main/scala/resonantinduction/core/debug/IUpdate.java b/src/main/scala/resonantinduction/core/debug/IUpdate.java deleted file mode 100644 index 389f6246a..000000000 --- a/src/main/scala/resonantinduction/core/debug/IUpdate.java +++ /dev/null @@ -1,9 +0,0 @@ -package resonantinduction.core.debug; - -/** Used by objects can update each tick - * - * @author Darkguardsman */ -public interface IUpdate -{ - public void update(); -} diff --git a/src/main/scala/resonantinduction/core/debug/UpdatePanel.java b/src/main/scala/resonantinduction/core/debug/UpdatePanel.java deleted file mode 100644 index eaf1f93b9..000000000 --- a/src/main/scala/resonantinduction/core/debug/UpdatePanel.java +++ /dev/null @@ -1,33 +0,0 @@ -package resonantinduction.core.debug; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Panel; - -import javax.swing.JPanel; - -/** @author Darkguardsman */ -@SuppressWarnings("serial") -public class UpdatePanel extends JPanel implements IUpdate -{ - public UpdatePanel() - { - } - - public UpdatePanel(BorderLayout borderLayout) - { - super(borderLayout); - } - - @Override - public void update() - { - for (Component component : getComponents()) - { - if (component instanceof IUpdate) - { - ((IUpdate) component).update(); - } - } - } -} diff --git a/src/main/scala/resonantinduction/core/debug/UpdatedLabel.java b/src/main/scala/resonantinduction/core/debug/UpdatedLabel.java deleted file mode 100644 index 788bbd2ac..000000000 --- a/src/main/scala/resonantinduction/core/debug/UpdatedLabel.java +++ /dev/null @@ -1,30 +0,0 @@ -package resonantinduction.core.debug; - -import java.awt.Label; - -/** Simple label with an update method - * - * @author Darkguardsman */ -@SuppressWarnings("serial") -public class UpdatedLabel extends Label implements IUpdate -{ - String start_string = "I Am a Label"; - - public UpdatedLabel(String start) - { - super(start); - this.start_string = start; - } - - @Override - public void update() - { - this.setText(buildLabel()); - } - - /** Recreates then returns the label's string value */ - public String buildLabel() - { - return start_string; - } -} diff --git a/src/main/scala/resonantinduction/core/handler/TextureHookHandler.java b/src/main/scala/resonantinduction/core/handler/TextureHookHandler.java deleted file mode 100644 index b47575656..000000000 --- a/src/main/scala/resonantinduction/core/handler/TextureHookHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -package resonantinduction.core.handler; - -import cpw.mods.fml.common.Mod; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import net.minecraftforge.client.event.TextureStitchEvent; -import resonant.lib.render.RenderUtility; -import resonantinduction.core.Reference; - -/** - * @author Calclavia - */ -public class TextureHookHandler -{ - @Mod.EventHandler - @SideOnly(Side.CLIENT) - public void preTextureHook(TextureStitchEvent.Pre event) - { - if (event.map.getTextureType() == 0) - { - RenderUtility.registerIcon(Reference.prefix() + "glyph_0", event.map); - RenderUtility.registerIcon(Reference.prefix() + "glyph_1", event.map); - RenderUtility.registerIcon(Reference.prefix() + "glyph_2", event.map); - RenderUtility.registerIcon(Reference.prefix() + "glyph_3", event.map); - - RenderUtility.registerIcon(Reference.prefix() + "mixture_flow", event.map); - RenderUtility.registerIcon(Reference.prefix() + "molten_flow", event.map); - RenderUtility.registerIcon(Reference.prefix() + "multimeter_screen", event.map); - RenderUtility.registerIcon(Reference.prefix() + "tankEdge", event.map); - } - } -} diff --git a/src/main/scala/resonantinduction/core/handler/TextureHookHandler.scala b/src/main/scala/resonantinduction/core/handler/TextureHookHandler.scala new file mode 100644 index 000000000..edded30b0 --- /dev/null +++ b/src/main/scala/resonantinduction/core/handler/TextureHookHandler.scala @@ -0,0 +1,31 @@ +package resonantinduction.core.handler + +import cpw.mods.fml.common.Mod +import cpw.mods.fml.relauncher.Side +import cpw.mods.fml.relauncher.SideOnly +import net.minecraftforge.client.event.TextureStitchEvent +import resonant.lib.render.RenderUtility +import resonantinduction.core.Reference + +/** Event handler for texture events + * @author Calclavia + */ +class TextureHookHandler +{ + @Mod.EventHandler + @SideOnly(Side.CLIENT) + def preTextureHook(event: TextureStitchEvent.Pre) + { + if (event.map.getTextureType == 0) + { + RenderUtility.registerIcon(Reference.prefix + "glyph_0", event.map) + RenderUtility.registerIcon(Reference.prefix + "glyph_1", event.map) + RenderUtility.registerIcon(Reference.prefix + "glyph_2", event.map) + RenderUtility.registerIcon(Reference.prefix + "glyph_3", event.map) + RenderUtility.registerIcon(Reference.prefix + "mixture_flow", event.map) + RenderUtility.registerIcon(Reference.prefix + "molten_flow", event.map) + RenderUtility.registerIcon(Reference.prefix + "multimeter_screen", event.map) + RenderUtility.registerIcon(Reference.prefix + "tankEdge", event.map) + } + } +} \ No newline at end of file diff --git a/src/main/scala/resonantinduction/core/interfaces/ICmdMachine.java b/src/main/scala/resonantinduction/core/interfaces/ICmdMachine.java deleted file mode 100644 index eceda9be1..000000000 --- a/src/main/scala/resonantinduction/core/interfaces/ICmdMachine.java +++ /dev/null @@ -1,21 +0,0 @@ -package resonantinduction.core.interfaces; - -import net.minecraft.command.ICommandSender; - -/** - * Used by machines that can be control by chat commands. Mainly for dev debug of the machine. - * - * @author robert - */ -public interface ICmdMachine -{ - /** - * Pre-check too see if this machine can even process the command - */ - public boolean canTakeCommand(ICommandSender sender, String[] args); - - /** - * Processing of the command - */ - public void processCommand(ICommandSender sender, String[] args); -} diff --git a/src/main/scala/resonantinduction/core/interfaces/IMechanicalNode.java b/src/main/scala/resonantinduction/core/interfaces/IMechanicalNode.java deleted file mode 100644 index 4f04e73d5..000000000 --- a/src/main/scala/resonantinduction/core/interfaces/IMechanicalNode.java +++ /dev/null @@ -1,56 +0,0 @@ -package resonantinduction.core.interfaces; - -import net.minecraftforge.common.util.ForgeDirection; -import universalelectricity.api.core.grid.INode; -import universalelectricity.core.transform.vector.IVectorWorld; - -/** - * Applied to any node that will act as a mechanical object - * - * @author Darkguardsman - */ -public interface IMechanicalNode extends INode, IVectorWorld -{ - /** - * Gets the radius of the gear in meters. Used to calculate torque and gear ratio for connections. - * Is not applied to direct face to face connections - * - * @param side - side of the machine - * @return radius in meters of the rotation peace - */ - public double getRadius(ForgeDirection side, IMechanicalNode with); - - /** - * The Rotational speed of the object - * - * @param side - side of the machine - * @return speed in meters per second - */ - public double getAngularSpeed(ForgeDirection side); - - /** - * Force applied from this side - * - * @param side - side of the machine - * @return force - */ - public double getForce(ForgeDirection side); - - /** - * Does the direction flip on this side for rotation - * - * @param side - side of the machine - * @return boolean, true = flipped, false = not - */ - public boolean inverseRotation(ForgeDirection side); - - /** - * Applies rotational force and velocity to this node increasing its current rotation value - * - * @param source - should not be null - * @param torque - force at an angle - * @param angularVelocity - speed of rotation - */ - public void apply(Object source, double torque, double angularVelocity); - -} diff --git a/src/main/scala/resonantinduction/core/interfaces/IMechanicalNode.scala b/src/main/scala/resonantinduction/core/interfaces/IMechanicalNode.scala new file mode 100644 index 000000000..9c511f310 --- /dev/null +++ b/src/main/scala/resonantinduction/core/interfaces/IMechanicalNode.scala @@ -0,0 +1,54 @@ +package resonantinduction.core.interfaces + +import net.minecraftforge.common.util.ForgeDirection +import universalelectricity.api.core.grid.INode +import universalelectricity.core.transform.vector.IVectorWorld + +/** + * Applied to any node that will act as a mechanical object + * + * @author Darkguardsman + */ +abstract trait IMechanicalNode extends INode with IVectorWorld { + /** + * Gets the radius of the gear in meters. Used to calculate torque and gear ratio for connections. + * Is not applied to direct face to face connections + * + * @param side - side of the machine + * @return radius in meters of the rotation peace + */ + def getRadius(side: ForgeDirection, `with`: IMechanicalNode): Double = 0.5 + + /** + * The Rotational speed of the object + * + * @param side - side of the machine + * @return speed in meters per second + */ + def getAngularSpeed(side: ForgeDirection): Double + + /** + * Force applied from this side + * + * @param side - side of the machine + * @return force + */ + def getForce(side: ForgeDirection): Double + + /** + * Does the direction flip on this side for rotation + * + * @param side - side of the machine + * @return boolean, true = flipped, false = not + */ + def inverseRotation(side: ForgeDirection): Boolean = false + + /** + * Applies rotational force and velocity to this node increasing its current rotation value + * + * @param source - should not be null + * @param torque - force at an angle + * @param angularVelocity - speed of rotation + */ + def apply(source: AnyRef, torque: Double, angularVelocity: Double) +} \ No newline at end of file diff --git a/src/main/scala/resonantinduction/mechanical/mech/DebugFrameMechanical.java b/src/main/scala/resonantinduction/mechanical/mech/DebugFrameMechanical.java index 7c53b8d20..376ecea09 100644 --- a/src/main/scala/resonantinduction/mechanical/mech/DebugFrameMechanical.java +++ b/src/main/scala/resonantinduction/mechanical/mech/DebugFrameMechanical.java @@ -12,9 +12,9 @@ import javax.swing.table.AbstractTableModel; import javax.swing.table.TableModel; import net.minecraftforge.common.util.ForgeDirection; -import resonantinduction.core.debug.FrameNodeDebug; -import resonantinduction.core.debug.UpdatePanel; -import resonantinduction.core.debug.UpdatedLabel; +import resonant.lib.debug.FrameNodeDebug; +import resonant.lib.debug.UpdatePanel; +import resonant.lib.debug.UpdatedLabel; import universalelectricity.api.core.grid.INode; import universalelectricity.api.core.grid.INodeProvider; diff --git a/src/main/scala/resonantinduction/mechanical/mech/process/grinder/TileGrindingWheel.java b/src/main/scala/resonantinduction/mechanical/mech/process/grinder/TileGrindingWheel.java index 0c67b2057..8707d9d1d 100644 --- a/src/main/scala/resonantinduction/mechanical/mech/process/grinder/TileGrindingWheel.java +++ b/src/main/scala/resonantinduction/mechanical/mech/process/grinder/TileGrindingWheel.java @@ -14,7 +14,7 @@ import resonant.api.recipe.RecipeResource; import resonantinduction.core.Reference; import resonantinduction.core.ResonantInduction; import resonant.content.factory.resources.RecipeType; -import resonantinduction.core.Timer; +import resonant.lib.utility.Timer; import universalelectricity.core.transform.region.Cuboid; import universalelectricity.core.transform.vector.Vector3; diff --git a/src/main/scala/resonantinduction/mechanical/mech/process/mixer/TileMixer.java b/src/main/scala/resonantinduction/mechanical/mech/process/mixer/TileMixer.java index dd4dc56e3..aff93ddda 100644 --- a/src/main/scala/resonantinduction/mechanical/mech/process/mixer/TileMixer.java +++ b/src/main/scala/resonantinduction/mechanical/mech/process/mixer/TileMixer.java @@ -18,7 +18,7 @@ import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.IFluidBlock; import resonant.api.recipe.MachineRecipes; import resonantinduction.core.Reference; -import resonantinduction.core.Timer; +import resonant.lib.utility.Timer; import resonant.content.factory.resources.block.BlockFluidMixture; import universalelectricity.api.core.grid.INode; import universalelectricity.core.transform.rotation.Quaternion;