From d9466144247e24361feb3b976bf8ccc5d2320b10 Mon Sep 17 00:00:00 2001 From: noil Date: Mon, 4 Nov 2019 13:47:55 -0500 Subject: [PATCH] Optimize NoWeather with a new event & patch in World --- .../api/event/world/EventRainStrength.java | 9 +++++++ .../impl/module/world/NoWeatherModule.java | 20 +++------------ .../seppuku/impl/patch/WorldPatch.java | 25 +++++++++++++++++++ 3 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 src/main/java/me/rigamortis/seppuku/api/event/world/EventRainStrength.java diff --git a/src/main/java/me/rigamortis/seppuku/api/event/world/EventRainStrength.java b/src/main/java/me/rigamortis/seppuku/api/event/world/EventRainStrength.java new file mode 100644 index 0000000..7b7fef6 --- /dev/null +++ b/src/main/java/me/rigamortis/seppuku/api/event/world/EventRainStrength.java @@ -0,0 +1,9 @@ +package me.rigamortis.seppuku.api.event.world; + +import me.rigamortis.seppuku.api.event.EventCancellable; + +/** + * created by noil on 11/4/19 at 1:27 PM + */ +public class EventRainStrength extends EventCancellable { +} diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/world/NoWeatherModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/world/NoWeatherModule.java index 7628850..2505746 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/module/world/NoWeatherModule.java +++ b/src/main/java/me/rigamortis/seppuku/impl/module/world/NoWeatherModule.java @@ -1,10 +1,8 @@ package me.rigamortis.seppuku.impl.module.world; -import me.rigamortis.seppuku.api.event.EventStageable; -import me.rigamortis.seppuku.api.event.player.EventPlayerUpdate; +import me.rigamortis.seppuku.api.event.world.EventRainStrength; import me.rigamortis.seppuku.api.module.Module; import me.rigamortis.seppuku.api.value.OptionalValue; -import net.minecraft.client.Minecraft; import team.stiff.pomelo.impl.annotated.handler.annotation.Listener; /** @@ -25,20 +23,8 @@ public final class NoWeatherModule extends Module { } @Listener - public void onUpdate(EventPlayerUpdate event) { - if (event.getStage() == EventStageable.EventStage.PRE) { - final Minecraft mc = Minecraft.getMinecraft(); - switch (this.mode.getInt()) { - case 0: - mc.world.setRainStrength(0); - mc.world.setThunderStrength(0); - break; - case 1: - mc.world.setRainStrength(1.0f); - mc.world.setThunderStrength(0); - break; - } - } + public void onRainStrength(EventRainStrength event) { + event.setCanceled(true); } } diff --git a/src/main/java/me/rigamortis/seppuku/impl/patch/WorldPatch.java b/src/main/java/me/rigamortis/seppuku/impl/patch/WorldPatch.java index 7218a64..bdfb73f 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/patch/WorldPatch.java +++ b/src/main/java/me/rigamortis/seppuku/impl/patch/WorldPatch.java @@ -2,6 +2,7 @@ package me.rigamortis.seppuku.impl.patch; import me.rigamortis.seppuku.Seppuku; import me.rigamortis.seppuku.api.event.world.EventLightUpdate; +import me.rigamortis.seppuku.api.event.world.EventRainStrength; import me.rigamortis.seppuku.api.patch.ClassPatch; import me.rigamortis.seppuku.api.patch.MethodPatch; import me.rigamortis.seppuku.impl.management.PatchManager; @@ -24,6 +25,7 @@ public final class WorldPatch extends ClassPatch { * This function is used to update light for blocks * It is VERY unoptimized and in some cases it's * better off to disable + * * @param methodNode * @param env */ @@ -58,4 +60,27 @@ public final class WorldPatch extends ClassPatch { return event.isCanceled(); } + @MethodPatch( + mcpName = "getRainStrength", + notchName = "j", + mcpDesc = "(F)F", + notchDesc = "(F)F") + public void getRainStrength(MethodNode methodNode, PatchManager.Environment env) { + final InsnList list = new InsnList(); + list.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(this.getClass()), "getRainStrengthHook", "()Z", false)); + final LabelNode jmp = new LabelNode(); + list.add(new JumpInsnNode(IFEQ, jmp)); + list.add(new InsnNode(ICONST_0)); + list.add(new InsnNode(FRETURN)); + list.add(jmp); + methodNode.instructions.insert(list); + } + + public static boolean getRainStrengthHook() { + final EventRainStrength event = new EventRainStrength(); + Seppuku.INSTANCE.getEventManager().dispatchEvent(event); + + return event.isCanceled(); + } + }