mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 18:46:15 +00:00
refactor: don't use chomens bot teams
This commit is contained in:
parent
d6a93ffef9
commit
3e05e6b89d
3 changed files with 47 additions and 7 deletions
|
|
@ -5,9 +5,11 @@ import net.minecraft.text.Text;
|
|||
|
||||
public interface Listener {
|
||||
default void packetReceived (Packet<?> packet) {}
|
||||
default void chatMessageReceived (Text message) {}
|
||||
default void packetSent (Packet<?> packet) {}
|
||||
|
||||
default void chatMessageReceived (Text message) {}
|
||||
default void overlayMessageReceived (Text message) {}
|
||||
|
||||
default void coreReady () {}
|
||||
default void coreMoved () {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ 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.OverlayMessageS2CPacket;
|
||||
import net.minecraft.registry.DynamicRegistryManager;
|
||||
import net.minecraft.resource.featuretoggle.FeatureSet;
|
||||
import net.minecraft.text.Text;
|
||||
|
|
@ -85,13 +86,24 @@ public class ClientPlayNetworkHandlerMixin {
|
|||
if (message.getSiblings().size() > 1) {
|
||||
final String suggestionId = message.getSiblings().getFirst().getString();
|
||||
|
||||
if (suggestionId.equals(ChomeNSBotCommandSuggestions.ID)) {
|
||||
if (suggestionId.equals(ChomeNSBotCommandSuggestions.REQUEST_SUGGESTIONS_ID)) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
@Inject(method = "onOverlayMessage", at = @At("TAIL"))
|
||||
private void onOverlayMessage(OverlayMessageS2CPacket packet, CallbackInfo ci) {
|
||||
for (Listener listener : ListenerManager.listeners) {
|
||||
listener.overlayMessageReceived(packet.text());
|
||||
}
|
||||
|
||||
// checking for the bot selector message doesn't really
|
||||
// do much here since the message is just an empty string,
|
||||
// so I do not ignore them
|
||||
}
|
||||
|
||||
@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
|
||||
private void sendChatMessage(String chatText, CallbackInfo ci) {
|
||||
final CommandManager commandManager = CommandManager.INSTANCE;
|
||||
|
|
|
|||
|
|
@ -9,13 +9,15 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
|||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableTextContent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ChomeNSBotCommandSuggestions implements Listener {
|
||||
public static final String ID = "chomens_bot_request_command_suggestion";
|
||||
public static final String BOT_SELECTOR_ID = "chomens_bot_selector";
|
||||
public static final String REQUEST_SUGGESTIONS_ID = "chomens_bot_request_command_suggestion";
|
||||
|
||||
public static ChomeNSBotCommandSuggestions INSTANCE = new ChomeNSBotCommandSuggestions(MinecraftClient.getInstance());
|
||||
|
||||
|
|
@ -23,6 +25,8 @@ public class ChomeNSBotCommandSuggestions implements Listener {
|
|||
|
||||
public boolean receivedSuggestions = false; // can be set through eval
|
||||
|
||||
public String botSelector = null;
|
||||
|
||||
public List<ChomeNSBotCommand> commands = new ArrayList<>();
|
||||
|
||||
public ChomeNSBotCommandSuggestions (MinecraftClient client) {
|
||||
|
|
@ -41,17 +45,39 @@ public class ChomeNSBotCommandSuggestions implements Listener {
|
|||
public void forceRequest () {
|
||||
final ClientPlayerEntity player = client.player;
|
||||
|
||||
if (player == null) return;
|
||||
if (botSelector == null || player == null) return;
|
||||
|
||||
final String selector = UUIDUtilities.selector(player.getUuid());
|
||||
|
||||
final Component component = Component
|
||||
.text(ID)
|
||||
.text(REQUEST_SUGGESTIONS_ID)
|
||||
.append(Component.text(selector));
|
||||
|
||||
final String serialized = GsonComponentSerializer.gson().serialize(component);
|
||||
|
||||
CommandCore.INSTANCE.run((KaboomCheck.INSTANCE.isKaboom ? "minecraft:tellraw " : "tellraw ") + "@a[team=chomens_bot] " + serialized);
|
||||
// minecraft:tellraw @p[nbt={UUID:[I;6,9,6,9]} {...}
|
||||
CommandCore.INSTANCE.run(
|
||||
String.format(
|
||||
"%s %s %s",
|
||||
(KaboomCheck.INSTANCE.isKaboom ? "minecraft:tellraw" : "tellraw"),
|
||||
botSelector,
|
||||
serialized
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void overlayMessageReceived (Text message) {
|
||||
if (
|
||||
!(message.getContent() instanceof TranslatableTextContent translatableTextContent)
|
||||
|| !translatableTextContent.getKey().isEmpty()
|
||||
|| translatableTextContent.getArgs().length != 2
|
||||
|| !(translatableTextContent.getArgs()[0] instanceof String id)
|
||||
|| !id.equals(BOT_SELECTOR_ID)
|
||||
|| !(translatableTextContent.getArgs()[1] instanceof String selector)
|
||||
) return;
|
||||
|
||||
this.botSelector = selector;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -60,7 +86,7 @@ public class ChomeNSBotCommandSuggestions implements Listener {
|
|||
if (children.isEmpty()) return;
|
||||
|
||||
final Text textComponent = children.getFirst();
|
||||
if (!textComponent.getString().equals(ID)) return;
|
||||
if (!textComponent.getString().equals(REQUEST_SUGGESTIONS_ID)) return;
|
||||
|
||||
commands = children.stream()
|
||||
.skip(1)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue