From a105fd3873f55f3fbb80e276f0cbb61971bb022a Mon Sep 17 00:00:00 2001 From: BlazingTwist Date: Sun, 21 Mar 2021 15:25:52 +0100 Subject: [PATCH] 1.1.0 testCannonGUI now sends/receives cmdBlock-locations to fix sliding bug also some debug code --- build.gradle | 4 +-- .../the_dark_jumper/cannontracer/Update.java | 2 +- .../configsaving/DataManager.java | 4 +++ .../cannontracer/gui/TestCannonGUI.java | 30 ++++++++++------ .../gui/guielements/ScrollableTable.java | 35 ++++++++++--------- src/main/resources/META-INF/mods.toml | 2 +- 6 files changed, 45 insertions(+), 32 deletions(-) diff --git a/build.gradle b/build.gradle index 16cc942..2611523 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' -version = '1.0.4' +version = '1.1.0' group = 'blazingtwist.cannontracer' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'cannontracer' @@ -108,7 +108,7 @@ dependencies { // The userdev artifact is a special name and will get all sorts of transformations applied to it. minecraft 'net.minecraftforge:forge:1.15.2-31.2.47' - provided name: 'JumperCommons', version: '1.0.4' + provided name: 'JumperCommons', version: '1.1.0' // You may put jars on which you depend on in ./libs or you may define them like so.. // compile "some.group:artifact:version:classifier" diff --git a/src/main/java/the_dark_jumper/cannontracer/Update.java b/src/main/java/the_dark_jumper/cannontracer/Update.java index 09702e5..1571194 100644 --- a/src/main/java/the_dark_jumper/cannontracer/Update.java +++ b/src/main/java/the_dark_jumper/cannontracer/Update.java @@ -18,7 +18,7 @@ public class Update { public static final String OUTDATED_MSG = "is outdated, please update using the button on the config screen!"; public static final String MOD_NAME = "CannonTracer "; - public static final String VERSION = "1.0.4"; + public static final String VERSION = "1.1.0"; public static void sendUpdateMessageIfNeeded() { if(checkUpdateAvailable()) { diff --git a/src/main/java/the_dark_jumper/cannontracer/configsaving/DataManager.java b/src/main/java/the_dark_jumper/cannontracer/configsaving/DataManager.java index aa3dc84..c46af15 100644 --- a/src/main/java/the_dark_jumper/cannontracer/configsaving/DataManager.java +++ b/src/main/java/the_dark_jumper/cannontracer/configsaving/DataManager.java @@ -191,9 +191,13 @@ public void load() { try { List lines = Files.readAllLines(Paths.get(configPathGNS.get())); + System.err.println("Found " + lines.size() + " lines at configPath: " + configPathGNS.get()); + StringBuilder jsonBuilder = new StringBuilder(); lines.forEach(line -> jsonBuilder.append(line).append("\n")); String json = jsonBuilder.toString(); + System.err.println("Collected lines to String: " + json); + ObjectMapper mapper = getObjectMapper(); this.tracerConfig = mapper.readValue(json, TracerConfig.class); } catch (Exception e) { diff --git a/src/main/java/the_dark_jumper/cannontracer/gui/TestCannonGUI.java b/src/main/java/the_dark_jumper/cannontracer/gui/TestCannonGUI.java index 7399fbf..6bdfe61 100644 --- a/src/main/java/the_dark_jumper/cannontracer/gui/TestCannonGUI.java +++ b/src/main/java/the_dark_jumper/cannontracer/gui/TestCannonGUI.java @@ -6,8 +6,10 @@ import java.util.ArrayList; import java.util.function.Consumer; import jumpercommons.GetterAndSetter; +import jumpercommons.SimpleLocation; import jumpercommons.TestCannon; import jumpercommons.TestCannonCharge; +import jumpercommons.TestCannonMessageObject; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.screen.Screen; @@ -61,6 +63,7 @@ public void onPressed(boolean pressed) { private boolean shouldClose = false; private boolean cancelCannonData = false; + private final SimpleLocation cmdLocation = new SimpleLocation(); private final TestCannon testCannon = new TestCannon(); public TestCannonGUI(GuiManager guiManager) { @@ -83,8 +86,8 @@ public void closeButtonPressed(boolean isPressed) { } } - private void cancelButtonPressed(boolean isPressed){ - if(isPressed){ + private void cancelButtonPressed(boolean isPressed) { + if (isPressed) { cancelCannonData = true; shouldClose = true; } @@ -220,15 +223,16 @@ private void createDoubleIncrementerFrame(FrameConfig config, FrameColors colors guiComponents.add(new ButtonFrame(this, "-", config.duplicate(), colors, incrementer::onDecrement)); } - public void open(String testCannonString) { + public void open(String messageObjectString) { try { + TestCannonMessageObject messageObject = objectMapper.readValue(messageObjectString, TestCannonMessageObject.class); TestCannon testCannon; - if (testCannonString.isEmpty()) { + if (messageObject.getTestCannonString().isEmpty()) { testCannon = new TestCannon(); } else { - testCannon = objectMapper.readValue(testCannonString, TestCannon.class); + testCannon = objectMapper.readValue(messageObject.getTestCannonString(), TestCannon.class); } - load(testCannon); + load(messageObject.getCmdLocation(), testCannon); generateScreenComponents(); Minecraft.getInstance().displayGuiScreen(this); } catch (JsonProcessingException e) { @@ -237,8 +241,9 @@ public void open(String testCannonString) { } } - public void load(TestCannon other) { - testCannon.load(other); + public void load(SimpleLocation location, TestCannon testCannon) { + this.cmdLocation.load(location); + this.testCannon.load(testCannon); } @Override @@ -338,9 +343,12 @@ public void onClose() { if (!cancelCannonData) { try { - String json = objectMapper.writeValueAsString(testCannon); - guiManager.main.serverChatListener.testCannonChannel.sendToServer(new StringPacket().setData(json)); - System.out.println("[TestCannonData]: " + json); + String testCannonJson = objectMapper.writeValueAsString(testCannon); + TestCannonMessageObject messageObject = new TestCannonMessageObject(cmdLocation, testCannonJson); + String message = objectMapper.writeValueAsString(messageObject); + + guiManager.main.serverChatListener.testCannonChannel.sendToServer(new StringPacket().setData(message)); + System.out.println("[TestCannonData]: " + message); } catch (JsonProcessingException e) { ChatUtils.messagePlayer("", "failed to build testCannonData!", false); e.printStackTrace(); diff --git a/src/main/java/the_dark_jumper/cannontracer/gui/guielements/ScrollableTable.java b/src/main/java/the_dark_jumper/cannontracer/gui/guielements/ScrollableTable.java index d1bde89..6601856 100644 --- a/src/main/java/the_dark_jumper/cannontracer/gui/guielements/ScrollableTable.java +++ b/src/main/java/the_dark_jumper/cannontracer/gui/guielements/ScrollableTable.java @@ -31,9 +31,9 @@ public class ScrollableTable implements IRenderableFrame, IClickableFrame, IKeyE @Override public boolean getHovered() {return false;} @Override public void setHovered(boolean hovered) {} - private double horizontalScrollFactor = 1; + private float horizontalScrollFactor = 1; private ScrollbarFrame horizontalScrollbar = null; - private double verticalScrollFactor = 1; + private float verticalScrollFactor = 1; private ScrollbarFrame verticalScrollbar = null; private FormatData uniformColFormat = null; private FormatData uniformRowFormat = null; @@ -109,11 +109,11 @@ public void updateScrollbarRanges() { FrameConfig lastConfig = getCellConfig(getAmountOfColumns() - 1, rows.size() - 1); if(horizontalScrollbar != null) { horizontalScrollbar.setScrollbarSize(100d / lastConfig.xEnd); - horizontalScrollFactor = lastConfig.xEnd / 100d; + horizontalScrollFactor = lastConfig.xEnd / 100f; } if(verticalScrollbar != null) { verticalScrollbar.setScrollbarSize(100d / lastConfig.yEnd); - verticalScrollFactor = lastConfig.yEnd / 100d; + verticalScrollFactor = lastConfig.yEnd / 100f; } } @@ -391,6 +391,7 @@ public void doFills(float x1, float y1, float x2, float y2, float borderPx) { } public void renderTableFrame(IRenderableFrame frame, float perceivedX1, float perceivedY1, float perceivedX2, float perceivedY2, int guiScale, FrameConfig frameConfig, boolean allowOutOfBounds) { + float epsilon = 0.01f; float width = perceivedX2 - perceivedX1; float height = perceivedY2 - perceivedY1; float x1 = getPercentValue(width, frameConfig.x) + perceivedX1; @@ -403,21 +404,21 @@ public void renderTableFrame(IRenderableFrame frame, float perceivedX1, float pe frame.drawTexts(x1, y1, x2, y2); return; } - double scrollViewStartX = perceivedX1; - double scrollViewEndX = perceivedX2; - double scrollViewStartY = perceivedY1; - double scrollViewEndY = perceivedY2; + float scrollViewStartX = perceivedX1; + float scrollViewEndX = perceivedX2; + float scrollViewStartY = perceivedY1; + float scrollViewEndY = perceivedY2; if(horizontalScrollbar != null) { double factor = width * horizontalScrollFactor; double scrollpos = horizontalScrollbar.scrollbarPos * (1 - horizontalScrollbar.getScrollbarSize()); - scrollViewStartX = perceivedX1 + (factor * scrollpos); - scrollViewEndX = perceivedX1 + (factor * (scrollpos + horizontalScrollbar.getScrollbarSize())); + scrollViewStartX = (float)(perceivedX1 + (factor * scrollpos)); + scrollViewEndX = (float)(perceivedX1 + (factor * (scrollpos + horizontalScrollbar.getScrollbarSize()))); } if(verticalScrollbar != null) { double factor = height * verticalScrollFactor; double scrollpos = verticalScrollbar.scrollbarPos * (1 - verticalScrollbar.getScrollbarSize()); - scrollViewStartY = perceivedY1 + (factor * scrollpos); - scrollViewEndY = perceivedY1 + (factor * (scrollpos + verticalScrollbar.getScrollbarSize())); + scrollViewStartY = (float)(perceivedY1 + (factor * scrollpos)); + scrollViewEndY = (float)(perceivedY1 + (factor * (scrollpos + verticalScrollbar.getScrollbarSize()))); } /*double scrollViewStartX = horizontalScrollbar.scrollbarPos * (1 - horizontalScrollbar.getScrollbarSize()); @@ -428,16 +429,16 @@ public void renderTableFrame(IRenderableFrame frame, float perceivedX1, float pe scrollViewEndX = (scrollViewEndX * width * horizontalScrollFactor) + perceivedX1; scrollViewStartY = (scrollViewStartY * height * verticalScrollFactor) + perceivedY1; scrollViewEndY = (scrollViewEndY * height * verticalScrollFactor) + perceivedY1;*/ - if(x1 < scrollViewStartX || x2 > scrollViewEndX || y1 < scrollViewStartY || y2 > scrollViewEndY) { + if((x1 + epsilon) < scrollViewStartX || (x2 - epsilon) > scrollViewEndX || (y1 + epsilon) < scrollViewStartY || (y2 - epsilon) > scrollViewEndY) { //frame would be outside of table //System.out.println("horizscrollbarpos: "+horizontalScrollbar.scrollbarPos+" | horizscrollbarsize: "+horizontalScrollbar.getScrollbarSize()+" | horizscrollfactor: "+horizontalScrollFactor+" | vertscrollbarpos: "+verticalScrollbar.scrollbarPos+" | vertscrollbarsize: "+verticalScrollbar.getScrollbarSize()+" | vertscrollfactor: "+verticalScrollFactor+" | width: "+width+" | height: "+height); //System.out.println("rendertableframe: "+x1+" | "+scrollViewStartX+" | "+x2+" | "+scrollViewEndX+" | "+y1+" | "+scrollViewStartY+" | "+y2+" | "+scrollViewEndY); return; } - x1 = (int)(x1 - scrollViewStartX + perceivedX1); - x2 = (int)(x2 - scrollViewStartX + perceivedX1); - y1 = (int)(y1 - scrollViewStartY + perceivedY1); - y2 = (int)(y2 - scrollViewStartY + perceivedY1); + x1 = (x1 - scrollViewStartX + perceivedX1); + x2 = (x2 - scrollViewStartX + perceivedX1); + y1 = (y1 - scrollViewStartY + perceivedY1); + y2 = (y2 - scrollViewStartY + perceivedY1); frame.doFills(x1, y1, x2, y2, frameConfig.borderThickness / guiScale); frame.drawTexts(x1, y1, x2, y2); } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 82d3413..de7bf5c 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -4,7 +4,7 @@ loaderVersion="[31,)" # A list of mods - how many allowed here is determined by the individual mod loader [[mods]] modId="cannontracer" -version="1.0.4" +version="1.1.0" displayName="Cannon Tracer" credits="Thanks for this mod goes to my no longer existing will to live" authors="The_Dark_Jumper"