Create IWorldData and IWorldProvider interfaces in api

This fully exposes waypoints in the api, next step is cached worlds!
This commit is contained in:
Brady
2018-09-24 14:42:22 -05:00
parent 1cf4c9419f
commit 35c8b03122
10 changed files with 133 additions and 15 deletions

View File

@@ -22,6 +22,7 @@ import baritone.api.Settings;
import baritone.behavior.Behavior;
import baritone.api.event.listener.IGameEventListener;
import baritone.behavior.*;
import baritone.cache.WorldProvider;
import baritone.event.GameEventHandler;
import baritone.utils.InputOverrideHandler;
import net.minecraft.client.Minecraft;
@@ -87,6 +88,8 @@ public enum Baritone {
// We might want to change this...
this.settings = BaritoneAPI.getSettings();
BaritoneAPI.registerProviders(WorldProvider.INSTANCE);
this.behaviors = new ArrayList<>();
{
registerBehavior(PathingBehavior.INSTANCE);

View File

@@ -42,12 +42,12 @@ public final class LocationTrackingBehavior extends Behavior implements Helper {
@Override
public void onBlockInteract(BlockInteractEvent event) {
if (event.getType() == BlockInteractEvent.Type.USE && BlockStateInterface.getBlock(event.getPos()) instanceof BlockBed) {
WorldProvider.INSTANCE.getCurrentWorld().waypoints.addWaypoint(new Waypoint("bed", Waypoint.Tag.BED, event.getPos()));
WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("bed", Waypoint.Tag.BED, event.getPos()));
}
}
@Override
public void onPlayerDeath() {
WorldProvider.INSTANCE.getCurrentWorld().waypoints.addWaypoint(new Waypoint("death", Waypoint.Tag.DEATH, playerFeet()));
WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("death", Waypoint.Tag.DEATH, playerFeet()));
}
}

View File

@@ -116,9 +116,7 @@ public final class CachedWorld implements Helper {
int regionZ = zoff + playerRegionZ;
CachedRegion region = getOrCreateRegion(regionX, regionZ);
if (region != null) {
for (BlockPos pos : region.getLocationsOf(block)) {
res.add(pos);
}
res.addAll(region.getLocationsOf(block));
}
}
}

View File

@@ -18,6 +18,8 @@
package baritone.cache;
import baritone.Baritone;
import baritone.api.cache.IWaypointCollection;
import baritone.api.cache.IWorldData;
import java.nio.file.Path;
@@ -26,9 +28,10 @@ import java.nio.file.Path;
*
* @author leijurv
*/
public class WorldData {
public class WorldData implements IWorldData {
public final CachedWorld cache;
public final Waypoints waypoints;
private final Waypoints waypoints;
//public final MapData map;
public final Path directory;
@@ -44,4 +47,9 @@ public class WorldData {
cache.save();
});
}
@Override
public IWaypointCollection getWaypoints() {
return this.waypoints;
}
}

View File

@@ -18,6 +18,8 @@
package baritone.cache;
import baritone.Baritone;
import baritone.api.cache.IWorldData;
import baritone.api.cache.IWorldProvider;
import baritone.utils.Helper;
import baritone.utils.accessor.IAnvilChunkLoader;
import baritone.utils.accessor.IChunkProviderServer;
@@ -38,7 +40,7 @@ import java.util.function.Consumer;
* @author Brady
* @since 8/4/2018 11:06 AM
*/
public enum WorldProvider implements Helper {
public enum WorldProvider implements IWorldProvider, Helper {
INSTANCE;
@@ -46,7 +48,8 @@ public enum WorldProvider implements Helper {
private WorldData currentWorld;
public final WorldData getCurrentWorld() {
@Override
public final IWorldData getCurrentWorld() {
return this.currentWorld;
}

View File

@@ -342,7 +342,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
event.cancel();
return;
}
Set<IWaypoint> waypoints = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getByTag(tag);
Set<IWaypoint> waypoints = WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().getByTag(tag);
// might as well show them from oldest to newest
List<IWaypoint> sorted = new ArrayList<>(waypoints);
sorted.sort(Comparator.comparingLong(IWaypoint::getCreationTimestamp));
@@ -355,7 +355,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
}
if (msg.startsWith("save")) {
String name = msg.substring(4).trim();
WorldProvider.INSTANCE.getCurrentWorld().waypoints.addWaypoint(new Waypoint(name, Waypoint.Tag.USER, playerFeet()));
WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().addWaypoint(new Waypoint(name, Waypoint.Tag.USER, playerFeet()));
logDirect("Saved user defined tag under name '" + name + "'. Say 'goto user' to set goal, say 'list user' to list.");
event.cancel();
return;
@@ -385,7 +385,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
PathingBehavior.INSTANCE.path();
return;
}
IWaypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(tag);
IWaypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().getMostRecentByTag(tag);
if (waypoint == null) {
logDirect("None saved for tag " + tag);
event.cancel();
@@ -402,7 +402,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
return;
}
if (msg.equals("spawn") || msg.equals("bed")) {
IWaypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(Waypoint.Tag.BED);
IWaypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().getMostRecentByTag(Waypoint.Tag.BED);
if (waypoint == null) {
BlockPos spawnPoint = player().getBedLocation();
// for some reason the default spawnpoint is underground sometimes
@@ -418,13 +418,13 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
return;
}
if (msg.equals("sethome")) {
WorldProvider.INSTANCE.getCurrentWorld().waypoints.addWaypoint(new Waypoint("", Waypoint.Tag.HOME, playerFeet()));
WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("", Waypoint.Tag.HOME, playerFeet()));
logDirect("Saved. Say home to set goal.");
event.cancel();
return;
}
if (msg.equals("home")) {
IWaypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(Waypoint.Tag.HOME);
IWaypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().getMostRecentByTag(Waypoint.Tag.HOME);
if (waypoint == null) {
logDirect("home not saved");
} else {