Create IWorldData and IWorldProvider interfaces in api
This fully exposes waypoints in the api, next step is cached worlds!
This commit is contained in:
parent
1cf4c9419f
commit
35c8b03122
@ -18,6 +18,7 @@
|
|||||||
package baritone.api;
|
package baritone.api;
|
||||||
|
|
||||||
import baritone.api.behavior.*;
|
import baritone.api.behavior.*;
|
||||||
|
import baritone.api.cache.IWorldProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API exposure for various things implemented in Baritone.
|
* API exposure for various things implemented in Baritone.
|
||||||
@ -31,6 +32,7 @@ public class BaritoneAPI {
|
|||||||
|
|
||||||
// General
|
// General
|
||||||
private static final Settings settings = new Settings();
|
private static final Settings settings = new Settings();
|
||||||
|
private static IWorldProvider worldProvider;
|
||||||
|
|
||||||
// Behaviors
|
// Behaviors
|
||||||
private static IFollowBehavior followBehavior;
|
private static IFollowBehavior followBehavior;
|
||||||
@ -63,6 +65,15 @@ public class BaritoneAPI {
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FOR INTERNAL USE ONLY
|
||||||
|
*/
|
||||||
|
public static void registerProviders(
|
||||||
|
IWorldProvider worldProvider
|
||||||
|
) {
|
||||||
|
BaritoneAPI.worldProvider = worldProvider;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FOR INTERNAL USE ONLY
|
* FOR INTERNAL USE ONLY
|
||||||
*/
|
*/
|
||||||
|
@ -25,13 +25,44 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public interface IWaypointCollection {
|
public interface IWaypointCollection {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a waypoint to this collection
|
||||||
|
*
|
||||||
|
* @param waypoint The waypoint
|
||||||
|
*/
|
||||||
void addWaypoint(IWaypoint waypoint);
|
void addWaypoint(IWaypoint waypoint);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a waypoint from this collection
|
||||||
|
*
|
||||||
|
* @param waypoint The waypoint
|
||||||
|
*/
|
||||||
void removeWaypoint(IWaypoint waypoint);
|
void removeWaypoint(IWaypoint waypoint);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the most recently created waypoint by the specified {@link IWaypoint.Tag}
|
||||||
|
*
|
||||||
|
* @param tag The tag
|
||||||
|
* @return The most recently created waypoint with the specified tag
|
||||||
|
*/
|
||||||
IWaypoint getMostRecentByTag(IWaypoint.Tag tag);
|
IWaypoint getMostRecentByTag(IWaypoint.Tag tag);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all of the waypoints that have the specified tag
|
||||||
|
*
|
||||||
|
* @see IWaypointCollection#getAllWaypoints()
|
||||||
|
*
|
||||||
|
* @param tag The tag
|
||||||
|
* @return All of the waypoints with the specified tag
|
||||||
|
*/
|
||||||
Set<IWaypoint> getByTag(IWaypoint.Tag tag);
|
Set<IWaypoint> getByTag(IWaypoint.Tag tag);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all of the waypoints in this collection, regardless of the tag.
|
||||||
|
*
|
||||||
|
* @see IWaypointCollection#getByTag(IWaypoint.Tag)
|
||||||
|
*
|
||||||
|
* @return All of the waypoints in this collection
|
||||||
|
*/
|
||||||
Set<IWaypoint> getAllWaypoints();
|
Set<IWaypoint> getAllWaypoints();
|
||||||
}
|
}
|
||||||
|
32
src/api/java/baritone/api/cache/IWorldData.java
vendored
Normal file
32
src/api/java/baritone/api/cache/IWorldData.java
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Baritone is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.api.cache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brady
|
||||||
|
* @since 9/24/2018
|
||||||
|
*/
|
||||||
|
public interface IWorldData {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the waypoint collection for this world.
|
||||||
|
*
|
||||||
|
* @return The waypoint collection for this world
|
||||||
|
*/
|
||||||
|
IWaypointCollection getWaypoints();
|
||||||
|
}
|
32
src/api/java/baritone/api/cache/IWorldProvider.java
vendored
Normal file
32
src/api/java/baritone/api/cache/IWorldProvider.java
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Baritone is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.api.cache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brady
|
||||||
|
* @since 9/24/2018
|
||||||
|
*/
|
||||||
|
public interface IWorldProvider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the data of the currently loaded world
|
||||||
|
*
|
||||||
|
* @return The current world data
|
||||||
|
*/
|
||||||
|
IWorldData getCurrentWorld();
|
||||||
|
}
|
@ -22,6 +22,7 @@ import baritone.api.Settings;
|
|||||||
import baritone.behavior.Behavior;
|
import baritone.behavior.Behavior;
|
||||||
import baritone.api.event.listener.IGameEventListener;
|
import baritone.api.event.listener.IGameEventListener;
|
||||||
import baritone.behavior.*;
|
import baritone.behavior.*;
|
||||||
|
import baritone.cache.WorldProvider;
|
||||||
import baritone.event.GameEventHandler;
|
import baritone.event.GameEventHandler;
|
||||||
import baritone.utils.InputOverrideHandler;
|
import baritone.utils.InputOverrideHandler;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
@ -87,6 +88,8 @@ public enum Baritone {
|
|||||||
// We might want to change this...
|
// We might want to change this...
|
||||||
this.settings = BaritoneAPI.getSettings();
|
this.settings = BaritoneAPI.getSettings();
|
||||||
|
|
||||||
|
BaritoneAPI.registerProviders(WorldProvider.INSTANCE);
|
||||||
|
|
||||||
this.behaviors = new ArrayList<>();
|
this.behaviors = new ArrayList<>();
|
||||||
{
|
{
|
||||||
registerBehavior(PathingBehavior.INSTANCE);
|
registerBehavior(PathingBehavior.INSTANCE);
|
||||||
|
@ -42,12 +42,12 @@ public final class LocationTrackingBehavior extends Behavior implements Helper {
|
|||||||
@Override
|
@Override
|
||||||
public void onBlockInteract(BlockInteractEvent event) {
|
public void onBlockInteract(BlockInteractEvent event) {
|
||||||
if (event.getType() == BlockInteractEvent.Type.USE && BlockStateInterface.getBlock(event.getPos()) instanceof BlockBed) {
|
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
|
@Override
|
||||||
public void onPlayerDeath() {
|
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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,9 +116,7 @@ public final class CachedWorld implements Helper {
|
|||||||
int regionZ = zoff + playerRegionZ;
|
int regionZ = zoff + playerRegionZ;
|
||||||
CachedRegion region = getOrCreateRegion(regionX, regionZ);
|
CachedRegion region = getOrCreateRegion(regionX, regionZ);
|
||||||
if (region != null) {
|
if (region != null) {
|
||||||
for (BlockPos pos : region.getLocationsOf(block)) {
|
res.addAll(region.getLocationsOf(block));
|
||||||
res.add(pos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
src/main/java/baritone/cache/WorldData.java
vendored
12
src/main/java/baritone/cache/WorldData.java
vendored
@ -18,6 +18,8 @@
|
|||||||
package baritone.cache;
|
package baritone.cache;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
|
import baritone.api.cache.IWaypointCollection;
|
||||||
|
import baritone.api.cache.IWorldData;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
@ -26,9 +28,10 @@ import java.nio.file.Path;
|
|||||||
*
|
*
|
||||||
* @author leijurv
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
public class WorldData {
|
public class WorldData implements IWorldData {
|
||||||
|
|
||||||
public final CachedWorld cache;
|
public final CachedWorld cache;
|
||||||
public final Waypoints waypoints;
|
private final Waypoints waypoints;
|
||||||
//public final MapData map;
|
//public final MapData map;
|
||||||
public final Path directory;
|
public final Path directory;
|
||||||
|
|
||||||
@ -44,4 +47,9 @@ public class WorldData {
|
|||||||
cache.save();
|
cache.save();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IWaypointCollection getWaypoints() {
|
||||||
|
return this.waypoints;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
package baritone.cache;
|
package baritone.cache;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
|
import baritone.api.cache.IWorldData;
|
||||||
|
import baritone.api.cache.IWorldProvider;
|
||||||
import baritone.utils.Helper;
|
import baritone.utils.Helper;
|
||||||
import baritone.utils.accessor.IAnvilChunkLoader;
|
import baritone.utils.accessor.IAnvilChunkLoader;
|
||||||
import baritone.utils.accessor.IChunkProviderServer;
|
import baritone.utils.accessor.IChunkProviderServer;
|
||||||
@ -38,7 +40,7 @@ import java.util.function.Consumer;
|
|||||||
* @author Brady
|
* @author Brady
|
||||||
* @since 8/4/2018 11:06 AM
|
* @since 8/4/2018 11:06 AM
|
||||||
*/
|
*/
|
||||||
public enum WorldProvider implements Helper {
|
public enum WorldProvider implements IWorldProvider, Helper {
|
||||||
|
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
@ -46,7 +48,8 @@ public enum WorldProvider implements Helper {
|
|||||||
|
|
||||||
private WorldData currentWorld;
|
private WorldData currentWorld;
|
||||||
|
|
||||||
public final WorldData getCurrentWorld() {
|
@Override
|
||||||
|
public final IWorldData getCurrentWorld() {
|
||||||
return this.currentWorld;
|
return this.currentWorld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
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
|
// might as well show them from oldest to newest
|
||||||
List<IWaypoint> sorted = new ArrayList<>(waypoints);
|
List<IWaypoint> sorted = new ArrayList<>(waypoints);
|
||||||
sorted.sort(Comparator.comparingLong(IWaypoint::getCreationTimestamp));
|
sorted.sort(Comparator.comparingLong(IWaypoint::getCreationTimestamp));
|
||||||
@ -355,7 +355,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
}
|
}
|
||||||
if (msg.startsWith("save")) {
|
if (msg.startsWith("save")) {
|
||||||
String name = msg.substring(4).trim();
|
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.");
|
logDirect("Saved user defined tag under name '" + name + "'. Say 'goto user' to set goal, say 'list user' to list.");
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
@ -385,7 +385,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
PathingBehavior.INSTANCE.path();
|
PathingBehavior.INSTANCE.path();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
IWaypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(tag);
|
IWaypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().getMostRecentByTag(tag);
|
||||||
if (waypoint == null) {
|
if (waypoint == null) {
|
||||||
logDirect("None saved for tag " + tag);
|
logDirect("None saved for tag " + tag);
|
||||||
event.cancel();
|
event.cancel();
|
||||||
@ -402,7 +402,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.equals("spawn") || msg.equals("bed")) {
|
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) {
|
if (waypoint == null) {
|
||||||
BlockPos spawnPoint = player().getBedLocation();
|
BlockPos spawnPoint = player().getBedLocation();
|
||||||
// for some reason the default spawnpoint is underground sometimes
|
// for some reason the default spawnpoint is underground sometimes
|
||||||
@ -418,13 +418,13 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.equals("sethome")) {
|
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.");
|
logDirect("Saved. Say home to set goal.");
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.equals("home")) {
|
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) {
|
if (waypoint == null) {
|
||||||
logDirect("home not saved");
|
logDirect("home not saved");
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user