From 40432e083b11271cf3148b9c38156cf759436699 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Tue, 5 Sep 2023 23:22:33 -0400 Subject: Initial code dump. --- .../trashyaddon/commands/BlockDataCommand.java | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/main/java/org/chrisoft/trashyaddon/commands/BlockDataCommand.java (limited to 'src/main/java/org/chrisoft/trashyaddon/commands/BlockDataCommand.java') diff --git a/src/main/java/org/chrisoft/trashyaddon/commands/BlockDataCommand.java b/src/main/java/org/chrisoft/trashyaddon/commands/BlockDataCommand.java new file mode 100644 index 0000000..185de2e --- /dev/null +++ b/src/main/java/org/chrisoft/trashyaddon/commands/BlockDataCommand.java @@ -0,0 +1,59 @@ +package org.chrisoft.trashyaddon.commands; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import meteordevelopment.meteorclient.commands.Command; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.RaycastContext; +import net.minecraft.command.CommandSource; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.text.Text; +import net.minecraft.util.math.Box; +import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.Vec3d; + +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; +public class BlockDataCommand extends Command { + private final MinecraftClient mc = MinecraftClient.getInstance(); + public BlockDataCommand() { + super("bd", "Dump client side data of targeted block."); + } + + @Override + public void build(LiteralArgumentBuilder builder) { + builder.executes(context -> { + double RANGE = 5; + Entity player = mc.cameraEntity; + Vec3d rot = player.getRotationVec(mc.getTickDelta()); + Vec3d min = player.getCameraPosVec(mc.getTickDelta()); + Vec3d max = min.add(rot.multiply(RANGE)); + RaycastContext rc = new RaycastContext(min, max, RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, player); + BlockHitResult bh = mc.world.raycast(rc); + if (bh == null) { + error("no block picked"); + return 100; + } + BlockPos bp = bh.getBlockPos(); + BlockState bs = mc.world.getBlockState(bp); + if (bs == null) + { + error("no block state"); + return 100; + } + info(Text.literal("block is ").append(bs.getBlock().getName())); + BlockEntity be = mc.world.getBlockEntity(bp); + if (be == null) + { + error("block has no block entity"); + return SINGLE_SUCCESS; + } + NbtCompound bd = be.createNbt(); + info(bd.toString()); + + return SINGLE_SUCCESS; + }); + } +} -- cgit v1.2.3