Jump to content

[1.12.2] Finding out which side of the block the collision happened on?


stepsword

Recommended Posts

Not really sure how to search for this since my searches come up with stuff I'm not looking for. When an entity collides with a block, is there a simple way to get the face of the block that it collided with (i.e. North South East West Up Down)? I was overriding "onEntityCollidedWithBlock" but I could put it somewhere else if it's easier to get elsewhere. Any ideas?

 

I guess one option would be to get the position of the entity and see if it's NSEWUD compared to the block? 

Edited by stepsword
Link to comment
Share on other sites

Thanks, @diesieben07. I did see that part of the code, namely this:

if (amount > 0.0F && this.canBlockDamageSource(source))
{
    this.damageShield(amount);
    amount = 0.0F;

    if (!source.isProjectile())
    {
        Entity entity = source.getImmediateSource();

        if (entity instanceof EntityLivingBase)
        {
            this.blockUsingShield((EntityLivingBase)entity);
        }
    }

    flag = true;
}

 

But blockUsingShield doesn't actually redirect the arrow - it only calls .knockback() if the damage source is a living entity. It may be obvious from my above posts but I was trying to reflect arrows off a block, so I wanted to see how shields coded the "bounce" part (and for some reason I cannot find the code for that animation anywhere), and then I could manually do the NSEWUD check.

 

But anyway I ended up finding the problem that was preventing bounces - ArrowEntity sets a private variable "inGround" which as far as I can tell can't be modified by any setter methods, and it seems to prevents the arrow from moving once it's buried in a block. Ended up using ObfuscationReflectionHelper to change it - I don't really like that "solution" since it seems hacky, but I'll keep it til I find something better if it exists. 

Edited by stepsword
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.
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.