From 576d226ff6fa73a0c22e902e2d3da236525e2eec Mon Sep 17 00:00:00 2001 From: noil Date: Wed, 6 Nov 2019 17:43:00 -0500 Subject: [PATCH] EventLoadWorld, portalfinder portals now clear on world load --- .../api/event/world/EventLoadWorld.java | 21 ++++++++++++ .../module/render/PortalFinderModule.java | 6 ++++ .../seppuku/impl/patch/MinecraftPatch.java | 32 +++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 src/main/java/me/rigamortis/seppuku/api/event/world/EventLoadWorld.java diff --git a/src/main/java/me/rigamortis/seppuku/api/event/world/EventLoadWorld.java b/src/main/java/me/rigamortis/seppuku/api/event/world/EventLoadWorld.java new file mode 100644 index 0000000..f5a6cf5 --- /dev/null +++ b/src/main/java/me/rigamortis/seppuku/api/event/world/EventLoadWorld.java @@ -0,0 +1,21 @@ +package me.rigamortis.seppuku.api.event.world; + +import me.rigamortis.seppuku.api.event.EventCancellable; +import net.minecraft.client.multiplayer.WorldClient; + +/** + * created by noil on 11/6/19 at 5:27 PM + */ +public class EventLoadWorld extends EventCancellable { + + private final WorldClient world; + + public EventLoadWorld(WorldClient world) { + this.world = world; + } + + public WorldClient getWorld() { + return world; + } +} + diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/render/PortalFinderModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/render/PortalFinderModule.java index 7598e7e..f8beeb6 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/module/render/PortalFinderModule.java +++ b/src/main/java/me/rigamortis/seppuku/impl/module/render/PortalFinderModule.java @@ -7,6 +7,7 @@ import me.rigamortis.seppuku.api.event.network.EventReceivePacket; import me.rigamortis.seppuku.api.event.render.EventRender2D; import me.rigamortis.seppuku.api.event.render.EventRender3D; import me.rigamortis.seppuku.api.event.world.EventChunk; +import me.rigamortis.seppuku.api.event.world.EventLoadWorld; import me.rigamortis.seppuku.api.module.Module; import me.rigamortis.seppuku.api.util.GLUProjection; import me.rigamortis.seppuku.api.util.RenderUtil; @@ -125,6 +126,11 @@ public final class PortalFinderModule extends Module { } } + @Listener + public void onLoadWorld(EventLoadWorld event) { + this.portals.clear(); + } + @Listener public void onChunkLoad(EventChunk event) { final Minecraft mc = Minecraft.getMinecraft(); diff --git a/src/main/java/me/rigamortis/seppuku/impl/patch/MinecraftPatch.java b/src/main/java/me/rigamortis/seppuku/impl/patch/MinecraftPatch.java index f3ac61e..e0b1e2b 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/patch/MinecraftPatch.java +++ b/src/main/java/me/rigamortis/seppuku/impl/patch/MinecraftPatch.java @@ -6,11 +6,13 @@ import me.rigamortis.seppuku.api.event.minecraft.EventDisplayGui; import me.rigamortis.seppuku.api.event.minecraft.EventKeyPress; import me.rigamortis.seppuku.api.event.minecraft.EventRunTick; import me.rigamortis.seppuku.api.event.minecraft.EventUpdateFramebufferSize; +import me.rigamortis.seppuku.api.event.world.EventLoadWorld; import me.rigamortis.seppuku.api.patch.ClassPatch; import me.rigamortis.seppuku.api.patch.MethodPatch; import me.rigamortis.seppuku.api.util.ASMUtil; import me.rigamortis.seppuku.impl.management.PatchManager; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.multiplayer.WorldClient; import org.lwjgl.input.Keyboard; import org.objectweb.asm.Type; import org.objectweb.asm.tree.*; @@ -30,6 +32,7 @@ public final class MinecraftPatch extends ClassPatch { /** * Patch the method "updateFramebufferSize" * Mainly used for shaders + * * @param methodNode */ @MethodPatch( @@ -53,6 +56,7 @@ public final class MinecraftPatch extends ClassPatch { * Patch the method "runTick" * The bytecode we are inserting here replicates this call * MinecraftPatch.runTickHook(EventStageable.EventStage.PRE); + * * @param methodNode * @param env */ @@ -90,6 +94,7 @@ public final class MinecraftPatch extends ClassPatch { /** * This is where key input is handled + * * @param methodNode * @param env */ @@ -101,7 +106,7 @@ public final class MinecraftPatch extends ClassPatch { //find the instruction that calls dispatchKeypresses final AbstractInsnNode target = ASMUtil.findMethodInsn(methodNode, INVOKEVIRTUAL, env == PatchManager.Environment.IDE ? "net/minecraft/client/Minecraft" : "bib", env == PatchManager.Environment.IDE ? "dispatchKeypresses" : "W", "()V"); - if(target != null) { + if (target != null) { //make a list of instructions final InsnList insnList = new InsnList(); //we use ILOAD to pass the "keycode" into our call @@ -118,7 +123,7 @@ public final class MinecraftPatch extends ClassPatch { */ public static void runTickKeyboardHook(int key) { //check if the key was just pressed - if(Keyboard.getEventKeyState()) { + if (Keyboard.getEventKeyState()) { //dispatch our event for key presses and pass in the keycode Seppuku.INSTANCE.getEventManager().dispatchEvent(new EventKeyPress(key)); } @@ -127,6 +132,7 @@ public final class MinecraftPatch extends ClassPatch { /** * This is used to tell if we just opened a gui screen * It can be cancelled + * * @param methodNode * @param env */ @@ -157,6 +163,7 @@ public final class MinecraftPatch extends ClassPatch { /** * Our display gui hook called when we open a gui + * * @param screen can be null! * @return */ @@ -169,4 +176,25 @@ public final class MinecraftPatch extends ClassPatch { return event.isCanceled(); } + @MethodPatch( + mcpName = "loadWorld", + notchName = "a", + mcpDesc = "(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V", + notchDesc = "(Lbsb;Ljava/lang/String;)V") + public void loadWorld(MethodNode methodNode, PatchManager.Environment env) { + final InsnList insnList = new InsnList(); + insnList.add(new VarInsnNode(ALOAD, 1)); + insnList.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(this.getClass()), "loadWorldHook", env == PatchManager.Environment.IDE ? "(Lnet/minecraft/client/multiplayer/WorldClient;)Z" : "(Lbsb;)Z", false)); + final LabelNode jmp = new LabelNode(); + insnList.add(new JumpInsnNode(IFEQ, jmp)); + insnList.add(new InsnNode(RETURN)); + insnList.add(jmp); + methodNode.instructions.insert(insnList); + } + + public static boolean loadWorldHook(WorldClient worldClient) { + final EventLoadWorld event = new EventLoadWorld(worldClient); + Seppuku.INSTANCE.getEventManager().dispatchEvent(event); + return event.isCanceled(); + } }