From 7fa040c4ee0d27a82b1fa3e218989a57350f48f5 Mon Sep 17 00:00:00 2001 From: Sophie <295312950+SophieMidnight@users.noreply.github.com> Date: Sat, 24 Oct 2026 17:56:45 +0800 Subject: [PATCH 1/4] int r, g, b, a -> int color --- .../birbaddons/feature/impl/Theodolite.java | 21 +++++----------- .../birbaddons/render/RenderUtils.java | 24 +++++++++---------- .../birbaddons/render/shapes/CircleXZ.java | 24 +++++++------------ .../render/shapes/InterCircleStrip.java | 20 ++++++---------- 4 files changed, 34 insertions(+), 55 deletions(-) diff --git a/src/client/java/yellowbirb/birbaddons/feature/impl/Theodolite.java b/src/client/java/yellowbirb/birbaddons/feature/impl/Theodolite.java index 8cba69c..9bd8704 100644 --- a/src/client/java/yellowbirb/birbaddons/feature/impl/Theodolite.java +++ b/src/client/java/yellowbirb/birbaddons/feature/impl/Theodolite.java @@ -48,30 +48,21 @@ public Theodolite() { float angleMargin = 2.5F; float heightMargin = 2.5F; - int boxyRingInnerColorR = 255; - int boxyRingInnerColorG = 0; - int boxyRingInnerColorB = 0; - int boxyRingInnerColorA = 255; + int boxyRingInnerColor = 0xFFFF0000; boolean boxyRingInnerVisibleThroughWalls = true; - int boxyRingOuterCornerColorR = 0; - int boxyRingOuterCornerColorG = 255; - int boxyRingOuterCornerColorB = 0; - int boxyRingOuterCornerColorA = 255; + int boxyRingOuterCornerColor = 0xFF00FF00; boolean boxyRingOuterCornerVisibleThroughWalls = false; - int boxyRingOuterPlaneColorR = 0; - int boxyRingOuterPlaneColorG = 255; - int boxyRingOuterPlaneColorB = 0; - int boxyRingOuterPlaneColorA = 50; + int boxyRingOuterPlaneColor = 0x3200FF00; boolean boxyRingOuterPlaneVisibleThroughWalls = false; RenderManager.add(RenderUtils.createBoxyRing(ID, "boxyRing" + boxyRingCounter++, alpha, deltaY, (float) player.getX(), (float) player.getY(), (float) player.getZ(), angleMargin, heightMargin, - boxyRingInnerColorR, boxyRingInnerColorG, boxyRingInnerColorB, boxyRingInnerColorA, boxyRingInnerVisibleThroughWalls, - boxyRingOuterCornerColorR, boxyRingOuterCornerColorG, boxyRingOuterCornerColorB, boxyRingOuterCornerColorA, boxyRingOuterCornerVisibleThroughWalls, - boxyRingOuterPlaneColorR, boxyRingOuterPlaneColorG, boxyRingOuterPlaneColorB, boxyRingOuterPlaneColorA, boxyRingOuterPlaneVisibleThroughWalls)); + boxyRingInnerColor, boxyRingInnerVisibleThroughWalls, + boxyRingOuterCornerColor, boxyRingOuterCornerVisibleThroughWalls, + boxyRingOuterPlaneColor, boxyRingOuterPlaneVisibleThroughWalls)); } }); diff --git a/src/client/java/yellowbirb/birbaddons/render/RenderUtils.java b/src/client/java/yellowbirb/birbaddons/render/RenderUtils.java index 2fd662e..c381bc2 100644 --- a/src/client/java/yellowbirb/birbaddons/render/RenderUtils.java +++ b/src/client/java/yellowbirb/birbaddons/render/RenderUtils.java @@ -11,9 +11,9 @@ public class RenderUtils { public static CompoundShape createBoxyRing(String featureID, String ID, double alpha, int deltaY, float playerX, float playerY, float playerZ, float angleMargin, float heightMargin, - int boxyRingInnerColorR, int boxyRingInnerColorG, int boxyRingInnerColorB, int boxyRingInnerColorA, boolean boxyRingInnerVisibleThroughWalls, - int boxyRingOuterCornerColorR, int boxyRingOuterCornerColorG, int boxyRingOuterCornerColorB, int boxyRingOuterCornerColorA, boolean boxyRingOuterCornerVisibleThroughWalls, - int boxyRingOuterPlaneColorR, int boxyRingOuterPlaneColorG, int boxyRingOuterPlaneColorB, int boxyRingOuterPlaneColorA, boolean boxyRingOuterPlaneVisibleThroughWalls) { + int boxyRingInnerColor, boolean boxyRingInnerVisibleThroughWalls, + int boxyRingOuterCornerColor, boolean boxyRingOuterCornerVisibleThroughWalls, + int boxyRingOuterPlaneColor, boolean boxyRingOuterPlaneVisibleThroughWalls) { double margin_rad = Math.toRadians(angleMargin); @@ -32,18 +32,18 @@ public static CompoundShape createBoxyRing(String featureID, String ID, float highY = playerY + deltaY + heightMargin; return new CompoundShape(featureID, ID, - new CircleXZ(radius1_1, segmentAmount, playerX, highY, playerZ, boxyRingOuterCornerColorR, boxyRingOuterCornerColorG, boxyRingOuterCornerColorB, boxyRingOuterCornerColorA, boxyRingOuterCornerVisibleThroughWalls), - new CircleXZ(radius1_2, segmentAmount, playerX, lowY , playerZ, boxyRingOuterCornerColorR, boxyRingOuterCornerColorG, boxyRingOuterCornerColorB, boxyRingOuterCornerColorA, boxyRingOuterCornerVisibleThroughWalls), + new CircleXZ(radius1_1, segmentAmount, playerX, highY, playerZ, boxyRingOuterCornerColor, boxyRingOuterCornerVisibleThroughWalls), + new CircleXZ(radius1_2, segmentAmount, playerX, lowY , playerZ, boxyRingOuterCornerColor, boxyRingOuterCornerVisibleThroughWalls), - new CircleXZ(radius2, segmentAmount, playerX, playerY + deltaY, playerZ, boxyRingInnerColorR, boxyRingInnerColorG, boxyRingInnerColorB, boxyRingInnerColorA, 2, boxyRingInnerVisibleThroughWalls), + new CircleXZ(radius2, segmentAmount, playerX, playerY + deltaY, playerZ, boxyRingInnerColor, 2, boxyRingInnerVisibleThroughWalls), - new CircleXZ(radius3_1, segmentAmount, playerX, highY, playerZ, boxyRingOuterCornerColorR, boxyRingOuterCornerColorG, boxyRingOuterCornerColorB, boxyRingOuterCornerColorA, boxyRingOuterCornerVisibleThroughWalls), - new CircleXZ(radius3_2, segmentAmount, playerX, lowY , playerZ, boxyRingOuterCornerColorR, boxyRingOuterCornerColorG, boxyRingOuterCornerColorB, boxyRingOuterCornerColorA, boxyRingOuterCornerVisibleThroughWalls), + new CircleXZ(radius3_1, segmentAmount, playerX, highY, playerZ, boxyRingOuterCornerColor, boxyRingOuterCornerVisibleThroughWalls), + new CircleXZ(radius3_2, segmentAmount, playerX, lowY , playerZ, boxyRingOuterCornerColor, boxyRingOuterCornerVisibleThroughWalls), - new InterCircleStrip(radius1_1, radius1_2, segmentAmount, playerX, highY, lowY , playerZ, boxyRingOuterPlaneColorR, boxyRingOuterPlaneColorG, boxyRingOuterPlaneColorB, boxyRingOuterPlaneColorA, boxyRingOuterPlaneVisibleThroughWalls), - new InterCircleStrip(radius3_1, radius3_2, segmentAmount, playerX, highY, lowY , playerZ, boxyRingOuterPlaneColorR, boxyRingOuterPlaneColorG, boxyRingOuterPlaneColorB, boxyRingOuterPlaneColorA, boxyRingOuterPlaneVisibleThroughWalls), - new InterCircleStrip(radius1_1, radius3_1, segmentAmount, playerX, highY, highY, playerZ, boxyRingOuterPlaneColorR, boxyRingOuterPlaneColorG, boxyRingOuterPlaneColorB, boxyRingOuterPlaneColorA, boxyRingOuterPlaneVisibleThroughWalls), - new InterCircleStrip(radius1_2, radius3_2, segmentAmount, playerX, lowY , lowY , playerZ, boxyRingOuterPlaneColorR, boxyRingOuterPlaneColorG, boxyRingOuterPlaneColorB, boxyRingOuterPlaneColorA, boxyRingOuterPlaneVisibleThroughWalls) + new InterCircleStrip(radius1_1, radius1_2, segmentAmount, playerX, highY, lowY , playerZ, boxyRingOuterPlaneColor, boxyRingOuterPlaneVisibleThroughWalls), + new InterCircleStrip(radius3_1, radius3_2, segmentAmount, playerX, highY, lowY , playerZ, boxyRingOuterPlaneColor, boxyRingOuterPlaneVisibleThroughWalls), + new InterCircleStrip(radius1_1, radius3_1, segmentAmount, playerX, highY, highY, playerZ, boxyRingOuterPlaneColor, boxyRingOuterPlaneVisibleThroughWalls), + new InterCircleStrip(radius1_2, radius3_2, segmentAmount, playerX, lowY , lowY , playerZ, boxyRingOuterPlaneColor, boxyRingOuterPlaneVisibleThroughWalls) ); } } \ No newline at end of file diff --git a/src/client/java/yellowbirb/birbaddons/render/shapes/CircleXZ.java b/src/client/java/yellowbirb/birbaddons/render/shapes/CircleXZ.java index 97b749a..79a0e38 100644 --- a/src/client/java/yellowbirb/birbaddons/render/shapes/CircleXZ.java +++ b/src/client/java/yellowbirb/birbaddons/render/shapes/CircleXZ.java @@ -18,33 +18,27 @@ public class CircleXZ implements RenderShape{ public final float x; public final float y; public final float z; - public final int r; - public final int g; - public final int b; - public final int a; + public final int color; public final int lineWidth; public final boolean visibleThroughWalls; - public CircleXZ(float radius, int segmentAmount, float x, float y, float z, int r, int g, int b, int a, int lineWidth, boolean visibleThroughWalls) { + public CircleXZ(float radius, int segmentAmount, float x, float y, float z, int color, int lineWidth, boolean visibleThroughWalls) { this.radius = radius; this.segmentAmount = max(8, segmentAmount); this.x = x; this.y = y; this.z = z; - this.r = r; - this.g = g; - this.b = b; - this.a = a; + this.color = color; this.lineWidth = lineWidth; this.visibleThroughWalls = visibleThroughWalls; } - public CircleXZ(float radius, int segmentAmount, float x, float y, float z, int r, int g, int b, int a, boolean visibleThroughWalls) { - this(radius, segmentAmount, x, y, z, r, g, b, a, 1, visibleThroughWalls); + public CircleXZ(float radius, int segmentAmount, float x, float y, float z, int color, boolean visibleThroughWalls) { + this(radius, segmentAmount, x, y, z, color, 1, visibleThroughWalls); } - public CircleXZ(float radius, float segmentLength, float x, float y, float z, int r, int g, int b, int a, boolean visibleThroughWalls) { - this(radius, max(8, (int) round((PI * radius * 2) / segmentLength)), x, y, z, r, g, b, a, visibleThroughWalls); + public CircleXZ(float radius, float segmentLength, float x, float y, float z, int color, boolean visibleThroughWalls) { + this(radius, max(8, (int) round((PI * radius * 2) / segmentLength)), x, y, z, color, visibleThroughWalls); } @Override @@ -76,11 +70,11 @@ public void render(PoseStack matrixStack, VertexConsumer vertexConsumer) { Vector3f normalVec = new Vector3f(x2-x1, 0, z2-z1).normalize(); vertexConsumer.addVertex(entry, x1, y, z1) - .setColor(r, g, b, a) + .setColor(color) .setNormal(entry, normalVec) .setLineWidth(lineWidth); vertexConsumer.addVertex(entry, x2, y, z2) - .setColor(r, g, b, a) + .setColor(color) .setNormal(entry, normalVec) .setLineWidth(lineWidth); } diff --git a/src/client/java/yellowbirb/birbaddons/render/shapes/InterCircleStrip.java b/src/client/java/yellowbirb/birbaddons/render/shapes/InterCircleStrip.java index c82f978..3602949 100644 --- a/src/client/java/yellowbirb/birbaddons/render/shapes/InterCircleStrip.java +++ b/src/client/java/yellowbirb/birbaddons/render/shapes/InterCircleStrip.java @@ -17,13 +17,10 @@ public class InterCircleStrip implements RenderShape{ public final float y1; // assumes same center and segmentAmount for both circles public final float y2; public final float z; - public final int r; - public final int g; - public final int b; - public final int a; + public final int color; public final boolean visibleThroughWalls; - public InterCircleStrip(float radius1, float radius2, int segmentAmount, float x, float y1, float y2, float z, int r, int g, int b, int a, boolean visibleThroughWalls) { + public InterCircleStrip(float radius1, float radius2, int segmentAmount, float x, float y1, float y2, float z, int color, boolean visibleThroughWalls) { this.radius1 = radius1; this.radius2 = radius2; this.segmentAmount = segmentAmount; @@ -31,10 +28,7 @@ public InterCircleStrip(float radius1, float radius2, int segmentAmount, float x this.y1 = y1; this.y2 = y2; this.z = z; - this.r = r; - this.g = g; - this.b = b; - this.a = a; + this.color = color; this.visibleThroughWalls = visibleThroughWalls; } @@ -59,10 +53,10 @@ public void render(PoseStack matrixStack, VertexConsumer vertexConsumer) { for (int i = 0; i < segmentAmount; i++) { int next = (i + 1) % segmentAmount; - vertexConsumer.addVertex(entry, getCircleVertex(i, segmentAmount, radius1, x, y1, z)).setColor(r, g, b, a); - vertexConsumer.addVertex(entry, getCircleVertex(i, segmentAmount, radius2, x, y2, z)).setColor(r, g, b, a); - vertexConsumer.addVertex(entry, getCircleVertex(next, segmentAmount, radius2, x, y2, z)).setColor(r, g, b, a); - vertexConsumer.addVertex(entry, getCircleVertex(next, segmentAmount, radius1, x, y1, z)).setColor(r, g, b, a); + vertexConsumer.addVertex(entry, getCircleVertex(i, segmentAmount, radius1, x, y1, z)).setColor(color); + vertexConsumer.addVertex(entry, getCircleVertex(i, segmentAmount, radius2, x, y2, z)).setColor(color); + vertexConsumer.addVertex(entry, getCircleVertex(next, segmentAmount, radius2, x, y2, z)).setColor(color); + vertexConsumer.addVertex(entry, getCircleVertex(next, segmentAmount, radius1, x, y1, z)).setColor(color); } } From 6ba78a5b9286c1bd0ffbc9459acc0fd0d104669e Mon Sep 17 00:00:00 2001 From: Sophie <295312950+SophieMidnight@users.noreply.github.com> Date: Sun, 25 Oct 2026 01:44:38 +0800 Subject: [PATCH 2/4] made Theodolite solver work at some limit values --- .../birbaddons/config/ConfigInteger.java | 40 ++++++ .../birbaddons/feature/impl/Theodolite.java | 115 ++++++++++++++---- .../birbaddons/render/RenderUtils.java | 23 ++-- 3 files changed, 139 insertions(+), 39 deletions(-) create mode 100644 src/client/java/yellowbirb/birbaddons/config/ConfigInteger.java diff --git a/src/client/java/yellowbirb/birbaddons/config/ConfigInteger.java b/src/client/java/yellowbirb/birbaddons/config/ConfigInteger.java new file mode 100644 index 0000000..eeab24a --- /dev/null +++ b/src/client/java/yellowbirb/birbaddons/config/ConfigInteger.java @@ -0,0 +1,40 @@ +package yellowbirb.birbaddons.config; + +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import net.fabricmc.fabric.api.client.command.v2.ClientCommands; +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import yellowbirb.birbaddons.util.Utils; + +import java.util.function.Consumer; + +public class ConfigInteger extends ConfigValue{ + public ConfigInteger(String featureKey, String valueKey, Integer defaultValue) { + super(featureKey, valueKey, defaultValue); + } + + @Override + public Integer getFromJsonElement(JsonElement json) { + return json.getAsInt(); + } + + @Override + public JsonElement getAsJsonElement(Integer value) { + return new JsonPrimitive(value); + } + + @Override + public LiteralArgumentBuilder getCommand(Consumer consumer) { + return ClientCommands.literal(getValueKey().toLowerCase()) + .then(ClientCommands.argument("integer", IntegerArgumentType.integer()) + .executes((ctx) -> { + int arg = IntegerArgumentType.getInteger(ctx, "integer"); + set(arg); + consumer.accept(arg); + Utils.displayMessage(ctx.getSource().getPlayer(), "set " + getValueKey() + " to " + arg); + return 1; + })); + } +} diff --git a/src/client/java/yellowbirb/birbaddons/feature/impl/Theodolite.java b/src/client/java/yellowbirb/birbaddons/feature/impl/Theodolite.java index 9bd8704..fa246ec 100644 --- a/src/client/java/yellowbirb/birbaddons/feature/impl/Theodolite.java +++ b/src/client/java/yellowbirb/birbaddons/feature/impl/Theodolite.java @@ -7,69 +7,113 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLevelEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.player.LocalPlayer; import net.minecraft.network.chat.Component; +import yellowbirb.birbaddons.config.ConfigBoolean; +import yellowbirb.birbaddons.config.ConfigInteger; import yellowbirb.birbaddons.event.ReceiveGameMessageEvent; import yellowbirb.birbaddons.feature.Feature; +import yellowbirb.birbaddons.gui.mainmenu.FeatureSettingsPopup; import yellowbirb.birbaddons.render.RenderManager; import yellowbirb.birbaddons.render.RenderUtils; import yellowbirb.birbaddons.util.Utils; +import java.util.function.Consumer; + public class Theodolite extends Feature { - private static final String THEODOLITE_MESSAGE = "The target is around [0-9]+ blocks (below|above), at a [1-9][0-9]? degrees angle!"; - private static final String PELT_REWARD_MESSAGE = "Killing the animal rewarded you [1-9][0-9]? pelts."; + private final ConfigInteger maxResults; + private final ConfigBoolean allowInputZero; + + private static final String THEODOLITE_MESSAGE_A = "The target is around \\d+ blocks (below|above), at a \\d+ degrees angle!"; + private static final String THEODOLITE_MESSAGE_B = "You are at the exact height!"; + private static final String TASK_COMPLETED_MESSAGE = "Return to the Trapper soon to get a new animal to hunt!"; private int boxyRingCounter = 0; public Theodolite() { super("Theodolite", "Theodolite"); - ReceiveGameMessageEvent.register(THEODOLITE_MESSAGE, (msg) -> { + maxResults = new ConfigInteger(ID, "maxResults", 2); + allowInputZero = new ConfigBoolean(ID, "allowInputZero", false); + + ReceiveGameMessageEvent.register(THEODOLITE_MESSAGE_A, (msg) -> { if (enabled.get()) { String[] words = msg.split("\\s"); + int rawDeltaY = Integer.parseInt(words[4]); + int rawAngle = Integer.parseInt(words[9]); - int deltaY = Integer.parseInt(words[4]); - double alpha = Math.toRadians(90 - Integer.parseInt(words[9])); - - LocalPlayer player = Minecraft.getInstance().player; - // can only be called in-game, so there must for sure be a player riiiiight - assert player != null; - - if (Integer.parseInt(words[9]) == 0) { - Utils.displayMessage("Cannot calculate with 0 degree angle"); + if (!allowInputZero.get() && rawAngle == 0) { + Utils.displayMessage("Skipping 0 degree angle"); return; } + float deltaY = rawDeltaY; + float deltaY1 = rawDeltaY + 2.5F; + float deltaY2 = rawDeltaY == 5 ? 0.5F : rawDeltaY - 2.5F; + if (words[6].equals("below,")) { deltaY = -deltaY; + deltaY1 = -deltaY1; + deltaY2 = -deltaY2; } - float angleMargin = 2.5F; - float heightMargin = 2.5F; + int angle = 90 - rawAngle; - int boxyRingInnerColor = 0xFFFF0000; - boolean boxyRingInnerVisibleThroughWalls = true; + double alpha = Math.toRadians(angle); + double alpha1 = Math.toRadians(Math.min(angle + 2.5, 90)); + double alpha2 = Math.toRadians(Math.max(angle - 2.5, 0)); - int boxyRingOuterCornerColor = 0xFF00FF00; - boolean boxyRingOuterCornerVisibleThroughWalls = false; + process(deltaY, deltaY1, deltaY2, alpha, alpha1, alpha2); + } + }); - int boxyRingOuterPlaneColor = 0x3200FF00; - boolean boxyRingOuterPlaneVisibleThroughWalls = false; + ReceiveGameMessageEvent.register(THEODOLITE_MESSAGE_B, (_) -> { + if (enabled.get()) { + if (!allowInputZero.get()) { + Utils.displayMessage("Skipping exact height"); + return; + } - RenderManager.add(RenderUtils.createBoxyRing(ID, "boxyRing" + boxyRingCounter++, - alpha, deltaY, (float) player.getX(), (float) player.getY(), (float) player.getZ(), - angleMargin, heightMargin, - boxyRingInnerColor, boxyRingInnerVisibleThroughWalls, - boxyRingOuterCornerColor, boxyRingOuterCornerVisibleThroughWalls, - boxyRingOuterPlaneColor, boxyRingOuterPlaneVisibleThroughWalls)); + process(0.0F, 0.5F, -0.5F, + 0, Math.toRadians(90), Math.toRadians(0)); } }); - ReceiveGameMessageEvent.register(PELT_REWARD_MESSAGE, (_) -> RenderManager.clear(ID)); + ReceiveGameMessageEvent.register(TASK_COMPLETED_MESSAGE, (_) -> RenderManager.clear(ID)); ClientPlayConnectionEvents.DISCONNECT.register((_, _) -> RenderManager.clear(ID)); ClientLevelEvents.AFTER_CLIENT_LEVEL_CHANGE.register((_, _) -> RenderManager.clear(ID)); + + // there could be a hud indicating the current minus target Y level + } + + private void process(float deltaY, float deltaY1, float deltaY2, + double alpha, double alpha1, double alpha2) { + + LocalPlayer player = Minecraft.getInstance().player; + // can only be called in-game, so there must for sure be a player riiiiight + assert player != null; + + int boxyRingInnerColor = 0xFFFF0000; + boolean boxyRingInnerVisibleThroughWalls = true; + + int boxyRingOuterCornerColor = 0xFF00FF00; + boolean boxyRingOuterCornerVisibleThroughWalls = false; + + int boxyRingOuterPlaneColor = 0x3200FF00; + boolean boxyRingOuterPlaneVisibleThroughWalls = false; + + boxyRingCounter = (boxyRingCounter + 1) % maxResults.get(); + + RenderManager.add(RenderUtils.createBoxyRing(ID, "boxyRing" + boxyRingCounter, + (float) player.getX(), (float) player.getY(), (float) player.getZ(), + alpha, alpha1, alpha2, + deltaY, deltaY1, deltaY2, + boxyRingInnerColor, boxyRingInnerVisibleThroughWalls, + boxyRingOuterCornerColor, boxyRingOuterCornerVisibleThroughWalls, + boxyRingOuterPlaneColor, boxyRingOuterPlaneVisibleThroughWalls)); } @Override @@ -81,6 +125,13 @@ public void onDisable() { public LiteralArgumentBuilder getCommand() { LiteralArgumentBuilder command = super.getCommand(); + LiteralArgumentBuilder set = ClientCommands.literal("set"); + + set.then(maxResults.getCommand()); + set.then(allowInputZero.getCommand()); + + command.then(set); + LiteralArgumentBuilder clear = ClientCommands.literal("clear").executes((context) -> { RenderManager.clear(ID); Utils.displayMessage(context.getSource().getPlayer(), "Cleared all Theodolite objects drawn in the world"); @@ -121,4 +172,14 @@ public LiteralArgumentBuilder getCommand() { return command; } + @Override + public FeatureSettingsPopup getSettingsPopup(int x, int y, int width, int height, Consumer removeWidgetConsumer) { + return new FeatureSettingsPopup(x, y, width, height, removeWidgetConsumer, this.name){ + @Override + protected void initSettings() { + addSwitch("Allow Input Zero", allowInputZero); + } + }; + } + } diff --git a/src/client/java/yellowbirb/birbaddons/render/RenderUtils.java b/src/client/java/yellowbirb/birbaddons/render/RenderUtils.java index c381bc2..b6f210f 100644 --- a/src/client/java/yellowbirb/birbaddons/render/RenderUtils.java +++ b/src/client/java/yellowbirb/birbaddons/render/RenderUtils.java @@ -9,27 +9,26 @@ public class RenderUtils { public static CompoundShape createBoxyRing(String featureID, String ID, - double alpha, int deltaY, float playerX, float playerY, float playerZ, - float angleMargin, float heightMargin, + float playerX, float playerY, float playerZ, + double alpha, double alpha1, double alpha2, + float deltaY, float deltaY1, float deltaY2, int boxyRingInnerColor, boolean boxyRingInnerVisibleThroughWalls, int boxyRingOuterCornerColor, boolean boxyRingOuterCornerVisibleThroughWalls, int boxyRingOuterPlaneColor, boolean boxyRingOuterPlaneVisibleThroughWalls) { - double margin_rad = Math.toRadians(angleMargin); + float radius1_1 = (float) (Math.min(Math.abs(Math.tan(alpha1) * deltaY1), 2e3)); + float radius1_2 = (float) (Math.min(Math.abs(Math.tan(alpha1) * deltaY2), 2e3)); - float radius1_1 = (float) (Math.abs(Math.tan(alpha + margin_rad) * (deltaY + heightMargin))); - float radius1_2 = (float) (Math.abs(Math.tan(alpha + margin_rad) * (deltaY - heightMargin))); + float radius2 = (float) (Math.min(Math.abs(Math.tan(alpha) * deltaY), 2e3)); - float radius2 = (float) (Math.abs(Math.tan(alpha) * deltaY)); - - float radius3_1 = (float) (Math.abs(Math.tan(alpha - margin_rad) * (deltaY + heightMargin))); - float radius3_2 = (float) (Math.abs(Math.tan(alpha - margin_rad) * (deltaY - heightMargin))); + float radius3_1 = (float) (Math.abs(Math.tan(alpha2) * deltaY1)); + float radius3_2 = (float) (Math.abs(Math.tan(alpha2) * deltaY2)); float segmentLength = 0.5f; // resampling segmentAmount to draw clean InterCircleStrips - int segmentAmount = max(8, (int) round((PI * max(radius1_1, max(radius1_2, max(radius2, max(radius3_1, radius3_2)))) * 2) / segmentLength)); - float lowY = playerY + deltaY - heightMargin; - float highY = playerY + deltaY + heightMargin; + int segmentAmount = (int) round(clamp((PI * max(radius1_1, radius1_2) * 2) / segmentLength, 8, 128)); + float highY = playerY + deltaY1; + float lowY = playerY + deltaY2; return new CompoundShape(featureID, ID, new CircleXZ(radius1_1, segmentAmount, playerX, highY, playerZ, boxyRingOuterCornerColor, boxyRingOuterCornerVisibleThroughWalls), From 011750fa341861ae129d5c6b5ce108afd64c0ea4 Mon Sep 17 00:00:00 2001 From: Sophie <295312950+SophieMidnight@users.noreply.github.com> Date: Sun, 25 Oct 2026 16:47:17 +0800 Subject: [PATCH 3/4] colorful --- .../birbaddons/feature/impl/Theodolite.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/client/java/yellowbirb/birbaddons/feature/impl/Theodolite.java b/src/client/java/yellowbirb/birbaddons/feature/impl/Theodolite.java index fa246ec..cd88d95 100644 --- a/src/client/java/yellowbirb/birbaddons/feature/impl/Theodolite.java +++ b/src/client/java/yellowbirb/birbaddons/feature/impl/Theodolite.java @@ -19,6 +19,7 @@ import yellowbirb.birbaddons.render.RenderUtils; import yellowbirb.birbaddons.util.Utils; +import java.awt.*; import java.util.function.Consumer; public class Theodolite extends Feature { @@ -81,10 +82,10 @@ public Theodolite() { } }); - ReceiveGameMessageEvent.register(TASK_COMPLETED_MESSAGE, (_) -> RenderManager.clear(ID)); + ReceiveGameMessageEvent.register(TASK_COMPLETED_MESSAGE, (_) -> clear()); - ClientPlayConnectionEvents.DISCONNECT.register((_, _) -> RenderManager.clear(ID)); - ClientLevelEvents.AFTER_CLIENT_LEVEL_CHANGE.register((_, _) -> RenderManager.clear(ID)); + ClientPlayConnectionEvents.DISCONNECT.register((_, _) -> clear()); + ClientLevelEvents.AFTER_CLIENT_LEVEL_CHANGE.register((_, _) -> clear()); // there could be a hud indicating the current minus target Y level } @@ -96,13 +97,15 @@ private void process(float deltaY, float deltaY1, float deltaY2, // can only be called in-game, so there must for sure be a player riiiiight assert player != null; - int boxyRingInnerColor = 0xFFFF0000; + float hue = (float) boxyRingCounter / maxResults.get() + 1.0F / 3; + + int boxyRingInnerColor = Color.HSBtoRGB(hue, 1.0F, 0.8F); boolean boxyRingInnerVisibleThroughWalls = true; - int boxyRingOuterCornerColor = 0xFF00FF00; + int boxyRingOuterCornerColor = Color.HSBtoRGB(hue, 1.0F, 1.0F); boolean boxyRingOuterCornerVisibleThroughWalls = false; - int boxyRingOuterPlaneColor = 0x3200FF00; + int boxyRingOuterPlaneColor = Color.HSBtoRGB(hue, 0.8F, 1.0F) & 0x00FFFFFF | 0x32000000; boolean boxyRingOuterPlaneVisibleThroughWalls = false; boxyRingCounter = (boxyRingCounter + 1) % maxResults.get(); @@ -116,9 +119,14 @@ private void process(float deltaY, float deltaY1, float deltaY2, boxyRingOuterPlaneColor, boxyRingOuterPlaneVisibleThroughWalls)); } + private void clear() { + RenderManager.clear(ID); + boxyRingCounter = 0; + } + @Override public void onDisable() { - RenderManager.clear(ID); + clear(); } @Override @@ -133,7 +141,7 @@ public LiteralArgumentBuilder getCommand() { command.then(set); LiteralArgumentBuilder clear = ClientCommands.literal("clear").executes((context) -> { - RenderManager.clear(ID); + clear(); Utils.displayMessage(context.getSource().getPlayer(), "Cleared all Theodolite objects drawn in the world"); return 1; }); @@ -177,7 +185,7 @@ public FeatureSettingsPopup getSettingsPopup(int x, int y, int width, int height return new FeatureSettingsPopup(x, y, width, height, removeWidgetConsumer, this.name){ @Override protected void initSettings() { - addSwitch("Allow Input Zero", allowInputZero); + addSwitch("Allow 0 as input", allowInputZero); } }; } From 6b12d39d44aad04492eaabc0bf3f6dfcf0ce134b Mon Sep 17 00:00:00 2001 From: Sophie <295312950+SophieMidnight@users.noreply.github.com> Date: Sun, 25 Oct 2026 19:52:56 +0800 Subject: [PATCH 4/4] optimization for high ping --- .../birbaddons/feature/impl/Theodolite.java | 82 ++++++++++++++----- 1 file changed, 60 insertions(+), 22 deletions(-) diff --git a/src/client/java/yellowbirb/birbaddons/feature/impl/Theodolite.java b/src/client/java/yellowbirb/birbaddons/feature/impl/Theodolite.java index cd88d95..225fb95 100644 --- a/src/client/java/yellowbirb/birbaddons/feature/impl/Theodolite.java +++ b/src/client/java/yellowbirb/birbaddons/feature/impl/Theodolite.java @@ -6,10 +6,20 @@ import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLevelEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; +import net.fabricmc.fabric.api.event.player.UseBlockCallback; +import net.fabricmc.fabric.api.event.player.UseItemCallback; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.player.LocalPlayer; +import net.minecraft.core.component.DataComponents; +import net.minecraft.nbt.StringTag; import net.minecraft.network.chat.Component; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.Vec3; import yellowbirb.birbaddons.config.ConfigBoolean; import yellowbirb.birbaddons.config.ConfigInteger; import yellowbirb.birbaddons.event.ReceiveGameMessageEvent; @@ -26,18 +36,33 @@ public class Theodolite extends Feature { private final ConfigInteger maxResults; private final ConfigBoolean allowInputZero; + private final ConfigBoolean colorfulRings; private static final String THEODOLITE_MESSAGE_A = "The target is around \\d+ blocks (below|above), at a \\d+ degrees angle!"; private static final String THEODOLITE_MESSAGE_B = "You are at the exact height!"; private static final String TASK_COMPLETED_MESSAGE = "Return to the Trapper soon to get a new animal to hunt!"; + private Vec3 lastUsedAt = Vec3.ZERO; private int boxyRingCounter = 0; public Theodolite() { super("Theodolite", "Theodolite"); - maxResults = new ConfigInteger(ID, "maxResults", 2); + maxResults = new ConfigInteger(ID, "maxResults", 3); allowInputZero = new ConfigBoolean(ID, "allowInputZero", false); + colorfulRings = new ConfigBoolean(ID, "colorfulRings", false); + + UseItemCallback.EVENT.register((player, level, hand) -> { + if (isTheodoliteItem(player.getItemInHand(hand))) + lastUsedAt = player.position(); + return InteractionResult.PASS; + }); + + UseBlockCallback.EVENT.register((player, level, hand, result) -> { + if (isTheodoliteItem(player.getItemInHand(hand))) + lastUsedAt = player.position(); + return InteractionResult.PASS; + }); ReceiveGameMessageEvent.register(THEODOLITE_MESSAGE_A, (msg) -> { if (enabled.get()) { @@ -60,13 +85,11 @@ public Theodolite() { deltaY2 = -deltaY2; } - int angle = 90 - rawAngle; - - double alpha = Math.toRadians(angle); - double alpha1 = Math.toRadians(Math.min(angle + 2.5, 90)); - double alpha2 = Math.toRadians(Math.max(angle - 2.5, 0)); + double angle = 90 - rawAngle; + double angle1 = Math.min(angle + 2.5, 90); + double angle2 = Math.max(angle - 2.5, 0); - process(deltaY, deltaY1, deltaY2, alpha, alpha1, alpha2); + process(deltaY, deltaY1, deltaY2, angle, angle1, angle2); } }); @@ -78,7 +101,7 @@ public Theodolite() { } process(0.0F, 0.5F, -0.5F, - 0, Math.toRadians(90), Math.toRadians(0)); + 0, 90, 0); } }); @@ -86,33 +109,45 @@ public Theodolite() { ClientPlayConnectionEvents.DISCONNECT.register((_, _) -> clear()); ClientLevelEvents.AFTER_CLIENT_LEVEL_CHANGE.register((_, _) -> clear()); + } - // there could be a hud indicating the current minus target Y level + private static boolean isTheodoliteItem(ItemStack itemStack) { + var tmp = itemStack.get(DataComponents.CUSTOM_DATA); + if (tmp != null) { + var tmp2 = tmp.copyTag().get("id"); + if (tmp2 instanceof StringTag(String value)) { + return "TALBOTS_THEODOLITE".equals(value); + } + } + return false; } private void process(float deltaY, float deltaY1, float deltaY2, - double alpha, double alpha1, double alpha2) { + double angle, double angle1, double angle2) { - LocalPlayer player = Minecraft.getInstance().player; - // can only be called in-game, so there must for sure be a player riiiiight - assert player != null; + int boxyRingInnerColor, boxyRingOuterCornerColor, boxyRingOuterPlaneColor; - float hue = (float) boxyRingCounter / maxResults.get() + 1.0F / 3; + if (colorfulRings.get()) { + float hue = (float) boxyRingCounter / maxResults.get() + 1.0F / 3; - int boxyRingInnerColor = Color.HSBtoRGB(hue, 1.0F, 0.8F); - boolean boxyRingInnerVisibleThroughWalls = true; + boxyRingInnerColor = Color.HSBtoRGB(hue, 1.0F, 0.8F); + boxyRingOuterCornerColor = Color.HSBtoRGB(hue, 1.0F, 1.0F); + boxyRingOuterPlaneColor = Color.HSBtoRGB(hue, 0.8F, 1.0F) & 0x00FFFFFF | 0x32000000; + } else { + boxyRingInnerColor = 0xFFFF0000; + boxyRingOuterCornerColor = 0xFF00FF00; + boxyRingOuterPlaneColor = 0x3200FF00; + } - int boxyRingOuterCornerColor = Color.HSBtoRGB(hue, 1.0F, 1.0F); + boolean boxyRingInnerVisibleThroughWalls = true; boolean boxyRingOuterCornerVisibleThroughWalls = false; - - int boxyRingOuterPlaneColor = Color.HSBtoRGB(hue, 0.8F, 1.0F) & 0x00FFFFFF | 0x32000000; boolean boxyRingOuterPlaneVisibleThroughWalls = false; boxyRingCounter = (boxyRingCounter + 1) % maxResults.get(); RenderManager.add(RenderUtils.createBoxyRing(ID, "boxyRing" + boxyRingCounter, - (float) player.getX(), (float) player.getY(), (float) player.getZ(), - alpha, alpha1, alpha2, + (float) lastUsedAt.x, (float) lastUsedAt.y, (float) lastUsedAt.z, + Math.toRadians(angle), Math.toRadians(angle1), Math.toRadians(angle2), deltaY, deltaY1, deltaY2, boxyRingInnerColor, boxyRingInnerVisibleThroughWalls, boxyRingOuterCornerColor, boxyRingOuterCornerVisibleThroughWalls, @@ -137,6 +172,7 @@ public LiteralArgumentBuilder getCommand() { set.then(maxResults.getCommand()); set.then(allowInputZero.getCommand()); + set.then(colorfulRings.getCommand()); command.then(set); @@ -157,6 +193,7 @@ public LiteralArgumentBuilder getCommand() { if (!enabled()) { Utils.displayMessage("Feature is not enabled!"); } else { + lastUsedAt = context.getSource().getPlayer().position(); int deltay = IntegerArgumentType.getInteger(context, "deltay"); int angle = IntegerArgumentType.getInteger(context, "angle"); if (deltay == 0) { @@ -186,6 +223,7 @@ public FeatureSettingsPopup getSettingsPopup(int x, int y, int width, int height @Override protected void initSettings() { addSwitch("Allow 0 as input", allowInputZero); + addSwitch("Colorful Rings", colorfulRings); } }; }