forked from RepoMirrors/seppuku
Optimize NoWeather with a new event & patch in World
This commit is contained in:
parent
9304f27bf5
commit
d946614424
|
@ -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 {
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue