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 have a block that doesn't take up a full block - it's placed on the side of existing blocks (and is therefore directional). It has a hitbox of about 16x16x2 pixels and does not collide, so it can be entered.

How should I detect when an entity's hitbox intersects with the block's? I simply need to return a boolean for an entity (a check triggered by entityInside, which covers the entire 16x16x16 cube) depending on whether they're in the block's hitbox or not. I tried using level.getEntities, but that seems to be only searching for entities' origins. There are a few other methods: several versions of getEntities, one getEntityCollisions, and one getCollisions, but those don't seem to be returning any hits when I step into the block either. Any advice?

You can override BlockBehaviour.entityInside() on your block to detect this. Look at BasePressurePlateBlock (activates the plate) or BaseFireBlock (sets entity on fire). 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • Author

entityInside() detects the entirety of the 16x16x16-pixel block. I want something that only detects when the entity is inside the small part of it that has a hitbox.

You can do additional checks yourself in that method.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • Author

Yes, I know. That's what I'm asking for help with.

12 hours ago, Syric said:

I simply need to return a boolean for an entity (a check triggered by entityInside, which covers the entire 16x16x16 cube) depending on whether they're in the block's hitbox or not.

I'm not sure which methods to use to check if their hitbox intersects the block's.

There are a few methods available.

There is AABB which lets you calculate an intersect(). For the entity you would just use entity.getBoundingBox(), the other one would be whatever part of your block you want to check.

There is a pretty complicated entity.collideBoundingBox() that lets you pass an intersection of shapes.

Or you could just do your own (optimised?) calculation based on the entity.getBoundingBox()

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • Author

Here's my solution, based on entity.isColliding(). You can just pass your block's VoxelShape in as shape; this block is directional so it needs a reference to the map.

This method returns 'true' if the hitbox of the entity in question intersects the provided shape, in this case the shape of a non-colliding block.

    private boolean isColliding(BlockPos pos, BlockState state, Entity entity) {
        VoxelShape shape = SHAPE_MAP.get(state.getValue(FACING));
        VoxelShape positionedShape = shape.move((double)pos.getX(), (double)pos.getY(), (double)pos.getZ());
        return Shapes.joinIsNotEmpty(positionedShape, Shapes.create(entity.getBoundingBox()), BooleanOp.AND);
    }

 

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.