diff --git a/Versionfiles b/Versionfiles index d64e03d..0ac611a 160000 --- a/Versionfiles +++ b/Versionfiles @@ -1 +1 @@ -Subproject commit d64e03d95901031e541d2167815e446e32dfe609 +Subproject commit 0ac611a8fad858045438cb4b11b899fcbb49149d diff --git a/build.gradle b/build.gradle index 6245b2b..0f5f33c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id "fabric-loom" version "1.13-SNAPSHOT" + id 'net.fabricmc.fabric-loom-remap' version "1.14-SNAPSHOT" // id "org.ajoberstar.grgit" version "3.1.1" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 1b33c55..f8e1ee3 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 d4081da..bad7c24 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.14.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 23d15a9..adff685 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -114,7 +114,6 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH="\\\"\\\"" # Determine the Java command to use to start the JVM. @@ -172,7 +171,6 @@ fi # For Cygwin or MSYS, switch paths to Windows format before running java if "$cygwin" || "$msys" ; then APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) JAVACMD=$( cygpath --unix "$JAVACMD" ) @@ -212,7 +210,6 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" diff --git a/gradlew.bat b/gradlew.bat index 5eed7ee..e509b2d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -70,11 +70,10 @@ goto fail :execute @rem Setup the command line -set CLASSPATH= @rem Execute Gradle -"%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" %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell diff --git a/src/main/java/win/baruna/blockmeter/BlockMeterClient.java b/src/main/java/win/baruna/blockmeter/BlockMeterClient.java index 6cfc8ef..8453bf5 100644 --- a/src/main/java/win/baruna/blockmeter/BlockMeterClient.java +++ b/src/main/java/win/baruna/blockmeter/BlockMeterClient.java @@ -19,7 +19,6 @@ 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; @@ -40,10 +39,35 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; + @SuppressWarnings("UnstableApiUsage") public class BlockMeterClient implements ClientModInitializer, InputUtils { /// Currently running Instance of BlockMeterClient private static BlockMeterClient instance; + private static ConfigManager confMgr; + /// The List of Measuring-Boxes currently created by the current User + private final List boxes = new ArrayList<>(); + /// The QuickMenu for changing of Color etc. + private final OptionsGui quickMenu; + /// The QuickMenu for selecting on of multiple Boxes. + private final SelectBoxGui selectBoxGui; + private final EditBoxGui editBoxGui; + /// The current state of the BlockMeter (activated/deactivated) + private boolean active; + /// The Item selected as BlockMeter + private Item currentItem; + /// A Map of Lists of Boxes currently created by other Users, with Text being the + /// Username + private Map> otherUsersBoxes; + + public BlockMeterClient() { + active = false; + quickMenu = new OptionsGui(); + selectBoxGui = new SelectBoxGui(); + editBoxGui = new EditBoxGui(); + otherUsersBoxes = null; + BlockMeterClient.instance = this; + } /// Currently running Instance of BlockMeterClient public static BlockMeterClient getInstance() { @@ -54,12 +78,6 @@ private static ClientPlayerEntity getPlayer() { return Objects.requireNonNull(MinecraftClient.getInstance().player); } - private static Window getWindow() { - return MinecraftClient.getInstance().getWindow(); - } - - private static ConfigManager confMgr; - /// Accessor for the ModConfigManager public static ConfigManager getConfigManager() { return confMgr; @@ -69,35 +87,6 @@ public static ModConfig getConfig() { return confMgr.getConfig(); } - /// The current state of the BlockMeter (activated/deactivated) - private boolean active; - - /// The Item selected as BlockMeter - private Item currentItem; - - /// 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 - private Map> otherUsersBoxes; - - /// The QuickMenu for changing of Color etc. - private final OptionsGui quickMenu; - - /// The QuickMenu for selecting on of multiple Boxes. - private final SelectBoxGui selectBoxGui; - private final EditBoxGui editBoxGui; - - public BlockMeterClient() { - active = false; - quickMenu = new OptionsGui(); - selectBoxGui = new SelectBoxGui(); - editBoxGui = new EditBoxGui(); - otherUsersBoxes = null; - BlockMeterClient.instance = this; - } - /** * Disables BlockMeter */ @@ -147,8 +136,7 @@ public boolean clear() { * Removes the last box */ public boolean undo() { - if (this.boxes.isEmpty()) - return false; + if (this.boxes.isEmpty()) return false; this.boxes.remove(this.boxes.size() - 1); sendBoxList(); @@ -167,29 +155,20 @@ public void renderOverlay(WorldRenderContext context) { final ModConfig cfg = AutoConfig.getConfigHolder(ModConfig.class).getConfig(); - // MEH! but this seems to be needed to get the first background - // rectangle - // client.textRenderer.draw("XXX", stack, -100, -100, 0); - - if (this.active || cfg.showBoxesWhenDisabled) + if ((this.active || cfg.showBoxesWhenDisabled)) { if (cfg.showOtherUsersBoxes) { if (otherUsersBoxes != null && !otherUsersBoxes.isEmpty()) { - this.otherUsersBoxes.forEach((playerText, boxList) -> boxList.forEach(box -> box.render( - context, currentDimension, Text.literal(playerText)))); + this.otherUsersBoxes.forEach((playerText, boxList) -> boxList.forEach(box -> box.render(context, currentDimension, playerText))); this.boxes.forEach(box -> { - if (!box.isFinished()) - box.render(context, currentDimension); + if (!box.isFinished()) box.render(context, currentDimension); }); } - if (!cfg.sendBoxes) - this.boxes.forEach(box -> { - if (box.isFinished()) - box.render(context, currentDimension, getPlayer().getDisplayName()); - else - box.render(context, currentDimension); - }); - } else - this.boxes.forEach(box -> box.render(context, currentDimension)); + if (!cfg.sendBoxes) this.boxes.forEach(box -> { + if (box.isFinished()) box.render(context, currentDimension, getPlayer().getDisplayName().getLiteralString()); + else box.render(context, currentDimension); + }); + } else this.boxes.forEach(box -> box.render(context, currentDimension)); + } } @@ -203,8 +182,7 @@ public void onDisconnected(ClientPlayNetworkHandler clientPlayNetworkHandler, Mi /** * Gets Triggered when the Player connects to the Server */ - private void onConnected(ClientPlayNetworkHandler clientPlayNetworkHandler, PacketSender packetSender, - MinecraftClient minecraftClient) { + private void onConnected(ClientPlayNetworkHandler clientPlayNetworkHandler, PacketSender packetSender, MinecraftClient minecraftClient) { sendBoxList(); // to make the server send other user's boxes } @@ -220,18 +198,13 @@ 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)); - final KeyBinding keyBindingMenu = new KeyBinding("key.blockmeter.menu", InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_LEFT_ALT, category); + final KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.blockmeter.assign", 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); KeyBindingHelper.registerKeyBinding(keyBindingMenu); - final KeyBinding keyBindingMeasureWithItem = new KeyBinding("key.blockmeter.useItem", -1, - category); + final KeyBinding keyBindingMeasureWithItem = new KeyBinding("key.blockmeter.useItem", -1, category); KeyBindingHelper.registerKeyBinding(keyBindingMeasureWithItem); - final KeyBinding keyBindingMeasure = new KeyBinding("key.blockmeter.measure", InputUtil.Type.MOUSE, - GLFW.GLFW_MOUSE_BUTTON_4, category); + final KeyBinding keyBindingMeasure = new KeyBinding("key.blockmeter.measure", InputUtil.Type.MOUSE, GLFW.GLFW_MOUSE_BUTTON_4, category); KeyBindingHelper.registerKeyBinding(keyBindingMeasure); WorldRenderEvents.BEFORE_DEBUG_RENDER.register(this::renderOverlay); @@ -248,11 +221,9 @@ public void onInitializeClient() { ClientTickEvents.START_CLIENT_TICK.register(e -> { if (keyBinding.wasPressed()) { if (isShift()) { - if (undo()) - getPlayer().sendMessage(Text.translatable("blockmeter.clearLast"), true); + if (undo()) getPlayer().sendMessage(Text.translatable("blockmeter.clearLast"), true); } else if (isCtrl()) { - if (clear()) - getPlayer().sendMessage(Text.translatable("blockmeter.clearAll"), true); + if (clear()) getPlayer().sendMessage(Text.translatable("blockmeter.clearAll"), true); } else if (this.active) { disable(); getPlayer().sendMessage(Text.translatable("blockmeter.toggle.off"), true); @@ -260,9 +231,7 @@ public void onInitializeClient() { active = true; ItemStack itemStack = getPlayer().getMainHandStack(); currentItem = itemStack.getItem(); - getPlayer().sendMessage( - Text.translatable("blockmeter.toggle.on", itemStack.getItemName()), - true); + getPlayer().sendMessage(Text.translatable("blockmeter.toggle.on", itemStack.getItemName()), true); } } @@ -290,10 +259,10 @@ public void onInitializeClient() { pressed = GLFW.glfwGetMouseButton(MinecraftClient.getInstance().getWindow().getHandle(), 1) == 1; } else { switch (key.getCategory()) { - case KEYSYM, SCANCODE -> pressed = GLFW.glfwGetKey(MinecraftClient.getInstance().getWindow() - .getHandle(), key.getCode()) == 1; - case MOUSE -> pressed = GLFW.glfwGetMouseButton(MinecraftClient.getInstance().getWindow() - .getHandle(), key.getCode()) == 1; + case KEYSYM, SCANCODE -> + pressed = GLFW.glfwGetKey(MinecraftClient.getInstance().getWindow().getHandle(), key.getCode()) == 1; + case MOUSE -> + pressed = GLFW.glfwGetMouseButton(MinecraftClient.getInstance().getWindow().getHandle(), key.getCode()) == 1; } } if (pressed) { @@ -322,12 +291,8 @@ public void onInitializeClient() { return ActionResult.PASS; }); AttackBlockCallback.EVENT.register(((player, world, hand, pos, direction) -> { - var inside = this.boxes.stream() - .filter(box -> box.miningRestriction == ClientMeasureBox.MiningRestriction.Inside) - .anyMatch(box -> !box.contains(pos)); - var outside = this.boxes.stream() - .filter(box -> box.miningRestriction == ClientMeasureBox.MiningRestriction.Outside) - .anyMatch(box -> box.contains(pos)); + var inside = this.boxes.stream().filter(box -> box.miningRestriction == ClientMeasureBox.MiningRestriction.Inside).anyMatch(box -> !box.contains(pos)); + var outside = this.boxes.stream().filter(box -> box.miningRestriction == ClientMeasureBox.MiningRestriction.Outside).anyMatch(box -> box.contains(pos)); if (!isShift() && (inside || outside)) { return ActionResult.FAIL; } else { @@ -377,8 +342,7 @@ private void onBlockMeterClick(final BlockPos block) { break; } } else { - final ClientMeasureBox box = ClientMeasureBox.getBox(block, - getPlayer().getEntityWorld().getRegistryKey().getValue()); + final ClientMeasureBox box = ClientMeasureBox.getBox(block, getPlayer().getEntityWorld().getRegistryKey().getValue()); this.boxes.add(box); } } else { @@ -402,8 +366,7 @@ private ClientMeasureBox[] findBoxes(BlockPos block) { * Sends BoxList to Server if enabled in the config */ private void sendBoxList() { - if (!AutoConfig.getConfigHolder(ModConfig.class).getConfig().sendBoxes) - return; + if (!AutoConfig.getConfigHolder(ModConfig.class).getConfig().sendBoxes) return; ClientPlayNetworking.send(new BoxPayload(Map.of("", new ArrayList<>(boxes)))); } @@ -411,10 +374,7 @@ private void sendBoxList() { * handles the BoxList of other Players */ private void handleServerBoxList(BoxPayload payload, ClientPlayNetworking.Context context) { - context.client().executeTask(() -> otherUsersBoxes = payload.receivedBoxes().entrySet().stream() - .map(entry -> Pair.of(entry.getKey(), entry.getValue().stream().map(ClientMeasureBox::new) - .toList())) - .collect(Collectors.toMap(Pair::getKey, Pair::getValue))); + context.client().executeTask(() -> otherUsersBoxes = payload.receivedBoxes().entrySet().stream().map(entry -> Pair.of(entry.getKey(), entry.getValue().stream().map(ClientMeasureBox::new).toList())).collect(Collectors.toMap(Pair::getKey, Pair::getValue))); } } diff --git a/src/main/java/win/baruna/blockmeter/ModConfig.java b/src/main/java/win/baruna/blockmeter/ModConfig.java index b1bf9eb..e21476b 100644 --- a/src/main/java/win/baruna/blockmeter/ModConfig.java +++ b/src/main/java/win/baruna/blockmeter/ModConfig.java @@ -13,8 +13,6 @@ public class ModConfig implements ConfigData { @ConfigEntry.Gui.Tooltip(count = 3) public boolean sendBoxes = true; public boolean showBoxesWhenDisabled = false; - @ConfigEntry.Gui.Excluded - public boolean backgroundForLabels = true; @ConfigEntry.BoundedDiscrete(max=200, min = 7) public int reach = 50; diff --git a/src/main/java/win/baruna/blockmeter/gui/OptionsGui.java b/src/main/java/win/baruna/blockmeter/gui/OptionsGui.java index da20fc7..c8d49bd 100644 --- a/src/main/java/win/baruna/blockmeter/gui/OptionsGui.java +++ b/src/main/java/win/baruna/blockmeter/gui/OptionsGui.java @@ -125,7 +125,7 @@ public void onPress(AbstractInput input) { ColorButton(final int x, final int y, final int width, final int height, final MutableText label, final Color color, final boolean selected, boolean texture, PressAction onPress) { - super(x, y, width, height, Text.literal(""), onPress, DEFAULT_NARRATION_SUPPLIER); + super(x, y, width, height, net.minecraft.text.Text.empty(), onPress, DEFAULT_NARRATION_SUPPLIER); this.selected = false; this.color = color; this.x = x + 2; @@ -136,35 +136,15 @@ public void onPress(AbstractInput input) { this.selected = selected; this.text = label; this.texture = texture; - // this.color = Color.ofRGBA(0.5f, 1f, 1f, 1f); } @Override - public void renderWidget(DrawContext context, final int int_1, final int int_2, final float float_1) { - + protected void drawIcon(DrawContext context, int mouseX, int mouseY, float deltaTicks) { context.drawGuiTexture( RenderPipelines.GUI_TEXTURED, TEXTURES.get(this.active, this.isSelected()), x, y, width, height, color.getColor() ); -// Tessellator tessellator = Tessellator.getInstance(); -// var bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); -// RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR); -// -// int r = this.color.getRed(); -// int g = this.color.getGreen(); -// int b = this.color.getBlue(); -// int a = texture ? 102 : 255; -// bufferBuilder.vertex(this.x - (texture ? 1 : 0), this.y - (texture ? 1 : 0), 0f) -// .color(r, g, b, a); -// bufferBuilder.vertex(this.x - (texture ? 1 : 0), this.y + this.height + (texture ? 1 : 0), 0f) -// .color(r, g, b, a); -// bufferBuilder.vertex(this.x + this.width + (texture ? 1 : 0), this.y + this.height + (texture ? 1 : 0), 0f) -// .color(r, g, b, a); -// bufferBuilder.vertex(this.x + this.width + (texture ? 1 : 0), this.y - (texture ? 1 : 0), 0f) -// .color(r, g, b, a); -// BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - if (text != null) { boolean dark = (0.299f * color.getRed() + 0.587f * color.getBlue() + 0.114f * color.getRed()) / 255f < 0.8f; @@ -180,5 +160,6 @@ public void renderWidget(DrawContext context, final int int_1, final int int_2, context.drawText(textRenderer, text, x + width / 2 - text_width / 2, y + height / 2 - 4, 0, false); } } + //drawButton(context); } } diff --git a/src/main/java/win/baruna/blockmeter/gui/SelectBoxGui.java b/src/main/java/win/baruna/blockmeter/gui/SelectBoxGui.java index a8cafb1..060440c 100644 --- a/src/main/java/win/baruna/blockmeter/gui/SelectBoxGui.java +++ b/src/main/java/win/baruna/blockmeter/gui/SelectBoxGui.java @@ -38,7 +38,7 @@ protected void init() { this.addDrawableChild(new ColorButton(this.width / 2 - (BUTTONWIDTH) / 2, this.height / 2 - uiHeight / 2 + i * (BUTTONHEIGHT + PADDING), BUTTONWIDTH, BUTTONHEIGHT, text, - Color.ofOpaque(box.getColor().getMapColor().color), false, true, button -> { + Color.ofOpaque(box.getColor()), false, true, button -> { BlockMeterClient.getInstance().editBox(box, block); MinecraftClient.getInstance().setScreen(null); })); diff --git a/src/main/java/win/baruna/blockmeter/measurebox/ClientMeasureBox.java b/src/main/java/win/baruna/blockmeter/measurebox/ClientMeasureBox.java index 12eadbe..da9e64a 100644 --- a/src/main/java/win/baruna/blockmeter/measurebox/ClientMeasureBox.java +++ b/src/main/java/win/baruna/blockmeter/measurebox/ClientMeasureBox.java @@ -1,64 +1,32 @@ package win.baruna.blockmeter.measurebox; -import com.mojang.blaze3d.pipeline.RenderPipeline; -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.world.WorldRenderContext; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gl.RenderPipelines; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.RenderPhase; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.VertexFormats; -import net.minecraft.client.util.BufferAllocator; -import net.minecraft.text.Text; +import net.minecraft.client.render.DrawStyle; import net.minecraft.util.DyeColor; import net.minecraft.util.Identifier; -import net.minecraft.util.math.*; +import net.minecraft.util.math.BlockBox; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.debug.gizmo.GizmoDrawing; +import net.minecraft.world.debug.gizmo.TextGizmo; import org.jetbrains.annotations.NotNull; -import org.joml.Matrix4f; -import org.joml.Quaternionf; import win.baruna.blockmeter.BlockMeterClient; import win.baruna.blockmeter.ModConfig; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.OptionalDouble; - -import static net.minecraft.client.gl.RenderPipelines.POSITION_COLOR_SNIPPET; public class ClientMeasureBox extends MeasureBox { - private static final RenderLayer.MultiPhase DEBUG_LINE_STRIP = RenderLayer.of( - "debug_line_strip_no_depth", - 1536, - RenderPipelines.register( - RenderPipeline.builder(POSITION_COLOR_SNIPPET) - .withLocation("pipeline/debug_line_strip") - .withVertexShader("core/position_color") - .withFragmentShader("core/position_color") - .withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST) - .withCull(false) - .withVertexFormat(VertexFormats.POSITION_COLOR, VertexFormat.DrawMode.DEBUG_LINE_STRIP) - .build() - ), - RenderLayer.MultiPhaseParameters.builder().lineWidth(new RenderPhase.LineWidth(OptionalDouble.of(4.0))).build(false) - - ); - private static final RenderLayer.MultiPhase DEBUG_QUADS = RenderLayer.of( - "debug_quads_no_depth", 1536, false, true, RenderPipelines.register( - RenderPipeline.builder(POSITION_COLOR_SNIPPET).withLocation("pipeline/debug_quads").withCull(false).withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST).build() - ), RenderLayer.MultiPhaseParameters.builder().build(false) - ); + @NotNull public MiningRestriction miningRestriction; private Box box; private int argb; - protected ClientMeasureBox(final BlockPos blockStart, final BlockPos blockEnd, final Identifier dimension, - final DyeColor color, final boolean finished, final int mode, final int orientation) { + protected ClientMeasureBox(final BlockPos blockStart, final BlockPos blockEnd, final Identifier dimension, final DyeColor color, final boolean finished, final int mode, final int orientation) { super(blockStart, blockEnd, dimension, color, finished, mode, orientation); miningRestriction = MiningRestriction.Off; argb = color.getEntityColor() | 0xFF000000; @@ -66,8 +34,7 @@ protected ClientMeasureBox(final BlockPos blockStart, final BlockPos blockEnd, f } public ClientMeasureBox(MeasureBox measureBox) { - this(measureBox.blockStart, measureBox.blockEnd, measureBox.dimension, measureBox.color, measureBox.finished, - measureBox.mode, measureBox.orientation); + this(measureBox.blockStart, measureBox.blockEnd, measureBox.dimension, measureBox.color, measureBox.finished, measureBox.mode, measureBox.orientation); } public static ClientMeasureBox getBox(final BlockPos block, final Identifier dimension) { @@ -145,9 +112,7 @@ public void setColor(final DyeColor color) { * @return true if block is a corner */ public boolean isCorner(final BlockPos block) { - return (block.getX() == blockStart.getX() || block.getX() == blockEnd.getX()) - && (block.getY() == blockStart.getY() || block.getY() == blockEnd.getY()) - && (block.getZ() == blockStart.getZ() || block.getZ() == blockEnd.getZ()); + return (block.getX() == blockStart.getX() || block.getX() == blockEnd.getX()) && (block.getY() == blockStart.getY() || block.getY() == blockEnd.getY()) && (block.getZ() == blockStart.getZ() || block.getZ() == blockEnd.getZ()); } /** @@ -165,50 +130,23 @@ public void loosenCorner(final BlockPos block) { finished = false; } - public void render(final WorldRenderContext context, final Identifier currentDimension) { + public void render(WorldRenderContext context, final Identifier currentDimension) { render(context, currentDimension, null); } - public void render(final WorldRenderContext context, final Identifier currentDimension, - final Text boxCreatorName) { + public void render(WorldRenderContext context, final Identifier currentDimension, final String boxCreatorName) { if (!(currentDimension.equals(this.dimension))) { return; } - final Vec3d pos = context.worldState().cameraRenderState.pos; - var stack = context.matrices(); - var buffer = context.consumers().getBuffer(DEBUG_LINE_STRIP); - - stack.push(); - stack.translate(-pos.x, -pos.y, -pos.z); - final Matrix4f model = stack.peek().getPositionMatrix(); - - buffer.vertex(model, (float) this.box.minX, (float) this.box.minY, (float) this.box.minZ).color(argb); - buffer.vertex(model, (float) this.box.maxX, (float) this.box.minY, (float) this.box.minZ).color(argb); - buffer.vertex(model, (float) this.box.maxX, (float) this.box.minY, (float) this.box.maxZ).color(argb); - buffer.vertex(model, (float) this.box.minX, (float) this.box.minY, (float) this.box.maxZ).color(argb); - buffer.vertex(model, (float) this.box.minX, (float) this.box.minY, (float) this.box.minZ).color(argb); - buffer.vertex(model, (float) this.box.minX, (float) this.box.maxY, (float) this.box.minZ).color(argb); - buffer.vertex(model, (float) this.box.minX, (float) this.box.maxY, (float) this.box.minZ).color(argb); - buffer.vertex(model, (float) this.box.maxX, (float) this.box.maxY, (float) this.box.minZ).color(argb); - buffer.vertex(model, (float) this.box.maxX, (float) this.box.maxY, (float) this.box.maxZ).color(argb); - buffer.vertex(model, (float) this.box.minX, (float) this.box.maxY, (float) this.box.maxZ).color(argb); - buffer.vertex(model, (float) this.box.minX, (float) this.box.maxY, (float) this.box.minZ).color(argb); - buffer.vertex(model, (float) this.box.minX, (float) this.box.maxY, (float) this.box.maxZ).color(argb); - buffer.vertex(model, (float) this.box.minX, (float) this.box.minY, (float) this.box.maxZ).color(argb); - buffer.vertex(model, (float) this.box.maxX, (float) this.box.minY, (float) this.box.maxZ).color(argb); - buffer.vertex(model, (float) this.box.maxX, (float) this.box.maxY, (float) this.box.maxZ).color(argb); - buffer.vertex(model, (float) this.box.maxX, (float) this.box.maxY, (float) this.box.minZ).color(argb); - buffer.vertex(model, (float) this.box.maxX, (float) this.box.minY, (float) this.box.minZ).color(argb); + + GizmoDrawing.box(this.box, DrawStyle.stroked(getColor(), 2f)).ignoreOcclusion(); if (BlockMeterClient.getConfigManager().getConfig().innerDiagonal) { - buffer = context.consumers().getBuffer(DEBUG_LINE_STRIP); - buffer.vertex(model, (float) this.box.minX, (float) this.box.minY, (float) this.box.minZ).color(argb); - buffer.vertex(model, (float) this.box.maxX, (float) this.box.maxY, (float) this.box.maxZ).color(argb); + GizmoDrawing.line(box.getMinPos(), box.getMaxPos(), getColor()).ignoreOcclusion(); } this.drawLengths(context, boxCreatorName); - stack.pop(); } /** @@ -222,179 +160,64 @@ private void updateBoundingBox() { final int by = this.blockEnd.getY(); final int bz = this.blockEnd.getZ(); - this.box = new Box(Math.min(ax, bx), Math.min(ay, by), Math.min(az, bz), - Math.max(ax, bx) + 1, Math.max(ay, by) + 1, Math.max(az, bz) + 1); + this.box = new Box(Math.min(ax, bx), Math.min(ay, by), Math.min(az, bz), Math.max(ax, bx) + 1, Math.max(ay, by) + 1, Math.max(az, bz) + 1); } - private void drawLengths(final WorldRenderContext context, final Text boxCreatorName) { + private void drawLengths(WorldRenderContext context, final String boxCreatorName) { final int lengthX = (int) this.box.getLengthX(); final int lengthY = (int) this.box.getLengthY(); final int lengthZ = (int) this.box.getLengthZ(); final Vec3d boxCenter = this.box.getCenter(); - 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)); + 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.worldState().cameraRenderState; - final var orientation = camera.orientation; - final Vec3d pos = camera.pos; + final Vec3d pos = context.worldState().cameraRenderState.pos; final List lines = new ArrayList<>(); - lines.add(new Line( - new Box(this.box.minX, this.box.minY, this.box.minZ, this.box.minX, this.box.minY, this.box.maxZ), - pos)); - lines.add(new Line( - new Box(this.box.minX, this.box.maxY, this.box.minZ, this.box.minX, this.box.maxY, this.box.maxZ), - pos)); - lines.add(new Line( - new Box(this.box.maxX, this.box.minY, this.box.minZ, this.box.maxX, this.box.minY, this.box.maxZ), - pos)); - lines.add(new Line( - new Box(this.box.maxX, this.box.maxY, this.box.minZ, this.box.maxX, this.box.maxY, this.box.maxZ), - pos)); + lines.add(new Line(new Box(this.box.minX, this.box.minY, this.box.minZ, this.box.minX, this.box.minY, this.box.maxZ), pos)); + lines.add(new Line(new Box(this.box.minX, this.box.maxY, this.box.minZ, this.box.minX, this.box.maxY, this.box.maxZ), pos)); + lines.add(new Line(new Box(this.box.maxX, this.box.minY, this.box.minZ, this.box.maxX, this.box.minY, this.box.maxZ), pos)); + lines.add(new Line(new Box(this.box.maxX, this.box.maxY, this.box.minZ, this.box.maxX, this.box.maxY, this.box.maxZ), pos)); Collections.sort(lines); - final Vec3d lineZ = lines.get(0).line.getCenter(); + final Vec3d lineZ = lines.getFirst().line.getCenter(); lines.clear(); - lines.add(new Line( - new Box(this.box.minX, this.box.minY, this.box.minZ, this.box.minX, this.box.maxY, this.box.minZ), - pos)); - lines.add(new Line( - new Box(this.box.minX, this.box.minY, this.box.maxZ, this.box.minX, this.box.maxY, this.box.maxZ), - pos)); - lines.add(new Line( - new Box(this.box.maxX, this.box.minY, this.box.minZ, this.box.maxX, this.box.maxY, this.box.minZ), - pos)); - lines.add(new Line( - new Box(this.box.maxX, this.box.minY, this.box.maxZ, this.box.maxX, this.box.maxY, this.box.maxZ), - pos)); + lines.add(new Line(new Box(this.box.minX, this.box.minY, this.box.minZ, this.box.minX, this.box.maxY, this.box.minZ), pos)); + lines.add(new Line(new Box(this.box.minX, this.box.minY, this.box.maxZ, this.box.minX, this.box.maxY, this.box.maxZ), pos)); + lines.add(new Line(new Box(this.box.maxX, this.box.minY, this.box.minZ, this.box.maxX, this.box.maxY, this.box.minZ), pos)); + lines.add(new Line(new Box(this.box.maxX, this.box.minY, this.box.maxZ, this.box.maxX, this.box.maxY, this.box.maxZ), pos)); Collections.sort(lines); - final Vec3d lineY = lines.get(0).line.getCenter(); + final Vec3d lineY = lines.getFirst().line.getCenter(); lines.clear(); - lines.add(new Line( - new Box(this.box.minX, this.box.minY, this.box.minZ, this.box.maxX, this.box.minY, this.box.minZ), - pos)); - lines.add(new Line( - new Box(this.box.minX, this.box.minY, this.box.maxZ, this.box.maxX, this.box.minY, this.box.maxZ), - pos)); - lines.add(new Line( - new Box(this.box.minX, this.box.maxY, this.box.minZ, this.box.maxX, this.box.maxY, this.box.minZ), - pos)); - lines.add(new Line( - new Box(this.box.minX, this.box.maxY, this.box.maxZ, this.box.maxX, this.box.maxY, this.box.maxZ), - pos)); + lines.add(new Line(new Box(this.box.minX, this.box.minY, this.box.minZ, this.box.maxX, this.box.minY, this.box.minZ), pos)); + lines.add(new Line(new Box(this.box.minX, this.box.minY, this.box.maxZ, this.box.maxX, this.box.minY, this.box.maxZ), pos)); + lines.add(new Line(new Box(this.box.minX, this.box.maxY, this.box.minZ, this.box.maxX, this.box.maxY, this.box.minZ), pos)); + lines.add(new Line(new Box(this.box.minX, this.box.maxY, this.box.maxZ, this.box.maxX, this.box.maxY, this.box.maxZ), pos)); Collections.sort(lines); - final Vec3d lineX = lines.get(0).line.getCenter(); - - final String playerNameStr = (boxCreatorName == null ? "" : boxCreatorName.getString() + " : "); + final Vec3d lineX = lines.getFirst().line.getCenter(); - if (BlockMeterClient.getConfigManager().getConfig().innerDiagonal) { - this.drawBackground(context, boxCenter, orientation, - playerNameStr + String.format("%.2f", diagonalLength), 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); + final String playerNameStr = (boxCreatorName == null ? "" : boxCreatorName + ": "); if (BlockMeterClient.getConfigManager().getConfig().innerDiagonal) { - this.drawText(context, boxCenter, orientation, - playerNameStr + String.format("%.2f", diagonalLength), pos); + this.drawText(boxCenter, playerNameStr + String.format("%.2f", diagonalLength), 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); + this.drawText(lineZ, playerNameStr + lengthZ, pos); + this.drawText(lineX, playerNameStr + lengthX, pos); + this.drawText(lineY, playerNameStr + lengthY, pos); } - 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; -// -// final var literalText = Text.literal(text); -// -// float size = 0.03f; -// 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)); -// if (dist > constDist) -// size = dist * size / constDist; -// } -// -// var stack = context.matrixStack(); -// 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.scale(size, -size, 0.001f); -// final int width = textRenderer.getWidth(literalText); -// stack.translate((-width / 2f), 0.0, 0.0); -// final Matrix4f model = stack.peek().getPositionMatrix(); -// -// final ModConfig conf = BlockMeterClient.getConfigManager().getConfig(); -// if (conf.backgroundForLabels) { -// var buffer = context.consumers().getBuffer(DEBUG_QUADS); -// buffer.vertex(model, -1, -1, 0).color(argb); -// buffer.vertex(model, -1, 8, 0).color(argb); -// buffer.vertex(model, width, 8, 0).color(argb); -// buffer.vertex(model, width, -1, 0).color(argb); -// } -// -// stack.pop(); - } - - 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); - - float size = 0.03f; + private void drawText(Vec3d pos, final String text, final Vec3d playerPos) { + float size = .3f; final int constDist = 10; if (AutoConfig.getConfigHolder(ModConfig.class).getConfig().minimalLabelSize) { var dist = (float) pos.distanceTo(playerPos); - if (dist > constDist) - size = dist * size / constDist; + if (dist > constDist) size = dist * size / constDist; } - var stack = context.matrices(); - stack.push(); - 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); - final Matrix4f model = stack.peek().getPositionMatrix(); - - int textColor = color.getSignColor(); - - final ModConfig conf = BlockMeterClient.getConfigManager().getConfig(); - // TODO figure this out -// if (conf.backgroundForLabels) { -// var color = new Color(argb); -// float luminance = (0.299f * color.getRed() + 0.587f * color.getGreen() + 0.114f * color.getBlue()); -// textColor = luminance < 0.4f ? DyeColor.WHITE.getSignColor() : DyeColor.BLACK.getSignColor(); -// } - - final VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(new BufferAllocator(0)); - textRenderer.draw( - literalText, - 0.0f, - 0.0f, - textColor, - !conf.backgroundForLabels, // shadow - model, // matrix - immediate, // draw buffer - TextRenderer.TextLayerType.SEE_THROUGH, - 0, // backgroundColor => underlineColor, - 15728880 // light - ); - immediate.draw(); - - stack.pop(); + GizmoDrawing.text(text, pos, TextGizmo.Style.left(getColor()).scaled(size)).ignoreOcclusion(); } public boolean contains(BlockPos block) { @@ -402,9 +225,7 @@ public boolean contains(BlockPos block) { } public enum MiningRestriction { - Off("options.off"), - Inside("blockmeter.restrictMining.inside"), - Outside("blockmeter.restrictMining.outside"); + Off("options.off"), Inside("blockmeter.restrictMining.inside"), Outside("blockmeter.restrictMining.outside"); public final String translation; MiningRestriction(String translation) { diff --git a/src/main/java/win/baruna/blockmeter/measurebox/MeasureBox.java b/src/main/java/win/baruna/blockmeter/measurebox/MeasureBox.java index 66030c5..32cba11 100644 --- a/src/main/java/win/baruna/blockmeter/measurebox/MeasureBox.java +++ b/src/main/java/win/baruna/blockmeter/measurebox/MeasureBox.java @@ -4,6 +4,7 @@ import net.minecraft.util.DyeColor; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ColorHelper; public class MeasureBox { @@ -27,8 +28,8 @@ public Identifier getDimension() { return dimension; } - public DyeColor getColor() { - return color; + public int getColor() { + return ColorHelper.fullAlpha(color.getSignColor()); } public boolean isFinished() { diff --git a/version.properties b/version.properties index 6842936..1de5074 100644 --- a/version.properties +++ b/version.properties @@ -1,2 +1,2 @@ -modVersion = 1.18 -minecraftVersion = 1.21.10 +modVersion = 1.19 +minecraftVersion = 1.21.11