mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 18:46:15 +00:00
feat: use time update parker Fresh from server
This commit is contained in:
parent
3830cde2a7
commit
a2ad37af35
4 changed files with 33 additions and 80 deletions
|
|
@ -18,4 +18,6 @@ public interface Listener {
|
|||
default void coreMoved () { }
|
||||
|
||||
default void positionChanged (final Vec3d newPosition) { }
|
||||
|
||||
default void timeUpdate () { }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ public abstract class ClientPlayNetworkHandlerMixin {
|
|||
|
||||
KaboomCheck.INSTANCE.onJoin();
|
||||
CommandManager.INSTANCE = new CommandManager(ChipmunkMod.CONFIG.commands.prefix, commandRegistryAccess);
|
||||
SelfCare.INSTANCE.onJoin();
|
||||
CommandCore.INSTANCE.init();
|
||||
SongPlayer.INSTANCE.coreReady();
|
||||
RainbowName.INSTANCE.init();
|
||||
|
|
@ -166,4 +165,9 @@ public abstract class ClientPlayNetworkHandlerMixin {
|
|||
CommandCore.INSTANCE.move(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "onWorldTimeUpdate", at = @At("TAIL"))
|
||||
private void onWorldTimeUpdate (final WorldTimeUpdateS2CPacket packet, final CallbackInfo ci) {
|
||||
for (final Listener listener : ListenerManager.listeners) listener.timeUpdate();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import java.util.Timer;
|
|||
import java.util.TimerTask;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class CommandCore {
|
||||
public class CommandCore implements Listener {
|
||||
public static CommandCore INSTANCE = new CommandCore(MinecraftClient.getInstance());
|
||||
|
||||
private final MinecraftClient client;
|
||||
|
|
@ -66,33 +66,15 @@ public class CommandCore {
|
|||
}
|
||||
};
|
||||
|
||||
final TimerTask refillTask = new TimerTask() {
|
||||
@Override
|
||||
public void run () {
|
||||
if (alreadyFilled) {
|
||||
alreadyFilled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
check();
|
||||
|
||||
if (!shouldRefill) return;
|
||||
|
||||
refill();
|
||||
|
||||
shouldRefill = false;
|
||||
}
|
||||
};
|
||||
|
||||
timer = new Timer();
|
||||
|
||||
timer.schedule(task, 50, 50);
|
||||
|
||||
timer.schedule(refillTask, 50, 1000);
|
||||
|
||||
if (client.player == null) return;
|
||||
|
||||
move(client.player.getPos());
|
||||
|
||||
ListenerManager.addListener(this);
|
||||
}
|
||||
|
||||
private void tick () {
|
||||
|
|
@ -110,6 +92,22 @@ public class CommandCore {
|
|||
noPos = ChipmunkMod.CONFIG.core.relativeArea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void timeUpdate () {
|
||||
if (alreadyFilled) {
|
||||
alreadyFilled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
check();
|
||||
|
||||
if (!shouldRefill) return;
|
||||
|
||||
refill();
|
||||
|
||||
shouldRefill = false;
|
||||
}
|
||||
|
||||
public void check () {
|
||||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||
|
||||
|
|
|
|||
|
|
@ -6,19 +6,12 @@ import land.chipmunk.chipmunkmod.listeners.ListenerManager;
|
|||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import static land.chipmunk.chipmunkmod.util.ServerUtilities.serverHasCommand;
|
||||
|
||||
public class SelfCare implements Listener {
|
||||
public static final SelfCare INSTANCE = new SelfCare(MinecraftClient.getInstance(), 500L); // make the intervals in config?
|
||||
public final long interval;
|
||||
public static final SelfCare INSTANCE = new SelfCare(MinecraftClient.getInstance());
|
||||
private final MinecraftClient client;
|
||||
public boolean opEnabled = ChipmunkMod.CONFIG.selfCare.op;
|
||||
public boolean gamemodeEnabled = ChipmunkMod.CONFIG.selfCare.gameMode;
|
||||
|
|
@ -26,12 +19,10 @@ public class SelfCare implements Listener {
|
|||
public String skin;
|
||||
public boolean hasSkin = false;
|
||||
private int gameMode;
|
||||
private Timer timer;
|
||||
private boolean cspy = false;
|
||||
|
||||
public SelfCare (final MinecraftClient client, final long interval) {
|
||||
public SelfCare (final MinecraftClient client) {
|
||||
this.client = client;
|
||||
this.interval = interval;
|
||||
|
||||
this.skin = ChipmunkMod.CONFIG.autoSkinUsername == null ? "off" : ChipmunkMod.CONFIG.autoSkinUsername;
|
||||
|
||||
|
|
@ -41,30 +32,6 @@ public class SelfCare implements Listener {
|
|||
public void init () {
|
||||
}
|
||||
|
||||
public void onJoin () {
|
||||
final TimerTask task = new TimerTask() {
|
||||
public void run () {
|
||||
tick();
|
||||
}
|
||||
};
|
||||
|
||||
timer = new Timer();
|
||||
|
||||
timer.schedule(task, interval, interval);
|
||||
}
|
||||
|
||||
public void cleanup () {
|
||||
if (timer == null) return;
|
||||
|
||||
timer.cancel();
|
||||
timer.purge();
|
||||
|
||||
gameMode = -1;
|
||||
|
||||
hasSkin = false;
|
||||
cspy = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chatMessageReceived (final Text message) {
|
||||
final String stringMessage = message.getString();
|
||||
|
|
@ -79,38 +46,20 @@ public class SelfCare implements Listener {
|
|||
) hasSkin = false;
|
||||
}
|
||||
|
||||
public void tick () {
|
||||
@Override
|
||||
public void timeUpdate () {
|
||||
final ClientPlayerEntity player = client.player;
|
||||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||
|
||||
if (networkHandler == null) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
if (networkHandler == null || player == null) return;
|
||||
|
||||
if (player != null && !player.hasPermissionLevel(2) && opEnabled && serverHasCommand("op"))
|
||||
if (!player.hasPermissionLevel(2) && opEnabled && serverHasCommand("op"))
|
||||
networkHandler.sendChatCommand("op @s[type=player]");
|
||||
else if (gameMode != 1 && gamemodeEnabled)
|
||||
else if (!player.isInCreativeMode() && gamemodeEnabled)
|
||||
networkHandler.sendChatCommand("gamemode creative");
|
||||
else if (!cspy && cspyEnabled && serverHasCommand("c"))
|
||||
networkHandler.sendChatCommand("c on");
|
||||
else if (!hasSkin && !skin.equalsIgnoreCase("off"))
|
||||
networkHandler.sendChatCommand("skin " + skin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (final Packet<?> packet) {
|
||||
if (packet instanceof GameJoinS2CPacket) packetReceived((GameJoinS2CPacket) packet);
|
||||
else if (packet instanceof GameStateChangeS2CPacket) packetReceived((GameStateChangeS2CPacket) packet);
|
||||
}
|
||||
|
||||
public void packetReceived (final GameJoinS2CPacket packet) {
|
||||
gameMode = packet.commonPlayerSpawnInfo().gameMode().getId();
|
||||
}
|
||||
|
||||
public void packetReceived (final GameStateChangeS2CPacket packet) {
|
||||
if (packet.getReason() != GameStateChangeS2CPacket.GAME_MODE_CHANGED) return;
|
||||
|
||||
gameMode = (int) packet.getValue();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue