Skip to content

Commit 5e99d21

Browse files
committed
feat: add onEntityTransformation
1 parent 98d006b commit 5e99d21

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Added `ll.onUnload` [#227]
1515
- Added onNpcCmd [#226]
1616
- Added onEffectAdded/Updated/Removed
17+
- Added onEntityTransformation
1718

1819
### Changed
1920

src/legacy/api/EventAPI.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -605,17 +605,9 @@ void EnableEventListener(int eventId) {
605605
lse::events::entity::ProjectileHitEntityEvent();
606606
break;
607607

608-
// case EVENT_TYPES::onEntityTransformation:
609-
// Event::EntityTransformEvent::subscribe([](const EntityTransformEvent
610-
// &ev) {
611-
// IF_LISTENED(EVENT_TYPES::onEntityTransformation) {
612-
// CallEvent(EVENT_TYPES::onEntityTransformation,
613-
// String::newString(to_string(ev.mBeforeEntityUniqueId->id)),
614-
// EntityClass::newEntity(ev.mAfterEntity));
615-
// }
616-
// IF_LISTENED_END(EVENT_TYPES::onEntityTransformation);
617-
// });
618-
// break;
608+
case EVENT_TYPES::onEntityTransformation:
609+
lse::events::entity::TransformationEvent();
610+
break;
619611

620612
case EVENT_TYPES::onProjectileHitBlock:
621613
lse::events::entity::ProjectileHitBlockEvent();

src/lse/events/EntityEvents.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "mc/deps/core/string/HashedString.h"
1212
#include "mc/entity/components_json_legacy/NpcComponent.h"
1313
#include "mc/entity/components_json_legacy/ProjectileComponent.h"
14+
#include "mc/entity/components_json_legacy/TransformationComponent.h"
1415
#include "mc/world/actor/ActorDamageCause.h"
1516
#include "mc/world/actor/ActorDamageSource.h"
1617
#include "mc/world/actor/ActorDefinitionIdentifier.h"
@@ -346,6 +347,30 @@ LL_TYPE_INSTANCE_HOOK(
346347
origin(mob);
347348
}
348349

350+
LL_TYPE_INSTANCE_HOOK(
351+
TransformationHook,
352+
HookPriority::Normal,
353+
TransformationComponent,
354+
&TransformationComponent::maintainOldData,
355+
void,
356+
::Actor& originalActor,
357+
::Actor& transformed,
358+
::TransformationDescription const& transformation,
359+
::ActorUniqueID const& ownerID,
360+
::Level const& level
361+
) {
362+
IF_LISTENED(EVENT_TYPES::onEntityTransformation) {
363+
CallEvent(
364+
EVENT_TYPES::onEntityTransformation,
365+
String::newString(std::to_string(originalActor.getOrCreateUniqueID().rawID)),
366+
EntityClass::newEntity(&transformed)
367+
);
368+
}
369+
IF_LISTENED_END(EVENT_TYPES::onEntityTransformation);
370+
371+
origin(originalActor, transformed, transformation, ownerID, level);
372+
}
373+
349374
void ProjectileSpawnEvent() {
350375
ProjectileSpawnHook1::hook();
351376
ProjectileSpawnHook2::hook();
@@ -361,4 +386,5 @@ void NpcCommandEvent() { NpcCommandHook::hook(); }
361386
void EffectApplyEvent() { EffectApplyHook::hook(); }
362387
void EffectExpiredEvent() { EffectExpiredHook::hook(); }
363388
void EffectUpdateEvent() { EffectUpdateHook::hook(); }
389+
void TransformationEvent() { TransformationHook::hook(); }
364390
} // namespace lse::events::entity

src/lse/events/EntityEvents.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ void NpcCommandEvent();
1212
void EffectApplyEvent();
1313
void EffectExpiredEvent();
1414
void EffectUpdateEvent();
15+
void TransformationEvent();
1516
}

0 commit comments

Comments
 (0)