Skip to content

Commit aa4906a

Browse files
committed
fix: fix onProjectileHitBlock and onStartDestroyBlock
1 parent 8caac8b commit aa4906a

File tree

2 files changed

+23
-33
lines changed

2 files changed

+23
-33
lines changed

src/lse/events/EntityEvents.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ LL_TYPE_INSTANCE_HOOK(
195195
IF_LISTENED(EVENT_TYPES::onProjectileHitBlock) {
196196
auto& region = owner.getDimensionBlockSourceConst();
197197
auto& block = region.getBlock(res.mBlock);
198-
if (res.mType == HitResultType::Tile && res.mBlock != BlockPos::ZERO() && block.isAir()) {
198+
if (res.mType == HitResultType::Tile && res.mBlock != BlockPos::ZERO() && !block.isAir()) {
199199
if (!CallEvent(
200200
EVENT_TYPES::onProjectileHitBlock,
201201
BlockClass::newBlock(block, res.mBlock, region),
@@ -295,10 +295,10 @@ LL_TYPE_INSTANCE_HOOK(
295295
::std::string const& sceneName
296296
) {
297297
IF_LISTENED(EVENT_TYPES::onNpcCmd) {
298-
auto& action =
299-
mActionsContainer->mUnke14f11.as<std::vector<std::variant<npc::CommandAction, npc::UrlAction>>>().at(
300-
actionIndex
301-
);
298+
auto& actionContainer =
299+
mActionsContainer->mUnke14f11.as<std::vector<std::variant<npc::CommandAction, npc::UrlAction>>>();
300+
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().info("Size: {}", actionContainer.size());
301+
auto& action = actionContainer.at(actionIndex);
302302
if (std::holds_alternative<npc::CommandAction>(action)) {
303303
auto& commands = std::get<npc::CommandAction>(action).commands;
304304
std::string command;

src/lse/events/PlayerEvents.cpp

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,30 +53,6 @@
5353
#include "mc/world/phys/HitResult.h"
5454

5555
namespace lse::events::player {
56-
LL_TYPE_INSTANCE_HOOK(
57-
StartDestroyHook,
58-
HookPriority::Normal,
59-
BlockEventCoordinator,
60-
&BlockEventCoordinator::sendBlockDestructionStarted,
61-
void,
62-
::Player& player,
63-
const ::BlockPos& blockPos,
64-
const ::Block& hitBlock,
65-
uchar face
66-
) {
67-
IF_LISTENED(EVENT_TYPES::onStartDestroyBlock) {
68-
if (!CallEvent(
69-
EVENT_TYPES::onStartDestroyBlock,
70-
PlayerClass::newPlayer(&player),
71-
BlockClass::newBlock(hitBlock, blockPos, player.getDimensionId())
72-
)) {
73-
return;
74-
}
75-
}
76-
IF_LISTENED_END(EVENT_TYPES::onStartDestroyBlock)
77-
origin(player, blockPos, hitBlock, face);
78-
}
79-
8056
LL_TYPE_INSTANCE_HOOK(
8157
DropItemHook1,
8258
HookPriority::Normal,
@@ -227,14 +203,15 @@ LL_TYPE_INSTANCE_HOOK(
227203
}
228204

229205
LL_STATIC_HOOK(
230-
AttackBlockHook,
206+
StartDestroyBlockHook,
231207
HookPriority::Normal,
232208
&ServerPlayerBlockUseHandler::onStartDestroyBlock,
233209
void,
234210
ServerPlayer& player,
235211
const BlockPos& pos,
236212
int face
237213
) {
214+
bool isCancelled = false;
238215
IF_LISTENED(EVENT_TYPES::onAttackBlock) {
239216
ItemStack const& item = player.getSelectedItem();
240217
if (!CallEvent(
@@ -243,10 +220,23 @@ LL_STATIC_HOOK(
243220
BlockClass::newBlock(pos, player.getDimensionId()),
244221
!item.isNull() ? ItemClass::newItem(&const_cast<ItemStack&>(item)) : Local<Value>()
245222
)) {
246-
return;
223+
isCancelled = true;
247224
}
248225
}
249226
IF_LISTENED_END(EVENT_TYPES::onAttackBlock);
227+
IF_LISTENED(EVENT_TYPES::onStartDestroyBlock) {
228+
if (!CallEvent(
229+
EVENT_TYPES::onStartDestroyBlock,
230+
PlayerClass::newPlayer(&player),
231+
BlockClass::newBlock(pos, player.getDimensionId())
232+
)) {
233+
isCancelled = true;
234+
}
235+
}
236+
IF_LISTENED_END(EVENT_TYPES::onStartDestroyBlock)
237+
if (isCancelled) {
238+
return;
239+
}
250240
return origin(player, pos, face);
251241
}
252242

@@ -663,7 +653,7 @@ LL_TYPE_INSTANCE_HOOK(
663653
origin(effect);
664654
}
665655

666-
void StartDestroyBlock() { StartDestroyHook::hook(); }
656+
void StartDestroyBlock() { StartDestroyBlockHook::hook(); }
667657
void DropItem() {
668658
DropItemHook1::hook();
669659
DropItemHook2::hook();
@@ -674,7 +664,7 @@ void CloseContainerEvent() {
674664
CloseContainerHook2::hook();
675665
}
676666
void ChangeSlotEvent() { ChangeSlotHook::hook(); }
677-
void AttackBlockEvent() { AttackBlockHook::hook(); }
667+
void AttackBlockEvent() { StartDestroyBlockHook::hook(); }
678668
void UseFrameEvent() {
679669
UseFrameHook1::hook();
680670
UseFrameHook2::hook();

0 commit comments

Comments
 (0)