waypoints module

waypoints: Minecraft 26.3 cheat module, full source for every implementation (4 clients: Meteor Client, MelaHack (ThunderHack fork), OfflineClient, …).

4 implementationsRenderCLIENTRENDERGeneral

Full module source: 4 implementations

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

Meteor ClientRendersrc/main/java/meteordevelopment/meteorclient/systems/modules/render/WaypointsModule.javaJava · 342 lines · 12.4 KB

Allows you to create waypoints.

Settingstext-render-distancewaypoint-fade-distancemax-death-positionschatDeath
WaypointsModule.javaJava · Minecraft 26.2 · 342 lines · 12.4 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
3
 * Copyright (c) Meteor Development.
4
 */
5
6
package meteordevelopment.meteorclient.systems.modules.render;
7
8
import meteordevelopment.meteorclient.events.game.OpenScreenEvent;
9
import meteordevelopment.meteorclient.events.render.Render2DEvent;
10
import meteordevelopment.meteorclient.gui.GuiTheme;
11
import meteordevelopment.meteorclient.gui.renderer.GuiRenderer;
12
import meteordevelopment.meteorclient.gui.screens.EditSystemScreen;
13
import meteordevelopment.meteorclient.gui.widgets.WLabel;
14
import meteordevelopment.meteorclient.gui.widgets.WWidget;
15
import meteordevelopment.meteorclient.gui.widgets.containers.WTable;
16
import meteordevelopment.meteorclient.gui.widgets.pressable.WButton;
17
import meteordevelopment.meteorclient.gui.widgets.pressable.WCheckbox;
18
import meteordevelopment.meteorclient.gui.widgets.pressable.WConfirmedMinus;
19
import meteordevelopment.meteorclient.pathing.PathManagers;
20
import meteordevelopment.meteorclient.renderer.text.TextRenderer;
21
import meteordevelopment.meteorclient.settings.*;
22
import meteordevelopment.meteorclient.systems.modules.Categories;
23
import meteordevelopment.meteorclient.systems.modules.Module;
24
import meteordevelopment.meteorclient.systems.waypoints.Waypoint;
25
import meteordevelopment.meteorclient.systems.waypoints.Waypoints;
26
import meteordevelopment.meteorclient.utils.Utils;
27
import meteordevelopment.meteorclient.utils.player.ChatUtils;
28
import meteordevelopment.meteorclient.utils.player.PlayerUtils;
29
import meteordevelopment.meteorclient.utils.render.NametagUtils;
30
import meteordevelopment.meteorclient.utils.render.color.Color;
31
import meteordevelopment.orbit.EventHandler;
32
import net.minecraft.client.Minecraft;
33
import net.minecraft.client.gui.screens.DeathScreen;
34
import net.minecraft.core.BlockPos;
35
import net.minecraft.network.chat.Component;
36
import net.minecraft.network.chat.MutableComponent;
37
import net.minecraft.server.permissions.Permissions;
38
import net.minecraft.world.phys.Vec3;
39
import org.joml.Vector3d;
40
41
import java.text.SimpleDateFormat;
42
import java.util.ArrayList;
43
import java.util.Date;
44
import java.util.List;
45
46
import static meteordevelopment.meteorclient.utils.player.ChatUtils.formatCoords;
47
48
public class WaypointsModule extends Module {
49
    private static final Color GRAY = new Color(200, 200, 200);
50
    private static final Color TEXT = new Color(255, 255, 255);
51
52
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
53
    private final SettingGroup sgDeathPosition = settings.createGroup("Death Position");
54
55
    public final Setting<Integer> textRenderDistance = sgGeneral.add(new IntSetting.Builder()
56
        .name("text-render-distance")
57
        .description("Maximum distance from the center of the screen at which text will be rendered.")
58
        .defaultValue(100)
59
        .min(0)
60
        .sliderMax(200)
61
        .build()
62
    );
63
64
    private final Setting<Integer> waypointFadeDistance = sgGeneral.add(new IntSetting.Builder()
65
        .name("waypoint-fade-distance")
66
        .description("The distance to a waypoint at which it begins to start fading.")
67
        .defaultValue(20)
68
        .sliderRange(0, 100)
69
        .min(0)
70
        .build()
71
    );
72
73
    private final Setting<Integer> maxDeathPositions = sgDeathPosition.add(new IntSetting.Builder()
74
        .name("max-death-positions")
75
        .description("The amount of death positions to save, 0 to disable")
76
        .defaultValue(0)
77
        .min(0)
78
        .sliderMax(20)
79
        .onChanged(this::cleanDeathWPs)
80
        .build()
81
    );
82
83
    private final Setting<Boolean> dpChat = sgDeathPosition.add(new BoolSetting.Builder()
84
        .name("chat")
85
        .description("Send a chat message with your position once you die")
86
        .defaultValue(false)
87
        .build()
88
    );
89
90
    public WaypointsModule() {
91
        super(Categories.Render, "waypoints", "Allows you to create waypoints.");
92
    }
93
94
    private final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
95
96
    @EventHandler
97
    private void onRender2D(Render2DEvent event) {
98
        TextRenderer text = TextRenderer.get();
99
        Vector3d center = new Vector3d(mc.getWindow().getWidth() / 2.0, mc.getWindow().getHeight() / 2.0, 0);
100
        int textRenderDist = textRenderDistance.get();
101
102
        List<Waypoint> toRemove = new ArrayList<>();
103
        for (Waypoint waypoint : Waypoints.get()) {
104
            // Continue if this waypoint should not be rendered
105
            if (!waypoint.visible.get() || !Waypoints.checkDimension(waypoint)) continue;
106
107
            // Calculate distance
108
            BlockPos blockPos = waypoint.getPos();
109
            Vector3d pos = new Vector3d(blockPos.getX() + 0.5, blockPos.getY(), blockPos.getZ() + 0.5);
110
            double dist = PlayerUtils.distanceToCamera(pos.x, pos.y, pos.z);
111
112
            // Only perform hide when near check if player is alive
113
            // Otherwise, death waypoints immediately get hidden
114
            boolean playerAlive = (mc.player != null && !mc.player.isDeadOrDying());
115
            boolean waypointIsNear = waypoint.actionWhenNearCheck((int) Math.floor(dist));
116
            if (playerAlive && waypointIsNear) {
117
                switch (waypoint.actionWhenNear.get()) {
118
                    case Hide -> waypoint.visible.set(false);
119
                    case Delete -> {
120
                        toRemove.add(waypoint);
121
                        continue;
122
                    }
123
                }
124
            }
125
126
            // Continue if this waypoint should not be rendered
127
            if (dist > waypoint.maxVisible.get()) continue;
128
            if (!NametagUtils.to2D(pos, waypoint.scale.get() - 0.2)) continue;
129
130
            // Calculate alpha and distance to center of the screen
131
            double distToCenter = pos.distance(center);
132
            double a = 1;
133
134
            if (dist < waypointFadeDistance.get()) {
135
                a = (dist - (waypointFadeDistance.get() / 2d)) / (waypointFadeDistance.get() / 2d);
136
                if (a < 0.01) continue;
137
            }
138
139
            // Render
140
            NametagUtils.begin(pos, event.graphics);
141
142
            // Render icon
143
            waypoint.renderIcon(-16, -16, a, 32);
144
145
            // Render text if cursor is close enough
146
            if (distToCenter <= textRenderDist) {
147
                // Setup text rendering
148
                int preTextA = TEXT.a;
149
                TEXT.a *= a;
150
                text.begin(event.graphics);
151
152
                // Render name
153
                text.render(waypoint.name.get(), -text.getWidth(waypoint.name.get()) / 2, -16 - text.getHeight(), TEXT, true);
154
155
                // Render distance
156
                String distText = String.format("%d blocks", (int) Math.round(dist));
157
                text.render(distText, -text.getWidth(distText) / 2, 16, TEXT, true);
158
159
                // End text rendering
160
                text.end();
161
                TEXT.a = preTextA;
162
            }
163
164
            NametagUtils.end(event.graphics);
165
        }
166
167
        Waypoints.get().removeAll(toRemove);
168
    }
169
170
    @EventHandler
171
    private void onOpenScreen(OpenScreenEvent event) {
172
        if (!(event.screen instanceof DeathScreen)) return;
173
174
        if (!event.isCancelled()) addDeath(mc.player.position());
175
    }
176
177
    public void addDeath(Vec3 deathPos) {
178
        String time = dateFormat.format(new Date());
179
        if (dpChat.get()) {
180
            MutableComponent text = Component.literal("Died at ");
181
            text.append(formatCoords(deathPos));
182
            text.append(String.format(" on %s.", time));
183
            info(text);
184
        }
185
186
        // Create waypoint
187
        if (maxDeathPositions.get() > 0) {
188
            Waypoint waypoint = new Waypoint.Builder()
189
                .name("Death " + time)
190
                .icon("skull")
191
                .pos(BlockPos.containing(deathPos).above(2))
192
                .dimension(PlayerUtils.getDimension())
193
                .build();
194
195
            // Configure death waypoints to auto delete when the player is within 4 blocks
196
            waypoint.actionWhenNear.set(Waypoint.NearAction.Delete);
197
            waypoint.actionWhenNearDistance.set(4);
198
199
            Waypoints.get().add(waypoint);
200
        }
201
202
        cleanDeathWPs(maxDeathPositions.get());
203
    }
204
205
    private void cleanDeathWPs(int max) {
206
        int oldWpC = 0;
207
208
        List<Waypoint> toRemove = new ArrayList<>();
209
        for (Waypoint wp : Waypoints.get()) {
210
            if (wp.name.get().startsWith("Death ") && wp.icon.get().equals("skull")) {
211
                oldWpC++;
212
213
                if (oldWpC > max) toRemove.add(wp);
214
            }
215
        }
216
217
        Waypoints.get().removeAll(toRemove);
218
    }
219
220
    @Override
221
    public WWidget getWidget(GuiTheme theme) {
222
        if (!Utils.canUpdate()) return theme.label("You need to be in a world.");
223
224
        WTable table = theme.table();
225
        initTable(theme, table);
226
        return table;
227
    }
228
229
    private void initTable(GuiTheme theme, WTable table) {
230
        table.clear();
231
232
        for (Waypoint waypoint : Waypoints.get()) {
233
            boolean validDim = Waypoints.checkDimension(waypoint);
234
235
            table.add(new WIcon(waypoint));
236
237
            WLabel name = table.add(theme.label(waypoint.name.get())).expandCellX().widget();
238
            if (!validDim) name.color = GRAY;
239
240
            WCheckbox visible = table.add(theme.checkbox(waypoint.visible.get())).widget();
241
            visible.action = () -> {
242
                waypoint.visible.set(visible.checked);
243
                Waypoints.get().save();
244
            };
245
246
            WButton edit = table.add(theme.button(GuiRenderer.EDIT)).widget();
247
            edit.action = () -> mc.gui.setScreen(new EditWaypointScreen(theme, waypoint, () -> initTable(theme, table)));
248
249
            // Goto
250
            if (validDim) {
251
                WButton gotoB = table.add(theme.button("Goto")).widget();
252
                gotoB.action = () -> {
253
                    if (PathManagers.get().isPathing())
254
                        PathManagers.get().stop();
255
256
                    PathManagers.get().moveTo(waypoint.getPos());
257
                };
258
            }
259
260
            boolean isOperator = mc.player.permissions().hasPermission(Permissions.COMMANDS_GAMEMASTER);
261
            if (isOperator) {
262
                WButton teleportB = table.add(theme.button("TP")).widget();
263
                teleportB.action = () -> {
264
                    BlockPos pos = waypoint.pos.get();
265
266
                    String command = String.format(
267
                        "/execute in %s run tp %d %d %d",
268
                        waypoint.dimension.toString(),
269
                        pos.getX(),
270
                        pos.getY(),
271
                        pos.getZ()
272
                    );
273
274
                    ChatUtils.sendPlayerMsg(command, false);
275
                };
276
            }
277
278
            WConfirmedMinus remove = table.add(theme.confirmedMinus()).widget();
279
            remove.action = () -> {
280
                Waypoints.get().remove(waypoint);
281
                initTable(theme, table);
282
            };
283
284
            table.row();
285
        }
286
287
        table.add(theme.horizontalSeparator()).expandX();
288
        table.row();
289
290
        WButton create = table.add(theme.button("Create")).expandX().widget();
291
        create.action = () -> mc.gui.setScreen(new EditWaypointScreen(theme, null, () -> initTable(theme, table)));
292
    }
293
294
    private static class EditWaypointScreen extends EditSystemScreen<Waypoint> {
295
        public EditWaypointScreen(GuiTheme theme, Waypoint value, Runnable reload) {
296
            super(theme, value, reload);
297
        }
298
299
        @Override
300
        public Waypoint create() {
301
            return new Waypoint.Builder()
302
                .pos(Minecraft.getInstance().player.blockPosition().above(2))
303
                .dimension(PlayerUtils.getDimension())
304
                .build();
305
        }
306
307
        @Override
308
        public boolean save() {
309
            if (value.name.get().isBlank()) return false;
310
311
            Waypoints.get().add(value);
312
            return true;
313
        }
314
315
        @Override
316
        public Settings getSettings() {
317
            return value.settings;
318
        }
319
    }
320
321
    private static class WIcon extends WWidget {
322
        private final Waypoint waypoint;
323
324
        public WIcon(Waypoint waypoint) {
325
            this.waypoint = waypoint;
326
        }
327
328
        @Override
329
        protected void onCalculateSize() {
330
            double s = theme.scale(32);
331
332
            width = s;
333
            height = s;
334
        }
335
336
        @Override
337
        protected void onRender(GuiRenderer renderer, double mouseX, double mouseY, double delta) {
338
            renderer.post(() -> waypoint.renderIcon(x, y, 1, width));
339
        }
340
    }
341
}
342
MelaHack (ThunderHack fork)CLIENTsrc/main/java/thunder/hack/features/modules/client/WayPoints.javaJava · 72 lines · 3.6 KB

