diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java b/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java index d8b1f97..7e5c357 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java @@ -22,8 +22,9 @@ public class CommandCore { private final MinecraftClient client; public boolean ready = false; public BlockPos origin; - public BlockArea relativeArea; - public BlockPos currentBlockRelative; + public BlockArea noPos; + public BlockPos block; + public BlockArea withPos; private Timer timer; @@ -62,32 +63,30 @@ public class CommandCore { } public void reloadRelativeArea () { - // makes a copy - relativeArea = new BlockArea( - new BlockPos(ChipmunkMod.CONFIG.core.relativeArea.start), - new BlockPos(ChipmunkMod.CONFIG.core.relativeArea.end) - ); - - relativeArea.start = new BlockPos( - relativeArea.start.getX(), - (int) MathUtilities.clamp(relativeArea.start.getY(), client.world.getDimension().minY(), client.world.getDimension().height()), - relativeArea.start.getZ() - ); - relativeArea.end = new BlockPos( - relativeArea.end.getX(), - (int) MathUtilities.clamp(relativeArea.end.getY(), client.world.getDimension().minY(), client.world.getDimension().height()), - relativeArea.end.getZ() - ); + noPos = ChipmunkMod.CONFIG.core.relativeArea; } public void move (Vec3d position) { origin = new BlockPos( ((int) position.getX() / 16) * 16, - 0, + (int) MathUtilities.clamp(noPos.start.getY(), client.world.getDimension().minY(), client.world.getDimension().height()), ((int) position.getZ() / 16) * 16 ); - currentBlockRelative = new BlockPos(relativeArea.start); + withPos = new BlockArea( + new BlockPos( + noPos.start.getX() + origin.getX(), + (int) MathUtilities.clamp(noPos.start.getY(), client.world.getDimension().minY(), client.world.getDimension().height()), + noPos.start.getZ() + origin.getZ() + ), + new BlockPos( + noPos.end.getX() + origin.getX(), + (int) MathUtilities.clamp(noPos.end.getY(), client.world.getDimension().minY(), client.world.getDimension().height()), + noPos.end.getZ() + origin.getZ() + ) + ); + + block = new BlockPos(withPos.start); refill(); for (Listener listener : ListenerManager.listeners) listener.coreMoved(); @@ -101,33 +100,29 @@ public class CommandCore { public void refill () { if (!runFillCommand) return; - // final PositionManager position = client.position(); - final BlockPos relStart = relativeArea.start; - final BlockPos relEnd = relativeArea.end; - final String command = String.format( KaboomCheck.INSTANCE.isKaboom ? "fill %s %s %s %s %s %s repeating_command_block replace" : "fill %s %s %s %s %s %s command_block", - relStart.getX() + origin.getX(), - relStart.getY() + origin.getY(), - relStart.getZ() + origin.getZ(), + withPos.start.getX(), + withPos.start.getY(), + withPos.start.getZ(), - relEnd.getX() + origin.getX(), - relEnd.getY() + origin.getY(), - relEnd.getZ() + origin.getZ() + withPos.end.getX(), + withPos.end.getY(), + withPos.end.getZ() ); client.getNetworkHandler().sendChatCommand(command); } public void incrementCurrentBlock () { - final BlockPos start = relativeArea.start; - final BlockPos end = relativeArea.end; + final BlockPos start = withPos.start; + final BlockPos end = withPos.end; - int x = currentBlockRelative.getX(); - int y = currentBlockRelative.getY(); - int z = currentBlockRelative.getZ(); + int x = block.getX(); + int y = block.getY(); + int z = block.getZ(); x++; @@ -147,21 +142,16 @@ public class CommandCore { z = start.getZ(); } - currentBlockRelative = new BlockPos(x, y, z); - } - - public BlockPos currentBlockAbsolute () { - return currentBlockRelative.add(origin); + block = new BlockPos(x, y, z); } public void run (String command) { final ClientConnection connection = client.getNetworkHandler().getConnection(); - final BlockPos currentBlock = currentBlockAbsolute(); if (KaboomCheck.INSTANCE.isKaboom) { connection.send( new UpdateCommandBlockC2SPacket( - currentBlock, + block, command, CommandBlockBlockEntity.Type.AUTO, false, @@ -172,7 +162,7 @@ public class CommandCore { } else { connection.send( new UpdateCommandBlockC2SPacket( - currentBlock, + block, "", CommandBlockBlockEntity.Type.REDSTONE, false, @@ -183,7 +173,7 @@ public class CommandCore { connection.send( new UpdateCommandBlockC2SPacket( - currentBlock, + block, command, CommandBlockBlockEntity.Type.REDSTONE, false, @@ -198,12 +188,11 @@ public class CommandCore { public CompletableFuture runTracked (String command) { final ClientConnection connection = client.getNetworkHandler().getConnection(); - final BlockPos currentBlock = currentBlockAbsolute(); if (KaboomCheck.INSTANCE.isKaboom) { connection.send( new UpdateCommandBlockC2SPacket( - currentBlock, + block, command, CommandBlockBlockEntity.Type.AUTO, true, @@ -214,7 +203,7 @@ public class CommandCore { } else { connection.send( new UpdateCommandBlockC2SPacket( - currentBlock, + block, "", CommandBlockBlockEntity.Type.REDSTONE, true, @@ -225,7 +214,7 @@ public class CommandCore { connection.send( new UpdateCommandBlockC2SPacket( - currentBlock, + block, command, CommandBlockBlockEntity.Type.REDSTONE, true, @@ -243,7 +232,7 @@ public class CommandCore { final TimerTask queryTask = new TimerTask() { public void run () { - client.getNetworkHandler().getDataQueryHandler().queryBlockNbt(currentBlock, future::complete); + client.getNetworkHandler().getDataQueryHandler().queryBlockNbt(block, future::complete); timer.cancel(); // ? Is this necesary? timer.purge(); @@ -261,8 +250,8 @@ public class CommandCore { timer.cancel(); timer.purge(); - origin = null; - currentBlockRelative = null; + withPos = null; + block = null; ready = false; } }