Skip to content

Commit

Permalink
fix: fix all explode events
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed Feb 1, 2024
1 parent d0bc10d commit e0d4fcf
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 82 deletions.
100 changes: 18 additions & 82 deletions src/legacy/api/EventAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,63 +554,21 @@ void EnableEventListener(int eventId) {
lse::events::ActorRideEvent();
break;

// case EVENT_TYPES::onEntityExplode:
// Event::EntityExplodeEvent::subscribe([](const EntityExplodeEvent &ev) {
// IF_LISTENED(EVENT_TYPES::onEntityExplode) {
// CallEvent(
// EVENT_TYPES::onEntityExplode,
// ev.mActor ? EntityClass::newEntity(ev.mActor) : Local<Value>(),
// FloatPos::newPos(ev.mPos, ev.mDimension->getDimensionId()),
// Number::newNumber(ev.mRadius),
// Number::newNumber(ev.mMaxResistance),
// Boolean::newBoolean(ev.mBreaking),
// Boolean::newBoolean(ev.mFire));
// }
// IF_LISTENED_END(EVENT_TYPES::onEntityExplode);
// });
// break;
case EVENT_TYPES::onEntityExplode:
lse::events::ExplodeEvent();
break;

// case EVENT_TYPES::onBlockExplode:
// Event::BlockExplodeEvent::subscribe([](const BlockExplodeEvent &ev) {
// IF_LISTENED(EVENT_TYPES::onBlockExplode) {
// BlockInstance bl(ev.mBlockInstance);
// CallEvent(
// EVENT_TYPES::onBlockExplode, BlockClass::newBlock(bl),
// IntPos::newPos(bl.getPosition(), bl.getDimensionId()),
// Number::newNumber(ev.mRadius),
// Number::newNumber(ev.mMaxResistance),
// Boolean::newBoolean(ev.mBreaking),
// Boolean::newBoolean(ev.mFire));
// }
// IF_LISTENED_END(EVENT_TYPES::onBlockExplode);
// });
// break;
case EVENT_TYPES::onBlockExplode:
lse::events::ExplodeEvent();
break;

// case EVENT_TYPES::onRespawnAnchorExplode:
// Event::BlockExplodeEvent::subscribe([](const BlockExplodeEvent &ev) {
// BlockInstance bl(ev.mBlockInstance);
// if (bl.getBlock()->getName() == "minecraft:respawn_anchor") {
// IF_LISTENED(EVENT_TYPES::onRespawnAnchorExplode) {
// CallEvent(EVENT_TYPES::onRespawnAnchorExplode,
// IntPos::newPos(bl.getPosition(), bl.getDimensionId()),
// Local<Value>());
// }
// IF_LISTENED_END(EVENT_TYPES::onRespawnAnchorExplode);
// }
// return true;
// });
// break;
case EVENT_TYPES::onRespawnAnchorExplode:
lse::events::RespawnAnchorExplodeEvent();
break;

// case EVENT_TYPES::onBlockExploded:
// Event::BlockExplodedEvent::subscribe([](const BlockExplodedEvent &ev) {
// IF_LISTENED(EVENT_TYPES::onBlockExploded) {
// CallEvent(EVENT_TYPES::onBlockExploded,
// BlockClass::newBlock(ev.mBlockInstance),
// EntityClass::newEntity(ev.mExplodeSource));
// }
// IF_LISTENED_END(EVENT_TYPES::onBlockExploded);
// });
// break;
case EVENT_TYPES::onBlockExploded:
lse::events::BlockExplodedEvent();
break;

// case EVENT_TYPES::onCmdBlockExecute:
// Event::CmdBlockExecuteEvent::subscribe([](const CmdBlockExecuteEvent
Expand Down Expand Up @@ -964,35 +922,13 @@ void EnableEventListener(int eventId) {
// });
// break;

// case EVENT_TYPES::onExplode:
// Event::EntityExplodeEvent::subscribe([](const EntityExplodeEvent &ev) {
// IF_LISTENED(EVENT_TYPES::onExplode) {
// CallEvent(
// EVENT_TYPES::onExplode,
// ev.mActor ? EntityClass::newEntity(ev.mActor) : Local<Value>(),
// FloatPos::newPos(ev.mPos, ev.mDimension->getDimensionId()),
// Number::newNumber(ev.mRadius),
// Number::newNumber(ev.mMaxResistance),
// Boolean::newBoolean(ev.mBreaking),
// Boolean::newBoolean(ev.mFire));
// }
// IF_LISTENED_END(EVENT_TYPES::onExplode);
// });
// break;
case EVENT_TYPES::onExplode:
lse::events::ExplodeEvent();
break;

// case EVENT_TYPES::onBedExplode:
// Event::BlockExplodeEvent::subscribe([](const BlockExplodeEvent &ev) {
// BlockInstance bl(ev.mBlockInstance);
// if (bl.getBlock()->getName() == "minecraft:bed") {
// IF_LISTENED(EVENT_TYPES::onBedExplode) {
// CallEvent(EVENT_TYPES::onBedExplode,
// IntPos::newPos(bl.getPosition(), bl.getDimensionId()));
// }
// IF_LISTENED_END(EVENT_TYPES::onBedExplode);
// }
// return true;
// });
// break;
case EVENT_TYPES::onBedExplode:
lse::events::ExplodeEvent();
break;

// case EVENT_TYPES::onPlayerPullFishingHook:
// Event::PlayerPullFishingHookEvent::subscribe(
Expand Down
115 changes: 115 additions & 0 deletions src/lse/events/EventHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
#include <mc/world/item/registry/ItemStack.h>
#include <mc/world/level/BlockEventCoordinator.h>
#include <mc/world/level/BlockSource.h>
#include <mc/world/level/Level.h>
#include <mc/world/level/Spawner.h>
#include <mc/world/level/block/BasePressurePlateBlock.h>
#include <mc/world/level/block/Block.h>
#include <mc/world/level/block/FarmBlock.h>
#include <mc/world/level/block/ItemFrameBlock.h>
#include <mc/world/level/block/RespawnAnchorBlock.h>
#include <mc/world/level/block/actor/BarrelBlockActor.h>
#include <mc/world/level/block/actor/BlockActor.h>
#include <mc/world/level/block/actor/ChestBlockActor.h>
Expand Down Expand Up @@ -483,6 +485,116 @@ LL_TYPE_INSTANCE_HOOK(
origin(instance);
}

LL_TYPE_INSTANCE_HOOK(
ExplodeHook,
HookPriority::Normal,
Level,
"?explode@Level@@UEAAXAEAVBlockSource@@PEAVActor@@AEBVVec3@@M_N3M3@Z",
void,
BlockSource& region,
Actor* source,
Vec3 const& pos,
float explosionRadius,
bool fire,
bool breaksBlocks,
float maxResistance,
bool allowUnderwater
) {
IF_LISTENED(EVENT_TYPES::onEntityExplode) {
if (source) {
CallEventVoid(
EVENT_TYPES::onEntityExplode,
EntityClass::newEntity(source),
FloatPos::newPos(pos, region.getDimensionId()),
Number::newNumber(explosionRadius),
Number::newNumber(maxResistance),
Boolean::newBoolean(breaksBlocks),
Boolean::newBoolean(fire)
);
}
}
IF_LISTENED_END(EVENT_TYPES::onEntityExplode);

IF_LISTENED(EVENT_TYPES::onBedExplode) {
if (region.getBlock(pos).getTypeName() == "minecraft:bed") {
CallEventVoid(EVENT_TYPES::onBedExplode, IntPos::newPos(pos, region.getDimensionId()));
}
}
IF_LISTENED_END(EVENT_TYPES::onBedExplode);

IF_LISTENED(EVENT_TYPES::onExplode) {
if (source) {
CallEventVoid(
EVENT_TYPES::onExplode,
EntityClass::newEntity(source),
FloatPos::newPos(pos, region.getDimensionId()),
Number::newNumber(explosionRadius),
Number::newNumber(maxResistance),
Boolean::newBoolean(breaksBlocks),
Boolean::newBoolean(fire)
);
}
}
IF_LISTENED_END(EVENT_TYPES::onExplode);

IF_LISTENED(EVENT_TYPES::onBlockExplode) {
CallEventVoid(
EVENT_TYPES::onBlockExplode,
BlockClass::newBlock(pos, region.getDimensionId()),
IntPos::newPos(pos, region.getDimensionId()),
Number::newNumber(explosionRadius),
Number::newNumber(maxResistance),
Boolean::newBoolean(breaksBlocks),
Boolean::newBoolean(fire)
);
}
IF_LISTENED_END(EVENT_TYPES::onBlockExplode);
origin(region, source, pos, explosionRadius, fire, breaksBlocks, maxResistance, allowUnderwater);
}

LL_TYPE_STATIC_HOOK(
RespawnAnchorExplodeHook,
HookPriority::Normal,
RespawnAnchorBlock,
&RespawnAnchorBlock::_explode,
void,
Player& player,
BlockPos const& pos,
BlockSource& region,
Level& level
) {
IF_LISTENED(EVENT_TYPES::onRespawnAnchorExplode) {
CallEventVoid(
EVENT_TYPES::onRespawnAnchorExplode,
IntPos::newPos(pos, region.getDimensionId()),
PlayerClass::newPlayer(&player)
);
}
IF_LISTENED_END(EVENT_TYPES::onRespawnAnchorExplode);
origin(player, pos, region, level);
}

LL_TYPE_INSTANCE_HOOK(
BlockExplodedHook,
HookPriority::Normal,
Block,
&Block::onExploded,
void,
BlockSource& region,
BlockPos const& pos,
Actor* entitySource
) {
IF_LISTENED(EVENT_TYPES::onBlockExploded) {
CallEventVoid(
EVENT_TYPES::onBlockExploded,
BlockClass::newBlock(pos, region.getDimensionId()),
EntityClass::newEntity(entitySource)
);
}
IF_LISTENED_END(EVENT_TYPES::onBlockExploded);
origin(region, pos, entitySource);
}

void PlayerStartDestroyBlock() { PlayerStartDestroyHook::hook(); }
void PlayerDropItem() { PlayerDropItemHook::hook(); }
void PlayerOpenContainerEvent() { PlayerOpenContainerHook::hook(); }
Expand All @@ -509,6 +621,9 @@ void WitherDestroyEvent() { WitherDestroyHook::hook(); }
void FarmDecayEvent() { FarmDecayHook::hook(); }
void PistonPushEvent() { PistonPushHook::hook(); }
void PlayerEatEvent() { PlayerEatHook::hook(); }
void ExplodeEvent() { ExplodeHook::hook(); }
void RespawnAnchorExplodeEvent() { RespawnAnchorExplodeHook::hook(); }
void BlockExplodedEvent() { BlockExplodedHook ::hook(); }

// NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast)
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
Expand Down
3 changes: 3 additions & 0 deletions src/lse/events/EventHooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ void ProjectileCreatedEvent();
void ProjectileSpawnEvent();
void WitherDestroyEvent();
void PlayerEatEvent();
void ExplodeEvent();
void RespawnAnchorExplodeEvent();
void BlockExplodedEvent();

} // namespace lse::events

0 comments on commit e0d4fcf

Please sign in to comment.