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.

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

Featured Replies

Posted

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

  • Author

Or, if anyone knows where the code is for shields reflecting arrows? The only related thing I can find in Shields is EntityLivingBase.knockback but that does not apply to arrows. 

  • Author

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

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.