Posted February 3, 20187 yr I've made an entity similar to a boat, and just like a boat it gets stuck on slabs, stairs, and even from transitioning from grass paths to normal dirt. I've been looking through the related code for a horse but I'm not finding anything that allows it to "climb" these things. Does anybody know what code allows me to do this? Edited February 3, 20187 yr by jonesto95
February 4, 20187 yr Author I've settled on just climbing slabs, and here's something I've put together that seems to work well. If anything could be improved upon, let me know. Spoiler // Checks if entity is approaching a slab when it is on a full block private boolean checkForSlab() { BlockPos currentPos = getPosition(); boolean bool1 = false; switch(getHorizontalFacing()) { case NORTH: bool1 = world.getBlockState(currentPos.north()).getBlock() instanceof BlockSlab; break; case EAST: bool1 = world.getBlockState(currentPos.east()).getBlock() instanceof BlockSlab; break; case SOUTH: bool1 = world.getBlockState(currentPos.south()).getBlock() instanceof BlockSlab; break; case WEST: bool1 = world.getBlockState(currentPos.west()).getBlock() instanceof BlockSlab; break; default: bool1 = false; } int dX = 0; if(Math.abs(motionX) > 0.0001F) dX = (motionX > 0) ? 1 : -1; int dZ = 0; if(Math.abs(motionZ) > 0.0001F) dZ = (motionZ > 0) ? 1 : -1; BlockPos futurePosition = this.getPosition().add(dX, 0, dZ); Block futureBlock = world.getBlockState(futurePosition).getBlock(); return bool1 || (futureBlock instanceof BlockSlab); } // Checks if an entity is approaching a full block when it is on a slab. private boolean checkForFullBlock() { BlockPos currentPos = getPosition(); boolean bool1 = true; Block testBlock; switch(getHorizontalFacing()) { case NORTH: testBlock = world.getBlockState(currentPos.north()).getBlock(); bool1 = testBlock instanceof BlockSlab || testBlock instanceof BlockAir; break; case EAST: testBlock = world.getBlockState(currentPos.east()).getBlock(); bool1 = testBlock instanceof BlockSlab || testBlock instanceof BlockAir; break; case SOUTH: testBlock = world.getBlockState(currentPos.south()).getBlock(); bool1 = testBlock instanceof BlockSlab || testBlock instanceof BlockAir; break; case WEST: testBlock = world.getBlockState(currentPos.west()).getBlock(); bool1 = testBlock instanceof BlockSlab || testBlock instanceof BlockAir; break; default: bool1 = true; break; } bool1 = !bool1; System.out.println(bool1); int dX = 0; if(Math.abs(motionX) > 0.0001F) dX = (motionX > 0) ? 1 : -1; int dZ = 0; if(Math.abs(motionZ) > 0.0001F) dZ = (motionZ > 0) ? 1 : -1; BlockPos futurePosition = this.getPosition().add(dX, 0, dZ); testBlock = world.getBlockState(futurePosition.down()).getBlock(); return bool1 || !(testBlock instanceof BlockSlab || testBlock instanceof BlockAir); } Edited February 4, 20187 yr by jonesto95
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.