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
	public BlockPos onGroundAir() {
		BlockPos pos = this.getPosition(); 
	//	for(int width = 1; width <= this.width / 2; width++) {
		    for(int y = 1; y <= 3.4; y++) { 
		      pos = new BlockPos(posX - width + width, posY - y * MathX.clamp(this.getScale(), 0.1, 1), posZ - width + width);
		    }
	//	}
		return pos;
	}
	
	public boolean onSolidGround() {
		IBlockState state = world.getBlockState(onGroundAir());
		return !state.getMaterial().isSolid();
		
	}

I had these two methods, basically they detect if the ground 3.4 blocks below the dragon is Air, if not then the dragon is setFlying to false, basically it detects if the dragon is onGround or not, and I cant use the normal vailla onGround method because they require the dragon to be directly sticking to the block and if at  least one block above is blocking it looks silly flying on the ground. I want to do it again but in a bigger area "square" with more blocks around, because the method above is only one line tall and is the middle of the dragon. Ill use it if the area above dragon is bug enough so it is able to fly around. They get stuck flying below the trees. this question is pretty basic.

Edited by TheRPGAdventurer

Is that your actual code or is that pseudo code?

 

Edit: 

The current code you have doesn't even need a loop. The way it's written,  it is only checking a single block position using the value at the end of the loop, not a 1 block high box the width of the entity. "y" will never be 3.4 because it is declared as an integer. 

 To do what it looks like your code was intended to work, and to check an entire box around the entity, you'd need roughly the following: 

// check a 1 block high plane below
public boolean onSolidGround()  {
    double y = this.posY - 3.4; // adjust this to the height to check

    for (double z = posZ - width/2; y < posZ + width/2; y++) {
        for(double x = posX - width/2; x < posX + width/2; x++) {
            if (!isSolid(new BlockPos(x, y, z)))
                return false;
        }
    }
    return true;
}

// check an entire box surrounding
public boolean onSolidGround2()  {
    double offsetStart = 0.0; // set this as how far below to start
    double offsetEnd = 0.0; // set this as how far above to stop
    
    for (double y = posY - offsetStart; y < y + height + offsetEnd; y++ ) {
        for (double z = posZ - width / 2; y < posZ + width / 2; y++) {
            for (double x = posX - width / 2; x < posX + width / 2; x++) {
                if (!isSolid(new BlockPos(x, y, z)))
                    return false;
            }
        }
    }
    return true;
}

public boolean isSolid(BlockPos pos) {
    IBlockState state = world.getBlockState(pos);
    return !state.getMaterial().isSolid();
}

 

Edited by lehjr

  • Author

ok so this method just checks if the dragon's block in 3.4 solid, it wont stand but fly on top of a 1 block thick area. so how do I check all blocks 3.4 below on the dragon is solid?

In my response, onSolidGround() will actually check if the entire area under the entity as you described what you thought your original methods were doing in your original post.

 

onSolidGround2() (naming? ) will check a box. Set offsetStart  to how far under the entity you want to start. Set offsetEnd to how far above you want to start. 

 

isSolid is just a helper for both. 

 

 

 

 

 

 

 

 

 

 

 

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.