forked from ChomeNS/chipmunkmod
imposter HClient 🧌
This commit is contained in:
parent
9c99b9edcf
commit
02488b4289
4 changed files with 104 additions and 6 deletions
|
@ -1,6 +1,7 @@
|
||||||
package land.chipmunk.chipmunkmod;
|
package land.chipmunk.chipmunkmod;
|
||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
import land.chipmunk.chipmunkmod.modules.KaboomCheck;
|
||||||
import land.chipmunk.chipmunkmod.modules.Players;
|
import land.chipmunk.chipmunkmod.modules.Players;
|
||||||
import land.chipmunk.chipmunkmod.util.gson.BlockPosTypeAdapter;
|
import land.chipmunk.chipmunkmod.util.gson.BlockPosTypeAdapter;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
@ -44,6 +45,7 @@ public class ChipmunkMod implements ModInitializer {
|
||||||
}
|
}
|
||||||
|
|
||||||
Players.INSTANCE.init();
|
Players.INSTANCE.init();
|
||||||
|
KaboomCheck.INSTANCE.init();
|
||||||
|
|
||||||
LOGGER.info("Loaded ChipmunkMod (chayapak's fork)");
|
LOGGER.info("Loaded ChipmunkMod (chayapak's fork)");
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,9 @@ package land.chipmunk.chipmunkmod.mixin;
|
||||||
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
||||||
import land.chipmunk.chipmunkmod.command.CommandManager;
|
import land.chipmunk.chipmunkmod.command.CommandManager;
|
||||||
import land.chipmunk.chipmunkmod.modules.*;
|
import land.chipmunk.chipmunkmod.modules.*;
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.client.network.ClientDynamicRegistryType;
|
import net.minecraft.client.network.ClientDynamicRegistryType;
|
||||||
import net.minecraft.client.network.PlayerListEntry;
|
|
||||||
import net.minecraft.command.CommandRegistryAccess;
|
import net.minecraft.command.CommandRegistryAccess;
|
||||||
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
|
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
|
||||||
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
|
|
||||||
import net.minecraft.network.packet.s2c.play.PlayerRemoveS2CPacket;
|
import net.minecraft.network.packet.s2c.play.PlayerRemoveS2CPacket;
|
||||||
import net.minecraft.registry.CombinedDynamicRegistries;
|
import net.minecraft.registry.CombinedDynamicRegistries;
|
||||||
import net.minecraft.resource.featuretoggle.FeatureSet;
|
import net.minecraft.resource.featuretoggle.FeatureSet;
|
||||||
|
@ -18,8 +15,6 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
@Mixin(net.minecraft.client.network.ClientPlayNetworkHandler.class)
|
@Mixin(net.minecraft.client.network.ClientPlayNetworkHandler.class)
|
||||||
public class ClientPlayNetworkHandlerMixin {
|
public class ClientPlayNetworkHandlerMixin {
|
||||||
@Shadow private FeatureSet enabledFeatures;
|
@Shadow private FeatureSet enabledFeatures;
|
||||||
|
@ -29,6 +24,7 @@ public class ClientPlayNetworkHandlerMixin {
|
||||||
private void onGameJoin (GameJoinS2CPacket packet, CallbackInfo ci) {
|
private void onGameJoin (GameJoinS2CPacket packet, CallbackInfo ci) {
|
||||||
final CommandRegistryAccess commandRegistryAccess = CommandRegistryAccess.of(this.combinedDynamicRegistries.getCombinedRegistryManager(), this.enabledFeatures);
|
final CommandRegistryAccess commandRegistryAccess = CommandRegistryAccess.of(this.combinedDynamicRegistries.getCombinedRegistryManager(), this.enabledFeatures);
|
||||||
|
|
||||||
|
KaboomCheck.INSTANCE.onJoin();
|
||||||
CommandManager.INSTANCE = new CommandManager(ChipmunkMod.CONFIG.commands.prefix, commandRegistryAccess);
|
CommandManager.INSTANCE = new CommandManager(ChipmunkMod.CONFIG.commands.prefix, commandRegistryAccess);
|
||||||
SelfCare.INSTANCE.init();
|
SelfCare.INSTANCE.init();
|
||||||
LoopCrouch.INSTANCE.init();
|
LoopCrouch.INSTANCE.init();
|
||||||
|
|
|
@ -56,6 +56,8 @@ public class CommandCore {
|
||||||
final BlockPos relEnd = relativeArea.end();
|
final BlockPos relEnd = relativeArea.end();
|
||||||
|
|
||||||
final String command = String.format(
|
final String command = String.format(
|
||||||
|
KaboomCheck.INSTANCE.isKaboom() ?
|
||||||
|
"fill %s %s %s %s %s %s repeating_command_block replace" :
|
||||||
"fill %s %s %s %s %s %s command_block",
|
"fill %s %s %s %s %s %s command_block",
|
||||||
relStart.getX() + origin.getX(),
|
relStart.getX() + origin.getX(),
|
||||||
relStart.getY() + origin.getY(),
|
relStart.getY() + origin.getY(),
|
||||||
|
|
|
@ -0,0 +1,98 @@
|
||||||
|
package land.chipmunk.chipmunkmod.modules;
|
||||||
|
|
||||||
|
import land.chipmunk.chipmunkmod.listeners.Listener;
|
||||||
|
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||||
|
import net.minecraft.network.packet.Packet;
|
||||||
|
import net.minecraft.network.packet.s2c.play.SubtitleS2CPacket;
|
||||||
|
import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
|
||||||
|
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
public class KaboomCheck extends Listener {
|
||||||
|
public static final String TITLE_START_TEXT = "Welcome to ";
|
||||||
|
public static final String TITLE_END_TEXT = "!";
|
||||||
|
|
||||||
|
public static final String SUBTITLE_START_TEXT = "Free OP";
|
||||||
|
|
||||||
|
@Getter private boolean isKaboom = false;
|
||||||
|
|
||||||
|
private boolean hasKaboomTitle = false;
|
||||||
|
private boolean hasKaboomSubtitle = false;
|
||||||
|
|
||||||
|
private Timer timer = null;
|
||||||
|
|
||||||
|
private final MinecraftClient client;
|
||||||
|
|
||||||
|
public static final KaboomCheck INSTANCE = new KaboomCheck(MinecraftClient.getInstance());
|
||||||
|
|
||||||
|
public KaboomCheck (MinecraftClient client) {
|
||||||
|
this.client = client;
|
||||||
|
|
||||||
|
ListenerManager.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init () {}
|
||||||
|
|
||||||
|
public void onJoin () {
|
||||||
|
final TimerTask task = new TimerTask() {
|
||||||
|
public void run () {
|
||||||
|
tick();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (timer != null) cleanup();
|
||||||
|
|
||||||
|
timer = new Timer();
|
||||||
|
|
||||||
|
timer.schedule(task, 50, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tick () {
|
||||||
|
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||||
|
|
||||||
|
if (networkHandler == null) cleanup();
|
||||||
|
|
||||||
|
if (hasKaboomTitle && hasKaboomSubtitle) isKaboom = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cleanup () {
|
||||||
|
if (timer == null) return;
|
||||||
|
|
||||||
|
isKaboom = false;
|
||||||
|
hasKaboomTitle = false;
|
||||||
|
hasKaboomSubtitle = false;
|
||||||
|
|
||||||
|
timer.purge();
|
||||||
|
timer.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void packetReceived(Packet<?> packet) {
|
||||||
|
if (packet instanceof TitleS2CPacket) packetReceived((TitleS2CPacket) packet);
|
||||||
|
else if (packet instanceof SubtitleS2CPacket) packetReceived((SubtitleS2CPacket) packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: move this to a util class
|
||||||
|
private String stripSectionSigns (String text) {
|
||||||
|
return text.replaceAll("§.", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void packetReceived(TitleS2CPacket packet) {
|
||||||
|
final String stripped = stripSectionSigns(packet.getTitle().getString());
|
||||||
|
|
||||||
|
if (
|
||||||
|
stripped.startsWith(TITLE_START_TEXT) &&
|
||||||
|
stripped.endsWith(TITLE_END_TEXT)
|
||||||
|
) hasKaboomTitle = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void packetReceived(SubtitleS2CPacket packet) {
|
||||||
|
final String stripped = stripSectionSigns(packet.getSubtitle().getString());
|
||||||
|
|
||||||
|
if (stripped.startsWith(SUBTITLE_START_TEXT)) hasKaboomSubtitle = true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue