Skip to content

Commit c1c0925

Browse files
committed
fix: fix onPortalTrySpawnPigZombie
1 parent 5024435 commit c1c0925

1 file changed

Lines changed: 47 additions & 21 deletions

File tree

src/lse/events/EntityEvents.cpp

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "ll/api/memory/Memory.h"
88
#include "ll/api/service/Bedrock.h"
99
#include "lse/api/Thread.h"
10-
#include "lse/api/helper/BlockHelper.h"
1110
#include "mc/common/Globals.h"
1211
#include "mc/deps/shared_types/legacy/actor/ActorDamageCause.h"
1312
#include "mc/entity/components_json_legacy/NpcComponent.h"
@@ -20,6 +19,7 @@
2019
#include "mc/world/actor/ActorHurtResult.h"
2120
#include "mc/world/actor/ActorType.h"
2221
#include "mc/world/actor/Mob.h"
22+
#include "mc/world/actor/SpawnChecks.h"
2323
#include "mc/world/actor/VanillaActorRendererId.h"
2424
#include "mc/world/actor/boss/WitherBoss.h"
2525
#include "mc/world/actor/item/FireworksRocketActor.h"
@@ -36,7 +36,9 @@
3636
#include "mc/world/level/BedrockSpawner.h"
3737
#include "mc/world/level/BlockSource.h"
3838
#include "mc/world/level/Level.h"
39+
#include "mc/world/level/PortalShape.h"
3940
#include "mc/world/level/block/PortalBlock.h"
41+
#include "mc/world/level/dimension/Dimension.h"
4042
#include "mc/world/phys/AABB.h"
4143
#include "mc/world/phys/HitResult.h"
4244

@@ -112,10 +114,10 @@ LL_TYPE_INSTANCE_HOOK(
112114
origin(item, player, durationLeft);
113115
}
114116

117+
namespace FireworksRocketSpawn {
115118
std::pair<Vec3, std::pair<Actor*, HashedString>> currentFirerocketSpawner;
116-
117119
LL_TYPE_INSTANCE_HOOK(
118-
FireworksRocketSpawnHook1,
120+
Hook1,
119121
HookPriority::Normal,
120122
ActorFactory,
121123
&ActorFactory::createSpawnedActor,
@@ -133,7 +135,7 @@ LL_TYPE_INSTANCE_HOOK(
133135
}
134136

135137
LL_TYPE_INSTANCE_HOOK(
136-
FireworksRocketSpawnHook2,
138+
Hook2,
137139
HookPriority::Normal,
138140
FireworksRocketActor,
139141
&FireworksRocketActor::init,
@@ -161,31 +163,47 @@ LL_TYPE_INSTANCE_HOOK(
161163
IF_LISTENED_END(EVENT_TYPES::onSpawnProjectile);
162164
origin(level, playerPos, rocketUserData, dir, attachedEntity, isProjectile);
163165
}
166+
} // namespace FireworksRocketSpawn
164167

165-
LL_TYPE_STATIC_HOOK(
166-
PortalTrySpawnPigZombieHook,
168+
namespace PortalTrySpawnPigZombie {
169+
std::pair<BlockPos, PortalAxis> currentPortal;
170+
LL_TYPE_INSTANCE_HOOK(
171+
PortalShapeEvalueateHook,
167172
HookPriority::Normal,
168-
PortalBlock,
169-
&PortalBlock::trySpawnPigZombie,
173+
PortalShape,
174+
&PortalShape::evaluate,
170175
void,
171-
BlockSource& region,
172-
BlockPos const& pos,
173-
PortalAxis axis
176+
::BlockPos const& originalPosition,
177+
::BlockSource const& source
178+
) {
179+
currentPortal = {originalPosition, mAxis};
180+
origin(originalPosition, source);
181+
}
182+
183+
LL_TYPE_STATIC_HOOK(
184+
PortalCanSpawnPigZombieHook,
185+
HookPriority::Normal,
186+
SpawnChecks,
187+
&SpawnChecks::canSpawnPigZombieFromPortal,
188+
bool,
189+
::Dimension const& dimension,
190+
::IRandom& random
174191
) {
175192
IF_LISTENED(EVENT_TYPES::onPortalTrySpawnPigZombie) {
176193
if (isServerThread()) {
177194
if (!CallEvent(
178195
EVENT_TYPES::onPortalTrySpawnPigZombie,
179-
IntPos::newPos(pos, region.getDimensionId()),
180-
Number::newNumber(static_cast<int>(axis))
196+
IntPos::newPos(currentPortal.first, dimension.getDimensionId()),
197+
Number::newNumber(static_cast<int>(currentPortal.second))
181198
)) {
182-
return;
199+
return false;
183200
}
184201
}
185202
}
186203
IF_LISTENED_END(EVENT_TYPES::onPortalTrySpawnPigZombie);
187-
origin(region, pos, axis);
204+
origin(dimension, random);
188205
}
206+
} // namespace PortalTrySpawnPigZombie
189207

190208
LL_TYPE_INSTANCE_HOOK(ActorRideHook, HookPriority::Normal, Actor, &Actor::$canAddPassenger, bool, Actor& passenger) {
191209
IF_LISTENED(EVENT_TYPES::onRide) {
@@ -327,8 +345,8 @@ LL_TYPE_INSTANCE_HOOK(
327345
) {
328346
IF_LISTENED(EVENT_TYPES::onMobHurt) {
329347
if (isServerThread()) {
330-
// Mob is still hurt after hook Mob::$hurtEffects, and all hurt events are handled by this function, but we
331-
// just need magic damage.
348+
// Mob is still hurt after hook Mob::$hurtEffects, and all hurt events are handled by this function, but
349+
// we just need magic damage.
332350
if (source.mCause == SharedTypes::Legacy::ActorDamageCause::Magic
333351
|| source.mCause == SharedTypes::Legacy::ActorDamageCause::Wither) {
334352
Actor* damageSource = nullptr;
@@ -487,11 +505,19 @@ LL_TYPE_INSTANCE_HOOK(
487505
}
488506

489507
void ProjectileSpawnEvent() {
490-
static ll::memory::
491-
HookRegistrar<ProjectileSpawnHook1, ProjectileSpawnHook2, FireworksRocketSpawnHook1, FireworksRocketSpawnHook2>
492-
reg;
508+
static ll::memory::HookRegistrar<
509+
ProjectileSpawnHook1,
510+
ProjectileSpawnHook2,
511+
FireworksRocketSpawn::Hook1,
512+
FireworksRocketSpawn::Hook2>
513+
reg;
493514
};
494-
void PortalTrySpawnPigZombieEvent() { static ll::memory::HookRegistrar<PortalTrySpawnPigZombieHook> reg; }
515+
void PortalTrySpawnPigZombieEvent() {
516+
static ll::memory::HookRegistrar<
517+
PortalTrySpawnPigZombie::PortalShapeEvalueateHook,
518+
PortalTrySpawnPigZombie::PortalCanSpawnPigZombieHook>
519+
reg;
520+
}
495521
void ProjectileCreatedEvent() { static ll::memory::HookRegistrar<ProjectileSpawnHook1> reg; };
496522
void ActorRideEvent() { static ll::memory::HookRegistrar<ActorRideHook> reg; }
497523
void WitherDestroyEvent() { static ll::memory::HookRegistrar<WitherDestroyHook> reg; }

0 commit comments

Comments
 (0)