Skip to content

Commit a105fd3

Browse files
committed
1.1.0
testCannonGUI now sends/receives cmdBlock-locations to fix sliding bug also some debug code
1 parent 4de40e3 commit a105fd3

File tree

6 files changed

+45
-32
lines changed

6 files changed

+45
-32
lines changed

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
1313
apply plugin: 'eclipse'
1414
apply plugin: 'maven-publish'
1515

16-
version = '1.0.4'
16+
version = '1.1.0'
1717
group = 'blazingtwist.cannontracer' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
1818
archivesBaseName = 'cannontracer'
1919

@@ -108,7 +108,7 @@ dependencies {
108108
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
109109
minecraft 'net.minecraftforge:forge:1.15.2-31.2.47'
110110

111-
provided name: 'JumperCommons', version: '1.0.4'
111+
provided name: 'JumperCommons', version: '1.1.0'
112112

113113
// You may put jars on which you depend on in ./libs or you may define them like so..
114114
// compile "some.group:artifact:version:classifier"

src/main/java/the_dark_jumper/cannontracer/Update.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class Update {
1818
public static final String OUTDATED_MSG = "is outdated, please update using the button on the config screen!";
1919
public static final String MOD_NAME = "CannonTracer ";
2020

21-
public static final String VERSION = "1.0.4";
21+
public static final String VERSION = "1.1.0";
2222

2323
public static void sendUpdateMessageIfNeeded() {
2424
if(checkUpdateAvailable()) {

src/main/java/the_dark_jumper/cannontracer/configsaving/DataManager.java

+4
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,13 @@ public void load() {
191191

192192
try {
193193
List<String> lines = Files.readAllLines(Paths.get(configPathGNS.get()));
194+
System.err.println("Found " + lines.size() + " lines at configPath: " + configPathGNS.get());
195+
194196
StringBuilder jsonBuilder = new StringBuilder();
195197
lines.forEach(line -> jsonBuilder.append(line).append("\n"));
196198
String json = jsonBuilder.toString();
199+
System.err.println("Collected lines to String: " + json);
200+
197201
ObjectMapper mapper = getObjectMapper();
198202
this.tracerConfig = mapper.readValue(json, TracerConfig.class);
199203
} catch (Exception e) {

src/main/java/the_dark_jumper/cannontracer/gui/TestCannonGUI.java

+19-11
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
import java.util.ArrayList;
77
import java.util.function.Consumer;
88
import jumpercommons.GetterAndSetter;
9+
import jumpercommons.SimpleLocation;
910
import jumpercommons.TestCannon;
1011
import jumpercommons.TestCannonCharge;
12+
import jumpercommons.TestCannonMessageObject;
1113
import net.minecraft.client.Minecraft;
1214
import net.minecraft.client.gui.FontRenderer;
1315
import net.minecraft.client.gui.screen.Screen;
@@ -61,6 +63,7 @@ public void onPressed(boolean pressed) {
6163
private boolean shouldClose = false;
6264
private boolean cancelCannonData = false;
6365

66+
private final SimpleLocation cmdLocation = new SimpleLocation();
6467
private final TestCannon testCannon = new TestCannon();
6568

6669
public TestCannonGUI(GuiManager guiManager) {
@@ -83,8 +86,8 @@ public void closeButtonPressed(boolean isPressed) {
8386
}
8487
}
8588

86-
private void cancelButtonPressed(boolean isPressed){
87-
if(isPressed){
89+
private void cancelButtonPressed(boolean isPressed) {
90+
if (isPressed) {
8891
cancelCannonData = true;
8992
shouldClose = true;
9093
}
@@ -220,15 +223,16 @@ private void createDoubleIncrementerFrame(FrameConfig config, FrameColors colors
220223
guiComponents.add(new ButtonFrame(this, "-", config.duplicate(), colors, incrementer::onDecrement));
221224
}
222225

223-
public void open(String testCannonString) {
226+
public void open(String messageObjectString) {
224227
try {
228+
TestCannonMessageObject messageObject = objectMapper.readValue(messageObjectString, TestCannonMessageObject.class);
225229
TestCannon testCannon;
226-
if (testCannonString.isEmpty()) {
230+
if (messageObject.getTestCannonString().isEmpty()) {
227231
testCannon = new TestCannon();
228232
} else {
229-
testCannon = objectMapper.readValue(testCannonString, TestCannon.class);
233+
testCannon = objectMapper.readValue(messageObject.getTestCannonString(), TestCannon.class);
230234
}
231-
load(testCannon);
235+
load(messageObject.getCmdLocation(), testCannon);
232236
generateScreenComponents();
233237
Minecraft.getInstance().displayGuiScreen(this);
234238
} catch (JsonProcessingException e) {
@@ -237,8 +241,9 @@ public void open(String testCannonString) {
237241
}
238242
}
239243

240-
public void load(TestCannon other) {
241-
testCannon.load(other);
244+
public void load(SimpleLocation location, TestCannon testCannon) {
245+
this.cmdLocation.load(location);
246+
this.testCannon.load(testCannon);
242247
}
243248

244249
@Override
@@ -338,9 +343,12 @@ public void onClose() {
338343

339344
if (!cancelCannonData) {
340345
try {
341-
String json = objectMapper.writeValueAsString(testCannon);
342-
guiManager.main.serverChatListener.testCannonChannel.sendToServer(new StringPacket().setData(json));
343-
System.out.println("[TestCannonData]: " + json);
346+
String testCannonJson = objectMapper.writeValueAsString(testCannon);
347+
TestCannonMessageObject messageObject = new TestCannonMessageObject(cmdLocation, testCannonJson);
348+
String message = objectMapper.writeValueAsString(messageObject);
349+
350+
guiManager.main.serverChatListener.testCannonChannel.sendToServer(new StringPacket().setData(message));
351+
System.out.println("[TestCannonData]: " + message);
344352
} catch (JsonProcessingException e) {
345353
ChatUtils.messagePlayer("", "failed to build testCannonData!", false);
346354
e.printStackTrace();

src/main/java/the_dark_jumper/cannontracer/gui/guielements/ScrollableTable.java

+18-17
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public class ScrollableTable implements IRenderableFrame, IClickableFrame, IKeyE
3131
@Override public boolean getHovered() {return false;}
3232
@Override public void setHovered(boolean hovered) {}
3333

34-
private double horizontalScrollFactor = 1;
34+
private float horizontalScrollFactor = 1;
3535
private ScrollbarFrame horizontalScrollbar = null;
36-
private double verticalScrollFactor = 1;
36+
private float verticalScrollFactor = 1;
3737
private ScrollbarFrame verticalScrollbar = null;
3838
private FormatData uniformColFormat = null;
3939
private FormatData uniformRowFormat = null;
@@ -109,11 +109,11 @@ public void updateScrollbarRanges() {
109109
FrameConfig lastConfig = getCellConfig(getAmountOfColumns() - 1, rows.size() - 1);
110110
if(horizontalScrollbar != null) {
111111
horizontalScrollbar.setScrollbarSize(100d / lastConfig.xEnd);
112-
horizontalScrollFactor = lastConfig.xEnd / 100d;
112+
horizontalScrollFactor = lastConfig.xEnd / 100f;
113113
}
114114
if(verticalScrollbar != null) {
115115
verticalScrollbar.setScrollbarSize(100d / lastConfig.yEnd);
116-
verticalScrollFactor = lastConfig.yEnd / 100d;
116+
verticalScrollFactor = lastConfig.yEnd / 100f;
117117
}
118118
}
119119

@@ -391,6 +391,7 @@ public void doFills(float x1, float y1, float x2, float y2, float borderPx) {
391391
}
392392

393393
public void renderTableFrame(IRenderableFrame frame, float perceivedX1, float perceivedY1, float perceivedX2, float perceivedY2, int guiScale, FrameConfig frameConfig, boolean allowOutOfBounds) {
394+
float epsilon = 0.01f;
394395
float width = perceivedX2 - perceivedX1;
395396
float height = perceivedY2 - perceivedY1;
396397
float x1 = getPercentValue(width, frameConfig.x) + perceivedX1;
@@ -403,21 +404,21 @@ public void renderTableFrame(IRenderableFrame frame, float perceivedX1, float pe
403404
frame.drawTexts(x1, y1, x2, y2);
404405
return;
405406
}
406-
double scrollViewStartX = perceivedX1;
407-
double scrollViewEndX = perceivedX2;
408-
double scrollViewStartY = perceivedY1;
409-
double scrollViewEndY = perceivedY2;
407+
float scrollViewStartX = perceivedX1;
408+
float scrollViewEndX = perceivedX2;
409+
float scrollViewStartY = perceivedY1;
410+
float scrollViewEndY = perceivedY2;
410411
if(horizontalScrollbar != null) {
411412
double factor = width * horizontalScrollFactor;
412413
double scrollpos = horizontalScrollbar.scrollbarPos * (1 - horizontalScrollbar.getScrollbarSize());
413-
scrollViewStartX = perceivedX1 + (factor * scrollpos);
414-
scrollViewEndX = perceivedX1 + (factor * (scrollpos + horizontalScrollbar.getScrollbarSize()));
414+
scrollViewStartX = (float)(perceivedX1 + (factor * scrollpos));
415+
scrollViewEndX = (float)(perceivedX1 + (factor * (scrollpos + horizontalScrollbar.getScrollbarSize())));
415416
}
416417
if(verticalScrollbar != null) {
417418
double factor = height * verticalScrollFactor;
418419
double scrollpos = verticalScrollbar.scrollbarPos * (1 - verticalScrollbar.getScrollbarSize());
419-
scrollViewStartY = perceivedY1 + (factor * scrollpos);
420-
scrollViewEndY = perceivedY1 + (factor * (scrollpos + verticalScrollbar.getScrollbarSize()));
420+
scrollViewStartY = (float)(perceivedY1 + (factor * scrollpos));
421+
scrollViewEndY = (float)(perceivedY1 + (factor * (scrollpos + verticalScrollbar.getScrollbarSize())));
421422
}
422423

423424
/*double scrollViewStartX = horizontalScrollbar.scrollbarPos * (1 - horizontalScrollbar.getScrollbarSize());
@@ -428,16 +429,16 @@ public void renderTableFrame(IRenderableFrame frame, float perceivedX1, float pe
428429
scrollViewEndX = (scrollViewEndX * width * horizontalScrollFactor) + perceivedX1;
429430
scrollViewStartY = (scrollViewStartY * height * verticalScrollFactor) + perceivedY1;
430431
scrollViewEndY = (scrollViewEndY * height * verticalScrollFactor) + perceivedY1;*/
431-
if(x1 < scrollViewStartX || x2 > scrollViewEndX || y1 < scrollViewStartY || y2 > scrollViewEndY) {
432+
if((x1 + epsilon) < scrollViewStartX || (x2 - epsilon) > scrollViewEndX || (y1 + epsilon) < scrollViewStartY || (y2 - epsilon) > scrollViewEndY) {
432433
//frame would be outside of table
433434
//System.out.println("horizscrollbarpos: "+horizontalScrollbar.scrollbarPos+" | horizscrollbarsize: "+horizontalScrollbar.getScrollbarSize()+" | horizscrollfactor: "+horizontalScrollFactor+" | vertscrollbarpos: "+verticalScrollbar.scrollbarPos+" | vertscrollbarsize: "+verticalScrollbar.getScrollbarSize()+" | vertscrollfactor: "+verticalScrollFactor+" | width: "+width+" | height: "+height);
434435
//System.out.println("rendertableframe: "+x1+" | "+scrollViewStartX+" | "+x2+" | "+scrollViewEndX+" | "+y1+" | "+scrollViewStartY+" | "+y2+" | "+scrollViewEndY);
435436
return;
436437
}
437-
x1 = (int)(x1 - scrollViewStartX + perceivedX1);
438-
x2 = (int)(x2 - scrollViewStartX + perceivedX1);
439-
y1 = (int)(y1 - scrollViewStartY + perceivedY1);
440-
y2 = (int)(y2 - scrollViewStartY + perceivedY1);
438+
x1 = (x1 - scrollViewStartX + perceivedX1);
439+
x2 = (x2 - scrollViewStartX + perceivedX1);
440+
y1 = (y1 - scrollViewStartY + perceivedY1);
441+
y2 = (y2 - scrollViewStartY + perceivedY1);
441442
frame.doFills(x1, y1, x2, y2, frameConfig.borderThickness / guiScale);
442443
frame.drawTexts(x1, y1, x2, y2);
443444
}

src/main/resources/META-INF/mods.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ loaderVersion="[31,)"
44
# A list of mods - how many allowed here is determined by the individual mod loader
55
[[mods]]
66
modId="cannontracer"
7-
version="1.0.4"
7+
version="1.1.0"
88
displayName="Cannon Tracer"
99
credits="Thanks for this mod goes to my no longer existing will to live"
1010
authors="The_Dark_Jumper"

0 commit comments

Comments
 (0)