consolidate and simplify into MovementHelper.isBottomSlab

This commit is contained in:
Leijurv 2018-09-03 09:50:26 -07:00
parent 7473e34602
commit 4b2f98ccfd
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
5 changed files with 25 additions and 30 deletions

View File

@ -20,7 +20,10 @@ package baritone.chunk;
import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementHelper;
import baritone.utils.Helper; import baritone.utils.Helper;
import baritone.utils.pathing.PathingBlockType; import baritone.utils.pathing.PathingBlockType;
import net.minecraft.block.*; import net.minecraft.block.Block;
import net.minecraft.block.BlockDoublePlant;
import net.minecraft.block.BlockFlower;
import net.minecraft.block.BlockTallGrass;
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.ResourceLocation; import net.minecraft.util.ResourceLocation;
@ -108,7 +111,7 @@ public final class ChunkPacker implements Helper {
return PathingBlockType.WATER; return PathingBlockType.WATER;
} }
if (MovementHelper.avoidWalkingInto(block) || block.equals(Blocks.FLOWING_WATER) || (block instanceof BlockSlab && state.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM)) { if (MovementHelper.avoidWalkingInto(block) || block.equals(Blocks.FLOWING_WATER) || MovementHelper.isBottomSlab(state)) {
return PathingBlockType.AVOID; return PathingBlockType.AVOID;
} }
// We used to do an AABB check here // We used to do an AABB check here

View File

@ -270,6 +270,16 @@ public interface MovementHelper extends ActionCosts, Helper {
return 0; // we won't actually mine it, so don't check fallings above return 0; // we won't actually mine it, so don't check fallings above
} }
static boolean isBottomSlab(IBlockState state) {
return state.getBlock() instanceof BlockSlab
&& !((BlockSlab) state.getBlock()).isDouble()
&& state.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM;
}
static boolean isBottomSlab(BlockPos pos) {
return isBottomSlab(BlockStateInterface.get(pos));
}
/** /**
* The entity the player is currently looking at * The entity the player is currently looking at
* *

View File

@ -28,7 +28,6 @@ import baritone.utils.InputOverrideHandler;
import baritone.utils.Utils; import baritone.utils.Utils;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockFalling; import net.minecraft.block.BlockFalling;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
@ -59,25 +58,12 @@ public class MovementAscend extends Movement {
return COST_INF; return COST_INF;
} }
// we can jump from soul sand, but not from a bottom slab // we can jump from soul sand, but not from a bottom slab
// the only thing we can ascend onto from a bottom slab is another bottom slab boolean jumpingFromBottomSlab = MovementHelper.isBottomSlab(srcDown);
boolean jumpingFromBottomSlab = false;
if (srcDown.getBlock() instanceof BlockSlab) {
BlockSlab jumpingFrom = (BlockSlab) srcDown.getBlock();
if (!jumpingFrom.isDouble()) {
jumpingFromBottomSlab = srcDown.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM;
}
}
IBlockState toPlace = BlockStateInterface.get(positionToPlace); IBlockState toPlace = BlockStateInterface.get(positionToPlace);
boolean jumpingToBottomSlab = false; boolean jumpingToBottomSlab = MovementHelper.isBottomSlab(toPlace);
if (toPlace.getBlock() instanceof BlockSlab) {
BlockSlab jumpingTo = (BlockSlab) toPlace.getBlock(); if (jumpingFromBottomSlab && !jumpingToBottomSlab) {
if (!jumpingTo.isDouble() && toPlace.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { return COST_INF;// the only thing we can ascend onto from a bottom slab is another bottom slab
jumpingToBottomSlab = true;
} else if (jumpingFromBottomSlab) {
return COST_INF;
}
} else if (jumpingFromBottomSlab) {
return COST_INF;
} }
if (!MovementHelper.canWalkOn(positionToPlace, toPlace)) { if (!MovementHelper.canWalkOn(positionToPlace, toPlace)) {
if (!context.hasThrowaway()) { if (!context.hasThrowaway()) {
@ -189,9 +175,8 @@ public class MovementAscend extends Movement {
return state.setStatus(MovementStatus.UNREACHABLE); return state.setStatus(MovementStatus.UNREACHABLE);
} }
MovementHelper.moveTowards(state, dest); MovementHelper.moveTowards(state, dest);
if (jumpingOnto.getBlock() instanceof BlockSlab && !((BlockSlab) jumpingOnto.getBlock()).isDouble() && jumpingOnto.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { if (MovementHelper.isBottomSlab(jumpingOnto)) {
IBlockState from = BlockStateInterface.get(src.down()); if (!MovementHelper.isBottomSlab(src.down())) {
if (!(from.getBlock() instanceof BlockSlab) || ((BlockSlab) from.getBlock()).isDouble() || from.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP) {
return state; // don't jump while walking from a non double slab into a bottom slab return state; // don't jump while walking from a non double slab into a bottom slab
} }
} }

View File

@ -27,7 +27,6 @@ import baritone.pathing.movement.MovementState.MovementTarget;
import baritone.utils.*; import baritone.utils.*;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockFalling; import net.minecraft.block.BlockFalling;
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.init.Items; import net.minecraft.init.Items;
@ -55,10 +54,8 @@ public class MovementFall extends Movement {
if (!MovementHelper.canWalkOn(dest.down(), fallOnto)) { if (!MovementHelper.canWalkOn(dest.down(), fallOnto)) {
return COST_INF; return COST_INF;
} }
if (fallOnto.getBlock() instanceof BlockSlab) { if (MovementHelper.isBottomSlab(fallOnto)) {
if (!((BlockSlab) fallOnto.getBlock()).isDouble() && fallOnto.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { return COST_INF; // falling onto a half slab is really glitchy, and can cause more fall damage than we'd expect
return COST_INF; // falling onto a half slab is really glitchy, and can cause more fall damage than we'd expect
}
} }
double placeBucketCost = 0.0; double placeBucketCost = 0.0;
if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > context.maxFallHeightNoWater()) { if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > context.maxFallHeightNoWater()) {

View File

@ -150,7 +150,7 @@ public class MovementPillar extends Movement {
if (playerFeet().equals(against.up()) || playerFeet().equals(dest)) { if (playerFeet().equals(against.up()) || playerFeet().equals(dest)) {
return state.setStatus(MovementState.MovementStatus.SUCCESS); return state.setStatus(MovementState.MovementStatus.SUCCESS);
} }
if (fromDown.getBlock() instanceof BlockSlab && !((BlockSlab) fromDown.getBlock()).isDouble() && fromDown.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { if (MovementHelper.isBottomSlab(src.down())) {
state.setInput(InputOverrideHandler.Input.JUMP, true); state.setInput(InputOverrideHandler.Input.JUMP, true);
} }
/* /*