Expose WorldScanner in API

This commit is contained in:
Brady 2018-10-06 20:30:09 -05:00
parent d5130aa6ba
commit 4b61452c62
No known key found for this signature in database
GPG Key ID: 73A788379A197567
4 changed files with 61 additions and 11 deletions

View File

@ -19,6 +19,7 @@ package baritone.api;
import baritone.api.behavior.*; import baritone.api.behavior.*;
import baritone.api.cache.IWorldProvider; import baritone.api.cache.IWorldProvider;
import baritone.api.cache.IWorldScanner;
import baritone.api.event.listener.IGameEventListener; import baritone.api.event.listener.IGameEventListener;
/** /**
@ -69,6 +70,13 @@ public interface IBaritoneProvider {
*/ */
IWorldProvider getWorldProvider(); IWorldProvider getWorldProvider();
/**
* @see IWorldScanner
*
* @return The {@link IWorldScanner} instance
*/
IWorldScanner getWorldScanner();
/** /**
* Registers a {@link IGameEventListener} with Baritone's "event bus". * Registers a {@link IGameEventListener} with Baritone's "event bus".
* *

View File

@ -0,0 +1,42 @@
/*
* 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;
import net.minecraft.block.Block;
import net.minecraft.util.math.BlockPos;
import java.util.List;
/**
* @author Brady
* @since 10/6/2018
*/
public interface IWorldScanner {
/**
* Scans the world, up to the specified max chunk radius, for the specified blocks.
*
* @param blocks The blocks to scan for
* @param max The maximum number of blocks to scan before cutoff
* @param yLevelThreshold If a block is found within this Y level, the current result will be
* returned, if the value is negative, then this condition doesn't apply.
* @param maxSearchRadius The maximum chunk search radius
* @return The matching block positions
*/
List<BlockPos> scanLoadedChunks(List<Block> blocks, int max, int yLevelThreshold, int maxSearchRadius);
}

View File

@ -20,9 +20,11 @@ package baritone;
import baritone.api.IBaritoneProvider; import baritone.api.IBaritoneProvider;
import baritone.api.behavior.*; import baritone.api.behavior.*;
import baritone.api.cache.IWorldProvider; import baritone.api.cache.IWorldProvider;
import baritone.api.cache.IWorldScanner;
import baritone.api.event.listener.IGameEventListener; import baritone.api.event.listener.IGameEventListener;
import baritone.behavior.*; import baritone.behavior.*;
import baritone.cache.WorldProvider; import baritone.cache.WorldProvider;
import baritone.cache.WorldScanner;
/** /**
* @author Brady * @author Brady
@ -60,6 +62,11 @@ public final class BaritoneProvider implements IBaritoneProvider {
return WorldProvider.INSTANCE; return WorldProvider.INSTANCE;
} }
@Override
public IWorldScanner getWorldScanner() {
return WorldScanner.INSTANCE;
}
@Override @Override
public void registerEventListener(IGameEventListener listener) { public void registerEventListener(IGameEventListener listener) {
Baritone.INSTANCE.registerEventListener(listener); Baritone.INSTANCE.registerEventListener(listener);

View File

@ -17,6 +17,7 @@
package baritone.cache; package baritone.cache;
import baritone.api.cache.IWorldScanner;
import baritone.utils.Helper; import baritone.utils.Helper;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -29,19 +30,11 @@ import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
public enum WorldScanner implements Helper { public enum WorldScanner implements IWorldScanner, Helper {
INSTANCE; INSTANCE;
/** @Override
* Scans the world, up to your render distance, for the specified blocks.
*
* @param blocks The blocks to scan for
* @param max The maximum number of blocks to scan before cutoff
* @param yLevelThreshold If a block is found within this Y level, the current result will be
* returned, if the value is negative, then this condition doesn't apply.
* @param maxSearchRadius The maximum chunk search radius
* @return The matching block positions
*/
public List<BlockPos> scanLoadedChunks(List<Block> blocks, int max, int yLevelThreshold, int maxSearchRadius) { public List<BlockPos> scanLoadedChunks(List<Block> blocks, int max, int yLevelThreshold, int maxSearchRadius) {
if (blocks.contains(null)) { if (blocks.contains(null)) {
throw new IllegalStateException("Invalid block name should have been caught earlier: " + blocks.toString()); throw new IllegalStateException("Invalid block name should have been caught earlier: " + blocks.toString());