Refactor of interaction events
i509VCB opened this issue ยท 7 comments
This issue exists to lay out the requests people may have for a refactored interaction events module. This would culminate in fabric-interaction-events-v1
The current interaction events module does work but it has issues such as combining notification and cancellation into the same callback.
The event instances in PlayerBlockBreakEvents
are the general structure I would use for the refactored module. However splitting BEFORE
into an ALLOW
and BEFORE
phase for the event.
The new module would also make it more specific which logical side the events are dispatched on: So PlayerBlockBreakEvents
would become ServerPlayerBlockBreakEvents
.
The new module would also include events for placing blocks on the server and client and porting over the server block break events to the client.
Another thing that will be considered is the existing block/entity attack/use callbacks. These callbacks do work but they do not separate cancellation and notification at all. These events would receive an implementation in a similar structure to block break events with a slight change to allow setting an action to occur. I believe these would require 4 events:
-
Allow
(Cancellable - Prevents the action completely and implicitly returnsActionResult.FAIL
)
Contractually you should not modify the world here. If an action is not allowed to occur no further events are called. -
Intercept
[Name is not final] (Allows a mod to capture full control the interaction and cancel an interaction event while specifying the action result to return). This may be used to for example use a wrench on a chest to rotate it but cancel opening the gui. -
Before
(Happens before the vanilla interaction method is called) -
After
(Happens after the vanilla interaction method is called)
Other existing events:
Item pick events could see enhancement, suggestions will be taken there.
Timeline: I plan to start on this and have a pull request in the next weeks.
Hand swing event would be cool.
An attack event which does not target a block or an entity, server-side, would be really cool as it's quite a tricky one.
I got confused with this module.
If I want to add a something like DamageEntityCallback
event to modify the damage taken (LivingEntity.damage(...)
), which module should I add it to?
fabric-entity-events-v1
has ServerEntityCombatEvents
and
fabric-events-interaction-v0
has AttackEntityCallback
...
I suggest making additional changes for fabric-events-interaction-v1
:
- Rename all events in the
net.fabricmc.fabric.api.event.player
package, add the "Player" prefix to them - Remove all events in this package and group them into two classes:
PlayerAttackEvents
andPlayerUseEvents
- And add the
net.fabricmc.fabric.api.event.entity
package for event that I described above and for future events, also with "Entity" prefix
Ah the illustrious entity damage events.
It seems like an easy event but no. You have several entities which override the damage logic without calling super which causes issues.
Even if we just cancel damage at the setHealth
call in living entity it does prevent health from dropping but there would still be side effects such as animals ceasing to be in love mode even though they too no damage.
Non living entities are worse to cover. And then the armor stand is a living entity in inheirtence but logically non-living.
And dont forget modded entities - these may do funky things.
However some events can easily be done, an AfterDamageLivingEntity event is very possible.
On your changes, I plan to prefix all events with Player to note that the player is the actor in that context. Also the events are being split per logical side - a client and server event. I should be able to resume on my work with this tonight.
Will you open PR of these changes soon? It will be great, maybe I can help you with that :)
I meant that this is a huge confusion that needs to be urgently addressed. And the event I wrote about is just an example of this.
But I still think that in addition to "Player" prefix, we should make "Entity" prefix and separate their APIs by packages.
I've started some stuff over here: https://github.com/i509VCB/fabric/tree/ft/interaction-evt-v1