Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.12.2] Getting a boat-like entity to go up stairs?


jonesto95
 Share

Recommended Posts

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 by jonesto95
Link to comment
Share on other sites

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 by jonesto95
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.