Jump to content

[1.10.2] [SOLVED] Apply damage when colliding with block


Recommended Posts

Posted (edited)

This seems like it should be straightforward. I have a campfire block, and I want players to take damage when they run into it. I copied this code directly from BlockCactus, but it doesn't work. Instead of taking damage, the player auto-jumps on top of the block.

 

    protected static final AxisAlignedBB CACTUS_COLLISION_AABB = new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 0.9375D, 0.9375D);
    protected static final AxisAlignedBB CACTUS_AABB = new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 1.0D, 0.9375D);

	@Override
    public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos)
    {
        return CACTUS_COLLISION_AABB;
    }

    @SideOnly(Side.CLIENT)
    public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World worldIn, BlockPos pos)
    {
        return CACTUS_AABB.offset(pos);
    }

	@Override
    public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
    {
        entityIn.attackEntityFrom(DamageSource.cactus, 1.0F);
    }

 

I saw a comment somewhere about using addCollisionBoxToList, so I played around with that a little. I didn't get anywhere with that. What do I need to do here?

Edited by Daeruin
Posted

Make the block shorter than 1 block tall.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

You need to override Block#isFullCube to return false. This will stop players being pushed out of the block and stop them suffocating in the block.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
15 minutes ago, Draco18s said:

Make the block shorter than 1 block tall.

I am using the AxisAlignedBB measurements shown in my original post. I copied them directly from BlockCactus.

 

1 minute ago, Choonster said:

You need to override Block#isFullCube to return false. This will stop players being pushed out of the block and stop them suffocating in the block.

I am already doing this. Sorry, I didn't include it in my original post.

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

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

Announcements



×
×
  • Create New...

Important Information

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