diff --git a/build.gradle b/build.gradle index 7dae85c..2c113d4 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,10 @@ plugins { id 'maven-publish' } +loom { + accessWidenerPath = file("src/main/resources/chipmunkmod.accesswidener") +} + sourceCompatibility = JavaVersion.VERSION_21 targetCompatibility = JavaVersion.VERSION_21 diff --git a/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/OptionsScreen.java b/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/OptionsScreen.java index 1d8dbd8..2320fc4 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/OptionsScreen.java +++ b/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/OptionsScreen.java @@ -1,9 +1,11 @@ package land.chipmunk.chipmunkmod.testclient.gui; +import com.mojang.blaze3d.systems.RenderSystem; import land.chipmunk.chipmunkmod.testclient.gui.components.Option; import land.chipmunk.chipmunkmod.testclient.gui.components.Module; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.Drawable; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.util.math.MatrixStack; @@ -23,6 +25,7 @@ public class OptionsScreen extends Screen { @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { + renderBackground(context, mouseX, mouseY, delta); context.fill(40, 40, width-40, height-40, backgroundColor); int textWidth = MinecraftClient.getInstance().textRenderer.getWidth(getTitle()); AtomicInteger lineY = new AtomicInteger(70); @@ -39,7 +42,9 @@ public class OptionsScreen extends Screen { option.widget.setX(width - 50 - option.widget.getWidth()); option.widget.setY(textY.get() - ((option.widget.getHeight()-9)/2)); } - super.render(context, mouseX, mouseY, delta); - + // had to use access widener cause minecraft is silly and wont lemme separate background and foreground manually + for (Drawable drawable : this.drawables) { + drawable.render(context, mouseX, mouseY, delta); + } } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/BooleanCheckboxOption.java b/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/BooleanCheckboxOption.java index 3291bf0..0df540d 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/BooleanCheckboxOption.java +++ b/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/BooleanCheckboxOption.java @@ -11,7 +11,7 @@ import java.lang.reflect.Field; public class BooleanCheckboxOption extends Option { private RunnableWithParameter onPress = value -> {}; - CheckboxWidget checkboxWidget = CheckboxWidget.builder(Text.empty(), MinecraftClient.getInstance().textRenderer) + CheckboxWidget checkboxWidget = CheckboxWidget.builder(Text.empty(), MinecraftClient.getInstance().textRenderer) .pos(0, 0) .maxWidth(20) .checked(optionValue) @@ -19,12 +19,7 @@ public class BooleanCheckboxOption extends Option { optionValue = !optionValue; onPress.run(optionValue); - // equivalent of `checked = optionValue`, but checked is private so i have to use this :( - try { - Field checkedField = CheckboxWidget.class.getDeclaredField("checked"); - checkedField.setAccessible(true); - checkedField.set(this, optionValue); - } catch(NoSuchFieldException | IllegalAccessException e) {e.printStackTrace();} + checkbox.checked = optionValue; }) .build(); diff --git a/src/main/resources/chipmunkmod.accesswidener b/src/main/resources/chipmunkmod.accesswidener new file mode 100644 index 0000000..dde8db5 --- /dev/null +++ b/src/main/resources/chipmunkmod.accesswidener @@ -0,0 +1,3 @@ +accessWidener v2 named +accessible field net/minecraft/client/gui/screen/Screen drawables Ljava/util/List; +accessible field net/minecraft/client/gui/widget/CheckboxWidget checked Z \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 0f6b0d6..fa2f8e1 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -3,6 +3,8 @@ "id": "chipmunkmod", "version": "${version}", + "accessWidener" : "chipmunkmod.accesswidener", + "name": "ChipmunkMod (Blackilykat's fork)", "description": "My fork of ChipmunkMod", "authors": [