[Change] Add Block Avoidance Settings

Fixes #392
This commit is contained in:
cdagaming 2019-04-20 12:04:07 -05:00
parent af0c3bbd5c
commit c4c85b4f49
3 changed files with 28 additions and 0 deletions

View File

@ -18,6 +18,7 @@
package baritone.api;
import baritone.api.utils.SettingsUtil;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
@ -146,6 +147,13 @@ public final class Settings {
Item.getItemFromBlock(Blocks.STONE)
)));
/**
* Blocks that Baritone will attempt to avoid (Used in avoidance)
*/
public final Setting<List<Block>> blocksToAvoid = new Setting<>(new ArrayList<>(Arrays.asList(
Blocks.VINE
)));
/**
* Enables some more advanced vine features. They're honestly just gimmicks and won't ever be needed in real
* pathing scenarios. And they can cause Baritone to get trapped indefinitely in a strange scenario.
@ -250,6 +258,15 @@ public final class Settings {
public final Setting<Integer> mobAvoidanceRadius = new Setting<>(8);
/**
* Set to 1.0 to effectively disable this feature
* <p>
* Set below 1.0 to go out of your way to walk near blocks
*/
public final Setting<Double> blockAvoidanceCoefficient = new Setting<>(1.5);
public final Setting<Integer> blockAvoidanceRadius = new Setting<>(8);
/**
* When running a goto towards a container block (chest, ender chest, furnace, etc),
* right click and open it once you arrive.

View File

@ -74,6 +74,9 @@ public interface MovementHelper extends ActionCosts, Helper {
if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof BlockSkull || block instanceof BlockTrapDoor) {
return false;
}
if (Baritone.settings().blocksToAvoid.value.contains(block)) {
return false;
}
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
// Because there's no nice method in vanilla to check if a door is openable or not, we just have to assume
// that anything that isn't an iron door isn't openable, ignoring that some doors introduced in mods can't

View File

@ -19,8 +19,10 @@ package baritone.utils.pathing;
import baritone.Baritone;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.BlockUtils;
import baritone.api.utils.IPlayerContext;
import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap;
import net.minecraft.block.Block;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.util.math.BlockPos;
@ -63,12 +65,18 @@ public class Avoidance {
List<Avoidance> res = new ArrayList<>();
double mobSpawnerCoeff = Baritone.settings().mobSpawnerAvoidanceCoefficient.value;
double mobCoeff = Baritone.settings().mobAvoidanceCoefficient.value;
double blockCoeff = Baritone.settings().blockAvoidanceCoefficient.value;
if (mobSpawnerCoeff != 1.0D) {
ctx.worldData().getCachedWorld().getLocationsOf("mob_spawner", 1, ctx.playerFeet().x, ctx.playerFeet().z, 2).forEach(mobspawner -> res.add(new Avoidance(mobspawner, mobSpawnerCoeff, Baritone.settings().mobSpawnerAvoidanceRadius.value)));
}
if (mobCoeff != 1.0D) {
ctx.world().loadedEntityList.stream().filter(entity -> entity instanceof EntityMob).forEach(entity -> res.add(new Avoidance(new BlockPos(entity), mobCoeff, Baritone.settings().mobAvoidanceRadius.value)));
}
if (blockCoeff != 1.0D) {
for (Block block : Baritone.settings().blocksToAvoid.value) {
ctx.worldData().getCachedWorld().getLocationsOf(BlockUtils.blockToString(block), 1, ctx.playerFeet().x, ctx.playerFeet().z, 2).forEach(blockPos -> res.add(new Avoidance(blockPos, blockCoeff, Baritone.settings().blockAvoidanceRadius.value)));
}
}
return res;
}