mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 22:16:14 +00:00
Compare commits
2 commits
69909de327
...
0cc74be280
| Author | SHA1 | Date | |
|---|---|---|---|
| 0cc74be280 | |||
| ea16395c15 |
4 changed files with 62 additions and 12 deletions
|
|
@ -2,6 +2,7 @@ package land.chipmunk.chipmunkmod.listeners;
|
||||||
|
|
||||||
import net.minecraft.network.packet.Packet;
|
import net.minecraft.network.packet.Packet;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
public interface Listener {
|
public interface Listener {
|
||||||
default void packetReceived (final Packet<?> packet) { }
|
default void packetReceived (final Packet<?> packet) { }
|
||||||
|
|
@ -15,4 +16,6 @@ public interface Listener {
|
||||||
default void coreReady () { }
|
default void coreReady () { }
|
||||||
|
|
||||||
default void coreMoved () { }
|
default void coreMoved () { }
|
||||||
|
|
||||||
|
default void positionChanged (final Vec3d newPosition) { }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,18 +9,22 @@ import land.chipmunk.chipmunkmod.listeners.Listener;
|
||||||
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
|
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
|
||||||
import land.chipmunk.chipmunkmod.modules.*;
|
import land.chipmunk.chipmunkmod.modules.*;
|
||||||
import land.chipmunk.chipmunkmod.modules.custom_chat.CustomChat;
|
import land.chipmunk.chipmunkmod.modules.custom_chat.CustomChat;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.hud.InGameHud;
|
import net.minecraft.client.gui.hud.InGameHud;
|
||||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||||
|
import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
|
import net.minecraft.client.world.ClientWorld;
|
||||||
import net.minecraft.command.CommandRegistryAccess;
|
import net.minecraft.command.CommandRegistryAccess;
|
||||||
import net.minecraft.command.CommandSource;
|
import net.minecraft.command.CommandSource;
|
||||||
import net.minecraft.network.packet.s2c.play.CommandTreeS2CPacket;
|
import net.minecraft.network.packet.s2c.play.*;
|
||||||
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
|
|
||||||
import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
|
|
||||||
import net.minecraft.registry.DynamicRegistryManager;
|
import net.minecraft.registry.DynamicRegistryManager;
|
||||||
import net.minecraft.resource.featuretoggle.FeatureSet;
|
import net.minecraft.resource.featuretoggle.FeatureSet;
|
||||||
import net.minecraft.text.PlainTextContent;
|
import net.minecraft.text.PlainTextContent;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.text.TranslatableTextContent;
|
import net.minecraft.text.TranslatableTextContent;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.ChunkPos;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
|
@ -29,7 +33,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
@Mixin(value = ClientPlayNetworkHandler.class, priority = 1001)
|
@Mixin(value = ClientPlayNetworkHandler.class, priority = 1001)
|
||||||
public class ClientPlayNetworkHandlerMixin {
|
public abstract class ClientPlayNetworkHandlerMixin {
|
||||||
@Final
|
@Final
|
||||||
@Shadow
|
@Shadow
|
||||||
private FeatureSet enabledFeatures;
|
private FeatureSet enabledFeatures;
|
||||||
|
|
@ -39,6 +43,8 @@ public class ClientPlayNetworkHandlerMixin {
|
||||||
@Shadow
|
@Shadow
|
||||||
private CommandDispatcher<CommandSource> commandDispatcher;
|
private CommandDispatcher<CommandSource> commandDispatcher;
|
||||||
|
|
||||||
|
@Shadow public abstract ClientWorld getWorld ();
|
||||||
|
|
||||||
@Inject(method = "onGameJoin", at = @At("TAIL"))
|
@Inject(method = "onGameJoin", at = @At("TAIL"))
|
||||||
private void onGameJoin (final GameJoinS2CPacket packet, final CallbackInfo ci) {
|
private void onGameJoin (final GameJoinS2CPacket packet, final CallbackInfo ci) {
|
||||||
final CommandRegistryAccess commandRegistryAccess = CommandRegistryAccess.of(this.combinedDynamicRegistries, this.enabledFeatures);
|
final CommandRegistryAccess commandRegistryAccess = CommandRegistryAccess.of(this.combinedDynamicRegistries, this.enabledFeatures);
|
||||||
|
|
@ -136,4 +142,28 @@ public class ClientPlayNetworkHandlerMixin {
|
||||||
CustomChat.INSTANCE.chat(content);
|
CustomChat.INSTANCE.chat(content);
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(method = "onPlayerPositionLook", at = @At("TAIL"))
|
||||||
|
private void setPosition (final PlayerPositionLookS2CPacket packet, final CallbackInfo ci) {
|
||||||
|
final Vec3d position = packet.change().position();
|
||||||
|
|
||||||
|
final BlockPos origin = CommandCore.INSTANCE.origin;
|
||||||
|
if (origin == null) {
|
||||||
|
CommandCore.INSTANCE.move(position);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final MinecraftClient client = MinecraftClient.getInstance();
|
||||||
|
final ClientPlayerEntity player = client.player;
|
||||||
|
|
||||||
|
if (player == null) return;
|
||||||
|
|
||||||
|
final int distanceSquared = player.getChunkPos().getSquaredDistance(new ChunkPos(origin));
|
||||||
|
final int distance = (int) Math.sqrt(distanceSquared);
|
||||||
|
|
||||||
|
if (distance > getWorld().getSimulationDistance()) {
|
||||||
|
CommandCore.INSTANCE.alreadyFilled = true;
|
||||||
|
CommandCore.INSTANCE.move(position);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ public abstract class ClientPlayerEntityMixin extends Entity {
|
||||||
final int distance = (int) Math.sqrt(distanceSquared);
|
final int distance = (int) Math.sqrt(distanceSquared);
|
||||||
|
|
||||||
if (distance > networkHandler.getWorld().getSimulationDistance()) {
|
if (distance > networkHandler.getWorld().getSimulationDistance()) {
|
||||||
CommandCore.INSTANCE.clientPlayerEntityFilled = true;
|
CommandCore.INSTANCE.alreadyFilled = true;
|
||||||
CommandCore.INSTANCE.move(this.getPos());
|
CommandCore.INSTANCE.move(this.getPos());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import net.minecraft.network.packet.c2s.play.UpdateCommandBlockC2SPacket;
|
||||||
import net.minecraft.util.math.BlockBox;
|
import net.minecraft.util.math.BlockBox;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import net.minecraft.world.dimension.DimensionType;
|
import net.minecraft.world.dimension.DimensionType;
|
||||||
|
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
|
|
@ -31,7 +32,7 @@ public class CommandCore {
|
||||||
public BlockPos block;
|
public BlockPos block;
|
||||||
public BlockBox withPos;
|
public BlockBox withPos;
|
||||||
public boolean runFillCommand = true;
|
public boolean runFillCommand = true;
|
||||||
public boolean clientPlayerEntityFilled = false;
|
public boolean alreadyFilled = false;
|
||||||
private Timer timer;
|
private Timer timer;
|
||||||
private boolean shouldRefill = false;
|
private boolean shouldRefill = false;
|
||||||
private DimensionType oldDimension;
|
private DimensionType oldDimension;
|
||||||
|
|
@ -53,8 +54,8 @@ public class CommandCore {
|
||||||
final TimerTask refillTask = new TimerTask() {
|
final TimerTask refillTask = new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run () {
|
public void run () {
|
||||||
if (clientPlayerEntityFilled) {
|
if (alreadyFilled) {
|
||||||
clientPlayerEntityFilled = false;
|
alreadyFilled = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,6 +75,8 @@ public class CommandCore {
|
||||||
|
|
||||||
timer.schedule(refillTask, 50, 1000);
|
timer.schedule(refillTask, 50, 1000);
|
||||||
|
|
||||||
|
if (client.player == null) return;
|
||||||
|
|
||||||
move(client.player.getPos());
|
move(client.player.getPos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,7 +165,13 @@ public class CommandCore {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refill () {
|
public void refill () {
|
||||||
if (!runFillCommand || withPos == null) return;
|
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||||
|
|
||||||
|
if (!runFillCommand || client.world == null || networkHandler == null || withPos == null) return;
|
||||||
|
|
||||||
|
final Chunk chunk = client.world.getChunk(withPos.getCenter());
|
||||||
|
|
||||||
|
if (chunk == null) return;
|
||||||
|
|
||||||
final String command = String.format(
|
final String command = String.format(
|
||||||
"fill %s %s %s %s %s %s command_block",
|
"fill %s %s %s %s %s %s command_block",
|
||||||
|
|
@ -204,7 +213,11 @@ public class CommandCore {
|
||||||
public void run (final String command) {
|
public void run (final String command) {
|
||||||
if (command.length() > 32767) return;
|
if (command.length() > 32767) return;
|
||||||
|
|
||||||
final ClientConnection connection = client.getNetworkHandler().getConnection();
|
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||||
|
|
||||||
|
if (networkHandler == null) return;
|
||||||
|
|
||||||
|
final ClientConnection connection = networkHandler.getConnection();
|
||||||
|
|
||||||
if (block == null) return;
|
if (block == null) return;
|
||||||
|
|
||||||
|
|
@ -249,7 +262,11 @@ public class CommandCore {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<NbtCompound> runTracked (final String command) {
|
public CompletableFuture<NbtCompound> runTracked (final String command) {
|
||||||
final ClientConnection connection = client.getNetworkHandler().getConnection();
|
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||||
|
|
||||||
|
if (networkHandler == null) return new CompletableFuture<>();
|
||||||
|
|
||||||
|
final ClientConnection connection = networkHandler.getConnection();
|
||||||
|
|
||||||
if (block == null) return new CompletableFuture<>();
|
if (block == null) return new CompletableFuture<>();
|
||||||
|
|
||||||
|
|
@ -298,7 +315,7 @@ public class CommandCore {
|
||||||
public void run () {
|
public void run () {
|
||||||
client.getNetworkHandler().getDataQueryHandler().queryBlockNbt(block, future::complete);
|
client.getNetworkHandler().getDataQueryHandler().queryBlockNbt(block, future::complete);
|
||||||
|
|
||||||
timer.cancel(); // ? Is this necesary?
|
timer.cancel(); // ? Is this necessary?
|
||||||
timer.purge();
|
timer.purge();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue