From 10cbb3bd8364d4e505519e19001265272425cd8c Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 18 Mar 2023 22:08:10 +0100 Subject: feat: super raw command to get block pos of cursor --- src/main/java/ftbsc/bscv/commands/Cursor.java | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main/java/ftbsc/bscv/commands/Cursor.java (limited to 'src/main/java/ftbsc') diff --git a/src/main/java/ftbsc/bscv/commands/Cursor.java b/src/main/java/ftbsc/bscv/commands/Cursor.java new file mode 100644 index 0000000..49a93aa --- /dev/null +++ b/src/main/java/ftbsc/bscv/commands/Cursor.java @@ -0,0 +1,46 @@ +package ftbsc.bscv.commands; + +import com.google.auto.service.AutoService; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; + +import ftbsc.bscv.api.ILoadable; +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; + +import static ftbsc.bscv.Boscovicino.log; + +@AutoService(ILoadable.class) +public class Cursor extends AbstractCommand { + + public LiteralArgumentBuilder register(LiteralArgumentBuilder builder) { + return builder + .then( + Commands.literal("pos") + .executes(ctx -> { + switch (MC.hitResult.getType()) { + case BLOCK: + BlockRayTraceResult result = (BlockRayTraceResult) MC.hitResult; + Direction dir = result.getDirection(); + BlockPos pos =result.getBlockPos(); + log("Block @ %s (%s)", pos.toString(), dir.toString()); + return 1; + case ENTITY: + log("Entity @ %s", MC.hitResult.getLocation().toString()); + return 1; + default: + case MISS: + log("[!] nothing under cursor"); + return 0; + } + }) + ) + .executes(ctx -> { + log("[!] no domain specified"); + return 0; + }); + } + +} -- cgit v1.2.3-56-ga3b1