Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
testCannonGUI now sends/receives cmdBlock-locations to fix sliding bug
also some debug code
  • Loading branch information
BlazingTwist committed Mar 21, 2021
1 parent 4de40e3 commit a105fd3
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 32 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/the_dark_jumper/cannontracer/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,13 @@ public void load() {

try {
List<String> 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) {
Expand Down
30 changes: 19 additions & 11 deletions src/main/java/the_dark_jumper/cannontracer/gui/TestCannonGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a105fd3

Please sign in to comment.