cool tunnel feature and various fixes
This commit is contained in:
parent
65cd6a92d3
commit
fcadf68c90
@ -61,6 +61,6 @@ public class GoalNear implements Goal, IGoalRenderPos {
|
|||||||
", y=" + y +
|
", y=" + y +
|
||||||
", z=" + z +
|
", z=" + z +
|
||||||
", rangeSq=" + rangeSq +
|
", rangeSq=" + rangeSq +
|
||||||
'}';
|
"}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* 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.api.pathing.goals;
|
||||||
|
|
||||||
|
import baritone.api.BaritoneAPI;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dig a tunnel in a certain direction, but if you have to deviate from the path, go back to where you started
|
||||||
|
*/
|
||||||
|
public class GoalStrictDirection implements Goal {
|
||||||
|
public final int x;
|
||||||
|
public final int y;
|
||||||
|
public final int z;
|
||||||
|
public final int dx;
|
||||||
|
public final int dz;
|
||||||
|
|
||||||
|
public GoalStrictDirection(BlockPos origin, EnumFacing direction) {
|
||||||
|
x = origin.getX();
|
||||||
|
y = origin.getY();
|
||||||
|
z = origin.getZ();
|
||||||
|
dx = direction.getXOffset();
|
||||||
|
dz = direction.getZOffset();
|
||||||
|
if (dx == 0 && dz == 0) {
|
||||||
|
throw new IllegalArgumentException(direction + "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInGoal(int x, int y, int z) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double heuristic(int x, int y, int z) {
|
||||||
|
int distanceFromStartInDesiredDirection = (x - this.x) * dx + (z - this.z) * dz;
|
||||||
|
|
||||||
|
int distanceFromStartInIncorrectDirection = Math.abs((x - this.x) * dz) + Math.abs((z - this.z) * dx);
|
||||||
|
|
||||||
|
int verticalDistanceFromStart = Math.abs(y - this.y);
|
||||||
|
|
||||||
|
// we want heuristic to decrease as desiredDirection increases
|
||||||
|
double heuristic = -distanceFromStartInDesiredDirection * 100;
|
||||||
|
|
||||||
|
heuristic += distanceFromStartInIncorrectDirection * 1000;
|
||||||
|
heuristic += verticalDistanceFromStart * 1000;
|
||||||
|
return heuristic;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "GoalStrictDirection{" +
|
||||||
|
"x=" + x +
|
||||||
|
", y=" + y +
|
||||||
|
", z=" + z +
|
||||||
|
", dx=" + dx +
|
||||||
|
", dz=" + dz +
|
||||||
|
"}";
|
||||||
|
}
|
||||||
|
}
|
@ -72,7 +72,7 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
|
|||||||
float oldPitch = ctx.player().rotationPitch;
|
float oldPitch = ctx.player().rotationPitch;
|
||||||
float desiredPitch = this.target.getPitch();
|
float desiredPitch = this.target.getPitch();
|
||||||
ctx.player().rotationPitch = desiredPitch;
|
ctx.player().rotationPitch = desiredPitch;
|
||||||
if (desiredPitch == oldPitch && Baritone.settings().freeLook.value) {
|
if (desiredPitch == oldPitch && !Baritone.settings().freeLook.value) {
|
||||||
nudgeToLevel();
|
nudgeToLevel();
|
||||||
}
|
}
|
||||||
this.target = null;
|
this.target = null;
|
||||||
|
@ -30,10 +30,7 @@ import baritone.pathing.movement.Movement;
|
|||||||
import baritone.pathing.movement.MovementHelper;
|
import baritone.pathing.movement.MovementHelper;
|
||||||
import baritone.pathing.movement.MovementState;
|
import baritone.pathing.movement.MovementState;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.*;
|
||||||
import net.minecraft.block.BlockDoor;
|
|
||||||
import net.minecraft.block.BlockFenceGate;
|
|
||||||
import net.minecraft.block.BlockSlab;
|
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@ -151,6 +148,8 @@ public class MovementTraverse extends Movement {
|
|||||||
@Override
|
@Override
|
||||||
public MovementState updateState(MovementState state) {
|
public MovementState updateState(MovementState state) {
|
||||||
super.updateState(state);
|
super.updateState(state);
|
||||||
|
IBlockState pb0 = BlockStateInterface.get(ctx, positionsToBreak[0]);
|
||||||
|
IBlockState pb1 = BlockStateInterface.get(ctx, positionsToBreak[1]);
|
||||||
if (state.getStatus() != MovementStatus.RUNNING) {
|
if (state.getStatus() != MovementStatus.RUNNING) {
|
||||||
// if the setting is enabled
|
// if the setting is enabled
|
||||||
if (!Baritone.settings().walkWhileBreaking.value) {
|
if (!Baritone.settings().walkWhileBreaking.value) {
|
||||||
@ -161,10 +160,10 @@ public class MovementTraverse extends Movement {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
// and if it's fine to walk into the blocks in front
|
// and if it's fine to walk into the blocks in front
|
||||||
if (MovementHelper.avoidWalkingInto(BlockStateInterface.get(ctx, positionsToBreak[0]).getBlock())) {
|
if (MovementHelper.avoidWalkingInto(pb0.getBlock())) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
if (MovementHelper.avoidWalkingInto(BlockStateInterface.get(ctx, positionsToBreak[1]).getBlock())) {
|
if (MovementHelper.avoidWalkingInto(pb1.getBlock())) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
// and we aren't already pressed up against the block
|
// and we aren't already pressed up against the block
|
||||||
@ -177,6 +176,10 @@ public class MovementTraverse extends Movement {
|
|||||||
// it's safe to do this since the two blocks we break (in a traverse) are right on top of each other and so will have the same yaw
|
// it's safe to do this since the two blocks we break (in a traverse) are right on top of each other and so will have the same yaw
|
||||||
float yawToDest = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.calculateBlockCenter(ctx.world(), dest), ctx.playerRotations()).getYaw();
|
float yawToDest = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.calculateBlockCenter(ctx.world(), dest), ctx.playerRotations()).getYaw();
|
||||||
float pitchToBreak = state.getTarget().getRotation().get().getPitch();
|
float pitchToBreak = state.getTarget().getRotation().get().getPitch();
|
||||||
|
if ((pb0.isFullCube() || pb0.getBlock() instanceof BlockAir && (pb1.isFullCube() || pb1.getBlock() instanceof BlockAir))) {
|
||||||
|
// in the meantime, before we're right up against the block, we can break efficiently at this angle
|
||||||
|
pitchToBreak = 26;
|
||||||
|
}
|
||||||
|
|
||||||
state.setTarget(new MovementState.MovementTarget(new Rotation(yawToDest, pitchToBreak), true));
|
state.setTarget(new MovementState.MovementTarget(new Rotation(yawToDest, pitchToBreak), true));
|
||||||
return state.setInput(Input.MOVE_FORWARD, true).setInput(Input.SPRINT, true);
|
return state.setInput(Input.MOVE_FORWARD, true).setInput(Input.SPRINT, true);
|
||||||
@ -187,8 +190,6 @@ public class MovementTraverse extends Movement {
|
|||||||
|
|
||||||
Block fd = BlockStateInterface.get(ctx, src.down()).getBlock();
|
Block fd = BlockStateInterface.get(ctx, src.down()).getBlock();
|
||||||
boolean ladder = fd == Blocks.LADDER || fd == Blocks.VINE;
|
boolean ladder = fd == Blocks.LADDER || fd == Blocks.VINE;
|
||||||
IBlockState pb0 = BlockStateInterface.get(ctx, positionsToBreak[0]);
|
|
||||||
IBlockState pb1 = BlockStateInterface.get(ctx, positionsToBreak[1]);
|
|
||||||
|
|
||||||
boolean door = pb0.getBlock() instanceof BlockDoor || pb1.getBlock() instanceof BlockDoor;
|
boolean door = pb0.getBlock() instanceof BlockDoor || pb1.getBlock() instanceof BlockDoor;
|
||||||
if (door) {
|
if (door) {
|
||||||
|
@ -366,6 +366,11 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
logDirect("Baritone settings reset");
|
logDirect("Baritone settings reset");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (msg.equals("tunnel")) {
|
||||||
|
customGoalProcess.setGoalAndPath(new GoalStrictDirection(ctx.playerFeet(), ctx.player().getHorizontalFacing()));
|
||||||
|
logDirect("tunneling");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (msg.equals("render")) {
|
if (msg.equals("render")) {
|
||||||
BetterBlockPos pf = ctx.playerFeet();
|
BetterBlockPos pf = ctx.playerFeet();
|
||||||
Minecraft.getMinecraft().renderGlobal.markBlockRangeForRenderUpdate(pf.x - 500, pf.y - 500, pf.z - 500, pf.x + 500, pf.y + 500, pf.z + 500);
|
Minecraft.getMinecraft().renderGlobal.markBlockRangeForRenderUpdate(pf.x - 500, pf.y - 500, pf.z - 500, pf.x + 500, pf.y + 500, pf.z + 500);
|
||||||
|
Loading…
Reference in New Issue
Block a user