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 ef67b1972..1b47c4e33 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 b7137ee4f..648702e53 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 = "#"; @@ -239,20 +239,7 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener return true; } if (msg.equals("repack") || msg.equals("rescan")) { - ChunkProviderClient cli = (ChunkProviderClient) 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, false, 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")) { @@ -500,6 +487,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"); @@ -512,6 +500,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]); @@ -601,6 +590,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" @@ -674,6 +664,23 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener return false; } + private int repack() { + ChunkProviderClient cli = (ChunkProviderClient) 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, false, 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); } @@ -692,7 +699,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 684613af1..a9e0c2d65 100644 --- a/src/main/java/baritone/behavior/InventoryBehavior.java +++ b/src/main/java/baritone/behavior/InventoryBehavior.java @@ -26,6 +26,7 @@ import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.init.Blocks; import net.minecraft.inventory.ClickType; import net.minecraft.item.*; +import net.minecraft.util.EnumFacing; import net.minecraft.util.NonNullList; import java.util.ArrayList; @@ -132,9 +133,12 @@ public final class InventoryBehavior extends Behavior { public boolean selectThrowawayForLocation(boolean select, int x, int y, int z) { IBlockState maybe = baritone.getBuilderProcess().placeAt(x, y, z); - if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).getBlock().equals(maybe.getBlock()))) { + if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof ItemBlock && maybe.equals(((ItemBlock) stack.getItem()).getBlock().getStateForPlacement(new BlockItemUseContext(new ItemUseContext(ctx.player(), stack, ctx.playerFeet(), EnumFacing.UP, (float) ctx.player().posX, (float) ctx.player().posY, (float) ctx.player().posZ)))))) { return true; // gotem } + if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof ItemBlock && ((ItemBlock) 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 d5265037b..9e4b4899e 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; @@ -133,7 +134,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil } private static ISchematic parse(NBTTagCompound schematic) { - return new Schematic(schematic); + return Baritone.settings().mapArtMode.value ? new MapArtSchematic(schematic) : new Schematic(schematic); } @Override @@ -529,6 +530,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; } @@ -537,6 +541,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; + } } } } @@ -635,7 +642,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil boolean allowSameLevel = !(ctx.world().getBlockState(pos.up()).getBlock() instanceof BlockAir); for (EnumFacing 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); @@ -658,9 +665,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; } @@ -668,6 +677,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; } @@ -732,6 +744,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil if (current.getBlock() instanceof BlockAir && desired.getBlock() instanceof BlockAir) { 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); } @@ -812,7 +827,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 diff --git a/src/main/java/baritone/utils/schematic/MapArtSchematic.java b/src/main/java/baritone/utils/schematic/MapArtSchematic.java index 296401ee9..134815239 100644 --- a/src/main/java/baritone/utils/schematic/MapArtSchematic.java +++ b/src/main/java/baritone/utils/schematic/MapArtSchematic.java @@ -35,8 +35,7 @@ public class MapArtSchematic extends Schematic { for (int x = 0; x < widthX; x++) { for (int z = 0; z < lengthZ; z++) { IBlockState[] column = states[x][z]; - - OptionalInt lowestBlockY = lastIndexMatching(column, block -> !(block instanceof BlockAir)); + OptionalInt lowestBlockY = lastIndexMatching(column, state -> !(state.getBlock() instanceof BlockAir)); if (lowestBlockY.isPresent()) { heightMap[x][z] = lowestBlockY.getAsInt(); } else {