Jump to content

New hook to override dismounting entities, and the location of dismounting


Recommended Posts

Posted

Currently, by default, when dismounting an entity, you teleport away from the entity. If there were a way to override this location via a DismountEntityEvent, the possibility to alter it based on various factors would be near endless. Example:

 

I have a mod, where you right click a chair, and it summons a "seat" entity, then mounts it. When you dismount it, you are teleported several blocks from the chair. With a hook to override this, I could make the player dismount the seat to a location relative to the seat; by grabbing the block-metadata at the seat coordinates, and applying a delta position. Then I could have it drop the player off right in front of the chair block, rather than 3 blocks away.

 

Any alternative ideas/workarounds? Anybody support this idea?

Posted

The problem is:

 

a) Then you are using the update method of the seat to constantly test that the player that was on the seat previously, is no longer there (Why store an additional entity field if not necessary)

b) The teleporting will look awful if jumping from pre-set location "A" to new location "B". I have just tried this, and it actually looks fine. At least in SSP. Not sure of SMP yet.

 

Keep in mind, that with 1.7, dismounting is done by sneaking, not right clicking. So it would need to be overridden at the source. I don't think bad-practice "work arounds" are an efficient way of programming, and there really should be an override method for it, as is. At the very least, the option to just cancel the integrated dismount and apply a new one manually.

  • 2 weeks later...
Posted

If you still want a hook for it, you (or any coremodder who wants to do it as well) can attempt to do ASM. I've done it for myself recently, since I need the sneak key for the landing when flying on an entity. Here's the ASM code:

https://github.com/SanAndreasP/SAPManagerPack/blob/master/java/sanandreasp/core/manpack/transformer/TransformPlayerDismountCtrl.java

 

It basically hooks into where the dismount happens (within EntityPlayer) and calls a newly created method (_SAP_canDismountWithLSHIFT) from the dismounted entity (ridingEntity). When the method returns true, it dismounts, otherwise it doesn't.

The method is injected within the Entity class.

 

The method is "runtime-overritten" in my custom entity and returns true when it's on the ground.

 

You could also turn this into an event and make a Pull Request to Forge.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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.