Compare commits

..

No commits in common. "main" and "v1.0.0" have entirely different histories.
main ... v1.0.0

27 changed files with 128 additions and 275 deletions

1
.gitignore vendored
View File

@ -1,6 +1,5 @@
# User-specific stuff # User-specific stuff
.idea/ .idea/
remappedSrc/
*.iml *.iml
*.ipr *.ipr

View File

@ -1,15 +1,11 @@
plugins { plugins {
id 'fabric-loom' version '1.7-SNAPSHOT' id 'fabric-loom' version '1.1-SNAPSHOT'
id 'maven-publish' id 'maven-publish'
} }
version = project.mod_version version = project.mod_version
group = project.maven_group group = project.maven_group
base {
archivesName = project.archives_base_name
}
repositories { repositories {
// Add repositories to retrieve artifacts from in here. // Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because // You should only use this when depending on other mods because
@ -22,17 +18,6 @@ repositories {
} }
} }
loom {
splitEnvironmentSourceSets()
mods {
"cmods" {
sourceSet sourceSets.client
sourceSet sourceSets.main
}
}
}
dependencies { dependencies {
// To change the versions see the gradle.properties file // To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}" minecraft "com.mojang:minecraft:${project.minecraft_version}"
@ -46,37 +31,47 @@ dependencies {
processResources { processResources {
inputs.property "version", project.version inputs.property "version", project.version
filteringCharset "UTF-8"
filesMatching("fabric.mod.json") { filesMatching("fabric.mod.json") {
expand "version": project.version expand "version": project.version
} }
} }
def targetJavaVersion = 17
tasks.withType(JavaCompile).configureEach { tasks.withType(JavaCompile).configureEach {
it.options.release = 21 // ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
// If Javadoc is generated, this must be specified in that task too.
it.options.encoding = "UTF-8"
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
it.options.release = targetJavaVersion
}
} }
java { java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
archivesBaseName = project.archives_base_name
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present. // if it is present.
// If you remove this line, sources will not be generated. // If you remove this line, sources will not be generated.
withSourcesJar() withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
} }
jar { jar {
from("LICENSE") { from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}"} rename { "${it}_${project.archivesBaseName}" }
} }
} }
// configure the maven publication // configure the maven publication
publishing { publishing {
publications { publications {
create("mavenJava", MavenPublication) { mavenJava(MavenPublication) {
artifactId = project.archives_base_name
from components.java from components.java
} }
} }
@ -89,91 +84,3 @@ publishing {
// retrieving dependencies. // retrieving dependencies.
} }
} }
//plugins {
// id 'fabric-loom' version '1.7-SNAPSHOT'
// id 'maven-publish'
//}
//
//version = project.mod_version
//group = project.maven_group
//
//repositories {
// // Add repositories to retrieve artifacts from in here.
// // You should only use this when depending on other mods because
// // Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// // See https://docs.gradle.org/current/userguide/declaring_repositories.html
// // for more information about repositories.
// maven {
// name = 'TerraformersMC'
// url = 'https://maven.terraformersmc.com/releases'
// }
//}
//
//dependencies {
// // To change the versions see the gradle.properties file
// minecraft "com.mojang:minecraft:${project.minecraft_version}"
// mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
// modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
//
// // Fabric API. This is technically optional, but you probably want it anyway.
// modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// modCompileOnly "com.terraformersmc:modmenu:4.1.1"
//}
//
//processResources {
// inputs.property "version", project.version
// filteringCharset "UTF-8"
//
// filesMatching("fabric.mod.json") {
// expand "version": project.version
// }
//}
//
//def targetJavaVersion = 21
//tasks.withType(JavaCompile).configureEach {
// // ensure that the encoding is set to UTF-8, no matter what the system default is
// // this fixes some edge cases with special characters not displaying correctly
// // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
// // If Javadoc is generated, this must be specified in that task too.
// it.options.encoding = "UTF-8"
// if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
// it.options.release = targetJavaVersion
// }
//}
//
//java {
// def javaVersion = JavaVersion.toVersion(targetJavaVersion)
// if (JavaVersion.current() < javaVersion) {
// toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
// }
// archivesBaseName = project.archives_base_name
// // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// // if it is present.
// // If you remove this line, sources will not be generated.
// withSourcesJar()
//}
//
//jar {
// from("LICENSE") {
// rename { "${it}_${project.archivesBaseName}" }
// }
//}
//
//// configure the maven publication
//publishing {
// publications {
// mavenJava(MavenPublication) {
// from components.java
// }
// }
//
// // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
// repositories {
// // Add repositories to publish to here.
// // Notice: This block does NOT have the same function as the block in the top level.
// // The repositories here will be used for publishing your artifact, not for
// // retrieving dependencies.
// }
//}

View File

@ -1,15 +1,14 @@
# Done to increase the memory available to gradle. # Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx4G org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true
# Fabric Properties # Fabric Properties
# check these on https://modmuss50.me/fabric.html # check these on https://modmuss50.me/fabric.html
minecraft_version=1.21.3 minecraft_version=1.19.3
yarn_mappings=1.21.3+build.2 yarn_mappings=1.19.3+build.5
loader_version=0.16.7 loader_version=0.14.13
# Mod Properties # Mod Properties
mod_version=1.2.3 mod_version=1.0.0
maven_group=cmods maven_group=cmods
archives_base_name=cmods archives_base_name=cmods
# Dependencies # Dependencies
# check this on https://modmuss50.me/fabric.html # check this on https://modmuss50.me/fabric.html
fabric_version=0.107.0+1.21.3 fabric_version=0.73.0+1.19.3

View File

@ -1,6 +1,5 @@
#Sun Jun 30 01:31:47 MDT 2024
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@ -1,18 +0,0 @@
package cmods.cmods.api;
import org.jetbrains.annotations.Nullable;
public class PropertyUtils {
public static boolean getBooleanProperty(@Nullable java.util.Properties properties, String key, Boolean default_value) {
if (properties == null)
return default_value;
return Boolean.parseBoolean(properties.getProperty(key, default_value.toString()));
}
@SuppressWarnings("unused")
public static int getIntegerProperty(@Nullable java.util.Properties properties, String key, Integer default_value) {
if (properties == null)
return default_value;
return Integer.parseInt(properties.getProperty(key, default_value.toString()));
}
}

View File

@ -1,6 +1,6 @@
package cmods.cmods.api; package cmods.cmods.api;
import cmods.cmods.ui.Line; import cmods.cmods.client.ui.Line;
import net.minecraft.util.Pair; import net.minecraft.util.Pair;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,9 +1,9 @@
package cmods.cmods.api; package cmods.cmods.api;
import cmods.cmods.options.CmodsOptions; import cmods.cmods.client.options.CmodsOptions;
import cmods.cmods.ui.CmodsOptionsScreen; import cmods.cmods.client.ui.CmodsOptionsScreen;
import cmods.cmods.ui.Line; import cmods.cmods.client.ui.Line;
import cmods.cmods.ui.UIOptionsScreen; import cmods.cmods.client.ui.UIOptionsScreen;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,4 +1,4 @@
package cmods.cmods; package cmods.cmods.client;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;

View File

