From ed4fba330d3e96078e1817c22e702a10edd68973 Mon Sep 17 00:00:00 2001 From: Graicc <33105645+Graicc@users.noreply.github.com> Date: Sat, 17 Aug 2019 11:59:30 -0400 Subject: [PATCH 1/5] Added mining certain amount of blocks to USAGE.md --- USAGE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/USAGE.md b/USAGE.md index b01bf3fa7..7b27a3fcd 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. From 5cbf1eef5fcc33814c6715be600a6cc025a1c26d Mon Sep 17 00:00:00 2001 From: Graicc <33105645+Graicc@users.noreply.github.com> Date: Sat, 17 Aug 2019 12:02:26 -0400 Subject: [PATCH 2/5] Grammer fix --- USAGE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/USAGE.md b/USAGE.md index 7b27a3fcd..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.) An amount of blocks can also be specified, for example `mine diamond_ore 64`. +- `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. From 24da012903b57a21215b8d13e9a04a735ce55b60 Mon Sep 17 00:00:00 2001 From: reb0rt <37573784+reb0rt@users.noreply.github.com> Date: Sun, 18 Aug 2019 13:04:39 +1000 Subject: [PATCH 3/5] Stop parseGoal from removing the last argument isNumeric returns false if the input is anything other than a positive integer. This meant that baritone wouldn't properly set goals if they ended in anything other than a positive integer. --- src/api/java/baritone/api/utils/ExampleBaritoneControl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/java/baritone/api/utils/ExampleBaritoneControl.java b/src/api/java/baritone/api/utils/ExampleBaritoneControl.java index 7a90f1beb..76849dae9 100644 --- a/src/api/java/baritone/api/utils/ExampleBaritoneControl.java +++ b/src/api/java/baritone/api/utils/ExampleBaritoneControl.java @@ -50,7 +50,7 @@ import net.minecraft.world.chunk.Chunk; 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 = "#"; @@ -694,7 +694,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) { From 1c36bf3300670499660ea2da56bb7b7b982edd36 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 17 Aug 2019 22:01:53 -0700 Subject: [PATCH 4/5] repack on mine cmd --- .../api/utils/ExampleBaritoneControl.java | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/api/java/baritone/api/utils/ExampleBaritoneControl.java b/src/api/java/baritone/api/utils/ExampleBaritoneControl.java index 76849dae9..16a56667c 100644 --- a/src/api/java/baritone/api/utils/ExampleBaritoneControl.java +++ b/src/api/java/baritone/api/utils/ExampleBaritoneControl.java @@ -241,20 +241,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.getLoadedChunk(x, z); - 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")) { @@ -502,6 +489,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"); @@ -514,6 +502,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]); @@ -603,6 +592,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" @@ -676,6 +666,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.getLoadedChunk(x, z); + if (chunk != null && !chunk.isEmpty()) { + 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); } @@ -722,7 +729,6 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener } - private double calculateDimensionFactor(String to) { return Math.pow(8, ctx.world().provider.getDimensionType().getId() - getDimensionByName(to.toLowerCase()).getId()); } From b9f0da7d27d9d62f7e671f05b087d9f30dce7e4a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 20 Aug 2019 11:23:23 -0700 Subject: [PATCH 5/5] major unscuff of builder --- src/api/java/baritone/api/Settings.java | 20 ++++++++++++++++ .../baritone/behavior/InventoryBehavior.java | 6 ++++- .../java/baritone/process/BuilderProcess.java | 23 +++++++++++++++---- .../utils/schematic/MapArtSchematic.java | 4 ++-- 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 7d575b0bc..cd7bdabe2 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -697,6 +697,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/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java index 684613af1..ae19af866 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(ctx.world(), ctx.playerFeet(), EnumFacing.UP, (float) ctx.player().posX, (float) ctx.player().posY, (float) ctx.player().posZ, stack.getItem().getMetadata(stack.getMetadata()), ctx.player())))) { 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 99edba4ac..daa04cb9a 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; @@ -130,7 +131,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 @@ -512,6 +513,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; } @@ -520,6 +524,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; + } } } } @@ -618,7 +625,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil boolean allowSameLevel = ctx.world().getBlockState(pos.up()).getBlock() != Blocks.AIR; for (EnumFacing facing : Movement.HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP) { if (MovementHelper.canPlaceAgainst(ctx, pos.offset(facing)) && ctx.world().mayPlace(bcc.getSchematic(pos.getX(), pos.getY(), pos.getZ()).getBlock(), pos, false, facing, null)) { - return new GoalAdjacent(pos, allowSameLevel); + return new GoalAdjacent(pos, pos.offset(facing), allowSameLevel); } } return new GoalPlace(pos); @@ -641,9 +648,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; } @@ -651,6 +660,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; } @@ -710,6 +722,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil private boolean valid(IBlockState current, IBlockState desired) { // TODO more complicated comparison logic I guess + if (current.getBlock() instanceof BlockLiquid && Baritone.settings().okIfWater.value) { + return true; + } return desired == null || current.equals(desired); } @@ -789,7 +804,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 1be131952..fa1c2d006 100644 --- a/src/main/java/baritone/utils/schematic/MapArtSchematic.java +++ b/src/main/java/baritone/utils/schematic/MapArtSchematic.java @@ -17,8 +17,8 @@ package baritone.utils.schematic; +import net.minecraft.block.BlockAir; import net.minecraft.block.state.IBlockState; -import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTTagCompound; import java.util.OptionalInt; @@ -36,7 +36,7 @@ public class MapArtSchematic extends Schematic { for (int z = 0; z < lengthZ; z++) { IBlockState[] column = states[x][z]; - OptionalInt lowestBlockY = lastIndexMatching(column, block -> block != Blocks.AIR); + OptionalInt lowestBlockY = lastIndexMatching(column, state -> !(state.getBlock() instanceof BlockAir)); if (lowestBlockY.isPresent()) { heightMap[x][z] = lowestBlockY.getAsInt(); } else {