dfghjkl;'
This commit is contained in:
parent
baf8d849b6
commit
412cabff8a
23 changed files with 706 additions and 18 deletions
|
@ -0,0 +1,72 @@
|
|||
package me.kawaiizenbo.moonlight.mixin;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.ParseResults;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
|
||||
import me.kawaiizenbo.moonlight.command.CommandManager;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.ChatInputSuggestor;
|
||||
import net.minecraft.client.gui.screen.ChatInputSuggestor.SuggestionWindow;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.command.CommandSource;
|
||||
|
||||
@Mixin(ChatInputSuggestor.class)
|
||||
public abstract class ChatInputSuggestorMixin
|
||||
{
|
||||
|
||||
@Shadow private ParseResults<CommandSource> parse;
|
||||
|
||||
@Shadow @Final private TextFieldWidget textField;
|
||||
|
||||
@Shadow @Final private MinecraftClient client;
|
||||
|
||||
@Shadow private boolean completingSuggestions;
|
||||
|
||||
@Shadow private CompletableFuture<Suggestions> pendingSuggestions;
|
||||
|
||||
@Shadow private SuggestionWindow window;
|
||||
|
||||
@Shadow protected abstract void showCommandSuggestions();
|
||||
|
||||
@Inject(method = "refresh",
|
||||
at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/StringReader;canRead()Z", remap = false),
|
||||
cancellable = true,
|
||||
locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
public void onRefresh(CallbackInfo ci, String string, StringReader reader) {
|
||||
String prefix = CommandManager.get().getPrefix();
|
||||
int length = prefix.length();
|
||||
if (reader.canRead(length) && reader.getString().startsWith(prefix, reader.getCursor())) {
|
||||
reader.setCursor(reader.getCursor() + length);
|
||||
assert this.client.player != null;
|
||||
// Pretty much copy&paste from the refresh method
|
||||
CommandDispatcher<CommandSource> commandDispatcher = CommandManager.get().getDispatcher();
|
||||
if (this.parse == null) {
|
||||
this.parse = commandDispatcher.parse(reader, CommandManager.get().getCommandSource());
|
||||
}
|
||||
|
||||
int cursor = textField.getCursor();
|
||||
if (cursor >= 1 && (this.window == null || !this.completingSuggestions)) {
|
||||
this.pendingSuggestions = commandDispatcher.getCompletionSuggestions(this.parse, cursor);
|
||||
this.pendingSuggestions.thenRun(() -> {
|
||||
if (this.pendingSuggestions.isDone()) {
|
||||
showCommandSuggestions();
|
||||
}
|
||||
});
|
||||
}
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package me.kawaiizenbo.moonlight.mixin;
|
||||
|
||||
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.CallbackInfo;
|
||||
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
|
||||
import me.kawaiizenbo.moonlight.command.CommandManager;
|
||||
import me.kawaiizenbo.moonlight.util.ChatUtils;
|
||||
import net.minecraft.network.ClientConnection;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket;
|
||||
|
||||
@Mixin(ClientConnection.class)
|
||||
public class ClientConnectionMixin
|
||||
{
|
||||
@Inject(method = "send(Lnet/minecraft/network/Packet;)V", at = @At("HEAD"), cancellable = true)
|
||||
public void send(Packet<?> packet, CallbackInfo ci)
|
||||
{
|
||||
// Call commands if the prefix is sent
|
||||
if(packet instanceof ChatMessageC2SPacket && ((ChatMessageC2SPacket) packet).chatMessage().startsWith(CommandManager.get().getPrefix()))
|
||||
{
|
||||
try
|
||||
{
|
||||
CommandManager.get().dispatch(((ChatMessageC2SPacket) packet).chatMessage().substring(CommandManager.get().getPrefix().length()));
|
||||
}
|
||||
catch (CommandSyntaxException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
ChatUtils.sendMsg(e.getMessage());
|
||||
}
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package me.kawaiizenbo.moonlight.mixin;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import me.kawaiizenbo.moonlight.ui.HUD;
|
||||
import net.minecraft.client.gui.hud.InGameHud;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
@Mixin(InGameHud.class)
|
||||
public class InGameHudMixin {
|
||||
|
||||
@Shadow private int scaledWidth;
|
||||
@Shadow private int scaledHeight;
|
||||
|
||||
@Inject(at = @At("TAIL"), method = "render")
|
||||
public void onRender (MatrixStack matrices, float tickDelta, CallbackInfo info)
|
||||
{
|
||||
HUD.INSTANCE.renderHUD(matrices, scaledWidth, scaledHeight);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package me.kawaiizenbo.moonlight.mixin;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
||||
import me.kawaiizenbo.moonlight.module.Module_;
|
||||
import me.kawaiizenbo.moonlight.module.ModuleManager;
|
||||
|
||||
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.CallbackInfo;
|
||||
|
||||
@Mixin(LivingEntity.class)
|
||||
public class LivingEntityMixin
|
||||
{
|
||||
@Inject(at = @At("HEAD"), method = "tick()V")
|
||||
private void init(CallbackInfo info)
|
||||
{
|
||||
for (Module_ mod : ModuleManager.INSTANCE.getEnabledModules())
|
||||
{
|
||||
if (MinecraftClient.getInstance().player != null) mod.tick();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +1,11 @@
|
|||
package me.kawaiizenbo.moonlight.mixin;
|
||||
|
||||
import me.kawaiizenbo.moonlight.ui.AltManagerScreen;
|
||||
|
||||
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.CallbackInfo;
|
||||
|
||||
import me.kawaiizenbo.moonlight.ui.altmanager.AltManagerScreen;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package me.kawaiizenbo.moonlight.mixin;
|
||||
|
||||
import me.kawaiizenbo.moonlight.Moonlight;
|
||||
import me.kawaiizenbo.moonlight.ui.AltManagerScreen;
|
||||
import me.kawaiizenbo.moonlight.ui.altmanager.AltManagerScreen;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue