fix world event post not firing for exit

This commit is contained in:
Leijurv 2018-08-28 15:24:43 -07:00
parent a3e5714e91
commit f99abd6170
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 11 additions and 10 deletions

View File

@ -35,10 +35,10 @@
package baritone.api.event; package baritone.api.event;
import baritone.Baritone; import baritone.Baritone;
import baritone.chunk.WorldProvider;
import baritone.api.event.events.*; import baritone.api.event.events.*;
import baritone.api.event.events.type.EventState; import baritone.api.event.events.type.EventState;
import baritone.api.event.listener.IGameEventListener; import baritone.api.event.listener.IGameEventListener;
import baritone.chunk.WorldProvider;
import baritone.utils.Helper; import baritone.utils.Helper;
import baritone.utils.InputOverrideHandler; import baritone.utils.InputOverrideHandler;
import baritone.utils.interfaces.Toggleable; import baritone.utils.interfaces.Toggleable;
@ -135,7 +135,6 @@ public final class GameEventHandler implements IGameEventListener, Helper {
switch (event.getState()) { switch (event.getState()) {
case PRE: case PRE:
cache.closeWorld();
break; break;
case POST: case POST:
cache.closeWorld(); cache.closeWorld();

View File

@ -18,11 +18,11 @@
package baritone.launch.mixins; package baritone.launch.mixins;
import baritone.Baritone; import baritone.Baritone;
import baritone.behavior.impl.PathingBehavior;
import baritone.api.event.events.BlockInteractEvent; import baritone.api.event.events.BlockInteractEvent;
import baritone.api.event.events.TickEvent; import baritone.api.event.events.TickEvent;
import baritone.api.event.events.WorldEvent; import baritone.api.event.events.WorldEvent;
import baritone.api.event.events.type.EventState; import baritone.api.event.events.type.EventState;
import baritone.behavior.impl.PathingBehavior;
import baritone.utils.ExampleBaritoneControl; import baritone.utils.ExampleBaritoneControl;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
@ -48,9 +48,12 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(Minecraft.class) @Mixin(Minecraft.class)
public class MixinMinecraft { public class MixinMinecraft {
@Shadow private int leftClickCounter; @Shadow
@Shadow public EntityPlayerSP player; private int leftClickCounter;
@Shadow public WorldClient world; @Shadow
public EntityPlayerSP player;
@Shadow
public WorldClient world;
@Inject( @Inject(
method = "init", method = "init",
@ -108,8 +111,9 @@ public class MixinMinecraft {
) )
private void preLoadWorld(WorldClient world, String loadingMessage, CallbackInfo ci) { private void preLoadWorld(WorldClient world, String loadingMessage, CallbackInfo ci) {
// If we're unloading the world but one doesn't exist, ignore it // If we're unloading the world but one doesn't exist, ignore it
if (this.world == null && world == null) if (this.world == null && world == null) {
return; return;
}
Baritone.INSTANCE.getGameEventHandler().onWorldEvent( Baritone.INSTANCE.getGameEventHandler().onWorldEvent(
new WorldEvent( new WorldEvent(
@ -124,9 +128,7 @@ public class MixinMinecraft {
at = @At("RETURN") at = @At("RETURN")
) )
private void postLoadWorld(WorldClient world, String loadingMessage, CallbackInfo ci) { private void postLoadWorld(WorldClient world, String loadingMessage, CallbackInfo ci) {
// If we're unloading the world but one doesn't exist, ignore it // still fire event for both null, as that means we've just finished exiting a world
if (this.world == null && world == null)
return;
Baritone.INSTANCE.getGameEventHandler().onWorldEvent( Baritone.INSTANCE.getGameEventHandler().onWorldEvent(
new WorldEvent( new WorldEvent(