From bcbfca100fd3ae98c9fb3ae3a52c7a1748d8a05c Mon Sep 17 00:00:00 2001 From: scorbett123 Date: Fri, 4 Sep 2020 10:43:05 +0100 Subject: [PATCH 1/6] add mineOnlyExposedOres setting Signed-off-by: scorbett123 --- src/api/java/baritone/api/Settings.java | 5 +++++ src/main/java/baritone/process/MineProcess.java | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 6ef5e5d1..ba62a1e8 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -726,6 +726,11 @@ public final class Settings { */ public final Setting maxCachedWorldScanCount = new Setting<>(10); + /** + * This will only allow baritone to mine exposed ores, can be used to stop ore obfuscators on servers that use them. + */ + public final Setting allowOnlyExposedOres = new Setting<>(false); + /** * When GetToBlock doesn't know any locations for the desired block, explore randomly instead of giving up. */ diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 6e8ba245..01d78b1e 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -40,6 +40,7 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3i; import java.util.*; import java.util.stream.Collectors; @@ -409,6 +410,8 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro // remove any that are implausible to mine (encased in bedrock, or touching lava) .filter(pos -> MineProcess.plausibleToBreak(ctx, pos)) + .filter(pos -> isNextToAir(ctx, pos)) + .filter(pos -> !blacklist.contains(pos)) .sorted(Comparator.comparingDouble(ctx.getBaritone().getPlayerContext().player()::getDistanceSq)) @@ -420,6 +423,19 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro return locs; } + public static boolean isNextToAir(CalculationContext ctx, BlockPos pos) { + if (!Baritone.settings().allowOnlyExposedOres.value) { + return true; + } + return (ctx.bsi.get0(pos.down()).getBlock() == Blocks.AIR || + ctx.bsi.get0(pos.up()).getBlock() == Blocks.AIR + || ctx.bsi.get0(pos.north()).getBlock() == Blocks.AIR || + ctx.bsi.get0(pos.south()).getBlock() == Blocks.AIR || + ctx.bsi.get0(pos.east()).getBlock() == Blocks.AIR + || ctx.bsi.get0(pos.west()).getBlock() == Blocks.AIR); + } + + public static boolean plausibleToBreak(CalculationContext ctx, BlockPos pos) { if (MovementHelper.getMiningDurationTicks(ctx, pos.getX(), pos.getY(), pos.getZ(), ctx.bsi.get0(pos), true) >= COST_INF) { return false; From 063f698bd2736388e6e59f9821b9722b31fae681 Mon Sep 17 00:00:00 2001 From: scorbett123 Date: Fri, 4 Sep 2020 18:42:06 +0100 Subject: [PATCH 2/6] need to remove diagonals, however this does most of what you suggest. Signed-off-by: scorbett123 --- src/api/java/baritone/api/Settings.java | 7 ++ .../java/baritone/process/MineProcess.java | 97 +++++++++++++++++-- 2 files changed, 95 insertions(+), 9 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index ba62a1e8..3001ab57 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -731,6 +731,13 @@ public final class Settings { */ public final Setting allowOnlyExposedOres = new Setting<>(false); + /** + * When allowOnlyExposedOres is enabled this is the distance around to search. + *

+ * I recommend keeping this value low as the amount of blocks that need to be scanned increases exponentially. + */ + public final Setting allowOnlyExposedOresDistance = new Setting<>(1); + /** * When GetToBlock doesn't know any locations for the desired block, explore randomly instead of giving up. */ diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 01d78b1e..2bf44f06 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -424,15 +424,8 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } public static boolean isNextToAir(CalculationContext ctx, BlockPos pos) { - if (!Baritone.settings().allowOnlyExposedOres.value) { - return true; - } - return (ctx.bsi.get0(pos.down()).getBlock() == Blocks.AIR || - ctx.bsi.get0(pos.up()).getBlock() == Blocks.AIR - || ctx.bsi.get0(pos.north()).getBlock() == Blocks.AIR || - ctx.bsi.get0(pos.south()).getBlock() == Blocks.AIR || - ctx.bsi.get0(pos.east()).getBlock() == Blocks.AIR - || ctx.bsi.get0(pos.west()).getBlock() == Blocks.AIR); + //need to remove diagonals + return makeSphere(pos, Baritone.settings().allowOnlyExposedOresDistance.value, ctx); } @@ -468,4 +461,90 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro rescan(new ArrayList<>(), new CalculationContext(baritone)); } } + + public static boolean makeSphere(BlockPos pos, double radius, CalculationContext ctx) { + double radiusX = radius; + double radiusY = radius; + double radiusZ = radius; + radiusX += 0.5; + radiusY += 0.5; + radiusZ += 0.5; + + final double invRadiusX = 1 / radiusX; + final double invRadiusY = 1 / radiusY; + final double invRadiusZ = 1 / radiusZ; + + final int ceilRadiusX = (int) Math.ceil(radiusX); + final int ceilRadiusY = (int) Math.ceil(radiusY); + final int ceilRadiusZ = (int) Math.ceil(radiusZ); + + double nextXn = 0; + forX: + for (int x = 0; x <= ceilRadiusX; ++x) { + final double xn = nextXn; + nextXn = (x + 1) * invRadiusX; + double nextYn = 0; + forY: + for (int y = 0; y <= ceilRadiusY; ++y) { + final double yn = nextYn; + nextYn = (y + 1) * invRadiusY; + double nextZn = 0; + forZ: + for (int z = 0; z <= ceilRadiusZ; ++z) { + final double zn = nextZn; + nextZn = (z + 1) * invRadiusZ; + + double distanceSq = lengthSq(xn, yn, zn); + if (distanceSq > 1) { + if (z == 0) { + if (y == 0) { + break forX; + } + break forY; + } + break forZ; + } + + if (isTransparent(pos.add(x, y, z), ctx)) { + return true; + } + if (isTransparent(pos.add(-x, y, z), ctx)) { + return true; + } + if (isTransparent(pos.add(x, -y, z), ctx)) { + return true; + } + if (isTransparent(pos.add(x, y, -z), ctx)) { + return true; + } + if (isTransparent(pos.add(-x, -y, z), ctx)) { + return true; + } + if (isTransparent(pos.add(x, -y, -z), ctx)) { + return true; + } + if (isTransparent(pos.add(-x, y, -z), ctx)) { + return true; + } + if (isTransparent(pos.add(-x, -y, -z), ctx)) { + return true; + } + } + } + } + + return false; + } + + private static double lengthSq(double x, double y, double z) { + return (x * x) + (y * y) + (z * z); + } + + public static boolean isTransparent(BlockPos pos, CalculationContext ctx) { + IBlockState blockState = ctx.bsi.get0(pos); + return blockState.getBlock() == Blocks.AIR || + blockState.getBlock() == Blocks.FLOWING_LAVA || + blockState.getBlock() == Blocks.FLOWING_WATER || + blockState.getBlock() == Blocks.WATER; + } } From 547db3a6b4dbd624a7f9baf24f26e16624712db3 Mon Sep 17 00:00:00 2001 From: Sam Corbett Date: Sat, 5 Sep 2020 17:07:06 +0100 Subject: [PATCH 3/6] make the ability to turn it off. Signed-off-by: Sam Corbett --- src/api/java/baritone/api/Settings.java | 2 +- src/main/java/baritone/process/MineProcess.java | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 3001ab57..55b5ca88 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -734,7 +734,7 @@ public final class Settings { /** * When allowOnlyExposedOres is enabled this is the distance around to search. *

- * I recommend keeping this value low as the amount of blocks that need to be scanned increases exponentially. + * It is recommended to keep this value low, as it exponentially increases calculation times and also to keep the */ public final Setting allowOnlyExposedOresDistance = new Setting<>(1); diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 2bf44f06..c733658b 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -40,7 +40,7 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3i; +import net.minecraft.util.math.Vec3d; import java.util.*; import java.util.stream.Collectors; @@ -410,7 +410,12 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro // remove any that are implausible to mine (encased in bedrock, or touching lava) .filter(pos -> MineProcess.plausibleToBreak(ctx, pos)) - .filter(pos -> isNextToAir(ctx, pos)) + .filter(pos -> { + if (Baritone.settings().allowOnlyExposedOres.value) + return isNextToAir(ctx, pos); + else + return true; + }) .filter(pos -> !blacklist.contains(pos)) @@ -494,7 +499,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro final double zn = nextZn; nextZn = (z + 1) * invRadiusZ; - double distanceSq = lengthSq(xn, yn, zn); + double distanceSq = new Vec3d(xn, yn, zn).lengthSquared(); if (distanceSq > 1) { if (z == 0) { if (y == 0) { @@ -536,10 +541,6 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro return false; } - private static double lengthSq(double x, double y, double z) { - return (x * x) + (y * y) + (z * z); - } - public static boolean isTransparent(BlockPos pos, CalculationContext ctx) { IBlockState blockState = ctx.bsi.get0(pos); return blockState.getBlock() == Blocks.AIR || From 071243b99a7ea3ff7c64b1171cdbaecf0081ec94 Mon Sep 17 00:00:00 2001 From: Sam Corbett Date: Tue, 8 Sep 2020 17:39:03 +0100 Subject: [PATCH 4/6] move is transparent to movement helper and circle maker --- .../pathing/movement/MovementHelper.java | 7 ++ .../java/baritone/process/MineProcess.java | 96 +++---------------- 2 files changed, 19 insertions(+), 84 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 7165303c..df8218e8 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -562,4 +562,11 @@ public interface MovementHelper extends ActionCosts, Helper { enum PlaceResult { READY_TO_PLACE, ATTEMPTING, NO_OPTION; } + public static boolean isTransparent(Block b) { + + return b== Blocks.AIR || + b == Blocks.FLOWING_LAVA || + b == Blocks.FLOWING_WATER || + b == Blocks.WATER; + } } diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index c733658b..2d51daf9 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -429,8 +429,18 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } public static boolean isNextToAir(CalculationContext ctx, BlockPos pos) { - //need to remove diagonals - return makeSphere(pos, Baritone.settings().allowOnlyExposedOresDistance.value, ctx); + int radius = Baritone.settings().allowOnlyExposedOresDistance.value; + for (int dx = -radius; dx <= radius; dx++) { + for (int dy = -radius; dy <= radius; dy++) { + for (int dz = -radius; dz <= radius; dz++) { + if (Math.abs(dx) + Math.abs(dy) + Math.abs(dz) <= radius + && MovementHelper.isTransparent(ctx.getBlock(pos.getX()+dx, pos.getY()+dy, pos.getZ()+dz))) { + return true; + } + } + } + } + return false; } @@ -466,86 +476,4 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro rescan(new ArrayList<>(), new CalculationContext(baritone)); } } - - public static boolean makeSphere(BlockPos pos, double radius, CalculationContext ctx) { - double radiusX = radius; - double radiusY = radius; - double radiusZ = radius; - radiusX += 0.5; - radiusY += 0.5; - radiusZ += 0.5; - - final double invRadiusX = 1 / radiusX; - final double invRadiusY = 1 / radiusY; - final double invRadiusZ = 1 / radiusZ; - - final int ceilRadiusX = (int) Math.ceil(radiusX); - final int ceilRadiusY = (int) Math.ceil(radiusY); - final int ceilRadiusZ = (int) Math.ceil(radiusZ); - - double nextXn = 0; - forX: - for (int x = 0; x <= ceilRadiusX; ++x) { - final double xn = nextXn; - nextXn = (x + 1) * invRadiusX; - double nextYn = 0; - forY: - for (int y = 0; y <= ceilRadiusY; ++y) { - final double yn = nextYn; - nextYn = (y + 1) * invRadiusY; - double nextZn = 0; - forZ: - for (int z = 0; z <= ceilRadiusZ; ++z) { - final double zn = nextZn; - nextZn = (z + 1) * invRadiusZ; - - double distanceSq = new Vec3d(xn, yn, zn).lengthSquared(); - if (distanceSq > 1) { - if (z == 0) { - if (y == 0) { - break forX; - } - break forY; - } - break forZ; - } - - if (isTransparent(pos.add(x, y, z), ctx)) { - return true; - } - if (isTransparent(pos.add(-x, y, z), ctx)) { - return true; - } - if (isTransparent(pos.add(x, -y, z), ctx)) { - return true; - } - if (isTransparent(pos.add(x, y, -z), ctx)) { - return true; - } - if (isTransparent(pos.add(-x, -y, z), ctx)) { - return true; - } - if (isTransparent(pos.add(x, -y, -z), ctx)) { - return true; - } - if (isTransparent(pos.add(-x, y, -z), ctx)) { - return true; - } - if (isTransparent(pos.add(-x, -y, -z), ctx)) { - return true; - } - } - } - } - - return false; - } - - public static boolean isTransparent(BlockPos pos, CalculationContext ctx) { - IBlockState blockState = ctx.bsi.get0(pos); - return blockState.getBlock() == Blocks.AIR || - blockState.getBlock() == Blocks.FLOWING_LAVA || - blockState.getBlock() == Blocks.FLOWING_WATER || - blockState.getBlock() == Blocks.WATER; - } } From 612510550f576d22d06582b302e88bc2037f4d32 Mon Sep 17 00:00:00 2001 From: Sam Corbett Date: Tue, 8 Sep 2020 19:00:41 +0100 Subject: [PATCH 5/6] fix javadoc. Signed-off-by: Sam Corbett --- src/api/java/baritone/api/Settings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index c5ba95bc..9cabe083 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -734,7 +734,7 @@ public final class Settings { /** * When allowOnlyExposedOres is enabled this is the distance around to search. *

- * It is recommended to keep this value low, as it exponentially increases calculation times and also to keep the + * It is recommended to keep this value low, as it dramatically increases calculation times. */ public final Setting allowOnlyExposedOresDistance = new Setting<>(1); From 39cfebeb344c321eae105b4dff8e460a7c9c2ace Mon Sep 17 00:00:00 2001 From: scorbett123 Date: Wed, 14 Oct 2020 19:56:09 +0100 Subject: [PATCH 6/6] fix formatting Signed-off-by: scorbett123 --- .../java/baritone/pathing/movement/MovementHelper.java | 4 ++-- src/main/java/baritone/process/MineProcess.java | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index df8218e8..8caa382b 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -562,9 +562,9 @@ public interface MovementHelper extends ActionCosts, Helper { enum PlaceResult { READY_TO_PLACE, ATTEMPTING, NO_OPTION; } - public static boolean isTransparent(Block b) { + static boolean isTransparent(Block b) { - return b== Blocks.AIR || + return b == Blocks.AIR || b == Blocks.FLOWING_LAVA || b == Blocks.FLOWING_WATER || b == Blocks.WATER; diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 2d51daf9..b8474e2f 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -40,7 +40,6 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; import java.util.*; import java.util.stream.Collectors; @@ -411,10 +410,11 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro .filter(pos -> MineProcess.plausibleToBreak(ctx, pos)) .filter(pos -> { - if (Baritone.settings().allowOnlyExposedOres.value) + if (Baritone.settings().allowOnlyExposedOres.value) { return isNextToAir(ctx, pos); - else + } else { return true; + } }) .filter(pos -> !blacklist.contains(pos)) @@ -434,7 +434,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro for (int dy = -radius; dy <= radius; dy++) { for (int dz = -radius; dz <= radius; dz++) { if (Math.abs(dx) + Math.abs(dy) + Math.abs(dz) <= radius - && MovementHelper.isTransparent(ctx.getBlock(pos.getX()+dx, pos.getY()+dy, pos.getZ()+dz))) { + && MovementHelper.isTransparent(ctx.getBlock(pos.getX() + dx, pos.getY() + dy, pos.getZ() + dz))) { return true; } }