mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 22:16:14 +00:00
feat: use deploy core automatically if core size is a single block
This commit is contained in:
parent
fa9c2954b3
commit
27757485d1
3 changed files with 92 additions and 51 deletions
|
|
@ -64,6 +64,8 @@ public class CoreCommand {
|
||||||
|
|
||||||
final CompletableFuture<NbtCompound> future = CommandCore.INSTANCE.runTracked(command);
|
final CompletableFuture<NbtCompound> future = CommandCore.INSTANCE.runTracked(command);
|
||||||
future.thenApply(tag -> {
|
future.thenApply(tag -> {
|
||||||
|
if (tag == null) return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
tag.get("LastOutput", TextCodecs.CODEC).ifPresent(source::sendFeedback);
|
tag.get("LastOutput", TextCodecs.CODEC).ifPresent(source::sendFeedback);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ public class ReloadConfigCommand {
|
||||||
try {
|
try {
|
||||||
ChipmunkMod.CONFIG = ChipmunkMod.loadConfig();
|
ChipmunkMod.CONFIG = ChipmunkMod.loadConfig();
|
||||||
|
|
||||||
CommandCore.INSTANCE.reloadRelativeArea();
|
CommandCore.INSTANCE.reloadFromConfig();
|
||||||
CustomChat.INSTANCE.reloadFromConfig();
|
CustomChat.INSTANCE.reloadFromConfig();
|
||||||
|
|
||||||
source.sendFeedback(Text.literal("Successfully reloaded the config"));
|
source.sendFeedback(Text.literal("Successfully reloaded the config"));
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,7 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.network.ClientConnection;
|
import net.minecraft.network.ClientConnection;
|
||||||
import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket;
|
import net.minecraft.network.packet.c2s.play.*;
|
||||||
import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket;
|
|
||||||
import net.minecraft.network.packet.c2s.play.UpdateCommandBlockC2SPacket;
|
|
||||||
import net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket;
|
|
||||||
import net.minecraft.registry.Registries;
|
import net.minecraft.registry.Registries;
|
||||||
import net.minecraft.registry.tag.BlockTags;
|
import net.minecraft.registry.tag.BlockTags;
|
||||||
import net.minecraft.state.property.Property;
|
import net.minecraft.state.property.Property;
|
||||||
|
|
@ -40,14 +37,11 @@ import net.minecraft.util.math.*;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import net.minecraft.world.dimension.DimensionType;
|
import net.minecraft.world.dimension.DimensionType;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.TimerTask;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class CommandCore implements Listener {
|
public class CommandCore implements Listener {
|
||||||
public static CommandCore INSTANCE = new CommandCore(MinecraftClient.getInstance());
|
public static final CommandCore INSTANCE = new CommandCore(MinecraftClient.getInstance());
|
||||||
|
|
||||||
private final MinecraftClient client;
|
private final MinecraftClient client;
|
||||||
|
|
||||||
|
|
@ -57,6 +51,7 @@ public class CommandCore implements Listener {
|
||||||
public BlockBox withPos;
|
public BlockBox withPos;
|
||||||
public BlockPos block;
|
public BlockPos block;
|
||||||
public boolean runFillCommand = true;
|
public boolean runFillCommand = true;
|
||||||
|
public boolean isSingleBlock = false;
|
||||||
public boolean alreadyFilled = false;
|
public boolean alreadyFilled = false;
|
||||||
|
|
||||||
private final Map<BlockPos, String> pendingSetBlockCommands = Collections.synchronizedMap(new Object2ObjectArrayMap<>());
|
private final Map<BlockPos, String> pendingSetBlockCommands = Collections.synchronizedMap(new Object2ObjectArrayMap<>());
|
||||||
|
|
@ -67,7 +62,7 @@ public class CommandCore implements Listener {
|
||||||
|
|
||||||
public CommandCore (final MinecraftClient client) {
|
public CommandCore (final MinecraftClient client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
reloadRelativeArea();
|
reloadFromConfig();
|
||||||
ListenerManager.addListener(this);
|
ListenerManager.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,11 +92,12 @@ public class CommandCore implements Listener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
reloadRelativeArea();
|
reloadFromConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadRelativeArea () {
|
public void reloadFromConfig () {
|
||||||
noPos = ChipmunkMod.CONFIG.core.relativeArea;
|
noPos = ChipmunkMod.CONFIG.core.relativeArea;
|
||||||
|
isSingleBlock = noPos.getDimensions().equals(Vec3i.ZERO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -144,6 +140,8 @@ public class CommandCore implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void check () {
|
public void check () {
|
||||||
|
if (isSingleBlock) return;
|
||||||
|
|
||||||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||||
|
|
||||||
if (networkHandler == null || withPos == null || !ready) return;
|
if (networkHandler == null || withPos == null || !ready) return;
|
||||||
|
|
@ -225,7 +223,7 @@ public class CommandCore implements Listener {
|
||||||
final ClientPlayerEntity player = client.player;
|
final ClientPlayerEntity player = client.player;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!runFillCommand
|
!runFillCommand || isSingleBlock
|
||||||
|| player == null
|
|| player == null
|
||||||
|| !player.isInCreativeMode()
|
|| !player.isInCreativeMode()
|
||||||
|| !player.hasPermissionLevel(2)
|
|| !player.hasPermissionLevel(2)
|
||||||
|
|
@ -254,7 +252,7 @@ public class CommandCore implements Listener {
|
||||||
networkHandler.sendChatCommand(command);
|
networkHandler.sendChatCommand(command);
|
||||||
refillTriesUsingPlaceBlock = 0;
|
refillTriesUsingPlaceBlock = 0;
|
||||||
} else {
|
} else {
|
||||||
runPlaceBlock(command);
|
runPlaceBlock(command, true, true);
|
||||||
refillTriesUsingPlaceBlock++;
|
refillTriesUsingPlaceBlock++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -284,8 +282,12 @@ public class CommandCore implements Listener {
|
||||||
public void run (final String command) {
|
public void run (final String command) {
|
||||||
if (command.length() > 32767) return;
|
if (command.length() > 32767) return;
|
||||||
|
|
||||||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
if (isSingleBlock) {
|
||||||
|
runPlaceBlock(command, false, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||||
if (networkHandler == null) return;
|
if (networkHandler == null) return;
|
||||||
|
|
||||||
final ClientConnection connection = networkHandler.getConnection();
|
final ClientConnection connection = networkHandler.getConnection();
|
||||||
|
|
@ -335,13 +337,17 @@ public class CommandCore implements Listener {
|
||||||
public CompletableFuture<NbtCompound> runTracked (final String command) {
|
public CompletableFuture<NbtCompound> runTracked (final String command) {
|
||||||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||||
|
|
||||||
if (networkHandler == null) return new CompletableFuture<>();
|
if (networkHandler == null) return CompletableFuture.completedFuture(null);
|
||||||
|
|
||||||
final ClientConnection connection = networkHandler.getConnection();
|
final ClientConnection connection = networkHandler.getConnection();
|
||||||
|
|
||||||
if (block == null) return new CompletableFuture<>();
|
if (block == null) return CompletableFuture.completedFuture(null);
|
||||||
|
|
||||||
if (KaboomCheck.INSTANCE.isKaboom) {
|
final BlockPos oldBlock;
|
||||||
|
|
||||||
|
if (isSingleBlock) {
|
||||||
|
oldBlock = runPlaceBlock(command, false, false);
|
||||||
|
} else if (KaboomCheck.INSTANCE.isKaboom) {
|
||||||
connection.send(
|
connection.send(
|
||||||
new UpdateCommandBlockC2SPacket(
|
new UpdateCommandBlockC2SPacket(
|
||||||
block,
|
block,
|
||||||
|
|
@ -352,6 +358,8 @@ public class CommandCore implements Listener {
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
oldBlock = block;
|
||||||
} else {
|
} else {
|
||||||
connection.send(
|
connection.send(
|
||||||
new UpdateCommandBlockC2SPacket(
|
new UpdateCommandBlockC2SPacket(
|
||||||
|
|
@ -374,17 +382,24 @@ public class CommandCore implements Listener {
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
oldBlock = block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (oldBlock == null) return CompletableFuture.completedFuture(null);
|
||||||
|
|
||||||
final CompletableFuture<NbtCompound> future = new CompletableFuture<>();
|
final CompletableFuture<NbtCompound> future = new CompletableFuture<>();
|
||||||
|
|
||||||
final Timer timer = new Timer();
|
final Timer timer = new Timer();
|
||||||
|
|
||||||
final BlockPos oldBlock = block;
|
|
||||||
|
|
||||||
final TimerTask queryTask = new TimerTask() {
|
final TimerTask queryTask = new TimerTask() {
|
||||||
public void run () {
|
public void run () {
|
||||||
client.getNetworkHandler().getDataQueryHandler().queryBlockNbt(oldBlock, future::complete);
|
client.getNetworkHandler().getDataQueryHandler().queryBlockNbt(oldBlock, result -> {
|
||||||
|
future.complete(result);
|
||||||
|
if (isSingleBlock && client.interactionManager != null) {
|
||||||
|
client.interactionManager.breakBlock(oldBlock);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -395,21 +410,21 @@ public class CommandCore implements Listener {
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runPlaceBlock (final String command) {
|
public BlockPos runPlaceBlock (final String command, final boolean fallbackToChat, final boolean replaceOldBlock) {
|
||||||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||||
if (networkHandler == null) return;
|
if (networkHandler == null) return null;
|
||||||
|
|
||||||
final ClientConnection connection = networkHandler.getConnection();
|
final ClientConnection connection = networkHandler.getConnection();
|
||||||
|
|
||||||
final ClientPlayerEntity player = client.player;
|
final ClientPlayerEntity player = client.player;
|
||||||
final ClientWorld world = client.world;
|
final ClientWorld world = client.world;
|
||||||
|
|
||||||
if (player == null || world == null || !player.isInCreativeMode()) return;
|
if (player == null || world == null || !player.isInCreativeMode()) return null;
|
||||||
|
|
||||||
final DimensionType dimensionType = world.getDimension();
|
final DimensionType dimensionType = world.getDimension();
|
||||||
|
|
||||||
final ClientPlayerInteractionManager interactionManager = client.interactionManager;
|
final ClientPlayerInteractionManager interactionManager = client.interactionManager;
|
||||||
if (interactionManager == null) return;
|
if (interactionManager == null) return null;
|
||||||
|
|
||||||
// stolen from two five hundred million dollars
|
// stolen from two five hundred million dollars
|
||||||
|
|
||||||
|
|
@ -420,8 +435,8 @@ public class CommandCore implements Listener {
|
||||||
|| pair.getLeft().getY() < dimensionType.minY()
|
|| pair.getLeft().getY() < dimensionType.minY()
|
||||||
|| pair.getLeft().getY() > dimensionType.height() + dimensionType.minY()
|
|| pair.getLeft().getY() > dimensionType.height() + dimensionType.minY()
|
||||||
) {
|
) {
|
||||||
networkHandler.sendChatCommand(command);
|
if (fallbackToChat) networkHandler.sendChatCommand(command);
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final BlockPos position = pair.getLeft();
|
final BlockPos position = pair.getLeft();
|
||||||
|
|
@ -455,8 +470,15 @@ public class CommandCore implements Listener {
|
||||||
connection.send(new UpdateSelectedSlotC2SPacket(freeHotBarSlot));
|
connection.send(new UpdateSelectedSlotC2SPacket(freeHotBarSlot));
|
||||||
}
|
}
|
||||||
|
|
||||||
interactionManager.breakBlock(position);
|
|
||||||
try (final PendingUpdateManager pendingUpdateManager = ((ClientWorldAccessor) world).getPendingUpdateManager()) {
|
try (final PendingUpdateManager pendingUpdateManager = ((ClientWorldAccessor) world).getPendingUpdateManager()) {
|
||||||
|
connection.send(
|
||||||
|
new PlayerActionC2SPacket(
|
||||||
|
PlayerActionC2SPacket.Action.START_DESTROY_BLOCK,
|
||||||
|
position,
|
||||||
|
Direction.UP,
|
||||||
|
pendingUpdateManager.incrementSequence().getSequence()
|
||||||
|
)
|
||||||
|
);
|
||||||
connection.send(
|
connection.send(
|
||||||
new PlayerInteractBlockC2SPacket(
|
new PlayerInteractBlockC2SPacket(
|
||||||
Hand.MAIN_HAND,
|
Hand.MAIN_HAND,
|
||||||
|
|
@ -469,22 +491,36 @@ public class CommandCore implements Listener {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
interactionManager.interactBlock(
|
|
||||||
player,
|
|
||||||
Hand.MAIN_HAND,
|
|
||||||
new BlockHitResult(
|
|
||||||
new Vec3d(position),
|
|
||||||
Direction.UP,
|
|
||||||
position,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (oldSelectedSlot != freeHotBarSlot) {
|
if (oldSelectedSlot != freeHotBarSlot) {
|
||||||
connection.send(new UpdateSelectedSlotC2SPacket(oldSelectedSlot));
|
connection.send(new UpdateSelectedSlotC2SPacket(oldSelectedSlot));
|
||||||
}
|
}
|
||||||
connection.send(new CreativeInventoryActionC2SPacket(slot, oldStack));
|
connection.send(new CreativeInventoryActionC2SPacket(slot, oldStack));
|
||||||
|
|
||||||
|
if (ChipmunkMod.CONFIG.core.logCommands)
|
||||||
|
ChipmunkMod.LOGGER.info("Executing place block core command: {}", command);
|
||||||
|
|
||||||
|
if (!replaceOldBlock) return position;
|
||||||
|
|
||||||
|
if (isSingleBlock) {
|
||||||
|
final Timer timer = new Timer();
|
||||||
|
timer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run () {
|
||||||
|
// we're gonna just only break the block for now
|
||||||
|
try (final PendingUpdateManager pendingUpdateManager = ((ClientWorldAccessor) world).getPendingUpdateManager()) {
|
||||||
|
connection.send(
|
||||||
|
new PlayerActionC2SPacket(
|
||||||
|
PlayerActionC2SPacket.Action.START_DESTROY_BLOCK,
|
||||||
|
position,
|
||||||
|
Direction.UP,
|
||||||
|
pendingUpdateManager.incrementSequence().getSequence()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 50 * 2);
|
||||||
|
} else {
|
||||||
final StringBuilder oldBlockString = new StringBuilder(Registries.BLOCK.getId(oldBlockState.getBlock()).toString());
|
final StringBuilder oldBlockString = new StringBuilder(Registries.BLOCK.getId(oldBlockState.getBlock()).toString());
|
||||||
if (!oldBlockState.getProperties().isEmpty()) {
|
if (!oldBlockState.getProperties().isEmpty()) {
|
||||||
oldBlockString.append('[');
|
oldBlockString.append('[');
|
||||||
|
|
@ -504,6 +540,9 @@ public class CommandCore implements Listener {
|
||||||
pendingSetBlockCommands.put(position, oldBlockString.toString());
|
pendingSetBlockCommands.put(position, oldBlockString.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
// also from two five hundred million dollars
|
// also from two five hundred million dollars
|
||||||
private Pair<BlockPos, BlockState> findBlockLocation () {
|
private Pair<BlockPos, BlockState> findBlockLocation () {
|
||||||
final ClientPlayerEntity player = client.player;
|
final ClientPlayerEntity player = client.player;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue