Skip to content

Commit 0d402e9

Browse files
committed
add player's position in the plot to the f3 menu
1 parent bad9915 commit 0d402e9

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package dev.dfonline.codeclient.mixin;
2+
3+
import dev.dfonline.codeclient.CodeClient;
4+
import dev.dfonline.codeclient.location.Plot;
5+
import net.minecraft.client.gui.hud.debug.DebugHudLines;
6+
import net.minecraft.client.gui.hud.debug.PlayerPositionDebugHudEntry;
7+
import net.minecraft.util.Identifier;
8+
import net.minecraft.world.World;
9+
import net.minecraft.world.chunk.WorldChunk;
10+
import org.spongepowered.asm.mixin.Final;
11+
import org.spongepowered.asm.mixin.Mixin;
12+
import org.spongepowered.asm.mixin.Shadow;
13+
import org.spongepowered.asm.mixin.injection.At;
14+
import org.spongepowered.asm.mixin.injection.Inject;
15+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
16+
17+
import java.util.List;
18+
import java.util.Locale;
19+
20+
@Mixin(PlayerPositionDebugHudEntry.class)
21+
public class PlayerPosDebugMixin {
22+
@Shadow @Final public static Identifier SECTION_ID;
23+
24+
@Inject(method = "render", at = @At("TAIL"))
25+
private void render(DebugHudLines lines, World world, WorldChunk clientChunk, WorldChunk chunk, CallbackInfo ci) {
26+
if (CodeClient.location instanceof Plot plot) {
27+
var plotLocation = CodeClient.MC.getCameraEntity().getEntityPos().subtract(plot.getPos());
28+
String size = plot.getSize() == null ? "UNKNOWN" : plot.getSize().name();
29+
lines.addLinesToSection(SECTION_ID, List.of(String.format(
30+
Locale.ROOT,
31+
"Plot: %.3f / %.5f / %.3f (%s)",
32+
plotLocation.getX(),
33+
plotLocation.getY(),
34+
plotLocation.getZ(),
35+
size
36+
)));
37+
}
38+
}
39+
}

src/main/resources/CodeClient.mixins.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"screen.MMultiplayerScreen", "screen.chat.MChatInputSuggester", "screen.chat.MChatScreen",
1515
"world.MWorldRenderer", "world.block.MAbstractBlockState", "world.block.MBarrierBlock",
1616
"world.block.MBlockItem", "world.block.MLightBlock", "world.block.MSignBlockEntity",
17-
"world.block.MStructureVoidBlock", "screen.MScreenHandler"
17+
"world.block.MStructureVoidBlock", "screen.MScreenHandler", "PlayerPosDebugMixin"
1818
],
1919
"injectors": {
2020
"defaultRequire": 1

0 commit comments

Comments
 (0)