mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 19:56:15 +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.text.Text;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public interface Listener {
|
||||
default void packetReceived (final Packet<?> packet) { }
|
||||
|
|
@ -15,4 +16,6 @@ public interface Listener {
|
|||
default void coreReady () { }
|
||||
|
||||
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.modules.*;
|
||||
import land.chipmunk.chipmunkmod.modules.custom_chat.CustomChat;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.hud.InGameHud;
|
||||
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.CommandSource;
|
||||
import net.minecraft.network.packet.s2c.play.CommandTreeS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.*;
|
||||
import net.minecraft.registry.DynamicRegistryManager;
|
||||
import net.minecraft.resource.featuretoggle.FeatureSet;
|
||||
import net.minecraft.text.PlainTextContent;
|
||||
import net.minecraft.text.Text;
|
||||
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.Mixin;
|
||||
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;
|
||||
|
||||
@Mixin(value = ClientPlayNetworkHandler.class, priority = 1001)
|
||||
public class ClientPlayNetworkHandlerMixin {
|
||||
public abstract class ClientPlayNetworkHandlerMixin {
|
||||
@Final
|
||||
@Shadow
|
||||
private FeatureSet enabledFeatures;
|
||||
|
|
@ -39,6 +43,8 @@ public class ClientPlayNetworkHandlerMixin {
|
|||
@Shadow
|
||||
private CommandDispatcher<CommandSource> commandDispatcher;
|
||||
|
||||
@Shadow public abstract ClientWorld getWorld ();
|
||||
|
||||
@Inject(method = "onGameJoin", at = @At("TAIL"))
|
||||
private void onGameJoin (final GameJoinS2CPacket packet, final CallbackInfo ci) {
|
||||
final CommandRegistryAccess commandRegistryAccess = CommandRegistryAccess.of(this.combinedDynamicRegistries, this.enabledFeatures);
|
||||
|
|
@ -136,4 +142,28 @@ public class ClientPlayNetworkHandlerMixin {
|
|||
CustomChat.INSTANCE.chat(content);
|
||||
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);
|
||||
|
||||
if (distance > networkHandler.getWorld().getSimulationDistance()) {
|
||||
CommandCore.INSTANCE.clientPlayerEntityFilled = true;
|
||||
CommandCore.INSTANCE.alreadyFilled = true;
|
||||
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.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
|
||||
import java.util.Timer;
|
||||
|
|
@ -31,7 +32,7 @@ public class CommandCore {
|
|||
public BlockPos block;
|
||||
public BlockBox withPos;
|
||||
public boolean runFillCommand = true;
|
||||
public boolean clientPlayerEntityFilled = false;
|
||||
public boolean alreadyFilled = false;
|
||||
private Timer timer;
|
||||
private boolean shouldRefill = false;
|
||||
private DimensionType oldDimension;
|
||||
|
|
@ -53,8 +54,8 @@ public class CommandCore {
|
|||
final TimerTask refillTask = new TimerTask() {
|
||||
@Override
|
||||
public void run () {
|
||||
if (clientPlayerEntityFilled) {
|
||||
clientPlayerEntityFilled = false;
|
||||
if (alreadyFilled) {
|
||||
alreadyFilled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -74,6 +75,8 @@ public class CommandCore {
|
|||
|
||||
timer.schedule(refillTask, 50, 1000);
|
||||
|
||||
if (client.player == null) return;
|
||||
|
||||
move(client.player.getPos());
|
||||
}
|
||||
|
||||
|
|
@ -162,7 +165,13 @@ public class CommandCore {
|
|||
}
|
||||
|
||||
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(
|
||||
"fill %s %s %s %s %s %s command_block",
|
||||
|
|
@ -204,7 +213,11 @@ public class CommandCore {
|
|||
public void run (final String command) {
|
||||
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;
|
||||
|
||||
|
|
@ -249,7 +262,11 @@ public class CommandCore {
|
|||
}
|
||||
|
||||
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<>();
|
||||
|
||||
|
|
@ -298,7 +315,7 @@ public class CommandCore {
|
|||
public void run () {
|
||||
client.getNetworkHandler().getDataQueryHandler().queryBlockNbt(block, future::complete);
|
||||
|
||||
timer.cancel(); // ? Is this necesary?
|
||||
timer.cancel(); // ? Is this necessary?
|
||||
timer.purge();
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue