diff --git a/Versionfiles b/Versionfiles index d8c36be..d64e03d 160000 --- a/Versionfiles +++ b/Versionfiles @@ -1 +1 @@ -Subproject commit d8c36be0a5151c69d29e21fb0eb01560dfc8af47 +Subproject commit d64e03d95901031e541d2167815e446e32dfe609 diff --git a/build.gradle b/build.gradle index 6292cd3..6245b2b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id "fabric-loom" version "1.10-SNAPSHOT" + id "fabric-loom" version "1.13-SNAPSHOT" // id "org.ajoberstar.grgit" version "3.1.1" } @@ -14,9 +14,6 @@ repositories { maven { url = 'https://masa.dy.fi/maven' } } -sourceCompatibility = 1.16 -targetCompatibility = 1.16 - ext.Version = new Properties() Version.load(file("version.properties").newReader()) @@ -28,8 +25,6 @@ Versions.load(file("Versionfiles/${Version['minecraftVersion']}.properties").new version = "${project.projectVersion}-${Version['minecraftVersion']}" -archivesBaseName = "blockmeter" - def getBranch() { if (System.getenv().GIT_BRANCH) { def branch = System.getenv().GIT_BRANCH diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index a4b76b9..1b33c55 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index cea7a79..d4081da 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index f5feea6..23d15a9 100755 --- a/gradlew +++ b/gradlew @@ -86,8 +86,7 @@ done # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s -' "$PWD" ) || exit +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -115,7 +114,7 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar +CLASSPATH="\\\"\\\"" # Determine the Java command to use to start the JVM. @@ -206,7 +205,7 @@ fi DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Collect all arguments for the java command: -# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, # and any embedded shellness will be escaped. # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be # treated as '${Hostname}' itself on the command line. @@ -214,7 +213,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" # Stop when "xargs" is not available. diff --git a/gradlew.bat b/gradlew.bat index 9b42019..5eed7ee 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -70,11 +70,11 @@ goto fail :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar +set CLASSPATH= @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell diff --git a/settings.gradle b/settings.gradle index b64c2cd..4e2af48 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,5 @@ pluginManagement { repositories { - jcenter() maven { name = "Fabric" url = "https://maven.fabricmc.net/" diff --git a/src/main/java/win/baruna/blockmeter/BlockMeterClient.java b/src/main/java/win/baruna/blockmeter/BlockMeterClient.java index 4ddc792..6cfc8ef 100644 --- a/src/main/java/win/baruna/blockmeter/BlockMeterClient.java +++ b/src/main/java/win/baruna/blockmeter/BlockMeterClient.java @@ -8,18 +8,18 @@ import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; -import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; +import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderContext; +import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderEvents; import net.fabricmc.fabric.api.event.player.AttackBlockCallback; import net.fabricmc.fabric.api.event.player.UseBlockCallback; import net.fabricmc.fabric.api.event.player.UseItemCallback; import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.option.KeyBinding; import net.minecraft.client.util.InputUtil; +import net.minecraft.client.util.Window; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.text.Text; @@ -41,17 +41,11 @@ import java.util.stream.Collectors; @SuppressWarnings("UnstableApiUsage") -public class BlockMeterClient implements ClientModInitializer { - /** - * Currently running Instance of BlockMeterClient - */ +public class BlockMeterClient implements ClientModInitializer, InputUtils { + /// Currently running Instance of BlockMeterClient private static BlockMeterClient instance; - /** - * Accessor for the BlockMeterClient Instance - * - * @return running Instance of BlockMeterClient - */ + /// Currently running Instance of BlockMeterClient public static BlockMeterClient getInstance() { return instance; } @@ -60,18 +54,14 @@ private static ClientPlayerEntity getPlayer() { return Objects.requireNonNull(MinecraftClient.getInstance().player); } - /** - * ConfigManager of BlockMeter - */ + private static Window getWindow() { + return MinecraftClient.getInstance().getWindow(); + } + private static ConfigManager confMgr; - /** - * Accessor for the ModConfigManager - * - * @return ConfigManager for handling the Config - */ + /// Accessor for the ModConfigManager public static ConfigManager getConfigManager() { - return confMgr; } @@ -79,35 +69,23 @@ public static ModConfig getConfig() { return confMgr.getConfig(); } - /** - * The current state of the BlockMeter (activated/deactivated) - */ + /// The current state of the BlockMeter (activated/deactivated) private boolean active; - /** - * The Item selected as BlockMeter - */ + /// The Item selected as BlockMeter private Item currentItem; - /** - * The List of Measuring-Boxes currently created by the current User - */ + /// The List of Measuring-Boxes currently created by the current User private final List boxes = new ArrayList<>(); - /** - * A Map of Lists of Boxes currently created by other Users, with Text being the - * Username - */ + /// A Map of Lists of Boxes currently created by other Users, with Text being the + /// Username private Map> otherUsersBoxes; - /** - * The QuickMenu for changing of Color etc. - */ + /// The QuickMenu for changing of Color etc. private final OptionsGui quickMenu; - /** - * The QuickMenu for selecting on of multiple Boxes. - */ + /// The QuickMenu for selecting on of multiple Boxes. private final SelectBoxGui selectBoxGui; private final EditBoxGui editBoxGui; @@ -185,7 +163,7 @@ public boolean undo() { } public void renderOverlay(WorldRenderContext context) { - final Identifier currentDimension = getPlayer().clientWorld.getRegistryKey().getValue(); + final Identifier currentDimension = getPlayer().getEntityWorld().getRegistryKey().getValue(); final ModConfig cfg = AutoConfig.getConfigHolder(ModConfig.class).getConfig(); @@ -241,17 +219,19 @@ public ClientMeasureBox getCurrentBox() { @Override public void onInitializeClient() { + var category = KeyBinding.Category.create(Identifier.of("category.blockmeter.key")); + var window = MinecraftClient.getInstance().getWindow(); final KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.blockmeter.assign", - InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_M, "category.blockmeter.key")); + InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_M, category)); final KeyBinding keyBindingMenu = new KeyBinding("key.blockmeter.menu", InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_LEFT_ALT, "category.blockmeter.key"); + GLFW.GLFW_KEY_LEFT_ALT, category); KeyBindingHelper.registerKeyBinding(keyBindingMenu); final KeyBinding keyBindingMeasureWithItem = new KeyBinding("key.blockmeter.useItem", -1, - "category.blockmeter.key"); + category); KeyBindingHelper.registerKeyBinding(keyBindingMeasureWithItem); final KeyBinding keyBindingMeasure = new KeyBinding("key.blockmeter.measure", InputUtil.Type.MOUSE, - GLFW.GLFW_MOUSE_BUTTON_4, "category.blockmeter.key"); + GLFW.GLFW_MOUSE_BUTTON_4, category); KeyBindingHelper.registerKeyBinding(keyBindingMeasure); WorldRenderEvents.BEFORE_DEBUG_RENDER.register(this::renderOverlay); @@ -267,10 +247,10 @@ public void onInitializeClient() { confMgr = (ConfigManager) AutoConfig.register(ModConfig.class, Toml4jConfigSerializer::new); ClientTickEvents.START_CLIENT_TICK.register(e -> { if (keyBinding.wasPressed()) { - if (Screen.hasShiftDown()) { + if (isShift()) { if (undo()) getPlayer().sendMessage(Text.translatable("blockmeter.clearLast"), true); - } else if (Screen.hasControlDown()) { + } else if (isCtrl()) { if (clear()) getPlayer().sendMessage(Text.translatable("blockmeter.clearAll"), true); } else if (this.active) { @@ -348,7 +328,7 @@ public void onInitializeClient() { var outside = this.boxes.stream() .filter(box -> box.miningRestriction == ClientMeasureBox.MiningRestriction.Outside) .anyMatch(box -> box.contains(pos)); - if (!Screen.hasShiftDown() && (inside || outside)) { + if (!isShift() && (inside || outside)) { return ActionResult.FAIL; } else { return ActionResult.PASS; @@ -382,7 +362,7 @@ private void onBlockMeterClick(final BlockPos block) { ClientMeasureBox currentBox = getCurrentBox(); if (currentBox == null) { - if (Screen.hasShiftDown()) { + if (isShift()) { ClientMeasureBox[] boxes = findBoxes(block); switch (boxes.length) { case 0: @@ -398,7 +378,7 @@ private void onBlockMeterClick(final BlockPos block) { } } else { final ClientMeasureBox box = ClientMeasureBox.getBox(block, - getPlayer().getWorld().getRegistryKey().getValue()); + getPlayer().getEntityWorld().getRegistryKey().getValue()); this.boxes.add(box); } } else { diff --git a/src/main/java/win/baruna/blockmeter/InputUtils.java b/src/main/java/win/baruna/blockmeter/InputUtils.java new file mode 100644 index 0000000..7b307c6 --- /dev/null +++ b/src/main/java/win/baruna/blockmeter/InputUtils.java @@ -0,0 +1,26 @@ +package win.baruna.blockmeter; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.util.InputUtil; +import net.minecraft.client.util.Window; + +import java.util.function.Function; +import java.util.function.Supplier; + +public interface InputUtils { + default Window window() { + return MinecraftClient.getInstance().getWindow(); + } + + default boolean isKey(int key) { + return InputUtil.isKeyPressed(window(), key); + } + + default boolean isShift() { + return isKey(InputUtil.GLFW_KEY_LEFT_SHIFT) || isKey(InputUtil.GLFW_KEY_RIGHT_SHIFT); + } + + default boolean isCtrl() { + return isKey(InputUtil.GLFW_KEY_LEFT_CONTROL) || isKey(InputUtil.GLFW_KEY_RIGHT_CONTROL); + } +} \ No newline at end of file diff --git a/src/main/java/win/baruna/blockmeter/gui/EditBoxGui.java b/src/main/java/win/baruna/blockmeter/gui/EditBoxGui.java index 7decd03..e7010c9 100644 --- a/src/main/java/win/baruna/blockmeter/gui/EditBoxGui.java +++ b/src/main/java/win/baruna/blockmeter/gui/EditBoxGui.java @@ -51,7 +51,6 @@ protected void init() { @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { - super.renderBackground(context, mouseX, mouseY, delta); super.render(context, mouseX, mouseY, delta); } diff --git a/src/main/java/win/baruna/blockmeter/gui/OptionsGui.java b/src/main/java/win/baruna/blockmeter/gui/OptionsGui.java index 2e8660e..da20fc7 100644 --- a/src/main/java/win/baruna/blockmeter/gui/OptionsGui.java +++ b/src/main/java/win/baruna/blockmeter/gui/OptionsGui.java @@ -11,6 +11,7 @@ import net.minecraft.client.gui.screen.ButtonTextures; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.input.AbstractInput; import net.minecraft.client.render.*; import net.minecraft.client.util.NarratorManager; import net.minecraft.text.MutableText; @@ -90,7 +91,6 @@ protected void init() { @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { -// super.renderBackground(context, mouseX, mouseY, delta); super.render(context, mouseX, mouseY, delta); } @@ -115,12 +115,12 @@ class ColorButton extends ButtonWidget { ); @Override - public void onPress() { + public void onPress(AbstractInput input) { System.out.println(color.getRed()); System.out.println(color.getGreen()); System.out.println(color.getBlue()); System.err.println("IK WHAT YOU ARE DOING"); - super.onPress(); + super.onPress(input); } ColorButton(final int x, final int y, final int width, final int height, final MutableText label, final Color color, diff --git a/src/main/java/win/baruna/blockmeter/gui/SelectBoxGui.java b/src/main/java/win/baruna/blockmeter/gui/SelectBoxGui.java index a1e6bf7..a8cafb1 100644 --- a/src/main/java/win/baruna/blockmeter/gui/SelectBoxGui.java +++ b/src/main/java/win/baruna/blockmeter/gui/SelectBoxGui.java @@ -55,7 +55,6 @@ protected void init() { @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { - super.renderBackground(context, mouseX, mouseY, delta); super.render(context, mouseX, mouseY, delta); } diff --git a/src/main/java/win/baruna/blockmeter/measurebox/ClientMeasureBox.java b/src/main/java/win/baruna/blockmeter/measurebox/ClientMeasureBox.java index ebb8e3b..12eadbe 100644 --- a/src/main/java/win/baruna/blockmeter/measurebox/ClientMeasureBox.java +++ b/src/main/java/win/baruna/blockmeter/measurebox/ClientMeasureBox.java @@ -4,7 +4,7 @@ import com.mojang.blaze3d.platform.DepthTestFunction; import com.mojang.blaze3d.vertex.VertexFormat; import me.shedaniel.autoconfig.AutoConfig; -import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderContext; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gl.RenderPipelines; @@ -19,6 +19,7 @@ import net.minecraft.util.math.*; import org.jetbrains.annotations.NotNull; import org.joml.Matrix4f; +import org.joml.Quaternionf; import win.baruna.blockmeter.BlockMeterClient; import win.baruna.blockmeter.ModConfig; @@ -173,8 +174,8 @@ public void render(final WorldRenderContext context, final Identifier currentDim if (!(currentDimension.equals(this.dimension))) { return; } - final Vec3d pos = context.camera().getPos(); - var stack = context.matrixStack(); + final Vec3d pos = context.worldState().cameraRenderState.pos; + var stack = context.matrices(); var buffer = context.consumers().getBuffer(DEBUG_LINE_STRIP); stack.push(); @@ -235,10 +236,9 @@ private void drawLengths(final WorldRenderContext context, final Text boxCreator final double diagonalLength = new Vec3d(this.box.minX, this.box.minY, this.box.minZ) .distanceTo(new Vec3d(this.box.maxX, this.box.maxY, this.box.maxZ)); - var camera = context.camera(); - final float yaw = camera.getYaw(); - final float pitch = camera.getPitch(); - final Vec3d pos = camera.getPos(); + var camera = context.worldState().cameraRenderState; + final var orientation = camera.orientation; + final Vec3d pos = camera.pos; final List lines = new ArrayList<>(); lines.add(new Line( @@ -291,25 +291,24 @@ private void drawLengths(final WorldRenderContext context, final Text boxCreator final String playerNameStr = (boxCreatorName == null ? "" : boxCreatorName.getString() + " : "); if (BlockMeterClient.getConfigManager().getConfig().innerDiagonal) { - this.drawBackground(context, boxCenter.x, boxCenter.y, boxCenter.z, yaw, pitch, + this.drawBackground(context, boxCenter, orientation, playerNameStr + String.format("%.2f", diagonalLength), pos); } - this.drawBackground(context, lineZ.x, lineZ.y, lineZ.z, yaw, pitch, playerNameStr + lengthZ, pos); - this.drawBackground(context, lineX.x, lineX.y, lineX.z, yaw, pitch, playerNameStr + lengthX, pos); - this.drawBackground(context, lineY.x, lineY.y, lineY.z, yaw, pitch, playerNameStr + lengthY, pos); + this.drawBackground(context, lineZ, orientation, playerNameStr + lengthZ, pos); + this.drawBackground(context, lineX, orientation, playerNameStr + lengthX, pos); + this.drawBackground(context, lineY, orientation, playerNameStr + lengthY, pos); if (BlockMeterClient.getConfigManager().getConfig().innerDiagonal) { - this.drawText(context, boxCenter.x, boxCenter.y, boxCenter.z, yaw, pitch, + this.drawText(context, boxCenter, orientation, playerNameStr + String.format("%.2f", diagonalLength), pos); } - this.drawText(context, lineZ.x, lineZ.y, lineZ.z, yaw, pitch, playerNameStr + lengthZ, pos); - this.drawText(context, lineX.x, lineX.y, lineX.z, yaw, pitch, playerNameStr + lengthX, pos); - this.drawText(context, lineY.x, lineY.y, lineY.z, yaw, pitch, playerNameStr + lengthY, pos); + this.drawText(context, lineZ, orientation, playerNameStr + lengthZ, pos); + this.drawText(context, lineX, orientation, playerNameStr + lengthX, pos); + this.drawText(context, lineY, orientation, playerNameStr + lengthY, pos); } - private void drawBackground(final WorldRenderContext context, final double x, final double y, final double z, - final float yaw, - final float pitch, final String text, final Vec3d playerPos) { + private void drawBackground(final WorldRenderContext context, Vec3d pos, + Quaternionf orientation, final String text, final Vec3d playerPos) { // TODO figure this out // final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; // @@ -347,9 +346,7 @@ private void drawBackground(final WorldRenderContext context, final double x, fi // stack.pop(); } - private void drawText(final WorldRenderContext context, final double x, final double y, final double z, - final float yaw, - final float pitch, final String text, final Vec3d playerPos) { + private void drawText(final WorldRenderContext context, Vec3d pos, Quaternionf orientation, final String text, final Vec3d playerPos) { final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; final var literalText = Text.literal(text); @@ -358,17 +355,15 @@ private void drawText(final WorldRenderContext context, final double x, final do final int constDist = 10; if (AutoConfig.getConfigHolder(ModConfig.class).getConfig().minimalLabelSize) { - final float dist = (float) Math.sqrt((x - playerPos.x) * (x - playerPos.x) - + (y - playerPos.y) * (y - playerPos.y) + (z - playerPos.z) * (z - playerPos.z)); + var dist = (float) pos.distanceTo(playerPos); if (dist > constDist) size = dist * size / constDist; } - var stack = context.matrixStack(); + var stack = context.matrices(); stack.push(); - stack.translate(x, y + 0.15, z); - stack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180.0F - yaw)); - stack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-pitch)); + stack.translate(pos.x, pos.y + 0.15, pos.z); + stack.multiply(orientation); stack.scale(size, -size, 0.001f); final int width = textRenderer.getWidth(literalText); stack.translate((-width / 2f), 0.0, 0.0); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index cdac1cd..dbbf114 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -19,7 +19,7 @@ "depends": { "fabricloader": "*", "fabric": "*", - "minecraft": ">=1.21.6" + "minecraft": ">=1.21.10" }, "recommends": { "modmenu": "*" diff --git a/version.properties b/version.properties index 6853471..6842936 100644 --- a/version.properties +++ b/version.properties @@ -1,2 +1,2 @@ -modVersion = 1.17 -minecraftVersion = 1.21.7 +modVersion = 1.18 +minecraftVersion = 1.21.10