Renders specified waypoints.

WayPoints.javaJava · Minecraft 26.2 · 72 lines · 3.6 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.client;
2
3
import net.minecraft.ChatFormatting;
4
import net.minecraft.client.gui.GuiGraphicsExtractor;
5
import net.minecraft.util.Mth;
6
import net.minecraft.world.phys.Vec3;
7
import org.joml.Vector4d;
8
import thunder.hack.ThunderHack;
9
import thunder.hack.core.Managers;
10
import thunder.hack.core.manager.world.WayPointManager;
11
import thunder.hack.gui.font.FontRenderers;
12
import thunder.hack.features.modules.Module;
13
import thunder.hack.utility.render.Render3DEngine;
14
import thunder.hack.utility.render.TextureStorage;
15
16
public final class WayPoints extends Module {
17
    public WayPoints() {
18
        super("WayPoints", Category.CLIENT);
19
    }
20
21
    @Override
22
    public void onEnable() {
23
        sendMessage(Managers.COMMAND.getPrefix() + "waypoint add x y z name");
24
    }
25
26
    public void onRender2D(GuiGraphicsExtractor context) {
27
        if (!Managers.WAYPOINT.getWayPoints().isEmpty() && !fullNullCheck()) {
28
            for (WayPointManager.WayPoint wp : Managers.WAYPOINT.getWayPoints()) {
29
                if (wp.getName() == null) continue;
30
                if ((mc.isLocalServer() && wp.getServer().equals("SinglePlayer"))
31
                        || (mc.getConnection().getServerData() != null && !mc.getConnection().getServerData().ip.contains(wp.getServer()))) continue;
32
                if (!mc.level.dimension().identifier().getPath().equals(wp.getDimension())) continue;
33
                double difX = wp.getX() - mc.player.position().x;
34
                double difZ = wp.getZ() - mc.player.position().z;
35
                float yaw = (float) Mth.wrapDegrees(Math.toDegrees(Math.atan2(difZ, difX)) - 90.0);
36
                double plYaw = Mth.wrapDegrees(mc.player.getYRot());
37
                if (Math.abs(yaw - plYaw) > 90) continue;
38
39
                Vec3 vector = new Vec3(wp.getX(), wp.getY(), wp.getZ());
40
                Vector4d position = null;
41
                vector = Render3DEngine.worldSpaceToScreenSpace(new Vec3(vector.x, vector.y, vector.z));
42
                position = new Vector4d(vector.x, vector.y, vector.z, 0);
43
                position.x = Math.min(vector.x, position.x);
44
                position.y = Math.min(vector.y, position.y);
45
                position.z = Math.max(vector.x, position.z);
46
47
                double posX = position.x;
48
                double posY = position.y;
49
                double endPosX = position.z;
50
51
                float diff = (float) (endPosX - posX) / 2;
52
                float tagX = (float) ((posX + diff - FontRenderers.sf_bold_mini.getStringWidth(wp.getName()) / 2) * 1);
53
54
                String coords = wp.getX() + " " + wp.getZ();
55
                float tagX2 = (float) ((posX + diff - FontRenderers.sf_bold_mini.getStringWidth(coords) / 2) * 1);
56
57
                String distance = String.format("%.0f", Math.sqrt(mc.player.distanceToSqr(wp.getX(), wp.getY(), wp.getZ()))) + "m";
58
                float tagX3 = (float) ((posX + diff - FontRenderers.sf_bold_mini.getStringWidth(distance) / 2) * 1);
59
60
                context.pose().pushMatrix();
61
                context.pose().translate((float) (posX - 10), (float) ((posY - 35)));
62
                context.blit(net.minecraft.client.renderer.RenderPipelines.GUI_TEXTURED, TextureStorage.waypoint, 0, 0, 20, 20, 0, 0, 20, 20, 20, 20);
63
                context.pose().popMatrix();
64
65
                FontRenderers.sf_bold_mini.drawString(context.pose(), wp.getName(), tagX, (float) posY - 10, -1);
66
                FontRenderers.sf_bold_mini.drawString(context.pose(), ChatFormatting.GRAY + coords, tagX2, (float) posY - 2, -1);
67
                FontRenderers.sf_bold_mini.drawString(context.pose(), ChatFormatting.GRAY + distance, tagX3, (float) posY + 6, -1);
68
            }
69
        }
70
    }
71
}
72
OfflineClientRENDERsrc/main/java/com/jellypudding/offlineclient/modules/render/Waypoints.javaJava · 248 lines · 10.4 KB

