Skip to content

Magma block detection #4742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: 1.19.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/api/java/baritone/api/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,11 @@ public final class Settings {
*/
public final Setting<Boolean> elytraChatSpam = new Setting<>(false);

/**
* Sneak when magma blocks are under feet
*/
public final Setting<Boolean> allowWalkOnMagmaBlocks = new Setting<>(false);

/**
* A map of lowercase setting field names to their respective setting
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class CalculationContext {
public double backtrackCostFavoringCoefficient;
public double jumpPenalty;
public final double walkOnWaterOnePenalty;
public final boolean allowWalkOnMagmaBlocks;
public final BetterWorldBorder worldBorder;

public final PrecomputedData precomputedData;
Expand Down Expand Up @@ -125,6 +126,7 @@ public CalculationContext(IBaritone baritone, boolean forUseOnAnotherThread) {
this.backtrackCostFavoringCoefficient = Baritone.settings().backtrackCostFavoringCoefficient.value;
this.jumpPenalty = Baritone.settings().jumpPenalty.value;
this.walkOnWaterOnePenalty = Baritone.settings().walkOnWaterOnePenalty.value;
this.allowWalkOnMagmaBlocks = Baritone.settings().allowWalkOnMagmaBlocks.value;
// why cache these things here, why not let the movements just get directly from settings?
// because if some movements are calculated one way and others are calculated another way,
// then you get a wildly inconsistent path that isn't optimal for either scenario.
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/baritone/pathing/movement/MovementHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -420,7 +421,7 @@ static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, BlockStat

static Ternary canWalkOnBlockState(BlockState state) {
Block block = state.getBlock();
if (isBlockNormalCube(state) && block != Blocks.MAGMA_BLOCK && block != Blocks.BUBBLE_COLUMN && block != Blocks.HONEY_BLOCK) {
if (isBlockNormalCube(state) && (Baritone.settings().allowWalkOnMagmaBlocks.value || block != Blocks.MAGMA_BLOCK) && block != Blocks.BUBBLE_COLUMN && block != Blocks.HONEY_BLOCK) {
return YES;
}
if (block instanceof AzaleaBlock) {
Expand Down Expand Up @@ -806,4 +807,16 @@ static boolean isTransparent(Block b) {
b == Blocks.LAVA ||
b == Blocks.WATER;
}

static List<BetterBlockPos> steppingOnBlocks(IPlayerContext ctx) {
List<BetterBlockPos> blocks = new ArrayList<>();
for (byte x = -1; x <= 1; x++) {
for (byte z = -1; z <= 1; z++) {
if (ctx.player().getBoundingBox().intersects(Vec3.atLowerCornerOf(ctx.player().blockPosition()).add(x, 0, z), Vec3.atLowerCornerOf(ctx.player().blockPosition()).add(x + 1, 1, z + 1))) {
blocks.add(new BetterBlockPos(ctx.player().getBlockX() + x, ctx.player().getBlockY() - 1, ctx.player().getBlockZ() + z));
}
}
}
return blocks;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public static double cost(CalculationContext context, int x, int y, int z, int d
// jumpingFromBottomSlab must be false
if (toPlace.getBlock() == Blocks.SOUL_SAND) {
walk = WALK_ONE_OVER_SOUL_SAND_COST;
} else if (toPlace.getBlock() == Blocks.MAGMA_BLOCK) {
walk = SNEAK_ONE_BLOCK_COST;
} else {
walk = Math.max(JUMP_ONE_BLOCK_COST, WALK_ONE_BLOCK_COST);
}
Expand Down Expand Up @@ -188,6 +190,9 @@ public MovementState updateState(MovementState state) {
return state;
}
MovementHelper.moveTowards(ctx, state, dest);

state.setInput(Input.SNEAK, Baritone.settings().allowWalkOnMagmaBlocks.value && jumpingOnto.getBlock().equals(Blocks.MAGMA_BLOCK));

if (MovementHelper.isBottomSlab(jumpingOnto) && !MovementHelper.isBottomSlab(BlockStateInterface.get(ctx, src.below()))) {
return state; // don't jump while walking from a non double slab into a bottom slab
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package baritone.pathing.movement.movements;

import baritone.Baritone;
import baritone.api.IBaritone;
import baritone.api.pathing.movement.MovementStatus;
import baritone.api.utils.BetterBlockPos;
Expand Down Expand Up @@ -255,6 +256,9 @@ public MovementState updateState(MovementState state) {
double x = ctx.player().position().x - (src.getX() + 0.5);
double z = ctx.player().position().z - (src.getZ() + 0.5);
double fromStart = Math.sqrt(x * x + z * z);

state.setInput(Input.SNEAK, Baritone.settings().allowWalkOnMagmaBlocks.value && BlockStateInterface.get(ctx, ctx.player().blockPosition().below()).getBlock().equals(Blocks.MAGMA_BLOCK));

if (!playerFeet.equals(dest) || ab > 0.25) {
if (numTicks++ < 20 && fromStart < 1.25) {
MovementHelper.moveTowards(ctx, state, fakeDest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public static void cost(CalculationContext context, int x, int y, int z, int des
BlockState destWalkOn;
boolean descend = false;
boolean frostWalker = false;
boolean sneaking = false;
if (!MovementHelper.canWalkThrough(context, destX, y, destZ, destInto)) {
ascend = true;
if (!context.allowDiagonalAscend || !MovementHelper.canWalkThrough(context, x, y + 2, z) || !MovementHelper.canWalkOn(context, destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context, destX, y + 2, destZ)) {
Expand All @@ -142,7 +143,11 @@ public static void cost(CalculationContext context, int x, int y, int z, int des
// For either possible soul sand, that affects half of our walking
if (destWalkOn.getBlock() == Blocks.SOUL_SAND) {
multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2;
} else if (frostWalker) {
} else if (context.allowWalkOnMagmaBlocks && destWalkOn.getBlock().equals(Blocks.MAGMA_BLOCK)) {
multiplier += (SNEAK_ONE_BLOCK_COST - WALK_ONE_BLOCK_COST) / 2;
sneaking = true;
}
else if (frostWalker) {
// frostwalker lets us walk on water without the penalty
} else if (destWalkOn.getBlock() == Blocks.WATER) {
multiplier += context.walkOnWaterOnePenalty * SQRT_2;
Expand All @@ -154,12 +159,16 @@ public static void cost(CalculationContext context, int x, int y, int z, int des
if (fromDownBlock == Blocks.SOUL_SAND) {
multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2;
}
else if (context.allowWalkOnMagmaBlocks && fromDownBlock.equals(Blocks.MAGMA_BLOCK)) {
multiplier += (SNEAK_ONE_BLOCK_COST - WALK_ONE_BLOCK_COST) / 2;
sneaking = true;
}
BlockState cuttingOver1 = context.get(x, y - 1, destZ);
if (cuttingOver1.getBlock() == Blocks.MAGMA_BLOCK || MovementHelper.isLava(cuttingOver1)) {
if ((context.allowWalkOnMagmaBlocks && cuttingOver1.getBlock().equals(Blocks.MAGMA_BLOCK)) || MovementHelper.isLava(cuttingOver1)) {
return;
}
BlockState cuttingOver2 = context.get(destX, y - 1, z);
if (cuttingOver2.getBlock() == Blocks.MAGMA_BLOCK || MovementHelper.isLava(cuttingOver2)) {
if ((context.allowWalkOnMagmaBlocks && cuttingOver1.getBlock().equals(Blocks.MAGMA_BLOCK)) || MovementHelper.isLava(cuttingOver2)) {
return;
}
boolean water = false;
Expand Down Expand Up @@ -234,7 +243,7 @@ public static void cost(CalculationContext context, int x, int y, int z, int des
}
} else {
// only can sprint if not edging around
if (context.canSprint && !water) {
if (context.canSprint && !water && !sneaking) {
// If we aren't edging around anything, and we aren't in water
// We can sprint =D
// Don't check for soul sand, since we can sprint on that too
Expand Down Expand Up @@ -270,6 +279,7 @@ public MovementState updateState(MovementState state) {
if (sprint()) {
state.setInput(Input.SPRINT, true);
}
state.setInput(Input.SNEAK, Baritone.settings().allowWalkOnMagmaBlocks.value && MovementHelper.steppingOnBlocks(ctx).stream().anyMatch(block -> BlockStateInterface.get(ctx, block).getBlock().equals(Blocks.MAGMA_BLOCK)));
MovementHelper.moveTowards(ctx, state, dest);
return state;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.pathing.movement.MovementState.MovementTarget;
import baritone.utils.BlockStateInterface;
import baritone.utils.pathing.MutableMoveResult;
import java.util.HashSet;
import java.util.Optional;
Expand All @@ -40,6 +41,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.AirBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LadderBlock;
Expand Down Expand Up @@ -94,6 +96,11 @@ public MovementState updateState(MovementState state) {
Rotation targetRotation = null;
BlockState destState = ctx.world().getBlockState(dest);
Block destBlock = destState.getBlock();

if (BlockStateInterface.get(ctx, dest.below()).getBlock().equals(Blocks.MAGMA_BLOCK) && MovementHelper.steppingOnBlocks(ctx).stream().allMatch(block -> BlockStateInterface.get(ctx, block).getBlock() instanceof AirBlock)) {
state.setInput(Input.SNEAK, true);
}

boolean isWater = destState.getFluidState().getType() instanceof WaterFluid;
if (!isWater && willPlaceBucket() && !playerFeet.equals(dest)) {
if (!Inventory.isHotbarSlot(ctx.player().getInventory().findSlotMatchingItem(STACK_BUCKET_WATER)) || ctx.world().dimension() == Level.NETHER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ public static void cost(CalculationContext context, int x, int y, int z, Directi
return; // can't jump out of water
}
int maxJump;
if (standingOn.getBlock() == Blocks.SOUL_SAND) {
if (context.allowWalkOnMagmaBlocks && standingOn.getBlock() == Blocks.MAGMA_BLOCK) {
maxJump = 2;
}
else if (standingOn.getBlock() == Blocks.SOUL_SAND) {
maxJump = 2; // 1 block gap
} else {
if (context.canSprint) {
maxJump = 4;
} else {
maxJump = 3;
}
} else if (context.canSprint) {
maxJump = 4;
}
else {
maxJump = 3;
}

// check parkour jumps from smallest to largest for obstacles/walls and landing positions
Expand Down Expand Up @@ -262,6 +264,11 @@ public MovementState updateState(MovementState state) {
if (dist >= 4 || ascend) {
state.setInput(Input.SPRINT, true);
}

if (Baritone.settings().allowWalkOnMagmaBlocks.value && BlockStateInterface.get(ctx, ctx.playerFeet().below()).getBlock().equals(Blocks.MAGMA_BLOCK)) {
state.setInput(Input.SNEAK, true);
}

MovementHelper.moveTowards(ctx, state, dest);
if (ctx.playerFeet().equals(dest)) {
Block d = BlockStateInterface.getBlock(ctx, dest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,10 @@ public MovementState updateState(MovementState state) {
}


state.setInput(Input.SNEAK, ctx.player().position().y > dest.getY() || ctx.player().position().y < src.getY() + 0.2D); // delay placement by 1 tick for ncp compatibility
state.setInput(Input.SNEAK, true);
// if (ctx.player().position().y > dest.getY() || ctx.player().position().y < src.getY() + 0.2D) {
// state.setInput(Input.SNEAK, true); // delay placement by 1 tick for ncp compatibility
// }
// since (lower down) we only right click once player.isSneaking, and that happens the tick after we request to sneak

double diffX = ctx.player().position().x - (dest.getX() + 0.5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public static double cost(CalculationContext context, int x, int y, int z, int d
if (frostWalker || MovementHelper.canWalkOn(context, destX, y - 1, destZ, destOn)) { //this is a walk, not a bridge
double WC = WALK_ONE_BLOCK_COST;
boolean water = false;
boolean sneaking = false;
if (MovementHelper.isWater(pb0) || MovementHelper.isWater(pb1)) {
WC = context.waterWalkSpeed;
water = true;
Expand All @@ -98,6 +99,9 @@ public static double cost(CalculationContext context, int x, int y, int z, int d
}
if (srcDownBlock == Blocks.SOUL_SAND) {
WC += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2;
} else if (context.allowWalkOnMagmaBlocks && srcDownBlock.equals(Blocks.MAGMA_BLOCK)) {
sneaking = true;
WC += (SNEAK_ONE_BLOCK_COST - WALK_ONE_BLOCK_COST) / 2;
}
}
double hardness1 = MovementHelper.getMiningDurationTicks(context, destX, y, destZ, pb1, false);
Expand All @@ -106,7 +110,7 @@ public static double cost(CalculationContext context, int x, int y, int z, int d
}
double hardness2 = MovementHelper.getMiningDurationTicks(context, destX, y + 1, destZ, pb0, true); // only include falling on the upper block to break
if (hardness1 == 0 && hardness2 == 0) {
if (!water && context.canSprint) {
if (!water && !sneaking && context.canSprint) {
// If there's nothing in the way, and this isn't water, and we aren't sneak placing
// We can sprint =D
// Don't check for soul sand, since we can sprint on that too
Expand Down Expand Up @@ -213,12 +217,12 @@ public MovementState updateState(MovementState state) {
.setInput(Input.SPRINT, true);
}

//sneak may have been set to true in the PREPPING state while mining an adjacent block
state.setInput(Input.SNEAK, false);

Block fd = BlockStateInterface.get(ctx, src.below()).getBlock();
boolean ladder = fd == Blocks.LADDER || fd == Blocks.VINE;

//sneak may have been set to true in the PREPPING state while mining an adjacent block, but we still want it to be true if the player is about to go on magma
state.setInput(Input.SNEAK, Baritone.settings().allowWalkOnMagmaBlocks.value && MovementHelper.steppingOnBlocks(ctx).stream().anyMatch(block -> BlockStateInterface.get(ctx, block).getBlock().equals(Blocks.MAGMA_BLOCK)));

if (pb0.getBlock() instanceof DoorBlock || pb1.getBlock() instanceof DoorBlock) {
boolean notPassable = pb0.getBlock() instanceof DoorBlock && !MovementHelper.isDoorPassable(ctx, src, dest) || pb1.getBlock() instanceof DoorBlock && !MovementHelper.isDoorPassable(ctx, dest, src);
boolean canOpen = !(Blocks.IRON_DOOR.equals(pb0.getBlock()) || Blocks.IRON_DOOR.equals(pb1.getBlock()));
Expand Down