mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-14 03:56:26 +00:00
Compare commits
No commits in common. "0cc74be280e220de7588c2d239216a0013561118" and "69909de32763f3e445d73812152882772c3837bd" have entirely different histories.
0cc74be280
...
69909de327
4 changed files with 12 additions and 62 deletions
|
|
@ -2,7 +2,6 @@ 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) { }
|
||||
|
|
@ -16,6 +15,4 @@ public interface Listener {
|
|||
default void coreReady () { }
|
||||
|
||||
default void coreMoved () { }
|
||||
|
||||
default void positionChanged (final Vec3d newPosition) { }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,22 +9,18 @@ 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.*;
|
||||
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.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;
|
||||
|
|
@ -33,7 +29,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(value = ClientPlayNetworkHandler.class, priority = 1001)
|
||||
public abstract class ClientPlayNetworkHandlerMixin {
|
||||
public class ClientPlayNetworkHandlerMixin {
|
||||
@Final
|
||||
@Shadow
|
||||
private FeatureSet enabledFeatures;
|
||||
|
|
@ -43,8 +39,6 @@ public abstract 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);
|
||||
|
|
@ -142,28 +136,4 @@ public abstract 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.alreadyFilled = true;
|
||||
CommandCore.INSTANCE.clientPlayerEntityFilled = true;
|
||||
CommandCore.INSTANCE.move(this.getPos());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ 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;
|
||||
|
|
@ -32,7 +31,7 @@ public class CommandCore {
|
|||
public BlockPos block;
|
||||
public BlockBox withPos;
|
||||
public boolean runFillCommand = true;
|
||||
public boolean alreadyFilled = false;
|
||||
public boolean clientPlayerEntityFilled = false;
|
||||
private Timer timer;
|
||||
private boolean shouldRefill = false;
|
||||
private DimensionType oldDimension;
|
||||
|
|
@ -54,8 +53,8 @@ public class CommandCore {
|
|||
final TimerTask refillTask = new TimerTask() {
|
||||
@Override
|
||||
public void run () {
|
||||
if (alreadyFilled) {
|
||||
alreadyFilled = false;
|
||||
if (clientPlayerEntityFilled) {
|
||||
clientPlayerEntityFilled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -75,8 +74,6 @@ public class CommandCore {
|
|||
|
||||
timer.schedule(refillTask, 50, 1000);
|
||||
|
||||
if (client.player == null) return;
|
||||
|
||||
move(client.player.getPos());
|
||||
}
|
||||
|
||||
|
|
@ -165,13 +162,7 @@ public class CommandCore {
|
|||
}
|
||||
|
||||
public void refill () {
|
||||
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;
|
||||
if (!runFillCommand || withPos == null) return;
|
||||
|
||||
final String command = String.format(
|
||||
"fill %s %s %s %s %s %s command_block",
|
||||
|
|
@ -213,11 +204,7 @@ public class CommandCore {
|
|||
public void run (final String command) {
|
||||
if (command.length() > 32767) return;
|
||||
|
||||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||
|
||||
if (networkHandler == null) return;
|
||||
|
||||
final ClientConnection connection = networkHandler.getConnection();
|
||||
final ClientConnection connection = client.getNetworkHandler().getConnection();
|
||||
|
||||
if (block == null) return;
|
||||
|
||||
|
|
@ -262,11 +249,7 @@ public class CommandCore {
|
|||
}
|
||||
|
||||
public CompletableFuture<NbtCompound> runTracked (final String command) {
|
||||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||
|
||||
if (networkHandler == null) return new CompletableFuture<>();
|
||||
|
||||
final ClientConnection connection = networkHandler.getConnection();
|
||||
final ClientConnection connection = client.getNetworkHandler().getConnection();
|
||||
|
||||
if (block == null) return new CompletableFuture<>();
|
||||
|
||||
|
|
@ -315,7 +298,7 @@ public class CommandCore {
|
|||
public void run () {
|
||||
client.getNetworkHandler().getDataQueryHandler().queryBlockNbt(block, future::complete);
|
||||
|
||||
timer.cancel(); // ? Is this necessary?
|
||||
timer.cancel(); // ? Is this necesary?
|
||||
timer.purge();
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue