forked from ChomeNS/chipmunkmod
Fix some gui stuff
This commit is contained in:
parent
de55b8208e
commit
deeb89bb45
5 changed files with 18 additions and 9 deletions
|
@ -3,6 +3,10 @@ plugins {
|
||||||
id 'maven-publish'
|
id 'maven-publish'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loom {
|
||||||
|
accessWidenerPath = file("src/main/resources/chipmunkmod.accesswidener")
|
||||||
|
}
|
||||||
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_21
|
sourceCompatibility = JavaVersion.VERSION_21
|
||||||
targetCompatibility = JavaVersion.VERSION_21
|
targetCompatibility = JavaVersion.VERSION_21
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package land.chipmunk.chipmunkmod.testclient.gui;
|
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.Option;
|
||||||
import land.chipmunk.chipmunkmod.testclient.gui.components.Module;
|
import land.chipmunk.chipmunkmod.testclient.gui.components.Module;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.DrawContext;
|
||||||
|
import net.minecraft.client.gui.Drawable;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
|
||||||
|
@ -23,6 +25,7 @@ public class OptionsScreen extends Screen {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
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);
|
context.fill(40, 40, width-40, height-40, backgroundColor);
|
||||||
int textWidth = MinecraftClient.getInstance().textRenderer.getWidth(getTitle());
|
int textWidth = MinecraftClient.getInstance().textRenderer.getWidth(getTitle());
|
||||||
AtomicInteger lineY = new AtomicInteger(70);
|
AtomicInteger lineY = new AtomicInteger(70);
|
||||||
|
@ -39,7 +42,9 @@ public class OptionsScreen extends Screen {
|
||||||
option.widget.setX(width - 50 - option.widget.getWidth());
|
option.widget.setX(width - 50 - option.widget.getWidth());
|
||||||
option.widget.setY(textY.get() - ((option.widget.getHeight()-9)/2));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import java.lang.reflect.Field;
|
||||||
public class BooleanCheckboxOption extends Option<Boolean> {
|
public class BooleanCheckboxOption extends Option<Boolean> {
|
||||||
private RunnableWithParameter<Boolean> onPress = value -> {};
|
private RunnableWithParameter<Boolean> onPress = value -> {};
|
||||||
|
|
||||||
CheckboxWidget checkboxWidget = CheckboxWidget.builder(Text.empty(), MinecraftClient.getInstance().textRenderer)
|
CheckboxWidget checkboxWidget = CheckboxWidget.builder(Text.empty(), MinecraftClient.getInstance().textRenderer)
|
||||||
.pos(0, 0)
|
.pos(0, 0)
|
||||||
.maxWidth(20)
|
.maxWidth(20)
|
||||||
.checked(optionValue)
|
.checked(optionValue)
|
||||||
|
@ -19,12 +19,7 @@ public class BooleanCheckboxOption extends Option<Boolean> {
|
||||||
optionValue = !optionValue;
|
optionValue = !optionValue;
|
||||||
onPress.run(optionValue);
|
onPress.run(optionValue);
|
||||||
|
|
||||||
// equivalent of `checked = optionValue`, but checked is private so i have to use this :(
|
checkbox.checked = optionValue;
|
||||||
try {
|
|
||||||
Field checkedField = CheckboxWidget.class.getDeclaredField("checked");
|
|
||||||
checkedField.setAccessible(true);
|
|
||||||
checkedField.set(this, optionValue);
|
|
||||||
} catch(NoSuchFieldException | IllegalAccessException e) {e.printStackTrace();}
|
|
||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
3
src/main/resources/chipmunkmod.accesswidener
Normal file
3
src/main/resources/chipmunkmod.accesswidener
Normal file
|
@ -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
|
|
@ -3,6 +3,8 @@
|
||||||
"id": "chipmunkmod",
|
"id": "chipmunkmod",
|
||||||
"version": "${version}",
|
"version": "${version}",
|
||||||
|
|
||||||
|
"accessWidener" : "chipmunkmod.accesswidener",
|
||||||
|
|
||||||
"name": "ChipmunkMod (Blackilykat's fork)",
|
"name": "ChipmunkMod (Blackilykat's fork)",
|
||||||
"description": "My fork of ChipmunkMod",
|
"description": "My fork of ChipmunkMod",
|
||||||
"authors": [
|
"authors": [
|
||||||
|
|
Loading…
Reference in a new issue