@ -1,11 +1,10 @@
package cmods.cmods; package cmods.cmods.client;
import cmods.cmods.ui.CmodsOptionsScreen; import cmods.cmods.client.ui.CmodsOptionsScreen;
import com.terraformersmc.modmenu.api.ConfigScreenFactory; import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi; import com.terraformersmc.modmenu.api.ModMenuApi;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
@SuppressWarnings("unused")
public class ModMenuConfig implements ModMenuApi { public class ModMenuConfig implements ModMenuApi {
@Override @Override
public ConfigScreenFactory<?> getModConfigScreenFactory() { public ConfigScreenFactory<?> getModConfigScreenFactory() {

View File

@ -1,11 +1,10 @@
package cmods.cmods.options; package cmods.cmods.client.options;
public class BooleanOption extends Option<Boolean> { public class BooleanOption extends Option<Boolean> {
public BooleanOption(Boolean default_value) { public BooleanOption(Boolean default_value) {
super(default_value); super(default_value);
} }
@SuppressWarnings("UnusedReturnValue")
public boolean toggle() { public boolean toggle() {
return value = !value; return value = !value;
} }

View File

@ -1,4 +1,4 @@
package cmods.cmods.options; package cmods.cmods.client.options;
import cmods.cmods.api.ModuleOptions; import cmods.cmods.api.ModuleOptions;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
@ -11,8 +11,6 @@ import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Properties; import java.util.Properties;
import static cmods.cmods.api.PropertyUtils.getBooleanProperty;
public final class CmodsOptions { public final class CmodsOptions {
private static CmodsOptions instance = null; private static CmodsOptions instance = null;
@ -84,34 +82,31 @@ public final class CmodsOptions {
} }
} }
private static boolean getBooleanProperty(@Nullable Properties properties, String key, Boolean default_value) {
if (properties == null)
return default_value;
return Boolean.parseBoolean(properties.getProperty(key, default_value.toString()));
}
public static class UIOptions { public static class UIOptions {
private final String PREFIX = "ui."; private final String PREFIX = "ui.";
public BooleanOption enabled = new BooleanOption(true); public BooleanOption enabled = new BooleanOption(true);
public BooleanOption show_coordinates = new BooleanOption(true); public BooleanOption show_coordinates = new BooleanOption(true);
public BooleanOption show_fps = new BooleanOption(true);
public BooleanOption show_in_pause = new BooleanOption(true);
public BooleanOption show_in_options = new BooleanOption(true);
UIOptions() { } UIOptions() { }
void load(@Nullable Properties properties) { void load(@Nullable Properties properties) {
enabled.value = getBooleanProperty(properties, PREFIX + "enabled", enabled.value); enabled.value = getBooleanProperty(properties, PREFIX + "enabled", true);
show_coordinates.value = getBooleanProperty(properties, PREFIX + "show_coordinates", show_coordinates.value); show_coordinates.value = getBooleanProperty(properties, PREFIX + "show_coordinates", true);
show_fps.value = getBooleanProperty(properties, PREFIX + "show_fps", show_coordinates.value);
show_in_pause.value = getBooleanProperty(properties, PREFIX + "show_in_pause", show_in_pause.value);
show_in_options.value = getBooleanProperty(properties, PREFIX + "show_in_options", show_in_options.value);
} }
void save(Properties properties) { void save(Properties properties) {
properties.setProperty(PREFIX + "enabled", enabled.value.toString()); properties.setProperty(PREFIX + "enabled", enabled.value.toString());
properties.setProperty(PREFIX + "show_coordinates", show_coordinates.value.toString()); properties.setProperty(PREFIX + "show_coordinates", show_coordinates.value.toString());
properties.setProperty(PREFIX + "show_fps", show_fps.value.toString());
properties.setProperty(PREFIX + "show_in_pause", show_in_pause.value.toString());
properties.setProperty(PREFIX + "show_in_options", show_in_options.value.toString());
} }
} }
} }

View File

@ -1,6 +1,5 @@
package cmods.cmods.options; package cmods.cmods.client.options;
@SuppressWarnings("unused")
public class IntegerOption extends Option<Integer> { public class IntegerOption extends Option<Integer> {
public IntegerOption(Integer default_value) { public IntegerOption(Integer default_value) {
super(default_value); super(default_value);

View File

@ -1,6 +1,5 @@
package cmods.cmods.options; package cmods.cmods.client.options;
@SuppressWarnings("unused")
public class Option<T> { public class Option<T> {
public T value; public T value;

View File

@ -1,20 +1,20 @@
package cmods.cmods.ui; package cmods.cmods.client.ui;
import cmods.cmods.api.ButtonBuilder; import cmods.cmods.api.ButtonBuilder;
import cmods.cmods.CmodsClient; import cmods.cmods.client.CmodsClient;
import cmods.cmods.options.CmodsOptions; import cmods.cmods.client.options.CmodsOptions;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.GridWidget; import net.minecraft.client.gui.widget.GridWidget;
import net.minecraft.client.gui.widget.SimplePositioningWidget; import net.minecraft.client.gui.widget.SimplePositioningWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.screen.ScreenTexts; import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Pair; import net.minecraft.util.Pair;
import java.util.ArrayList; import java.util.ArrayList;
import static cmods.cmods.ui.Constants.*; import static cmods.cmods.client.ui.Constants.*;
public class CmodsOptionsScreen extends Screen { public class CmodsOptionsScreen extends Screen {
private final CmodsOptions options = CmodsOptions.getInstance(); private final CmodsOptions options = CmodsOptions.getInstance();
@ -49,9 +49,9 @@ public class CmodsOptionsScreen extends Screen {
adder.add(ButtonWidget.builder(ScreenTexts.DONE, button -> client.setScreen(parent)) adder.add(ButtonWidget.builder(ScreenTexts.DONE, button -> client.setScreen(parent))
.width(doneButtonWidth).build(), 2, adder.copyPositioner().marginTop(doneButtonRowIncrement)); .width(doneButtonWidth).build(), 2, adder.copyPositioner().marginTop(doneButtonRowIncrement));
grid.refreshPositions(); grid.recalculateDimensions();
SimplePositioningWidget.setPos(grid, 0, startHeight, this.width, this.height, 0.5f, 0.0f); SimplePositioningWidget.setPos(grid, 0, startHeight, this.width, this.height, 0.5f, 0.0f);
grid.forEachChild(this::addDrawableChild); addDrawableChild(grid);
} }
public static void addExtraButtons(ArrayList<ButtonBuilder> buttons, int precedence) { public static void addExtraButtons(ArrayList<ButtonBuilder> buttons, int precedence) {
@ -67,15 +67,15 @@ public class CmodsOptionsScreen extends Screen {
extraWidgets.add(newPair); extraWidgets.add(newPair);
} }
public void render(DrawContext context, int mouseX, int mouseY, float delta) { public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
// renderBackground(context, mouseX, mouseY, delta); renderBackground(matrices);
super.render(context, mouseX, mouseY, delta);
Text versionText = Text.literal("v" + CmodsClient.version); Text versionText = Text.literal("v" + CmodsClient.version);
context.drawCenteredTextWithShadow(textRenderer, title, this.width / 2, 15, 0xffffff);
context.drawTextWithShadow(textRenderer, versionText, this.width - textRenderer.getWidth(versionText) - 2, drawCenteredText(matrices, textRenderer, title, this.width / 2, 15, 0xffffff);
drawTextWithShadow(matrices, textRenderer, versionText, this.width - textRenderer.getWidth(versionText) - 2,
this.height - textRenderer.fontHeight - 2, 0xffffff); this.height - textRenderer.fontHeight - 2, 0xffffff);
super.render(matrices, mouseX, mouseY, delta);
} }
public void removed() { public void removed() {

View File

@ -1,6 +1,5 @@
package cmods.cmods.ui; package cmods.cmods.client.ui;
@SuppressWarnings("unused")
public class Constants { public class Constants {
public static final int buttonWidth = 150; public static final int buttonWidth = 150;
public static final int buttonHeight = 20; public static final int buttonHeight = 20;

View File

@ -1,19 +1,17 @@
package cmods.cmods.ui; package cmods.cmods.client.ui;
import cmods.cmods.options.IntegerOption; import cmods.cmods.client.options.IntegerOption;
import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.gui.widget.WrapperWidget; import net.minecraft.client.gui.widget.WrapperWidget;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.function.Consumer; import java.util.List;
@SuppressWarnings("unused")
public class IntegerAdjustWidget extends WrapperWidget { public class IntegerAdjustWidget extends WrapperWidget {
private final ArrayList<ButtonWidget> elements; private final ArrayList<ButtonWidget> children;
private final IntegerOption option; private final IntegerOption option;
private final Text text;
private final int delta; private final int delta;
public IntegerAdjustWidget(Text text, IntegerOption option) { public IntegerAdjustWidget(Text text, IntegerOption option) {
@ -21,15 +19,25 @@ public class IntegerAdjustWidget extends WrapperWidget {
} }
public IntegerAdjustWidget(Text text, IntegerOption option, int delta) { public IntegerAdjustWidget(Text text, IntegerOption option, int delta) {
super(0, 0, 150, 20); super(0, 0, 150, 20, text);
this.text = text;
this.option = option; this.option = option;
this.delta = delta; this.delta = delta;
elements = new ArrayList<>(3); children = new ArrayList<>(3);
refreshDimensions(); refreshDimensions();
} }
@Override
protected List<? extends ClickableWidget> wrappedWidgets() {
return children;
}
@Override
public void setWidth(int width) {
super.setWidth(width);
refreshDimensions();
}
@Override @Override
public void setX(int x) { public void setX(int x) {
super.setX(x); super.setX(x);
@ -42,11 +50,17 @@ public class IntegerAdjustWidget extends WrapperWidget {
refreshDimensions(); refreshDimensions();
} }
@Override
public void setPos(int x, int y) {
super.setPos(x, y);
refreshDimensions();
}
private void refreshDimensions() { private void refreshDimensions() {
final int button_width = 25; final int button_width = 25;
final String labelStr = text.getString() + ": "; final String labelStr = getMessage().getString() + ": ";
elements.clear(); children.clear();
ButtonWidget middle = ButtonWidget.builder(Text.literal(labelStr + option.get()), button -> {}) ButtonWidget middle = ButtonWidget.builder(Text.literal(labelStr + option.get()), button -> {})
.dimensions(getX() + button_width - 1, getY(),width - (button_width * 2) + 2, height).build(); .dimensions(getX() + button_width - 1, getY(),width - (button_width * 2) + 2, height).build();
@ -59,15 +73,8 @@ public class IntegerAdjustWidget extends WrapperWidget {
button -> middle.setMessage(Text.literal(labelStr + option.inc(delta)))) button -> middle.setMessage(Text.literal(labelStr + option.inc(delta))))
.dimensions(getX() + width - button_width + 1, getY(), button_width, height).build(); .dimensions(getX() + width - button_width + 1, getY(), button_width, height).build();
elements.add(sub); children.add(sub);
elements.add(middle); children.add(middle);
elements.add(add); children.add(add);
}
@Override
public void forEachElement(Consumer<Widget> consumer) {
for (Widget element: elements) {
consumer.accept(element);
}
} }
} }

View File

@ -1,4 +1,4 @@
package cmods.cmods.ui; package cmods.cmods.client.ui;
import net.minecraft.text.Text; import net.minecraft.text.Text;

View File

@ -1,8 +1,8 @@
package cmods.cmods.ui; package cmods.cmods.client.ui;
import cmods.cmods.options.BooleanOption; import cmods.cmods.client.options.BooleanOption;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import org.apache.http.util.TextUtils; import org.apache.http.util.TextUtils;
@ -15,7 +15,7 @@ public class ToggleButton extends ButtonWidget {
public ToggleButton(int x, int y, int width, int height, Text name, BooleanOption option) { public ToggleButton(int x, int y, int width, int height, Text name, BooleanOption option) {
this(x, y, width, height, name, option, DEFAULT_NARRATION_SUPPLIER); this(x, y, width, height, name, option, ButtonWidget.DEFAULT_NARRATION_SUPPLIER);
} }
public ToggleButton(int x, int y, int width, int height, Text name, BooleanOption option, public ToggleButton(int x, int y, int width, int height, Text name, BooleanOption option,
@ -36,8 +36,8 @@ public class ToggleButton extends ButtonWidget {
} }
@Override @Override
public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) { public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) {
updateText(); updateText();
super.renderWidget(context, mouseX, mouseY, delta); super.renderButton(matrices, mouseX, mouseY, delta);
} }
} }

View File

@ -1,19 +1,19 @@
package cmods.cmods.ui; package cmods.cmods.client.ui;
import cmods.cmods.api.ButtonBuilder; import cmods.cmods.api.ButtonBuilder;
import cmods.cmods.options.CmodsOptions; import cmods.cmods.client.options.CmodsOptions;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.GridWidget; import net.minecraft.client.gui.widget.GridWidget;
import net.minecraft.client.gui.widget.SimplePositioningWidget; import net.minecraft.client.gui.widget.SimplePositioningWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.screen.ScreenTexts; import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Pair; import net.minecraft.util.Pair;
import java.util.ArrayList; import java.util.ArrayList;
import static cmods.cmods.ui.Constants.*; import static cmods.cmods.client.ui.Constants.*;
public class UIOptionsScreen extends Screen { public class UIOptionsScreen extends Screen {
private final Screen parent; private final Screen parent;
@ -42,15 +42,6 @@ public class UIOptionsScreen extends Screen {
adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight, adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight,
Text.translatable("cmods.options.ui.show_coordinates"), options.uiOptions.show_coordinates)); Text.translatable("cmods.options.ui.show_coordinates"), options.uiOptions.show_coordinates));
adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight,
Text.translatable("cmods.options.ui.show_fps"), options.uiOptions.show_fps));
adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight,
Text.translatable("cmods.options.ui.show_in_pause"), options.uiOptions.show_in_pause));
adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight,
Text.translatable("cmods.options.ui.show_in_options"), options.uiOptions.show_in_options));
for (Pair<ArrayList<ButtonBuilder>, Integer> buttonArray : extraButtons) { for (Pair<ArrayList<ButtonBuilder>, Integer> buttonArray : extraButtons) {
for (ButtonBuilder buttonBuilder : buttonArray.getLeft()) { for (ButtonBuilder buttonBuilder : buttonArray.getLeft()) {
adder.add(buttonBuilder.build(this, client)); adder.add(buttonBuilder.build(this, client));
@ -60,9 +51,9 @@ public class UIOptionsScreen extends Screen {
adder.add(ButtonWidget.builder(ScreenTexts.DONE, button -> client.setScreen(parent)) adder.add(ButtonWidget.builder(ScreenTexts.DONE, button -> client.setScreen(parent))
.width(doneButtonWidth).build(), 2, adder.copyPositioner().marginTop(doneButtonRowIncrement)); .width(doneButtonWidth).build(), 2, adder.copyPositioner().marginTop(doneButtonRowIncrement));
grid.refreshPositions(); grid.recalculateDimensions();
SimplePositioningWidget.setPos(grid, 0, startHeight, this.width, this.height, 0.5f, 0.0f); SimplePositioningWidget.setPos(grid, 0, startHeight, this.width, this.height, 0.5f, 0.0f);
grid.forEachChild(this::addDrawableChild); addDrawableChild(grid);
} }
public static void addButtons(ArrayList<ButtonBuilder> buttons, int precedence) { public static void addButtons(ArrayList<ButtonBuilder> buttons, int precedence) {
@ -78,10 +69,10 @@ public class UIOptionsScreen extends Screen {
extraButtons.add(newPair); extraButtons.add(newPair);
} }
public void render(DrawContext context, int mouseX, int mouseY, float delta) { public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
// this.renderBackground(context, mouseX, mouseY, delta); this.renderBackground(matrices);
super.render(context, mouseX, mouseY, delta); drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 0xffffff);
context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 15, 0xffffff); super.render(matrices, mouseX, mouseY, delta);
} }
public void removed() { public void removed() {

View File

@ -1,14 +1,13 @@
package cmods.cmods.mixin; package cmods.cmods.mixin;
import cmods.cmods.client.options.CmodsOptions;
import cmods.cmods.api.HudRenderCallback; import cmods.cmods.api.HudRenderCallback;
import cmods.cmods.options.CmodsOptions; import cmods.cmods.client.ui.Line;
import cmods.cmods.ui.Line;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer; import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.hud.DebugHud;
import net.minecraft.client.gui.hud.InGameHud; import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.render.RenderTickCounter; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Pair; import net.minecraft.util.Pair;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -23,19 +22,17 @@ import java.util.ArrayList;
import java.util.function.Consumer; import java.util.function.Consumer;
@Mixin(InGameHud.class) @Mixin(InGameHud.class)
public abstract class HudMixin { public abstract class HudMixin extends DrawableHelper {
@Shadow @Final private MinecraftClient client; @Shadow @Final private MinecraftClient client;
@Shadow public abstract TextRenderer getTextRenderer(); @Shadow public abstract TextRenderer getTextRenderer();
@Shadow @Final private DebugHud debugHud;
@Inject(at = @At("TAIL"), method = "render") @Inject(at = @At("TAIL"), method = "render")
private void render(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) { private void render(MatrixStack matrices, float tickDelta, CallbackInfo ci) {
CmodsOptions options = CmodsOptions.getInstance(); CmodsOptions options = CmodsOptions.getInstance();
if (this.debugHud.shouldShowDebugHud() || this.client.isPaused() || client.player == null || if (this.client.options.debugEnabled || this.client.isPaused() || client.player == null ||
!options.uiOptions.enabled.get()) { !options.uiOptions.enabled.get()) {
return; return;
} }
@ -55,12 +52,6 @@ public abstract class HudMixin {
lines.add(new Line(Text.literal(coordinate_string), white, 0)); lines.add(new Line(Text.literal(coordinate_string), white, 0));
} }
if (options.uiOptions.show_fps.get()) {
int fps = client.getCurrentFps();
String fps_string = String.format("FPS: %d", fps);
lines.add(new Line(Text.literal(fps_string), white, 0));
}
for (Pair<Consumer<ArrayList<Line>>, Integer> callback: HudRenderCallback.callbacks) { for (Pair<Consumer<ArrayList<Line>>, Integer> callback: HudRenderCallback.callbacks) {
callback.getLeft().accept(lines); callback.getLeft().accept(lines);
} }
@ -75,7 +66,8 @@ public abstract class HudMixin {
y += 2; y += 2;
} }
context.drawTextWithShadow(textRenderer, line.text(), x + (5 * line.indent()), y, line.color()); DrawableHelper.drawTextWithShadow(matrices, textRenderer, line.text(), x + (5 * line.indent()), y,
line.color());
y += textRenderer.fontHeight; y += textRenderer.fontHeight;
} }
} }

View File

@ -1,7 +1,6 @@
package cmods.cmods.mixin; package cmods.cmods.mixin;
import cmods.cmods.options.CmodsOptions; import cmods.cmods.client.ui.CmodsOptionsScreen;
import cmods.cmods.ui.CmodsOptionsScreen;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.option.OptionsScreen; import net.minecraft.client.gui.screen.option.OptionsScreen;
import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ButtonWidget;
@ -20,7 +19,7 @@ public class OptionsMixin extends Screen {
@Inject(at = @At("TAIL"), method = "init") @Inject(at = @At("TAIL"), method = "init")
private void init(CallbackInfo ci) { private void init(CallbackInfo ci) {
if (client == null || !CmodsOptions.getInstance().uiOptions.show_in_options.get()) if (client == null)
return; return;
addDrawableChild(ButtonWidget.builder(Text.translatable("cmods.options"), addDrawableChild(ButtonWidget.builder(Text.translatable("cmods.options"),

View File

@ -1,8 +1,7 @@
package cmods.cmods.mixin; package cmods.cmods.mixin;
import cmods.cmods.options.CmodsOptions; import cmods.cmods.client.ui.CmodsOptionsScreen;
import cmods.cmods.ui.CmodsOptionsScreen;
import net.minecraft.client.gui.screen.GameMenuScreen; import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ButtonWidget;
@ -21,7 +20,7 @@ public class PauseMixin extends Screen {
@Inject(at = @At("TAIL"), method = "init") @Inject(at = @At("TAIL"), method = "init")
public void init(CallbackInfo ci) { public void init(CallbackInfo ci) {
if (client == null || !CmodsOptions.getInstance().uiOptions.show_in_pause.get()) if (client == null)
return; return;
addDrawableChild(ButtonWidget.builder(Text.translatable("cmods.options"), addDrawableChild(ButtonWidget.builder(Text.translatable("cmods.options"),

View File

@ -10,8 +10,5 @@
"cmods.options.ui": "UI", "cmods.options.ui": "UI",
"cmods.options.ui.title": "UI Options", "cmods.options.ui.title": "UI Options",
"cmods.options.ui.hud_enabled": "Show HUD", "cmods.options.ui.hud_enabled": "Show HUD",
"cmods.options.ui.show_coordinates": "Show Coordinates", "cmods.options.ui.show_coordinates": "Show Coordinates"
"cmods.options.ui.show_fps": "Show FPS",
"cmods.options.ui.show_in_pause": "Show In Pause",
"cmods.options.ui.show_in_options": "Show In Options"
} }

View File

@ -2,7 +2,7 @@
"required": true, "required": true,
"minVersion": "0.8", "minVersion": "0.8",
"package": "cmods.cmods.mixin", "package": "cmods.cmods.mixin",
"compatibilityLevel": "JAVA_21", "compatibilityLevel": "JAVA_17",
"mixins": [ "mixins": [
], ],
"client": [ "client": [

View File

@ -5,32 +5,24 @@
"name": "Cmods", "name": "Cmods",
"description": "<description>", "description": "<description>",
"authors": [ "authors": [
"Cameron Reed" "CameronReed"
], ],
"contact": { "contact": {
"sources": "https://gitea.cam123.dev/" "repo": "https://gitea.cam123.dev/"
}, },
"license": "MIT", "license": "MIT",
"icon": "assets/cmods/icon.png", "icon": "assets/cmods/icon.png",
"environment": "client", "environment": "client",
"entrypoints": { "entrypoints": {
"client": [ "client": ["cmods.cmods.client.CmodsClient"],
"cmods.cmods.CmodsClient" "modmenu": ["cmods.cmods.client.ModMenuConfig"]
],
"modmenu": [
"cmods.cmods.ModMenuConfig"
]
}, },
"mixins": [ "mixins": [
{ "cmods.mixins.json"
"config": "cmods.client.mixins.json",
"environment": "client"
}
], ],
"depends": { "depends": {
"fabricloader": ">=0.14.10", "fabricloader": ">=0.14.11",
"minecraft": "1.21.3", "fabric": "*",
"java": ">=21", "minecraft": "1.19.3"
"fabric-api": "*"
} }
} }