]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/commitdiff
Rewrite line renderer
authorishland <ishlandmc@yeah.net>
Sun, 1 Aug 2021 14:59:08 +0000 (22:59 +0800)
committerirtimaled <irtimaled@gmail.com>
Sun, 15 Aug 2021 18:36:02 +0000 (11:36 -0700)
Mostly fixes https://github.com/irtimaled/BoundingBoxOutlineReloaded/issues/130

src/main/java/com/irtimaled/bbor/client/config/ConfigManager.java
src/main/java/com/irtimaled/bbor/client/gui/IntSettingSlider.java
src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java
src/main/java/com/irtimaled/bbor/client/renderers/AbstractRenderer.java
src/main/java/com/irtimaled/bbor/client/renderers/RenderHelper.java
src/main/java/com/irtimaled/bbor/mixin/client/renderer/MixinWorldRenderer.java
src/main/resources/assets/bbor/lang/en_us.json

index ceeda1200de481a575b9e19ce920151d9d64065b..a15959c9718b9cae17ad6f25b0969628f7232dba 100644 (file)
@@ -9,6 +9,7 @@ public class ConfigManager {
     private static File configDir;
 
     public static Setting<Boolean> fill;
+    public static Setting<Integer> lineWidthModifier;
     public static Setting<Boolean> drawVillages;
     public static Setting<Boolean> drawDesertTemples;
     public static Setting<Boolean> drawJungleTemples;
@@ -117,6 +118,7 @@ public class ConfigManager {
         invertBoxColorPlayerInside = setup(config, "general", "invertBoxColorPlayerInside", false, "If set to true the color of any bounding box the player is inside will be inverted.");
         renderSphereAsDots = setup(config, "general", "renderSphereAsDots", false, "If set to true spheres will be rendered as dots.");
         buttonOnOverlay = setup(config, "general", "buttonEnabledOverlay", HexColor.from("#3000ff00"), "The color and alpha of the button overlay when a button is on.");
+        lineWidthModifier = setup(config, "general", "lineWidthModifier", 1, "");
 
         drawBeacons = setup(config, "beacons", "drawBeacons", true, "If set to true beacon bounding boxes will be drawn.");
 
index a681e6d2e8cf1ac5bd9315751b2b77fdf4da6919..fb643d0d3ebaa323531b4215a794f643389ab1bf 100644 (file)
@@ -1,5 +1,7 @@
 package com.irtimaled.bbor.client.gui;
 
+import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
 import com.irtimaled.bbor.client.config.Setting;
 import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
 import net.minecraft.client.resource.language.I18n;
@@ -7,6 +9,7 @@ import net.minecraft.text.LiteralText;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.stream.IntStream;
 
 class IntSettingSlider extends AbstractSlider {
     private final String format;
@@ -36,6 +39,17 @@ class IntSettingSlider extends AbstractSlider {
         return this;
     }
 
+    IntSettingSlider addDisplayValueRange(int start, int end) {
+        return addDisplayValueRange(start, end, String::valueOf);
+    }
+
+    IntSettingSlider addDisplayValueRange(int start, int end, Function<Integer, String> formatter) {
+        Preconditions.checkArgument(start <= end);
+        Preconditions.checkNotNull(formatter);
+        IntStream.range(start, end).forEach(value -> addDisplayValue(value, formatter.apply(value)));
+        return this;
+    }
+
     protected Integer getSettingValue() {
         return minValue + getPosition();
     }
index 49e5e6828b228e00d9c2db2298113929bc1d851a..73f28353de5732d45be4c2ef971e7b08300e431f 100644 (file)
@@ -53,7 +53,9 @@ public class SettingsScreen extends ListScreen {
                             }
                         },
                         width -> new BoolSettingButton(width, I18n.translate("bbor.options.outerBoxOnly"), ConfigManager.outerBoxesOnly),
-                        width -> new BoolSettingButton(width, I18n.translate("bbor.options.fill"), ConfigManager.fill))
+                        width -> new BoolSettingButton(width, I18n.translate("bbor.options.fill"), ConfigManager.fill),
+                        width -> new IntSettingSlider(width, 1, 25, I18n.translate("bbor.options.lineWidthModifier"), ConfigManager.lineWidthModifier)
+                                .addDisplayValueRange(1, 25))
                 .section(I18n.translate("bbor.features.spawnChunks"),
                         width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.features.spawnChunks"), BoundingBoxType.WorldSpawn),
                         width -> new BoundingBoxTypeButton(width, I18n.translate("bbor.features.lazyChunks"), BoundingBoxType.LazySpawnChunks),
index 683c19a4d3dc033d38475bbae214b41cba04a7c6..a4d237fca06c2d0c810b3c4b3d8c7d72f4bc321b 100644 (file)
@@ -30,7 +30,7 @@ public abstract class AbstractRenderer<T extends AbstractBoundingBox> {
     public static final double PHI_SEGMENT = TAU / 90D;
     private static final double PI = TAU / 2D;
     public static final double THETA_SEGMENT = PHI_SEGMENT / 2D;
-    private static final float LINE_RADIUS = 0.0025f;
+    private static final float DEFAULT_LINE_WIDTH = 0.0025f;
 
     private final VertexBuffer solidBox = new VertexBuffer();
     private final VertexBuffer outlinedBox = new VertexBuffer();
@@ -50,7 +50,9 @@ public abstract class AbstractRenderer<T extends AbstractBoundingBox> {
         RenderHelper.polygonModeFill();
         matrixStack.push();
 
+        RenderSystem.depthMask(false);
         renderCuboid0(matrixStack, nudge, color, fillOnly, fillAlpha);
+        RenderSystem.depthMask(true);
 
         matrixStack.pop();
         RenderSystem.setShaderColor(1, 1, 1, 1);
@@ -89,12 +91,12 @@ public abstract class AbstractRenderer<T extends AbstractBoundingBox> {
         if (!fillOnly) {
             RenderSystem.setShaderColor(color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F, 1F);
 //            outlinedBox.setShader(viewMatrix, projMatrix, shader);
-            final double minXL = minX - LINE_RADIUS;
-            final double minYL = minY - LINE_RADIUS;
-            final double minZL = minZ - LINE_RADIUS;
-            final double maxXL = maxX + LINE_RADIUS;
-            final double maxYL = maxY + LINE_RADIUS;
-            final double maxZL = maxZ + LINE_RADIUS;
+            final double minXL = minX - getLineWidth();
+            final double minYL = minY - getLineWidth();
+            final double minZL = minZ - getLineWidth();
+            final double maxXL = maxX + getLineWidth();
+            final double maxYL = maxY + getLineWidth();
+            final double maxZL = maxZ + getLineWidth();
             stack.push();
             stack.peek().getModel().load(lastStack.getModel());
             stack.peek().getNormal().load(lastStack.getNormal());
@@ -122,11 +124,17 @@ public abstract class AbstractRenderer<T extends AbstractBoundingBox> {
                 nudge.getMin().getZ() < 0 && nudge.getMax().getZ() > 0;
     }
 
+    private double getLineWidth() {
+        return DEFAULT_LINE_WIDTH * ConfigManager.lineWidthModifier.get();
+    }
+
     void renderLine(MatrixStack matrixStack, OffsetPoint startPoint, OffsetPoint endPoint, Color color) {
         if ((startPoint.getY() == endPoint.getY() && startPoint.getZ() == endPoint.getZ()) ||
                 (startPoint.getX() == endPoint.getX() && startPoint.getZ() == endPoint.getZ()) ||
                 (startPoint.getX() == endPoint.getX() && startPoint.getY() == endPoint.getY())) {
-            renderCuboid(matrixStack, new OffsetBox(startPoint.offset(-LINE_RADIUS, -LINE_RADIUS, -LINE_RADIUS), endPoint.offset(LINE_RADIUS, LINE_RADIUS, LINE_RADIUS)), color, true, 255);
+            RenderSystem.depthMask(true);
+            renderCuboid0(matrixStack, new OffsetBox(startPoint.offset(-getLineWidth(), -getLineWidth(), -getLineWidth()), endPoint.offset(getLineWidth(), getLineWidth(), getLineWidth())), color, true, 255);
+            RenderSystem.depthMask(false);
             return;
         }
 
index 17bddf7a442444d7d1d88cf8c3ca96a91daa6929..6cb77eb6f85a6cc49d1452941074bf77ab52dc2e 100644 (file)
@@ -22,7 +22,7 @@ public class RenderHelper {
         GL11.glEnable(GL11.GL_LINE_SMOOTH);
         RenderSystem.disableCull();
         enableDepthTest();
-        RenderSystem.depthMask(false);
+        RenderSystem.depthMask(true);
         RenderSystem.depthFunc(GL11.GL_LEQUAL);
 
         if (ConfigManager.alwaysVisible.get()) {
index fcaa9c412693eea43826685883fa141519d2dc1e..c3b818823e4b2a4862a492a121cb51fb2f5425c6 100644 (file)
@@ -26,7 +26,7 @@ public class MixinWorldRenderer {
 
     @Shadow private Frustum frustum;
 
-    @Inject(method = "render", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiler/Profiler;swap(Ljava/lang/String;)V", args = "ldc=string", shift = At.Shift.BEFORE))
+    @Inject(method = "render", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiler/Profiler;swap(Ljava/lang/String;)V", args = "ldc=blockentities", shift = At.Shift.BEFORE))
     private void onRender(MatrixStack matrixStack, float partialTicks, long ignored_2, boolean ignored_3, Camera ignored_4, GameRenderer ignored_5, LightmapTextureManager ignored_6, Matrix4f ignored_7, CallbackInfo ci) {
         Preconditions.checkNotNull(this.client.player);
         RenderCulling.setFrustum(frustum);
index 2bf1bac9b1445d2b7d0bc7c107d4dcf07c6a760d..481c654f73b02701548288de8b11c3718f3c77ef 100644 (file)
@@ -7,6 +7,7 @@
   "bbor.options.active": "Active",
   "bbor.options.outerBoxOnly": "Outer Box Only",
   "bbor.options.fill": "Fill",
+  "bbor.options.lineWidthModifier": "Line Width Modifier",
 
   "bbor.options.maxY": "Max Y: %s",
   "bbor.options.maxY.activated": "Activated",