mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 18:46:15 +00:00
refactor: remove
This commit is contained in:
parent
0f9b6f4cdb
commit
7ed4d1ee84
6 changed files with 76 additions and 75 deletions
|
|
@ -1,8 +1,6 @@
|
|||
package land.chipmunk.chipmunkmod.mixin;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
||||
import land.chipmunk.chipmunkmod.data.ChomeNSBotCommand;
|
||||
import land.chipmunk.chipmunkmod.modules.ChomeNSBotCommandSuggestions;
|
||||
|
|
@ -38,8 +36,8 @@ public abstract class ChatScreenMixin {
|
|||
chatField.setMaxLength(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@WrapMethod(method = "sendMessage")
|
||||
private void sendMessage (final String chatText, final boolean addToHistory, final Operation<Void> original) {
|
||||
@Inject(method = "sendMessage", at = @At("HEAD"), cancellable = true)
|
||||
private void sendMessage (final String chatText, final boolean addToHistory, final CallbackInfo ci) {
|
||||
final MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
||||
if (addToHistory) {
|
||||
|
|
@ -98,6 +96,7 @@ public abstract class ChatScreenMixin {
|
|||
) {
|
||||
try {
|
||||
BotValidationUtilities.chomens(chatText.substring(prefixLength));
|
||||
ci.cancel();
|
||||
return;
|
||||
} catch (final Exception ignored) {
|
||||
}
|
||||
|
|
@ -112,6 +111,6 @@ public abstract class ChatScreenMixin {
|
|||
client.player.networkHandler.sendChatMessage(chatText);
|
||||
}
|
||||
|
||||
// :D
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ import net.minecraft.sound.SoundEvent;
|
|||
import net.minecraft.util.Identifier;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
|
@ -28,11 +31,11 @@ public class ClientConnectionMixin {
|
|||
@Unique
|
||||
private static final Pattern CUSTOM_PITCH_PATTERN = Pattern.compile(".*\\.pitch\\.(.*)");
|
||||
|
||||
@WrapMethod(method = "handlePacket")
|
||||
@Inject(method = "handlePacket", at = @At("HEAD"), cancellable = true)
|
||||
private static <T extends PacketListener> void handlePacket (
|
||||
final Packet<T> packet,
|
||||
final PacketListener packetListener,
|
||||
final Operation<Void> original
|
||||
final CallbackInfo ci
|
||||
) {
|
||||
for (final Listener listener : ListenerManager.listeners) {
|
||||
listener.packetReceived(packet);
|
||||
|
|
@ -45,7 +48,7 @@ public class ClientConnectionMixin {
|
|||
packet instanceof final ParticleS2CPacket t_packet
|
||||
&& t_packet.getCount() > MAX_PARTICLES_PER_PACKET
|
||||
) {
|
||||
return;
|
||||
ci.cancel();
|
||||
} else if (packet instanceof final PlaySoundS2CPacket t_packet) {
|
||||
final SoundEvent soundEvent = t_packet.getSound().value();
|
||||
|
||||
|
|
@ -53,10 +56,7 @@ public class ClientConnectionMixin {
|
|||
|
||||
final Matcher matcher = CUSTOM_PITCH_PATTERN.matcher(sound.getPath());
|
||||
|
||||
if (!matcher.find()) {
|
||||
original.call(packet, packetListener);
|
||||
return;
|
||||
}
|
||||
if (!matcher.find()) return;
|
||||
|
||||
try {
|
||||
final String stringPitch = matcher.group(1);
|
||||
|
|
@ -65,10 +65,7 @@ public class ClientConnectionMixin {
|
|||
|
||||
final ClientWorld world = client.world;
|
||||
|
||||
if (world == null) {
|
||||
original.call(packet, packetListener);
|
||||
return;
|
||||
}
|
||||
if (world == null) return;
|
||||
|
||||
final SoundEvent newSound = SoundEvent.of(
|
||||
Identifier.of(
|
||||
|
|
@ -93,15 +90,16 @@ public class ClientConnectionMixin {
|
|||
t_packet.getSeed()
|
||||
));
|
||||
|
||||
ci.cancel();
|
||||
return;
|
||||
} catch (final NumberFormatException e) {
|
||||
ChipmunkMod.LOGGER.error("Failed to parse custom pitch", e);
|
||||
}
|
||||
|
||||
if (t_packet.getVolume() == 1 && sound.getPath().equals("entity.enderman.scream")) return;
|
||||
if (t_packet.getVolume() == 1 && sound.getPath().equals("entity.enderman.scream")) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
original.call(packet, packetListener);
|
||||
}
|
||||
|
||||
@WrapMethod(method = "send(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/PacketCallbacks;Z)V")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package land.chipmunk.chipmunkmod.mixin;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
|
@ -12,11 +11,11 @@ import land.chipmunk.chipmunkmod.modules.*;
|
|||
import land.chipmunk.chipmunkmod.modules.custom_chat.CustomChat;
|
||||
import net.minecraft.client.gui.hud.InGameHud;
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
import net.minecraft.client.network.message.MessageHandler;
|
||||
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.registry.DynamicRegistryManager;
|
||||
import net.minecraft.resource.featuretoggle.FeatureSet;
|
||||
import net.minecraft.text.PlainTextContent;
|
||||
|
|
@ -59,46 +58,46 @@ public class ClientPlayNetworkHandlerMixin {
|
|||
KaboomCheck.INSTANCE.onCommandTree(this.commandDispatcher);
|
||||
}
|
||||
|
||||
@WrapOperation(
|
||||
@Inject(
|
||||
method = "onGameMessage",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/client/network/message/MessageHandler;onGameMessage(Lnet/minecraft/text/Text;Z)V"
|
||||
)
|
||||
),
|
||||
cancellable = true
|
||||
)
|
||||
private void onGameMessage (final MessageHandler instance, final Text message, final boolean overlay, final Operation<Void> original) {
|
||||
try {
|
||||
if (
|
||||
(
|
||||
RainbowName.INSTANCE.enabled &&
|
||||
(
|
||||
message.getString().startsWith("Your nickname is now ") ||
|
||||
message.getString().startsWith("Nickname changed.")
|
||||
)
|
||||
) ||
|
||||
(
|
||||
message.getContent() instanceof final TranslatableTextContent translatableTextContent &&
|
||||
(
|
||||
translatableTextContent.getKey().equals("advMode.setCommand.success")
|
||||
|| translatableTextContent.getKey().equals("قيادة المجموعة: %s")
|
||||
)
|
||||
)
|
||||
) return;
|
||||
private void onGameMessage (final GameMessageS2CPacket packet, final CallbackInfo ci) {
|
||||
final Text message = packet.content();
|
||||
|
||||
for (final Listener listener : ListenerManager.listeners) {
|
||||
listener.chatMessageReceived(message);
|
||||
}
|
||||
|
||||
if (
|
||||
message.getSiblings().size() > 1
|
||||
&& message.getSiblings().getFirst().getContent() instanceof final PlainTextContent textContent
|
||||
&& textContent.string().equals(ChomeNSBotCommandSuggestions.REQUEST_SUGGESTIONS_ID)
|
||||
) return;
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
if (
|
||||
(
|
||||
RainbowName.INSTANCE.enabled &&
|
||||
(
|
||||
message.getString().startsWith("Your nickname is now ") ||
|
||||
message.getString().startsWith("Nickname changed.")
|
||||
)
|
||||
) ||
|
||||
(
|
||||
message.getContent() instanceof final TranslatableTextContent translatableTextContent &&
|
||||
(
|
||||
translatableTextContent.getKey().equals("advMode.setCommand.success")
|
||||
|| translatableTextContent.getKey().equals("قيادة المجموعة: %s")
|
||||
)
|
||||
)
|
||||
) {
|
||||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
original.call(instance, message, overlay);
|
||||
for (final Listener listener : ListenerManager.listeners) {
|
||||
listener.chatMessageReceived(message);
|
||||
}
|
||||
|
||||
if (
|
||||
message.getSiblings().size() > 1
|
||||
&& message.getSiblings().getFirst().getContent() instanceof final PlainTextContent textContent
|
||||
&& textContent.string().equals(ChomeNSBotCommandSuggestions.REQUEST_SUGGESTIONS_ID)
|
||||
) ci.cancel();
|
||||
}
|
||||
|
||||
@WrapOperation(
|
||||
|
|
@ -121,11 +120,12 @@ public class ClientPlayNetworkHandlerMixin {
|
|||
// so I do not ignore them
|
||||
}
|
||||
|
||||
@WrapMethod(method = "sendChatMessage")
|
||||
private void sendChatMessage (final String content, final Operation<Void> original) {
|
||||
@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
|
||||
private void sendChatMessage (final String content, final CallbackInfo ci) {
|
||||
final CommandManager commandManager = CommandManager.INSTANCE;
|
||||
if (content.startsWith(commandManager.prefix)) {
|
||||
commandManager.executeCommand(content.substring(commandManager.prefix.length()));
|
||||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -135,7 +135,6 @@ public class ClientPlayNetworkHandlerMixin {
|
|||
}
|
||||
|
||||
CustomChat.INSTANCE.chat(content);
|
||||
|
||||
// :D
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,22 @@
|
|||
package land.chipmunk.chipmunkmod.mixin;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import net.minecraft.client.particle.ElderGuardianAppearanceParticle;
|
||||
import net.minecraft.client.particle.Particle;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.particle.SimpleParticleType;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ElderGuardianAppearanceParticle.Factory.class)
|
||||
public class ElderGuardianAppearanceParticleMixin {
|
||||
@WrapMethod(
|
||||
method = "createParticle(Lnet/minecraft/particle/SimpleParticleType;Lnet/minecraft/client/world/ClientWorld;DDDDDD)Lnet/minecraft/client/particle/Particle;"
|
||||
@Inject(
|
||||
method = "createParticle(Lnet/minecraft/particle/SimpleParticleType;Lnet/minecraft/client/world/ClientWorld;DDDDDD)Lnet/minecraft/client/particle/Particle;",
|
||||
at = @At("RETURN"),
|
||||
cancellable = true
|
||||
)
|
||||
private Particle createParticle (
|
||||
private void createParticle (
|
||||
final SimpleParticleType simpleParticleType,
|
||||
final ClientWorld clientWorld,
|
||||
final double d,
|
||||
|
|
@ -22,9 +25,9 @@ public class ElderGuardianAppearanceParticleMixin {
|
|||
final double g,
|
||||
final double h,
|
||||
final double i,
|
||||
final Operation<Particle> original
|
||||
final CallbackInfoReturnable<Particle> cir
|
||||
) {
|
||||
// slash scare command
|
||||
return null;
|
||||
cir.setReturnValue(null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
package land.chipmunk.chipmunkmod.mixin;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import net.minecraft.client.sound.SoundInstance;
|
||||
import net.minecraft.client.sound.SoundSystem;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(SoundSystem.class)
|
||||
public class SoundSystemMixin {
|
||||
@WrapMethod(method = "getAdjustedPitch")
|
||||
private float getAdjustedPitch (final SoundInstance sound, final Operation<Float> original) {
|
||||
return sound.getPitch();
|
||||
@Inject(method = "getAdjustedPitch", at = @At("RETURN"), cancellable = true)
|
||||
private void getAdjustedPitch (final SoundInstance sound, final CallbackInfoReturnable<Float> cir) {
|
||||
cir.setReturnValue(sound.getPitch());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
package land.chipmunk.chipmunkmod.mixin;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import net.minecraft.util.StringHelper;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(StringHelper.class)
|
||||
public class StringHelperMixin {
|
||||
@WrapMethod(method = "isValidChar")
|
||||
private static boolean isValidChar (final char c, final Operation<Boolean> original) {
|
||||
// very legal [NUL] [LF] §
|
||||
return true;
|
||||
@Inject(method = "isValidChar", at = @At("RETURN"), cancellable = true)
|
||||
private static void isValidChar (final char c, final CallbackInfoReturnable<Boolean> cir) {
|
||||
// very legal [NUL] [LF] § Allowance.
|
||||
cir.setReturnValue(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue