fixed fall detection

This commit is contained in:
Leijurv 2018-08-07 07:39:55 -07:00
parent b7eaf881a0
commit b5a6112bde
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
3 changed files with 19 additions and 9 deletions

View File

@ -56,6 +56,10 @@ public interface MovementHelper extends ActionCosts, Helper {
*/ */
static boolean canWalkThrough(BlockPos pos) { static boolean canWalkThrough(BlockPos pos) {
IBlockState state = BlockStateInterface.get(pos); IBlockState state = BlockStateInterface.get(pos);
return canWalkThrough(pos, state);
}
static boolean canWalkThrough(BlockPos pos, IBlockState state) {
Block block = state.getBlock(); Block block = state.getBlock();
if (block instanceof BlockLilyPad if (block instanceof BlockLilyPad
|| block instanceof BlockFire || block instanceof BlockFire
@ -193,6 +197,7 @@ public interface MovementHelper extends ActionCosts, Helper {
return new MovementDescend(pos, destDown); return new MovementDescend(pos, destDown);
} }
} }
System.out.println(dest + " descend distance!");
// we're clear for a fall 2 // we're clear for a fall 2
// let's see how far we can fall // let's see how far we can fall
for (int fallHeight = 3; true; fallHeight++) { for (int fallHeight = 3; true; fallHeight++) {
@ -200,14 +205,15 @@ public interface MovementHelper extends ActionCosts, Helper {
if (onto.getY() <= 0) { if (onto.getY() <= 0) {
break; break;
} }
if (BlockStateInterface.isAir(onto)) { IBlockState ontoBlock = BlockStateInterface.get(onto);
if (BlockStateInterface.isWater(ontoBlock.getBlock())) {
return new MovementFall(pos, onto);
}
if (canWalkThrough(onto, ontoBlock)) {
continue; continue;
} }
if (BlockStateInterface.isWater(onto)) { if (canWalkOn(onto, ontoBlock)) {
return new MovementFall(pos, onto); return new MovementFall(pos, onto.up());
}
if (MovementHelper.canWalkOn(onto)) {
return new MovementFall(pos, onto);
} }
break; break;
} }

View File

@ -70,6 +70,10 @@ public class BlockStateInterface {
return BlockStateInterface.getBlock(pos).equals(Blocks.AIR); return BlockStateInterface.getBlock(pos).equals(Blocks.AIR);
} }
public static boolean isAir(IBlockState state) {
return state.getBlock().equals(Blocks.AIR);
}
static boolean canFall(BlockPos pos) { static boolean canFall(BlockPos pos) {
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling; return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
} }