Merge branch 'backfill-2'
This commit is contained in:
commit
315cc26525
@ -427,6 +427,11 @@ public final class Settings {
|
|||||||
*/
|
*/
|
||||||
public final Setting<Boolean> containerMemory = new Setting<>(false);
|
public final Setting<Boolean> containerMemory = new Setting<>(false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fill in blocks behind you
|
||||||
|
*/
|
||||||
|
public final Setting<Boolean> backfill = new Setting<>(false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print all the debug messages to chat
|
* Print all the debug messages to chat
|
||||||
*/
|
*/
|
||||||
|
@ -51,5 +51,10 @@ public enum PathingCommandType {
|
|||||||
* <p>
|
* <p>
|
||||||
* Cancel the current path if the goals are not equal
|
* Cancel the current path if the goals are not equal
|
||||||
*/
|
*/
|
||||||
FORCE_REVALIDATE_GOAL_AND_PATH
|
FORCE_REVALIDATE_GOAL_AND_PATH,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Go and ask the next process what to do
|
||||||
|
*/
|
||||||
|
DEFER
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,7 @@ public class Baritone implements IBaritone {
|
|||||||
private CustomGoalProcess customGoalProcess;
|
private CustomGoalProcess customGoalProcess;
|
||||||
private BuilderProcess builderProcess;
|
private BuilderProcess builderProcess;
|
||||||
private ExploreProcess exploreProcess;
|
private ExploreProcess exploreProcess;
|
||||||
|
private BackfillProcess backfillProcess;
|
||||||
private FarmProcess farmProcess;
|
private FarmProcess farmProcess;
|
||||||
|
|
||||||
private PathingControlManager pathingControlManager;
|
private PathingControlManager pathingControlManager;
|
||||||
@ -119,6 +120,7 @@ public class Baritone implements IBaritone {
|
|||||||
getToBlockProcess = new GetToBlockProcess(this);
|
getToBlockProcess = new GetToBlockProcess(this);
|
||||||
builderProcess = new BuilderProcess(this);
|
builderProcess = new BuilderProcess(this);
|
||||||
exploreProcess = new ExploreProcess(this);
|
exploreProcess = new ExploreProcess(this);
|
||||||
|
backfillProcess = new BackfillProcess(this);
|
||||||
farmProcess = new FarmProcess(this);
|
farmProcess = new FarmProcess(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,13 +130,13 @@ public class InventoryBehavior extends Behavior {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean selectThrowawayForLocation(int x, int y, int z) {
|
public boolean selectThrowawayForLocation(boolean select, int x, int y, int z) {
|
||||||
IBlockState maybe = baritone.getBuilderProcess().placeAt(x, y, z);
|
IBlockState maybe = baritone.getBuilderProcess().placeAt(x, y, z);
|
||||||
if (maybe != null && throwaway(true, stack -> stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).getBlock().equals(maybe.getBlock()))) {
|
if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).getBlock().equals(maybe.getBlock()))) {
|
||||||
return true; // gotem
|
return true; // gotem
|
||||||
}
|
}
|
||||||
for (Item item : Baritone.settings().acceptableThrowawayItems.value) {
|
for (Item item : Baritone.settings().acceptableThrowawayItems.value) {
|
||||||
if (throwaway(true, stack -> item.equals(stack.getItem()))) {
|
if (throwaway(select, stack -> item.equals(stack.getItem()))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,4 +270,8 @@ public abstract class Movement implements IMovement, MovementHelper {
|
|||||||
}
|
}
|
||||||
return toWalkIntoCached;
|
return toWalkIntoCached;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BlockPos[] toBreakAll() {
|
||||||
|
return positionsToBreak;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -487,8 +487,8 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
BlockPos against1 = placeAt.offset(HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i]);
|
BlockPos against1 = placeAt.offset(HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i]);
|
||||||
if (MovementHelper.canPlaceAgainst(ctx, against1)) {
|
if (MovementHelper.canPlaceAgainst(ctx, against1)) {
|
||||||
if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(placeAt.getX(), placeAt.getY(), placeAt.getZ())) { // get ready to place a throwaway block
|
if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(false, placeAt.getX(), placeAt.getY(), placeAt.getZ())) { // get ready to place a throwaway block
|
||||||
Helper.HELPER.logDebug("bb pls get me some blocks. dirt or cobble");
|
Helper.HELPER.logDebug("bb pls get me some blocks. dirt, netherrack, cobble");
|
||||||
state.setStatus(MovementStatus.UNREACHABLE);
|
state.setStatus(MovementStatus.UNREACHABLE);
|
||||||
return PlaceResult.NO_OPTION;
|
return PlaceResult.NO_OPTION;
|
||||||
}
|
}
|
||||||
@ -514,10 +514,15 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
EnumFacing side = ctx.objectMouseOver().sideHit;
|
EnumFacing side = ctx.objectMouseOver().sideHit;
|
||||||
// only way for selectedBlock.equals(placeAt) to be true is if it's replacable
|
// only way for selectedBlock.equals(placeAt) to be true is if it's replacable
|
||||||
if (selectedBlock.equals(placeAt) || (MovementHelper.canPlaceAgainst(ctx, selectedBlock) && selectedBlock.offset(side).equals(placeAt))) {
|
if (selectedBlock.equals(placeAt) || (MovementHelper.canPlaceAgainst(ctx, selectedBlock) && selectedBlock.offset(side).equals(placeAt))) {
|
||||||
|
((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, placeAt.getX(), placeAt.getY(), placeAt.getZ());
|
||||||
return PlaceResult.READY_TO_PLACE;
|
return PlaceResult.READY_TO_PLACE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return found ? PlaceResult.ATTEMPTING : PlaceResult.NO_OPTION;
|
if (found) {
|
||||||
|
((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, placeAt.getX(), placeAt.getY(), placeAt.getZ());
|
||||||
|
return PlaceResult.ATTEMPTING;
|
||||||
|
}
|
||||||
|
return PlaceResult.NO_OPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum PlaceResult {
|
enum PlaceResult {
|
||||||
|
@ -208,7 +208,7 @@ public class MovementPillar extends Movement {
|
|||||||
return state;
|
return state;
|
||||||
} else {
|
} else {
|
||||||
// Get ready to place a throwaway block
|
// Get ready to place a throwaway block
|
||||||
if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(src.x, src.y, src.z)) {
|
if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, src.x, src.y, src.z)) {
|
||||||
return state.setStatus(MovementStatus.UNREACHABLE);
|
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
139
src/main/java/baritone/process/BackfillProcess.java
Normal file
139
src/main/java/baritone/process/BackfillProcess.java
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Baritone is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.process;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
|
import baritone.api.process.PathingCommand;
|
||||||
|
import baritone.api.process.PathingCommandType;
|
||||||
|
import baritone.api.utils.input.Input;
|
||||||
|
import baritone.pathing.movement.Movement;
|
||||||
|
import baritone.pathing.movement.MovementHelper;
|
||||||
|
import baritone.pathing.movement.MovementState;
|
||||||
|
import baritone.pathing.path.PathExecutor;
|
||||||
|
import baritone.utils.BaritoneProcessHelper;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.chunk.EmptyChunk;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class BackfillProcess extends BaritoneProcessHelper {
|
||||||
|
|
||||||
|
public HashMap<BlockPos, IBlockState> blocksToReplace = new HashMap<>();
|
||||||
|
|
||||||
|
public BackfillProcess(Baritone baritone) {
|
||||||
|
super(baritone);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActive() {
|
||||||
|
if (ctx.player() == null || ctx.world() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!Baritone.settings().backfill.value) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (Baritone.settings().allowParkour.value) {
|
||||||
|
logDirect("Backfill cannot be used with allowParkour true");
|
||||||
|
Baritone.settings().backfill.value = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
amIBreakingABlockHMMMMMMM();
|
||||||
|
for (BlockPos pos : new ArrayList<>(blocksToReplace.keySet())) {
|
||||||
|
if (ctx.world().getChunk(pos) instanceof EmptyChunk) {
|
||||||
|
blocksToReplace.remove(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
baritone.getInputOverrideHandler().clearAllKeys();
|
||||||
|
|
||||||
|
return !toFillIn().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
||||||
|
if (!isSafeToCancel) {
|
||||||
|
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||||
|
}
|
||||||
|
baritone.getInputOverrideHandler().clearAllKeys();
|
||||||
|
for (BlockPos toPlace : toFillIn()) {
|
||||||
|
MovementState fake = new MovementState();
|
||||||
|
switch (MovementHelper.attemptToPlaceABlock(fake, baritone, toPlace, false)) {
|
||||||
|
case NO_OPTION:
|
||||||
|
continue;
|
||||||
|
case READY_TO_PLACE:
|
||||||
|
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
|
||||||
|
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||||
|
case ATTEMPTING:
|
||||||
|
// patience
|
||||||
|
baritone.getLookBehavior().updateTarget(fake.getTarget().getRotation().get(), true);
|
||||||
|
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new PathingCommand(null, PathingCommandType.DEFER); // cede to other process
|
||||||
|
}
|
||||||
|
|
||||||
|
public void amIBreakingABlockHMMMMMMM() {
|
||||||
|
if (!ctx.getSelectedBlock().isPresent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
blocksToReplace.put(ctx.getSelectedBlock().get(), ctx.world().getBlockState(ctx.getSelectedBlock().get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BlockPos> toFillIn() {
|
||||||
|
return blocksToReplace
|
||||||
|
.keySet()
|
||||||
|
.stream()
|
||||||
|
.filter(pos -> ctx.world().getBlockState(pos).getBlock() == Blocks.AIR)
|
||||||
|
.filter(pos -> ctx.world().mayPlace(Blocks.DIRT, pos, false, EnumFacing.UP, null))
|
||||||
|
.filter(pos -> !partOfCurrentMovement(pos))
|
||||||
|
.sorted(Comparator.<BlockPos>comparingDouble(ctx.player()::getDistanceSq).reversed())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean partOfCurrentMovement(BlockPos pos) {
|
||||||
|
PathExecutor exec = baritone.getPathingBehavior().getCurrent();
|
||||||
|
if (exec == null || exec.finished() || exec.failed()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Movement movement = (Movement) exec.getPath().movements().get(exec.getPosition());
|
||||||
|
return Arrays.asList(movement.toBreakAll()).contains(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLostControl() {
|
||||||
|
blocksToReplace.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String displayName0() {
|
||||||
|
return "Backfill";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTemporary() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double priority() {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
}
|
@ -92,8 +92,8 @@ public class PathingControlManager implements IPathingControlManager {
|
|||||||
p.secretInternalSetGoal(null);
|
p.secretInternalSetGoal(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (inControlThisTick != inControlLastTick && command.commandType != PathingCommandType.REQUEST_PAUSE) {
|
if (inControlThisTick != inControlLastTick && command.commandType != PathingCommandType.REQUEST_PAUSE && inControlLastTick != null && !inControlLastTick.isTemporary()) {
|
||||||
// if control has changed, and the new process wants to do something
|
// if control has changed from a real process to another real process, and the new process wants to do something
|
||||||
p.cancelSegmentIfSafe();
|
p.cancelSegmentIfSafe();
|
||||||
// get rid of the in progress stuff from the last process
|
// get rid of the in progress stuff from the last process
|
||||||
}
|
}
|
||||||
@ -200,10 +200,10 @@ public class PathingControlManager implements IPathingControlManager {
|
|||||||
PathingCommand exec = proc.onTick(Objects.equals(proc, inControlLastTick) && baritone.getPathingBehavior().calcFailedLastTick(), baritone.getPathingBehavior().isSafeToCancel());
|
PathingCommand exec = proc.onTick(Objects.equals(proc, inControlLastTick) && baritone.getPathingBehavior().calcFailedLastTick(), baritone.getPathingBehavior().isSafeToCancel());
|
||||||
if (exec == null) {
|
if (exec == null) {
|
||||||
if (proc.isActive()) {
|
if (proc.isActive()) {
|
||||||
throw new IllegalStateException(proc.displayName() + " returned null PathingCommand");
|
throw new IllegalStateException(proc.displayName() + " actively returned null PathingCommand");
|
||||||
}
|
}
|
||||||
proc.onLostControl();
|
// no need to call onLostControl; they are reporting inactive.
|
||||||
} else {
|
} else if (exec.commandType != PathingCommandType.DEFER) {
|
||||||
inControlThisTick = proc;
|
inControlThisTick = proc;
|
||||||
if (!proc.isTemporary()) {
|
if (!proc.isTemporary()) {
|
||||||
iterator.forEachRemaining(IBaritoneProcess::onLostControl);
|
iterator.forEachRemaining(IBaritoneProcess::onLostControl);
|
||||||
|
Loading…
Reference in New Issue
Block a user