diff --git a/USAGE.md b/USAGE.md index b01bf3fa7..869d68c27 100644 --- a/USAGE.md +++ b/USAGE.md @@ -24,7 +24,7 @@ Some common examples: - `goal clear` to clear the goal - `cancel` or `stop` to stop everything - `goto portal` or `goto ender_chest` or `goto block_type` to go to a block. (in Impact, `.goto` is an alias for `.b goto` for the most part) -- `mine diamond_ore` to mine diamond ore (turn on the setting `legitMine` to only mine ores that it can actually see. It will explore randomly around y=11 until it finds them.) +- `mine diamond_ore` to mine diamond ore (turn on the setting `legitMine` to only mine ores that it can actually see. It will explore randomly around y=11 until it finds them.) An amount of blocks can also be specified, for example, `mine diamond_ore 64`. - `click` to click your destination on the screen. Right click path to on top of the block, left click to path into it (either at foot level or eye level), and left click and drag to clear all blocks from an area. - `follow playerName` to follow a player. `followplayers` to follow any players in range (combine with Kill Aura for a fun time). `followentities` to follow any entities. `followentity pig` to follow entities of a specific type. - `save waypointName` to save a waypoint. `goto waypointName` to go to it. diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index d485aa448..f76dda7dd 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -701,6 +701,26 @@ public final class Settings { */ public final Setting goalBreakFromAbove = new Setting<>(false); + /** + * Build in map art mode, which makes baritone only care about the top block in each column + */ + public final Setting mapArtMode = new Setting<>(false); + + /** + * Override builder's behavior to not attempt to correct blocks that are currently water + */ + public final Setting okIfWater = new Setting<>(false); + + /** + * The set of incorrect blocks can never grow beyond this size + */ + public final Setting incorrectSize = new Setting<>(100); + + /** + * Multiply the cost of breaking a block that's correct in the builder's schematic by this coefficient + */ + public final Setting breakCorrectBlockPenaltyMultiplier = new Setting<>(10d); + /** * While mining, should it also consider dropped items of the correct type as a pathing destination (as well as ore blocks)? */ diff --git a/src/api/java/baritone/api/utils/ExampleBaritoneControl.java b/src/api/java/baritone/api/utils/ExampleBaritoneControl.java index eeb621efd..7654ebb0f 100644 --- a/src/api/java/baritone/api/utils/ExampleBaritoneControl.java +++ b/src/api/java/baritone/api/utils/ExampleBaritoneControl.java @@ -49,7 +49,7 @@ import net.minecraft.world.dimension.DimensionType; import java.nio.file.Path; import java.util.*; -import static org.apache.commons.lang3.StringUtils.isNumeric; +import static org.apache.commons.lang3.math.NumberUtils.isCreatable; public class ExampleBaritoneControl implements Helper, AbstractGameEventListener { private static final String COMMAND_PREFIX = "#"; @@ -222,20 +222,7 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener return true; } if (msg.equals("repack") || msg.equals("rescan")) { - ClientChunkProvider cli = (ClientChunkProvider) ctx.world().getChunkProvider(); - int playerChunkX = ctx.playerFeet().getX() >> 4; - int playerChunkZ = ctx.playerFeet().getZ() >> 4; - int count = 0; - for (int x = playerChunkX - 40; x <= playerChunkX + 40; x++) { - for (int z = playerChunkZ - 40; z <= playerChunkZ + 40; z++) { - Chunk chunk = cli.getChunk(x, z, null, false); - if (chunk != null) { - count++; - baritone.getWorldProvider().getCurrentWorld().getCachedWorld().queueForPacking(chunk); - } - } - } - logDirect("Queued " + count + " chunks for repacking"); + logDirect("Queued " + repack() + " chunks for repacking"); return true; } if (msg.startsWith("build")) { @@ -483,6 +470,7 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener return true; } if (msg.startsWith("find")) { + repack(); String blockType = msg.substring(4).trim(); ArrayList locs = baritone.getWorldProvider().getCurrentWorld().getCachedWorld().getLocationsOf(blockType, 1, ctx.playerFeet().getX(), ctx.playerFeet().getZ(), 4); logDirect("Have " + locs.size() + " locations"); @@ -495,6 +483,7 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener return true; } if (msg.startsWith("mine")) { + repack(); String[] blockTypes = msg.substring(4).trim().split(" "); try { int quantity = Integer.parseInt(blockTypes[1]); @@ -584,6 +573,7 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener return true; } if (msg.startsWith("goto")) { + repack(); String waypointType = msg.substring(4).trim(); if (waypointType.endsWith("s") && IWaypoint.Tag.fromString(waypointType.substring(0, waypointType.length() - 1)) != null) { // for example, "show deaths" @@ -657,6 +647,23 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener return false; } + private int repack() { + ClientChunkProvider cli = (ClientChunkProvider) ctx.world().getChunkProvider(); + int playerChunkX = ctx.playerFeet().getX() >> 4; + int playerChunkZ = ctx.playerFeet().getZ() >> 4; + int count = 0; + for (int x = playerChunkX - 40; x <= playerChunkX + 40; x++) { + for (int z = playerChunkZ - 40; z <= playerChunkZ + 40; z++) { + Chunk chunk = cli.getChunk(x, z, null, false); + if (chunk != null) { + count++; + baritone.getWorldProvider().getCurrentWorld().getCachedWorld().queueForPacking(chunk); + } + } + } + return count; + } + private int parseOrDefault(String str, int i, double dimensionFactor) { return str.equals("~") ? i : str.startsWith("~") ? (int) (Integer.parseInt(str.substring(1)) * dimensionFactor) + i : (int) (Integer.parseInt(str) * dimensionFactor); } @@ -675,7 +682,7 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener BetterBlockPos playerFeet = ctx.playerFeet(); int length = params.length - 1; // length has to be smaller when a dimension parameter is added - if (params.length < 1 || (isNumeric(params[params.length - 1]) || params[params.length - 1].startsWith("~"))) { + if (params.length < 1 || (isCreatable(params[params.length - 1]) || params[params.length - 1].startsWith("~"))) { length = params.length; } switch (length) { diff --git a/src/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java index 3c2e15c72..61b2915df 100644 --- a/src/main/java/baritone/behavior/InventoryBehavior.java +++ b/src/main/java/baritone/behavior/InventoryBehavior.java @@ -26,7 +26,11 @@ import net.minecraft.block.Blocks; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.inventory.container.ClickType; import net.minecraft.item.*; +import net.minecraft.util.Direction; +import net.minecraft.util.Hand; import net.minecraft.util.NonNullList; +import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraft.util.math.Vec3d; import java.util.ArrayList; import java.util.OptionalInt; @@ -132,9 +136,12 @@ public final class InventoryBehavior extends Behavior { public boolean selectThrowawayForLocation(boolean select, int x, int y, int z) { BlockState maybe = baritone.getBuilderProcess().placeAt(x, y, z); - if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof BlockItem && ((BlockItem) stack.getItem()).getBlock().equals(maybe.getBlock()))) { + if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof BlockItem && maybe.equals(((BlockItem) stack.getItem()).getBlock().getStateForPlacement(new BlockItemUseContext(new ItemUseContext(ctx.world(), ctx.player(), Hand.MAIN_HAND, stack, new BlockRayTraceResult(new Vec3d(ctx.player().posX, ctx.player().posY, ctx.player().posZ), Direction.UP, ctx.playerFeet(), false)) {}))))) { return true; // gotem } + if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof BlockItem && ((BlockItem) stack.getItem()).getBlock().equals(maybe.getBlock()))) { + return true; + } for (Item item : Baritone.settings().acceptableThrowawayItems.value) { if (throwaway(select, stack -> item.equals(stack.getItem()))) { return true; diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 6b1e67b94..3fffda7c6 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -34,6 +34,7 @@ import baritone.utils.BaritoneProcessHelper; import baritone.utils.BlockStateInterface; import baritone.utils.PathingCommandContext; import baritone.utils.schematic.AirSchematic; +import baritone.utils.schematic.MapArtSchematic; import baritone.utils.schematic.Schematic; import baritone.utils.schematic.schematica.SchematicaHelper; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; @@ -134,7 +135,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil } private static ISchematic parse(CompoundNBT schematic) { - return new Schematic(schematic); + return Baritone.settings().mapArtMode.value ? new MapArtSchematic(schematic) : new Schematic(schematic); } @Override @@ -528,6 +529,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil } else { incorrectPositions.add(new BetterBlockPos(blockX, blockY, blockZ)); observedCompleted.remove(BetterBlockPos.longHash(blockX, blockY, blockZ)); + if (incorrectPositions.size() > Baritone.settings().incorrectSize.value) { + return; + } } continue; } @@ -536,6 +540,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil // and we've never seen this position be correct // therefore mark as incorrect incorrectPositions.add(new BetterBlockPos(blockX, blockY, blockZ)); + if (incorrectPositions.size() > Baritone.settings().incorrectSize.value) { + return; + } } } } @@ -634,7 +641,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil boolean allowSameLevel = !(ctx.world().getBlockState(pos.up()).getBlock() instanceof AirBlock); for (Direction facing : Movement.HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP) { if (MovementHelper.canPlaceAgainst(ctx, pos.offset(facing)) && placementPlausible(pos, bcc.getSchematic(pos.getX(), pos.getY(), pos.getZ()))) { - return new GoalAdjacent(pos, allowSameLevel); + return new GoalAdjacent(pos, pos.offset(facing), allowSameLevel); } } return new GoalPlace(pos); @@ -657,9 +664,11 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil public static class GoalAdjacent extends GoalGetToBlock { private boolean allowSameLevel; + private BlockPos no; - public GoalAdjacent(BlockPos pos, boolean allowSameLevel) { + public GoalAdjacent(BlockPos pos, BlockPos no, boolean allowSameLevel) { super(pos); + this.no = no; this.allowSameLevel = allowSameLevel; } @@ -667,6 +676,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil if (x == this.x && y == this.y && z == this.z) { return false; } + if (x == no.getX() && y == no.getY() && z == no.getZ()) { + return false; + } if (!allowSameLevel && y == this.y - 1) { return false; } @@ -731,6 +743,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil if (current.getBlock() instanceof AirBlock && desired.getBlock() instanceof AirBlock) { return true; } + if ((current.getBlock() == Blocks.WATER || current.getBlock() == Blocks.LAVA) && Baritone.settings().okIfWater.value) { + return true; + } // TODO more complicated comparison logic I guess return current.equals(desired); } @@ -811,7 +826,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil // it should be a real block // is it already that block? if (valid(bsi.get0(x, y, z), sch)) { - return 3; + return Baritone.settings().breakCorrectBlockPenaltyMultiplier.value; } else { // can break if it's wrong // would be great to return less than 1 here, but that would actually make the cost calculation messed up