Separate cache for bots
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
package baritone.api.event.events;
|
||||
|
||||
import baritone.api.event.events.type.EventState;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
@@ -29,14 +29,14 @@ public final class WorldEvent {
|
||||
/**
|
||||
* The new world that is being loaded. {@code null} if being unloaded.
|
||||
*/
|
||||
private final WorldClient world;
|
||||
private final World world;
|
||||
|
||||
/**
|
||||
* The state of the event
|
||||
*/
|
||||
private final EventState state;
|
||||
|
||||
public WorldEvent(WorldClient world, EventState state) {
|
||||
public WorldEvent(World world, EventState state) {
|
||||
this.world = world;
|
||||
this.state = state;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public final class WorldEvent {
|
||||
/**
|
||||
* @return The new world that is being loaded. {@code null} if being unloaded.
|
||||
*/
|
||||
public final WorldClient getWorld() {
|
||||
public final World getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import baritone.api.BaritoneAPI;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.event.events.ChunkEvent;
|
||||
import baritone.api.event.events.type.EventState;
|
||||
import baritone.bot.handler.BotNetHandlerPlayClient;
|
||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||
import net.minecraft.network.play.server.SPacketChunkData;
|
||||
import net.minecraft.network.play.server.SPacketCombatEvent;
|
||||
@@ -33,7 +34,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
* @author Brady
|
||||
* @since 8/3/2018
|
||||
*/
|
||||
@Mixin(NetHandlerPlayClient.class)
|
||||
@Mixin(value = {NetHandlerPlayClient.class, BotNetHandlerPlayClient.class})
|
||||
public class MixinNetHandlerPlayClient {
|
||||
|
||||
@Inject(
|
||||
|
||||
@@ -114,7 +114,7 @@ public class Baritone implements IBaritone {
|
||||
farmProcess = new FarmProcess(this);
|
||||
}
|
||||
|
||||
this.worldProvider = new WorldProvider();
|
||||
this.worldProvider = new WorldProvider(this);
|
||||
this.selectionManager = new SelectionManager(this);
|
||||
this.commandManager = new CommandManager(this);
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ package baritone.bot;
|
||||
import baritone.Baritone;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.bot.IBaritoneUser;
|
||||
import baritone.api.event.events.WorldEvent;
|
||||
import baritone.api.event.events.type.EventState;
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import baritone.bot.spec.BotMinecraft;
|
||||
import baritone.bot.spec.BotWorld;
|
||||
@@ -67,9 +69,13 @@ public final class BaritoneUser implements IBaritoneUser {
|
||||
}
|
||||
|
||||
public void onWorldLoad(BotWorld world, EntityBot player, IPlayerController playerController) {
|
||||
this.baritone.getGameEventHandler().onWorldEvent(new WorldEvent(world, EventState.PRE));
|
||||
|
||||
this.mc.player = this.player = player;
|
||||
this.player.world = this.world = world;
|
||||
this.playerController = playerController;
|
||||
|
||||
this.baritone.getGameEventHandler().onWorldEvent(new WorldEvent(world, EventState.POST));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,15 +17,11 @@
|
||||
|
||||
package baritone.bot;
|
||||
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.bot.IBaritoneUser;
|
||||
import baritone.api.cache.IWorldData;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import baritone.api.utils.RayTraceUtils;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public final class BotPlayerContext implements IPlayerContext {
|
||||
@@ -65,7 +61,6 @@ public final class BotPlayerContext implements IPlayerContext {
|
||||
|
||||
@Override
|
||||
public IWorldData worldData() {
|
||||
// TODO: (bot-system): Create a solution for Bot World Data
|
||||
return BaritoneAPI.getProvider().getPrimaryBaritone().getWorldProvider().getCurrentWorld();
|
||||
return bot.getBaritone().getWorldProvider().getCurrentWorld();
|
||||
}
|
||||
}
|
||||
|
||||
10
src/main/java/baritone/cache/WorldProvider.java
vendored
10
src/main/java/baritone/cache/WorldProvider.java
vendored
@@ -20,6 +20,7 @@ package baritone.cache;
|
||||
import baritone.Baritone;
|
||||
import baritone.api.cache.IWorldProvider;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.bot.BotPlayerContext;
|
||||
import baritone.utils.accessor.IAnvilChunkLoader;
|
||||
import baritone.utils.accessor.IChunkProviderServer;
|
||||
import net.minecraft.server.integrated.IntegratedServer;
|
||||
@@ -43,8 +44,13 @@ public class WorldProvider implements IWorldProvider, Helper {
|
||||
|
||||
private static final Map<Path, WorldData> worldCache = new HashMap<>(); // this is how the bots have the same cached world
|
||||
|
||||
private Baritone baritone;
|
||||
private WorldData currentWorld;
|
||||
|
||||
public WorldProvider(Baritone baritone) {
|
||||
this.baritone = baritone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final WorldData getCurrentWorld() {
|
||||
return this.currentWorld;
|
||||
@@ -91,6 +97,10 @@ public class WorldProvider implements IWorldProvider, Helper {
|
||||
out.write("https://github.com/cabaletta/baritone\n".getBytes());
|
||||
} catch (IOException ignored) {}
|
||||
|
||||
if (this.baritone.getPlayerContext() instanceof BotPlayerContext) {
|
||||
directory = new File(directory, "bot");
|
||||
}
|
||||
|
||||
// We will actually store the world data in a subfolder: "DIM<id>"
|
||||
Path dir = new File(directory, "DIM" + dimension).toPath();
|
||||
if (!Files.exists(dir)) {
|
||||
|
||||
@@ -22,9 +22,7 @@ import baritone.api.cache.IWorldData;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import baritone.api.utils.RayTraceUtils;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user