1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
package de.hysky.skyblocker.skyblock;
import de.hysky.skyblocker.annotations.Init;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.render.RenderHelper;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.util.StringIdentifiable;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.ColorHelper;
import net.minecraft.util.math.Vec3d;
import java.awt.*;
public class GyroOverlay {
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();
private static float[] colorComponents;
private static final int GYRO_RADIUS = 10;
private static final int SEGMENTS = 32;
private static final int MAX_REACH = 24;
// init ofcourse
@Init
public static void init() {
configCallback(SkyblockerConfigManager.get().uiAndVisuals.gyroOverlay.gyroOverlayColor);
WorldRenderEvents.AFTER_TRANSLUCENT.register(GyroOverlay::render);
}
// render
/**
* Renders a visual overlay in the world when the player is holding the Gyrokinetic Wand on Skyblock.
* <p>
* The overlay type depends on the configuration setting:
* <ul>
* <li>{@code OFF} – does not render anything.</li>
* <li>{@code CIRCLE_OUTLINE} – renders a ring-shaped outline using quads.</li>
* <li>{@code CIRCLE} – renders a filled circle.</li>
* <li>{@code SPHERE} – renders a 3D sphere.</li>
* </ul>
* The overlay is only rendered if:
* <ul>
* <li>The player is in a Skyblock world.</li>
* <li>The overlay mode is not {@code OFF}.</li>
* <li>The player is holding the {@code GYROKINETIC_WAND} in the main hand.</li>
* <li>The raycast from the camera hits a block or entity (i.e., not a miss).</li>
* </ul>
*
* @param wrc The {@link WorldRenderContext} provided during world rendering,
* containing rendering matrices and utilities for rendering custom elements.
*/
public static void render(WorldRenderContext wrc) {
if (CLIENT.player == null || CLIENT.world == null) return;
if (!Utils.isOnSkyblock()) return;
if (SkyblockerConfigManager.get().uiAndVisuals.gyroOverlay.gyroOverlayMode == Mode.OFF) return;
String heldItem = CLIENT.player.getMainHandStack().getSkyblockId();
if (!heldItem.equals("GYROKINETIC_WAND")) return;
HitResult hit = CLIENT.cameraEntity.raycast(MAX_REACH, MinecraftClient.getInstance().getRenderTickCounter().getTickProgress(false), false);
if (hit.getType() == HitResult.Type.MISS) {
return;
}
int color = ColorHelper.fromFloats(colorComponents[3], colorComponents[0], colorComponents[1], colorComponents[2]);
switch (SkyblockerConfigManager.get().uiAndVisuals.gyroOverlay.gyroOverlayMode) {
case OFF -> {}
case CIRCLE_OUTLINE -> RenderHelper.renderCircleOutlineWithQuads(wrc, hit.getPos().add(new Vec3d(0, 0.1, 0)), GYRO_RADIUS, 0.25f, SEGMENTS, color);
case CIRCLE -> RenderHelper.renderCircleFilled(wrc, hit.getPos().add(new Vec3d(0, 0.1, 0)), GYRO_RADIUS, SEGMENTS, color);
case SPHERE -> RenderHelper.renderSphere(wrc, hit.getPos(), GYRO_RADIUS, SEGMENTS, SEGMENTS, color);
}
}
public static void configCallback(Color color) {
colorComponents = color.getRGBComponents(null);
}
public enum Mode implements StringIdentifiable {
OFF("OFF"),
CIRCLE("CIRCLE"),
CIRCLE_OUTLINE("CIRCLE_OUTLINE"),
SPHERE("SPHERE");
private final String key;
Mode(String key) {
this.key = "skyblocker.config.uiAndVisuals.gyroOverlay.mode." + key;
}
@Override
public String asString() {
return name().toLowerCase();
}
@Override
public String toString() {
return I18n.translate(this.key);
}
}
}
|