Fix conflicting files

This commit is contained in:
Brady 2018-08-04 23:44:42 -05:00
parent 10c847074a
commit 12aeab4943
No known key found for this signature in database
GPG Key ID: 73A788379A197567
3 changed files with 55 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import baritone.bot.behavior.Behavior;
import baritone.bot.event.IGameEventListener; import baritone.bot.event.IGameEventListener;
import baritone.bot.event.events.ChatEvent; import baritone.bot.event.events.ChatEvent;
import baritone.bot.event.events.ChunkEvent; import baritone.bot.event.events.ChunkEvent;
import baritone.bot.event.events.WorldEvent;
import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.settings.KeyBinding;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
@ -54,6 +55,28 @@ public final class GameEventHandler implements IGameEventListener {
@Override @Override
public void onChunkEvent(ChunkEvent event) { public void onChunkEvent(ChunkEvent event) {
/*
EventState state = event.getState();
ChunkEvent.Type type = event.getType();
boolean isPostPopulate = state == EventState.POST
&& type == ChunkEvent.Type.POPULATE;
// Whenever the server sends us to another dimension, chunks are unloaded
// technically after the new world has been loaded, so we perform a check
// to make sure the chunk being unloaded is already loaded.
boolean isPreUnload = state == EventState.PRE
&& type == ChunkEvent.Type.UNLOAD
&& mc.world.getChunkProvider().isChunkGeneratedAt(event.getX(), event.getZ());
if (isPostPopulate || isPreUnload) {
CachedWorldProvider.INSTANCE.ifWorldLoaded(world ->
world.updateCachedChunk(event.getX(), event.getZ(),
ChunkPacker.createPackedChunk(mc.world.getChunk(event.getX(), event.getZ()))));
}
*/
dispatch(behavior -> behavior.onChunkEvent(event)); dispatch(behavior -> behavior.onChunkEvent(event));
} }
@ -62,6 +85,26 @@ public final class GameEventHandler implements IGameEventListener {
dispatch(Behavior::onRenderPass); dispatch(Behavior::onRenderPass);
} }
@Override
public void onWorldEvent(WorldEvent event) {
/*
CachedWorldProvider cache = CachedWorldProvider.INSTANCE;
switch (event.getState()) {
case PRE:
cache.ifWorldLoaded(CachedWorld::save);
break;
case POST:
cache.closeWorld();
if (event.getWorld() != null)
cache.initWorld(event.getWorld());
break;
}
*/
dispatch(behavior -> behavior.onWorldEvent(event));
}
private void dispatch(Consumer<Behavior> dispatchFunction) { private void dispatch(Consumer<Behavior> dispatchFunction) {
Baritone.INSTANCE.getBehaviors().stream().filter(Behavior::isEnabled).forEach(dispatchFunction); Baritone.INSTANCE.getBehaviors().stream().filter(Behavior::isEnabled).forEach(dispatchFunction);
} }

View File

@ -2,6 +2,7 @@ package baritone.bot.event;
import baritone.bot.event.events.ChatEvent; import baritone.bot.event.events.ChatEvent;
import baritone.bot.event.events.ChunkEvent; import baritone.bot.event.events.ChunkEvent;
import baritone.bot.event.events.WorldEvent;
/** /**
* An implementation of {@link IGameEventListener} that has all methods * An implementation of {@link IGameEventListener} that has all methods
@ -35,4 +36,7 @@ public interface AbstractGameEventListener extends IGameEventListener {
@Override @Override
default void onRenderPass() {} default void onRenderPass() {}
@Override
default void onWorldEvent(WorldEvent event) {}
} }

View File

@ -2,6 +2,7 @@ package baritone.bot.event;
import baritone.bot.event.events.ChatEvent; import baritone.bot.event.events.ChatEvent;
import baritone.bot.event.events.ChunkEvent; import baritone.bot.event.events.ChunkEvent;
import baritone.bot.event.events.WorldEvent;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.multiplayer.WorldClient;
@ -54,4 +55,11 @@ public interface IGameEventListener {
* @see EntityRenderer#renderWorldPass(int, float, long) * @see EntityRenderer#renderWorldPass(int, float, long)
*/ */
void onRenderPass(); void onRenderPass();
/**
* Runs before and after whenever a new world is loaded
*
* @see Minecraft#loadWorld(WorldClient, String)
*/
void onWorldEvent(WorldEvent event);
} }