From 70a55dce59802b8acb6874a2f6dd34ffb3ac33f0 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 30 Dec 2017 11:03:09 -0500 Subject: [PATCH] Added features to Hologram hardware - Fixes #63 and #67 --- .../java/net/simon987/cubotplugin/Cubot.java | 10 ++++++---- .../net/simon987/cubotplugin/CubotHologram.java | 17 +++++++++++++++++ .../java/net/simon987/server/assembly/Util.java | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java index 1526c28..bc9f07e 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java @@ -13,7 +13,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit { private static final char MAP_INFO = 0x0080; public static final int ID = 1; - private char hologram = 0; + private int hologram = 0; private String hologramString = ""; private HologramMode hologramMode = HologramMode.CLEARED; @@ -88,7 +88,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit { json.put("heldItem", heldItem); json.put("hp", hp); json.put("action", lastAction.ordinal()); - json.put("holo", (int) hologram); + json.put("holo", hologram); json.put("holoStr", hologramString); json.put("holoMode", lastHologramMode.ordinal()); json.put("energy", energy); @@ -158,7 +158,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit { return currentAction; } - public void setHologram(char hologram) { + public void setHologram(int hologram) { this.hologram = hologram; } @@ -223,7 +223,9 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit { public enum HologramMode { CLEARED, HEX, - STRING + STRING, + DEC, + COLOR } @Override diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotHologram.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotHologram.java index 7e07839..9729311 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotHologram.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotHologram.java @@ -20,6 +20,8 @@ public class CubotHologram extends CpuHardware { private static final int CLEAR = 0; private static final int DISPLAY_HEX = 1; private static final int DISPLAY_STRING = 2; + private static final int DISPLAY_DEC = 3; + private static final int DISPLAY_COLOR = 4; private static final int STR_MAX_LEN = 8; @@ -57,6 +59,21 @@ public class CubotHologram extends CpuHardware { cubot.setHologramString(holoString.toString()); cubot.setHologramMode(Cubot.HologramMode.STRING); + } else if (a == DISPLAY_DEC) { + //Display decimal number + char b = getCpu().getRegisterSet().getRegister("B").getValue(); + cubot.setHologram(b); + cubot.setHologramMode(Cubot.HologramMode.DEC); + + } else if (a == DISPLAY_COLOR) { + + if (cubot.spendEnergy(4)) { + int b = getCpu().getRegisterSet().getRegister("B").getValue(); + int c = getCpu().getRegisterSet().getRegister("C").getValue(); + + cubot.setHologramMode(Cubot.HologramMode.COLOR); + cubot.setHologram((c | (b << 16)) & 0x00FFFFFF); //B:C, ignore first byte + } } } diff --git a/Server/src/main/java/net/simon987/server/assembly/Util.java b/Server/src/main/java/net/simon987/server/assembly/Util.java index cffafa2..437033a 100755 --- a/Server/src/main/java/net/simon987/server/assembly/Util.java +++ b/Server/src/main/java/net/simon987/server/assembly/Util.java @@ -42,7 +42,7 @@ public class Util { } public static String toHex(int a) { - return String.format("%04X ", uShort(a)); + return String.format("%04X ", a); } public static String toHex(byte[] byteArray) {