Marks the coordinates you saved in the world.

SettingsBeamBeam heightBoxLabelDistanceCoordinatesScaleRangeAcross dimensionsHide withinAutomatic coloursNext colourMark deathsDeaths keptDeath message
Waypoints.javaJava · Minecraft 26.2 · 248 lines · 10.4 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.render;
2
3
import com.jellypudding.offlineclient.config.WaypointStore;
4
import com.jellypudding.offlineclient.event.Subscribe;
5
import com.jellypudding.offlineclient.event.events.Render2DEvent;
6
import com.jellypudding.offlineclient.event.events.Render3DEvent;
7
import com.jellypudding.offlineclient.event.events.TickEvent;
8
import com.jellypudding.offlineclient.module.Category;
9
import com.jellypudding.offlineclient.module.Module;
10
import com.jellypudding.offlineclient.render.DrawBatch;
11
import com.jellypudding.offlineclient.render.WorldToScreen;
12
import com.jellypudding.offlineclient.setting.BoolSetting;
13
import com.jellypudding.offlineclient.setting.ColorSetting;
14
import com.jellypudding.offlineclient.setting.NumberSetting;
15
import com.jellypudding.offlineclient.util.BlockUtil;
16
import com.jellypudding.offlineclient.util.ChatUtil;
17
import com.jellypudding.offlineclient.util.ColorUtil;
18
import com.jellypudding.offlineclient.util.RenderUtil;
19
import net.minecraft.client.gui.Font;
20
import net.minecraft.client.gui.GuiGraphicsExtractor;
21
import net.minecraft.client.player.LocalPlayer;
22
import net.minecraft.core.BlockPos;
23
import net.minecraft.world.phys.AABB;
24
import net.minecraft.world.phys.Vec3;
25
26
import java.time.LocalTime;
27
import java.time.format.DateTimeFormatter;
28
import java.util.ArrayList;
29
import java.util.List;
30
import java.util.Locale;
31
32
public final class Waypoints extends Module {
33
34
    // Death markers are named Death followed by the time of day.
35
    private static final String DEATH_PREFIX = "Death";
36
    private static final DateTimeFormatter DEATH_TIME = DateTimeFormatter.ofPattern("HH:mm:ss");
37
    private static final int DEATH_HUE = 0;
38
39
    private final BoolSetting beam = new BoolSetting("Beam",
40
        "Draws a tall line that shows a marker over hills.", true);
41
    private final NumberSetting beamHeight = new NumberSetting("Beam height",
42
        "How far the line reaches up and down.", 64, 8, 320, 8, " blocks").min(1);
43
    private final BoolSetting box = new BoolSetting("Box",
44
        "Draw a box on the marked block.", true);
45
    private final BoolSetting label = new BoolSetting("Label",
46
        "Write the name above the marker.", true);
47
    private final BoolSetting distance = new BoolSetting("Distance",
48
        "Add how far away the marker is to the label.", true);
49
    private final BoolSetting coordinates = new BoolSetting("Coordinates",
50
        "Add the block position to the label.", false);
51
    private final NumberSetting scale = new NumberSetting("Scale",
52
        "Size of the labels.", 1, 0.5, 3, 0.1).min(0.1);
53
    private final NumberSetting range = new NumberSetting("Range",
54
        "Furthest marker to draw or zero for every one.", 0, 0, 2000, 100, " blocks").min(0);
55
    private final BoolSetting acrossDimensions = new BoolSetting("Across dimensions",
56
        "Shows overworld markers in the nether and the other way round with the coordinates scaled by eight.",
57
        true);
58
    private final NumberSetting hideWithin = new NumberSetting("Hide within",
59
        "Markers this close fade out so they do not fill your screen. Zero keeps them.",
60
        0, 0, 32, 1, " blocks").min(0);
61
    private final BoolSetting autoColor = new BoolSetting("Automatic colours",
62
        "Each new waypoint takes a colour from its name. Off gives it the colour below.", true);
63
    private final ColorSetting nextColor = new ColorSetting("Next colour",
64
        "Colour of the next waypoint you add. Recolour an old one with the waypoint colour command.", 200, false)
65
        .unless(autoColor);
66
    private final BoolSetting markDeaths = new BoolSetting("Mark deaths",
67
        "Saves a red waypoint where you die so you can find your things again.", false);
68
    private final NumberSetting deathsKept = new NumberSetting("Deaths kept",
69
        "How many death markers are kept in each world. The oldest goes when a new one is saved.",
70
        5, 1, 20, 1).min(1)
71
        .under(markDeaths);
72
    private final BoolSetting deathChat = new BoolSetting("Death message",
73
        "Tells you in chat where you died.", false)
74
        .under(markDeaths);
75
76
    // Rebuilt once a tick.
77
    private List<WaypointStore.Waypoint> shown = List.of();
78
79
    // The player whose death was last marked. A respawn hands over a new one.
80
    private LocalPlayer marked;
81
82
    public Waypoints() {
83
        super("Waypoints", "Marks the coordinates you saved in the world.", Category.RENDER);
84
        addSettings(beam, beamHeight, box, label, distance, coordinates, scale, range,
85
            acrossDimensions, hideWithin, autoColor, nextColor, markDeaths, deathsKept, deathChat);
86
        searchTags("waypoint", "marker", "coords");
87
    }
88
89
    @Override
90
    public String getSuffix() {
91
        return count(shown.size());
92
    }
93
94
    @Override
95
    protected void onEnable() {
96
        shown = List.of();
97
    }
98
99
    @Override
100
    protected void onDisable() {
101
        shown = List.of();
102
    }
103
104
    @Subscribe
105
    private void onTick(TickEvent event) {
106
        shown = inGame() ? visible() : List.of();
107
        if (inGame() && mc.player.isDeadOrDying()) {
108
            markDeath(mc.player.position());
109
        }
110
    }
111
112
    private List<WaypointStore.Waypoint> visible() {
113
        List<WaypointStore.Waypoint> all = new ArrayList<>(WaypointStore.get().here());
114
        if (acrossDimensions.isOn()) {
115
            all.addAll(WaypointStore.get().mirrored());
116
        }
117
        all.removeIf(WaypointStore.Waypoint::hidden);
118
        return all;
119
    }
120
121
    // How solid a marker draws. Close ones fade and do not fill the screen.
122
    private float strength(double away) {
123
        double limit = hideWithin.getValue();
124
        if (limit <= 0) {
125
            return 1;
126
        }
127
        return (float) Math.clamp((away - limit / 2) / (limit / 2), 0, 1);
128
    }
129
130
    // Saves a marker on the spot of a death. AutoRespawn calls this before it
131
    // respawns and the tick above catches a death without it. Once per death.
132
    public void markDeath(Vec3 position) {
133
        if (!markDeaths.isOn() || !inGame() || mc.player == marked) {
134
            return;
135
        }
136
        marked = mc.player;
137
        BlockPos at = BlockPos.containing(position);
138
        String name = DEATH_PREFIX + LocalTime.now().format(DEATH_TIME);
139
        WaypointStore.get().add(new WaypointStore.Waypoint(name, at.getX(), at.getY(), at.getZ(),
140
            WaypointStore.currentDimension(), WaypointStore.currentServer(), DEATH_HUE));
141
        dropOldDeaths();
142
        if (deathChat.isOn()) {
143
            ChatUtil.message("§cYou died at §f" + BlockUtil.text(at) + "§c.");
144
        }
145
    }
146
147
    // Keeps only the newest death markers in this world.
148
    private void dropOldDeaths() {
149
        List<String> deaths = new ArrayList<>();
150
        for (WaypointStore.Waypoint waypoint : WaypointStore.get().here()) {
151
            if (isDeathMarker(waypoint.name())) {
152
                deaths.add(waypoint.name());
153
            }
154
        }
155
        for (int i = 0; i < deaths.size() - deathsKept.getInt(); i++) {
156
            WaypointStore.get().remove(deaths.get(i));
157
        }
158
    }
159
160
    private static boolean isDeathMarker(String name) {
161
        return name.length() > DEATH_PREFIX.length() && name.startsWith(DEATH_PREFIX)
162
            && Character.isDigit(name.charAt(DEATH_PREFIX.length()));
163
    }
164
165
    // The hue the next added waypoint gets. Below zero leaves it to the name.
166
    public int nextHue() {
167
        return autoColor.isOn() ? WaypointStore.Waypoint.AUTO_HUE : Math.round(nextColor.getHue());
168
    }
169
170
    // A chosen hue wins. Otherwise the same name always gets the same hue.
171
    public static int colorOf(WaypointStore.Waypoint waypoint) {
172
        int hue = waypoint.hue() >= 0 ? waypoint.hue()
173
            : Math.floorMod(waypoint.name().toLowerCase(Locale.ROOT).hashCode(), 360);
174
        return ColorUtil.hsv(hue, 0.7f, 1f);
175
    }
176
177
    @Subscribe
178
    private void onRender3D(Render3DEvent event) {
179
        if (!inGame()) {
180
            return;
181
        }
182
        DrawBatch batch = event.getBatch();
183
        double limit = range.getValue();
184
        double reach = beamHeight.getValue();
185
        Vec3 eye = mc.player.getEyePosition();
186
187
        for (WaypointStore.Waypoint waypoint : shown) {
188
            Vec3 middle = new Vec3(waypoint.x() + 0.5, waypoint.y() + 0.5, waypoint.z() + 0.5);
189
            if (limit > 0 && eye.distanceTo(middle) > limit) {
190
                continue;
191
            }
192
            float strength = strength(eye.distanceTo(middle));
193
            if (strength <= 0) {
194
                continue;
195
            }
196
            int color = ColorUtil.fade(colorOf(waypoint), strength);
197
            if (beam.isOn()) {
198
                batch.line(middle.subtract(0, reach, 0), middle.add(0, reach, 0), color, true);
199
            }
200
            if (box.isOn()) {
201
                AABB shape = new AABB(waypoint.x(), waypoint.y(), waypoint.z(),
202
                    waypoint.x() + 1, waypoint.y() + 1, waypoint.z() + 1);
203
                batch.outlineBox(shape, color, true);
204
                batch.solidBox(shape, ColorUtil.withAlpha(color, Math.round(50 * strength)), true);
205
            }
206
        }
207
    }
208
209
    @Subscribe
210
    private void onRender2D(Render2DEvent event) {
211
        if (!label.isOn() || !inGame() || !WorldToScreen.update()) {
212
            return;
213
        }
214
        List<WaypointStore.Waypoint> waypoints = shown;
215
        if (waypoints.isEmpty()) {
216
            return;
217
        }
218
        GuiGraphicsExtractor context = event.getContext();
219
        Font font = mc.font;
220
        Vec3 camera = WorldToScreen.cameraPos();
221
        double limit = range.getValue();
222
        float factor = scale.getFloat();
223
224
        for (WaypointStore.Waypoint waypoint : waypoints) {
225
            Vec3 middle = new Vec3(waypoint.x() + 0.5, waypoint.y() + 1.5, waypoint.z() + 0.5);
226
            double away = camera.distanceTo(middle);
227
            if (limit > 0 && away > limit) {
228
                continue;
229
            }
230
            Vec3 screen = WorldToScreen.project(middle);
231
            if (screen == null || strength(away) < 1) {
232
                continue;
233
            }
234
235
            StringBuilder text = new StringBuilder(waypoint.name());
236
            if (coordinates.isOn()) {
237
                text.append(" ").append(waypoint.x()).append(" ")
238
                    .append(waypoint.y()).append(" ").append(waypoint.z());
239
            }
240
            if (distance.isOn()) {
241
                text.append(" ").append(Math.round(away)).append("m");
242
            }
243
            RenderUtil.label(context, font, screen.x, screen.y, factor,
244
                List.of(text.toString()), List.of(colorOf(waypoint)));
245
        }
246
    }
247
}
248
NicotineGeneralsrc/client/java/nicotine/mod/mods/general/Waypoints.javaJava · 85 lines · 3.3 KB
SettingsScaleNameCordsManage
Waypoints.javaJava · Minecraft 26.3 · 85 lines · 3.3 KB · complete file, verbatimOriginal ↗
1
package nicotine.mod.mods.general;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.world.level.Level;
5
import net.minecraft.world.phys.Vec3;
6
import nicotine.events.RenderBeforeEvent;
7
import nicotine.events.RenderEvent;
8
import nicotine.mod.Mod;
9
import nicotine.mod.ModCategory;
10
import nicotine.mod.option.ClickOption;
11
import nicotine.mod.option.RGBOption;
12
import nicotine.mod.option.SliderOption;
13
import nicotine.screens.clickgui.WaypointScreen;
14
import nicotine.util.*;
15
import nicotine.util.render.Render3D;
16
import org.apache.commons.lang3.StringUtils;
17
18
import java.util.*;
19
20
import static nicotine.util.Common.*;
21
22
public class Waypoints extends Mod {
23
24
    private final SliderOption scale = new SliderOption(
25
            "Scale",
26
            1,
27
            0.5f,
28
            3.0f,
29
            true
30
    );
31
32
    private final RGBOption nameRGB = new RGBOption("Name");
33
    private final RGBOption cordsRGB = new RGBOption("Cords");
34
    private final ClickOption manage = new ClickOption("Manage") {
35
        @Override
36
        public void click() {
37
          mc.gui.setScreen(new WaypointScreen());
38
        }
39
    };
40
41
    public Waypoints() {
42
        super(ModCategory.General, "Waypoints");
43
        this.addOptions(Arrays.asList(manage, scale, nameRGB, cordsRGB));
44
    }
45
46
    private static Vec3 getAdjustedPosition(BlockPos pos) {
47
        Vec3 adjustedPosition = new Vec3(pos.getX(), pos.getY() + 3, pos.getZ());
48
49
        if (!Player.isPositionInRenderDistance(adjustedPosition)) {
50
            adjustedPosition = mc.player.position().add(adjustedPosition.subtract(mc.player.position()).normalize().scale(mc.options.renderDistance().get() * 16));
51
        }
52
53
        return adjustedPosition;
54
    }
55
56
    @Override
57
    protected void init() {
58
        EventBus.register(RenderBeforeEvent.class, event -> {
59
            if (!this.enabled || mc.hasSingleplayerServer())
60
                return true;
61
62
            for (WaypointInstance waypointInstance : waypointInstances) {
63
                if (!waypointInstance.server.equals(currentServer.ip))
64
                    continue;
65
66
                LinkedHashMap<String, Integer> texts = new LinkedHashMap<>();
67
                BlockPos pos = new BlockPos(waypointInstance.x, waypointInstance.y, waypointInstance.z);
68
69
                if (mc.level.dimension().identifier().toString().equals(waypointInstance.dimension)) {
70
                    texts.put(waypointInstance.name, nameRGB.getColor());
71
                    texts.put(String.format("%d %d %d", pos.getX(), pos.getY(), pos.getZ()), cordsRGB.getColor());
72
                    Render3D.drawTexts(event.submitNodeStorage, event.matrixStack, event.camera, getAdjustedPosition(pos), texts, scale.value, true);
73
                }  else if (mc.level.dimension().equals(Level.NETHER) && Level.OVERWORLD.identifier().toString().equals(waypointInstance.dimension)) {
74
                    pos = new BlockPos(waypointInstance.x / 8, waypointInstance.y, waypointInstance.z / 8);
75
                    texts.put(String.format("%s [OW]", waypointInstance.name), nameRGB.getColor());
76
                    texts.put(String.format("%d %d %d", pos.getX(), pos.getY(), pos.getZ()), cordsRGB.getColor());
77
                    Render3D.drawTexts(event.submitNodeStorage, event.matrixStack, event.camera, getAdjustedPosition(pos), texts, scale.value, true);
78
                }
79
            }
80
81
            return true;
82
        });
83
    }
84
}
85