This commit is contained in:
Chayapak 2023-08-29 20:32:25 +07:00
parent 40c9f94293
commit bb30748a00

View file

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