PlexToolUi start
Signed-off-by: PlexSheep <PlexSheep@protonmail.com>
This commit is contained in:
parent
82805f1486
commit
fb7a320d02
|
@ -1,6 +0,0 @@
|
|||
package de.cscherr.plextool;
|
||||
public class PlexMenu {
|
||||
|
||||
public PlexMenu() {
|
||||
}
|
||||
}
|
|
@ -4,9 +4,6 @@ import net.fabricmc.api.ModInitializer;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import de.cscherr.plextool.PlexMenu;
|
||||
import de.cscherr.plextool.mixin.PlexToolMixin;
|
||||
|
||||
public class PlexTool implements ModInitializer {
|
||||
// This logger is used to write text to the console and the log file.
|
||||
// It is considered best practice to use your mod id as the logger's name.
|
||||
|
@ -15,8 +12,6 @@ public class PlexTool implements ModInitializer {
|
|||
public static final String VERSION_NUMBER = "0.1.0";
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
|
||||
public PlexMenu menu;
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
||||
|
@ -24,6 +19,5 @@ public class PlexTool implements ModInitializer {
|
|||
// Proceed with mild caution.
|
||||
|
||||
LOGGER.info("Initializing PlexTool");
|
||||
menu = new PlexMenu();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package de.cscherr.plextool;
|
||||
|
||||
import de.cscherr.plextool.mixin.PlexToolUIMixin;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.util.Monitor;
|
||||
import net.minecraft.client.util.Window;
|
||||
import net.minecraft.screen.ScreenTexts;
|
||||
import net.minecraft.text.Text;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class PlexToolUiScreen extends Screen {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PlexToolUiScreen.class.getSimpleName());
|
||||
private static final Text INFO_TEXT = Text.literal("Hello world");
|
||||
private final Screen parent;
|
||||
|
||||
public PlexToolUiScreen(String name, Screen parent) {
|
||||
super(Text.literal(name));
|
||||
this.parent = parent;
|
||||
LOGGER.info("Constructed the UI");
|
||||
}
|
||||
@Override
|
||||
protected void init() {
|
||||
//assert this.client != null;
|
||||
//Window window = this.client.getWindow();
|
||||
//Monitor monitor = window.getMonitor();
|
||||
|
||||
this.addDrawable(ButtonWidget.builder(INFO_TEXT, button -> {
|
||||
LOGGER.info("Pressed dummy button");
|
||||
}).dimensions(this.width / 2 - 100, this.height - 10, 200, 20).build());
|
||||
//this.addDrawableChild(ButtonWidget.builder(ScreenTexts.DONE, button -> {
|
||||
// this.client.options.write();
|
||||
// this.apply();
|
||||
// this.client.setScreen(this.parent);
|
||||
//}).dimensions(this.width / 2 - 100, this.height - 27, 200, 20).build());
|
||||
}
|
||||
|
||||
private void apply() {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package de.cscherr.plextool.mixin;
|
||||
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
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 org.slf4j.Logger;
|
||||
|
||||
import java.time.Duration;
|
||||
import de.cscherr.plextool.PlexTool;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.listener.ServerPlayPacketListener;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
@Mixin(ClientPlayNetworkHandler.class)
|
||||
public class PlexToolMixin {
|
||||
// 'V' is appended because the return type is void
|
||||
// see https://fabricmc.net/wiki/tutorial:mixin_injects
|
||||
public final Logger PLEX_LOGGER = PlexTool.LOGGER;
|
||||
public boolean log_packets = true;
|
||||
@Inject(at = @At("HEAD"), method = "sendPacket()V")
|
||||
// Method signature is diffrent, but thats what the mixin library wants according to its errors.
|
||||
// I could not find this in the documentation.
|
||||
private void sendPacket(Packet<ServerPlayPacketListener> packet, CallbackInfo callInfo) {
|
||||
// this works!
|
||||
// I am now logging every packet i send! Yay me!
|
||||
if log_packets {
|
||||
this.PLEX_LOGGER.info("Sending Packet: " + packet.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package de.cscherr.plextool.mixin;
|
||||
|
||||
import net.minecraft.network.ClientConnection;
|
||||
import net.minecraft.network.PacketCallbacks;
|
||||
import net.minecraft.network.listener.PacketListener;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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(ClientPlayNetworkHandler.class)
|
||||
public class PlexToolMixin {
|
||||
// 'V' is appended because the return type is void
|
||||
// see https://fabricmc.net/wiki/tutorial:mixin_injects
|
||||
public final Logger PLEX_LOGGER = PlexTool.LOGGER;
|
||||
public boolean log_packets = true;
|
||||
@Inject(at = @At("HEAD"), method = "sendPacket()V")
|
||||
// Method signature is diffrent, but thats what the mixin library wants according to its errors.
|
||||
// I could not find this in the documentation.
|
||||
private void sendPacket(Packet<ServerPlayPacketListener> packet, CallbackInfo callInfo) {
|
||||
// this works!
|
||||
// I am now logging every packet i send! Yay me!
|
||||
if (log_packets) {
|
||||
this.PLEX_LOGGER.info(
|
||||
"Sending Packet: <Type:" +
|
||||
packet.getClass().getName() +
|
||||
"\nData: " +
|
||||
packet.getClass().chan +
|
||||
">"
|
||||
);
|
||||
this.PLEX_LOGGER.debug("Callbackinfo for package dump: {}", callInfo);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
@Mixin(ClientConnection.class)
|
||||
public class PlexToolPackets {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger("PlexToolMixin");
|
||||
private static boolean logSent = true;
|
||||
private static boolean logReceived = false;
|
||||
|
||||
public void setLogSent(boolean logSent) {
|
||||
this.logSent = logSent;
|
||||
}
|
||||
|
||||
public void setLogReceived(boolean logReceived) {
|
||||
this.logReceived = logReceived;
|
||||
}
|
||||
|
||||
public boolean isLogSent() {
|
||||
return logSent;
|
||||
}
|
||||
|
||||
public boolean isLogReceived() {
|
||||
return logReceived;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject to the method that sends packets. Must not be static for some reason
|
||||
*
|
||||
* @param packet the Network packet to be sent
|
||||
* @param callbacks magical fabric mixin stuff
|
||||
* @param ci magical fabric mixin stuff
|
||||
*/
|
||||
@Inject(method = "sendImmediately", at = @At("HEAD"))
|
||||
private void logSentPacket(Packet<?> packet, @Nullable PacketCallbacks callbacks, CallbackInfo ci) {
|
||||
if (logSent) {
|
||||
LOGGER.info(String.format("Sent Package: %s",
|
||||
packet.getClass().getSimpleName()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject to the method that receives and handles packets.
|
||||
* Must be static for some reason
|
||||
*
|
||||
* @param packet the Network packet to be sent
|
||||
* @param listener i dont know what this does
|
||||
* @param ci magical fabric mixin stuff
|
||||
*/
|
||||
@Inject(method = "handlePacket", at = @At("HEAD"))
|
||||
private static void logReceivedPacket(Packet<?> packet, PacketListener listener, CallbackInfo ci) {
|
||||
if (logReceived) {
|
||||
LOGGER.info(String.format("Received Package: %s",
|
||||
packet.getClass().getSimpleName()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package de.cscherr.plextool.mixin;
|
||||
|
||||
import de.cscherr.plextool.PlexToolUiScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.option.OptionsScreen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.util.Monitor;
|
||||
import net.minecraft.client.util.Window;
|
||||
import net.minecraft.text.Text;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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(OptionsScreen.class)
|
||||
public abstract class PlexToolUIMixin extends Screen {
|
||||
private static final Text PLEXTOOL_TEXT = Text.literal("PlexTool");
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PlexToolUIMixin.class.getSimpleName());
|
||||
|
||||
protected PlexToolUIMixin(Text title) {
|
||||
super(title);
|
||||
}
|
||||
|
||||
@Inject(method = "init", at = @At("RETURN"))
|
||||
private void init(CallbackInfo callback) {
|
||||
addDrawable(ButtonWidget.builder(Text.literal("PT"), button -> {
|
||||
assert client != null;
|
||||
client.setScreen(new PlexToolUiScreen(PLEXTOOL_TEXT.getString(), (OptionsScreen)(Object)this));
|
||||
}).position(this.width / 2 - 180, this.height / 6 + 120 - 6).size(20, 20).build());
|
||||
}
|
||||
}
|
|
@ -6,7 +6,8 @@
|
|||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
"PlexToolMixin"
|
||||
"PlexToolPackets",
|
||||
"PlexToolUIMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Reference in New Issue