Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • 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 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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.