diff options
author | alemi <me@alemi.dev> | 2023-03-18 22:08:10 +0100 |
---|---|---|
committer | alemi <me@alemi.dev> | 2023-03-18 22:08:10 +0100 |
commit | 10cbb3bd8364d4e505519e19001265272425cd8c (patch) | |
tree | c382865531fd72a905442e7f8ee296dd06dd211c | |
parent | 5f5005fb3a94bb6c7dc4607e169f26d88c6c07f2 (diff) |
feat: super raw command to get block pos of cursor
-rw-r--r-- | src/main/java/ftbsc/bscv/commands/Cursor.java | 46 |
1 files changed, 46 insertions, 0 deletions
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<CommandSource> register(LiteralArgumentBuilder<CommandSource> 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; + }); + } + +} |