Skip to content

Commit 9c84fa5

Browse files
authored
Merge branch 'cabaletta:1.19.4' into bridging-improvements
2 parents 1a3d302 + 95212d6 commit 9c84fa5

File tree

10 files changed

+68
-19
lines changed

10 files changed

+68
-19
lines changed

src/api/java/baritone/api/Settings.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,11 @@ public final class Settings {
15501550
*/
15511551
public final Setting<Boolean> elytraChatSpam = new Setting<>(false);
15521552

1553+
/**
1554+
* Sneak when magma blocks are under feet
1555+
*/
1556+
public final Setting<Boolean> allowWalkOnMagmaBlocks = new Setting<>(false);
1557+
15531558
/**
15541559
* A map of lowercase setting field names to their respective setting
15551560
*/

src/main/java/baritone/pathing/movement/CalculationContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public class CalculationContext {
7979
public double backtrackCostFavoringCoefficient;
8080
public double jumpPenalty;
8181
public final double walkOnWaterOnePenalty;
82+
public final boolean allowWalkOnMagmaBlocks;
8283
public final BetterWorldBorder worldBorder;
8384

8485
public final PrecomputedData precomputedData;
@@ -125,6 +126,7 @@ public CalculationContext(IBaritone baritone, boolean forUseOnAnotherThread) {
125126
this.backtrackCostFavoringCoefficient = Baritone.settings().backtrackCostFavoringCoefficient.value;
126127
this.jumpPenalty = Baritone.settings().jumpPenalty.value;
127128
this.walkOnWaterOnePenalty = Baritone.settings().walkOnWaterOnePenalty.value;
129+
this.allowWalkOnMagmaBlocks = Baritone.settings().allowWalkOnMagmaBlocks.value;
128130
// why cache these things here, why not let the movements just get directly from settings?
129131
// because if some movements are calculated one way and others are calculated another way,
130132
// then you get a wildly inconsistent path that isn't optimal for either scenario.

src/main/java/baritone/pathing/movement/MovementHelper.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import net.minecraft.world.phys.Vec3;
5353
import org.jetbrains.annotations.NotNull;
5454

55+
import java.util.ArrayList;
5556
import java.util.List;
5657
import java.util.Optional;
5758

@@ -387,7 +388,7 @@ static boolean isHorizontalBlockPassable(BlockPos blockPos, BlockState blockStat
387388
static boolean avoidWalkingInto(BlockState state) {
388389
Block block = state.getBlock();
389390
return !state.getFluidState().isEmpty()
390-
|| block == Blocks.MAGMA_BLOCK
391+
|| (block == Blocks.MAGMA_BLOCK && !Baritone.settings().allowWalkOnMagmaBlocks.value)
391392
|| block == Blocks.CACTUS
392393
|| block == Blocks.SWEET_BERRY_BUSH
393394
|| block instanceof BaseFireBlock
@@ -423,7 +424,7 @@ static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, BlockStat
423424

424425
static Ternary canWalkOnBlockState(BlockState state) {
425426
Block block = state.getBlock();
426-
if (isBlockNormalCube(state) && block != Blocks.MAGMA_BLOCK && block != Blocks.BUBBLE_COLUMN && block != Blocks.HONEY_BLOCK) {
427+
if (isBlockNormalCube(state) && (block != Blocks.MAGMA_BLOCK || Baritone.settings().allowWalkOnMagmaBlocks.value) && block != Blocks.BUBBLE_COLUMN && block != Blocks.HONEY_BLOCK) {
427428
return YES;
428429
}
429430
if (block instanceof AzaleaBlock) {
@@ -859,4 +860,16 @@ static boolean isTransparent(Block b) {
859860
b == Blocks.LAVA ||
860861
b == Blocks.WATER;
861862
}
863+
864+
static List<BetterBlockPos> steppingOnBlocks(IPlayerContext ctx) {
865+
List<BetterBlockPos> blocks = new ArrayList<>();
866+
for (byte x = -1; x <= 1; x++) {
867+
for (byte z = -1; z <= 1; z++) {
868+
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))) {
869+
blocks.add(new BetterBlockPos(ctx.player().getBlockX() + x, ctx.player().getBlockY() - 1, ctx.player().getBlockZ() + z));
870+
}
871+
}
872+
}
873+
return blocks;
874+
}
862875
}

src/main/java/baritone/pathing/movement/movements/MovementAscend.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ public static double cost(CalculationContext context, int x, int y, int z, int d
131131
}
132132
} else {
133133
// jumpingFromBottomSlab must be false
134-
if (toPlace.getBlock() == Blocks.SOUL_SAND) {
134+
if (toPlace.is(Blocks.SOUL_SAND)) {
135135
walk = WALK_ONE_OVER_SOUL_SAND_COST;
136+
} else if (toPlace.is(Blocks.MAGMA_BLOCK)) {
137+
walk = SNEAK_ONE_BLOCK_COST;
136138
} else {
137139
walk = Math.max(JUMP_ONE_BLOCK_COST, WALK_ONE_BLOCK_COST);
138140
}
@@ -188,6 +190,9 @@ public MovementState updateState(MovementState state) {
188190
return state;
189191
}
190192
MovementHelper.moveTowards(ctx, state, dest);
193+
194+
state.setInput(Input.SNEAK, Baritone.settings().allowWalkOnMagmaBlocks.value && jumpingOnto.is(Blocks.MAGMA_BLOCK));
195+
191196
if (MovementHelper.isBottomSlab(jumpingOnto) && !MovementHelper.isBottomSlab(BlockStateInterface.get(ctx, src.below()))) {
192197
return state; // don't jump while walking from a non double slab into a bottom slab
193198
}

src/main/java/baritone/pathing/movement/movements/MovementDescend.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package baritone.pathing.movement.movements;
1919

20+
import baritone.Baritone;
2021
import baritone.api.IBaritone;
2122
import baritone.api.pathing.movement.MovementStatus;
2223
import baritone.api.utils.BetterBlockPos;
@@ -255,6 +256,9 @@ public MovementState updateState(MovementState state) {
255256
double x = ctx.player().position().x - (src.getX() + 0.5);
256257
double z = ctx.player().position().z - (src.getZ() + 0.5);
257258
double fromStart = Math.sqrt(x * x + z * z);
259+
260+
state.setInput(Input.SNEAK, Baritone.settings().allowWalkOnMagmaBlocks.value && ctx.world().getBlockState(ctx.player().blockPosition().below()).is(Blocks.MAGMA_BLOCK));
261+
258262
if (!playerFeet.equals(dest) || ab > 0.25) {
259263
if (numTicks++ < 20 && fromStart < 1.25) {
260264
MovementHelper.moveTowards(ctx, state, fakeDest);

src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public static void cost(CalculationContext context, int x, int y, int z, int des
118118
BlockState destWalkOn;
119119
boolean descend = false;
120120
boolean frostWalker = false;
121+
boolean sneaking = false;
121122
if (!MovementHelper.canWalkThrough(context, destX, y, destZ, destInto)) {
122123
ascend = true;
123124
if (!context.allowDiagonalAscend || !MovementHelper.canWalkThrough(context, x, y + 2, z) || !MovementHelper.canWalkOn(context, destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context, destX, y + 2, destZ)) {
@@ -140,8 +141,11 @@ public static void cost(CalculationContext context, int x, int y, int z, int des
140141
}
141142
double multiplier = WALK_ONE_BLOCK_COST;
142143
// For either possible soul sand, that affects half of our walking
143-
if (destWalkOn.getBlock() == Blocks.SOUL_SAND) {
144+
if (destWalkOn.is(Blocks.SOUL_SAND)) {
144145
multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2;
146+
} else if (context.allowWalkOnMagmaBlocks && destWalkOn.is(Blocks.MAGMA_BLOCK)) {
147+
multiplier += (SNEAK_ONE_BLOCK_COST - WALK_ONE_BLOCK_COST) / 2;
148+
sneaking = true;
145149
} else if (frostWalker) {
146150
// frostwalker lets us walk on water without the penalty
147151
} else if (destWalkOn.getBlock() == Blocks.WATER) {
@@ -153,13 +157,16 @@ public static void cost(CalculationContext context, int x, int y, int z, int des
153157
}
154158
if (fromDownBlock == Blocks.SOUL_SAND) {
155159
multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2;
160+
} else if (context.allowWalkOnMagmaBlocks && fromDownBlock.equals(Blocks.MAGMA_BLOCK)) {
161+
multiplier += (SNEAK_ONE_BLOCK_COST - WALK_ONE_BLOCK_COST) / 2;
162+
sneaking = true;
156163
}
157164
BlockState cuttingOver1 = context.get(x, y - 1, destZ);
158-
if (cuttingOver1.getBlock() == Blocks.MAGMA_BLOCK || MovementHelper.isLava(cuttingOver1)) {
165+
if ((!context.allowWalkOnMagmaBlocks && cuttingOver1.is(Blocks.MAGMA_BLOCK)) || MovementHelper.isLava(cuttingOver1)) {
159166
return;
160167
}
161168
BlockState cuttingOver2 = context.get(destX, y - 1, z);
162-
if (cuttingOver2.getBlock() == Blocks.MAGMA_BLOCK || MovementHelper.isLava(cuttingOver2)) {
169+
if ((!context.allowWalkOnMagmaBlocks && cuttingOver1.is(Blocks.MAGMA_BLOCK)) || MovementHelper.isLava(cuttingOver2)) {
163170
return;
164171
}
165172
boolean water = false;
@@ -234,7 +241,7 @@ public static void cost(CalculationContext context, int x, int y, int z, int des
234241
}
235242
} else {
236243
// only can sprint if not edging around
237-
if (context.canSprint && !water) {
244+
if (context.canSprint && !water && !sneaking) {
238245
// If we aren't edging around anything, and we aren't in water
239246
// We can sprint =D
240247
// Don't check for soul sand, since we can sprint on that too
@@ -270,6 +277,7 @@ public MovementState updateState(MovementState state) {
270277
if (sprint()) {
271278
state.setInput(Input.SPRINT, true);
272279
}
280+
state.setInput(Input.SNEAK, Baritone.settings().allowWalkOnMagmaBlocks.value && MovementHelper.steppingOnBlocks(ctx).stream().anyMatch(block -> ctx.world().getBlockState(block).is(Blocks.MAGMA_BLOCK)));
273281
MovementHelper.moveTowards(ctx, state, dest);
274282
return state;
275283
}

src/main/java/baritone/pathing/movement/movements/MovementFall.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public MovementState updateState(MovementState state) {
9494
Rotation targetRotation = null;
9595
BlockState destState = ctx.world().getBlockState(dest);
9696
Block destBlock = destState.getBlock();
97+
98+
if (ctx.world().getBlockState(dest.below()).is(Blocks.MAGMA_BLOCK) && MovementHelper.steppingOnBlocks(ctx).stream().allMatch(block -> MovementHelper.canWalkThrough(ctx, block))) {
99+
state.setInput(Input.SNEAK, true);
100+
}
101+
97102
boolean isWater = destState.getFluidState().getType() instanceof WaterFluid;
98103
if (!isWater && willPlaceBucket() && !playerFeet.equals(dest)) {
99104
if (!Inventory.isHotbarSlot(ctx.player().getInventory().findSlotMatchingItem(STACK_BUCKET_WATER)) || ctx.world().dimension() == Level.NETHER) {

src/main/java/baritone/pathing/movement/movements/MovementParkour.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ public static void cost(CalculationContext context, int x, int y, int z, Directi
102102
return; // can't jump out of water
103103
}
104104
int maxJump;
105-
if (standingOn.getBlock() == Blocks.SOUL_SAND) {
105+
if (context.allowWalkOnMagmaBlocks && standingOn.is(Blocks.MAGMA_BLOCK)) {
106+
maxJump = 2;
107+
} else if (standingOn.getBlock() == Blocks.SOUL_SAND) {
106108
maxJump = 2; // 1 block gap
109+
} else if (context.canSprint) {
110+
maxJump = 4;
107111
} else {
108-
if (context.canSprint) {
109-
maxJump = 4;
110-
} else {
111-
maxJump = 3;
112-
}
112+
maxJump = 3;
113113
}
114114

115115
// check parkour jumps from smallest to largest for obstacles/walls and landing positions
@@ -262,6 +262,10 @@ public MovementState updateState(MovementState state) {
262262
if (dist >= 4 || ascend) {
263263
state.setInput(Input.SPRINT, true);
264264
}
265+
if (Baritone.settings().allowWalkOnMagmaBlocks.value && ctx.world().getBlockState(ctx.playerFeet().below()).is(Blocks.MAGMA_BLOCK)) {
266+
state.setInput(Input.SNEAK, true);
267+
}
268+
265269
MovementHelper.moveTowards(ctx, state, dest);
266270
if (ctx.playerFeet().equals(dest)) {
267271
Block d = BlockStateInterface.getBlock(ctx, dest);

src/main/java/baritone/pathing/movement/movements/MovementPillar.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ public MovementState updateState(MovementState state) {
229229
return state.setStatus(MovementStatus.UNREACHABLE);
230230
}
231231

232-
233-
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
232+
state.setInput(Input.SNEAK, true);
234233
// since (lower down) we only right click once player.isSneaking, and that happens the tick after we request to sneak
235234

236235
double diffX = ctx.player().position().x - (dest.getX() + 0.5);

src/main/java/baritone/pathing/movement/movements/MovementTraverse.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public static double cost(CalculationContext context, int x, int y, int z, int d
8585
if (frostWalker || MovementHelper.canWalkOn(context, destX, y - 1, destZ, destOn)) { //this is a walk, not a bridge
8686
double WC = WALK_ONE_BLOCK_COST;
8787
boolean water = false;
88+
boolean sneaking = false;
8889
if (MovementHelper.isWater(pb0) || MovementHelper.isWater(pb1)) {
8990
WC = context.waterWalkSpeed;
9091
water = true;
@@ -98,6 +99,9 @@ public static double cost(CalculationContext context, int x, int y, int z, int d
9899
}
99100
if (srcDownBlock == Blocks.SOUL_SAND) {
100101
WC += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2;
102+
} else if (context.allowWalkOnMagmaBlocks && srcDownBlock.equals(Blocks.MAGMA_BLOCK)) {
103+
sneaking = true;
104+
WC += (SNEAK_ONE_BLOCK_COST - WALK_ONE_BLOCK_COST) / 2;
101105
}
102106
}
103107
double hardness1 = MovementHelper.getMiningDurationTicks(context, destX, y, destZ, pb1, false);
@@ -106,7 +110,7 @@ public static double cost(CalculationContext context, int x, int y, int z, int d
106110
}
107111
double hardness2 = MovementHelper.getMiningDurationTicks(context, destX, y + 1, destZ, pb0, true); // only include falling on the upper block to break
108112
if (hardness1 == 0 && hardness2 == 0) {
109-
if (!water && context.canSprint) {
113+
if (!water && !sneaking && context.canSprint) {
110114
// If there's nothing in the way, and this isn't water, and we aren't sneak placing
111115
// We can sprint =D
112116
// Don't check for soul sand, since we can sprint on that too
@@ -213,12 +217,12 @@ public MovementState updateState(MovementState state) {
213217
.setInput(Input.SPRINT, true);
214218
}
215219

216-
//sneak may have been set to true in the PREPPING state while mining an adjacent block
217-
state.setInput(Input.SNEAK, false);
218-
219220
Block fd = BlockStateInterface.get(ctx, src.below()).getBlock();
220221
boolean ladder = fd == Blocks.LADDER || fd == Blocks.VINE;
221222

223+
//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
224+
state.setInput(Input.SNEAK, Baritone.settings().allowWalkOnMagmaBlocks.value && MovementHelper.steppingOnBlocks(ctx).stream().anyMatch(block -> ctx.world().getBlockState(block).is(Blocks.MAGMA_BLOCK)));
225+
222226
if (pb0.getBlock() instanceof DoorBlock || pb1.getBlock() instanceof DoorBlock) {
223227
boolean notPassable = pb0.getBlock() instanceof DoorBlock && !MovementHelper.isDoorPassable(ctx, src, dest) || pb1.getBlock() instanceof DoorBlock && !MovementHelper.isDoorPassable(ctx, dest, src);
224228
boolean canOpen = !(Blocks.IRON_DOOR.equals(pb0.getBlock()) || Blocks.IRON_DOOR.equals(pb1.getBlock()));

0 commit comments

Comments
 (0)