Skip to content

Commit 4a52d03

Browse files
committed
refactor: disable onLiquidFlow temporarily
1 parent 2f4cfa0 commit 4a52d03

File tree

5 files changed

+52
-28
lines changed

5 files changed

+52
-28
lines changed

src/legacy/api/BlockAPI.cpp

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
#include "ll/api/service/Bedrock.h"
1212
#include "mc/deps/core/string/HashedString.h"
1313
#include "mc/deps/core/utility/optional_ref.h"
14-
#include "mc/nbt/CompoundTag.h"
1514
#include "mc/world/level/BlockSource.h"
16-
#include "mc/world/level/Level.h"
1715
#include "mc/world/level/block/Block.h"
1816
#include "mc/world/level/block/actor/BlockActor.h"
1917
#include "mc/world/level/block/block_serialization_utils/BlockSerializationUtils.h"
2018
#include "mc/world/level/block/components/BlockLiquidDetectionComponent.h"
2119
#include "mc/world/level/dimension/Dimension.h"
2220
#include "mc/world/level/block/BedrockBlockNames.h"
21+
#include "mc/world/level/ChunkBlockPos.h"
22+
#include "mc/world/level/chunk/LevelChunk.h"
2323

2424
#include <exception>
2525

@@ -66,6 +66,24 @@ ClassDefine<BlockClass> BlockClassBuilder =
6666
.instanceFunction("getTag", &BlockClass::getNbt)
6767
.build();
6868

69+
namespace lse::BlockAPI {
70+
inline bool isValidHeight(WeakRef<Dimension> dim, std::variant<int, float> height) {
71+
if (dim) {
72+
if (std::holds_alternative<int>(height)) {
73+
int y = std::get<int>(height);
74+
return dim->getMinHeight() <= y && dim->getHeight() >= y;
75+
} else {
76+
float y = std::get<float>(height);
77+
return dim->getMinHeight() <= y && dim->getHeight() >= y;
78+
}
79+
}
80+
81+
return false;
82+
}
83+
} // namespace lse::BlockAPI
84+
85+
using lse::BlockAPI::isValidHeight;
86+
6987
//////////////////// Classes ////////////////////
7088

7189
BlockClass::BlockClass(Block const& block) : ScriptClass(ScriptClass::ConstructFromCpp<BlockClass>{}), block(&block) {
@@ -85,9 +103,11 @@ Local<Object> BlockClass::newBlock(Block const& block, BlockPos const& pos, Dime
85103
}
86104

87105
Local<Object> BlockClass::newBlock(BlockPos const& pos, DimensionType dim) {
88-
if (pos.y < 320 && pos.y >= -64) {
89-
auto& bl = ll::service::getLevel()->getDimension(dim)->getBlockSourceFromMainChunkSource().getBlock(pos);
90-
return BlockClass::newBlock(bl, pos, dim);
106+
if (auto dimension = ll::service::getLevel()->getDimension(dim)) {
107+
if (isValidHeight(dimension, pos.y)) {
108+
auto& bl = dimension->getBlockSourceFromMainChunkSource().getBlock(pos);
109+
return BlockClass::newBlock(bl, pos, dim);
110+
}
91111
}
92112
auto block = Block::tryGetFromRegistry(BedrockBlockNames::Air());
93113
if (!block) {
@@ -103,9 +123,11 @@ Local<Object> BlockClass::newBlock(Block const& block, BlockPos const& pos, Bloc
103123

104124
Local<Object> BlockClass::newBlock(IntVec4 pos) {
105125
BlockPos bp = {(float)pos.x, (float)pos.y, (float)pos.z};
106-
if (bp.y < 320 && bp.y >= -64) {
107-
auto& bl = ll::service::getLevel()->getDimension(pos.dim)->getBlockSourceFromMainChunkSource().getBlock(bp);
108-
return BlockClass::newBlock(bl, bp, pos.dim);
126+
if (auto dimension = ll::service::getLevel()->getDimension(pos.dim)) {
127+
if (isValidHeight(dimension, pos.y)) {
128+
auto& bl = dimension->getBlockSourceFromMainChunkSource().getBlock(bp);
129+
return BlockClass::newBlock(bl, bp, pos.dim);
130+
}
109131
}
110132
auto block = Block::tryGetFromRegistry(BedrockBlockNames::Air());
111133
if (!block) {
@@ -390,8 +412,6 @@ Local<Value> BlockClass::removeBlockEntity(const Arguments&) {
390412
}
391413
CATCH("Fail in removeBlockEntity!");
392414
}
393-
#include "mc/world/level/ChunkBlockPos.h"
394-
#include "mc/world/level/chunk/LevelChunk.h"
395415

396416
// public API
397417
Local<Value> McClass::getBlock(const Arguments& args) {
@@ -440,11 +460,15 @@ Local<Value> McClass::getBlock(const Arguments& args) {
440460
if (!dimPtr) {
441461
return {};
442462
}
443-
BlockSource& bs = dimPtr->getBlockSourceFromMainChunkSource();
444-
auto lc = bs.getChunkAt(pos.getBlockPos());
445-
if (!lc) return {};
446-
short minHeight = dimPtr->getMinHeight();
447-
if (pos.y < minHeight || pos.y > dimPtr->getHeight()) return {};
463+
BlockSource& bs = dimPtr->getBlockSourceFromMainChunkSource();
464+
short minHeight = dimPtr->getMinHeight();
465+
if (pos.y < minHeight || pos.y > dimPtr->getHeight()) {
466+
return {};
467+
}
468+
auto lc = bs.getChunkAt(pos.getBlockPos());
469+
if (!lc) {
470+
return {};
471+
}
448472
ChunkBlockPos cbpos = ChunkBlockPos(pos.getBlockPos(), minHeight);
449473
auto& block = lc->getBlock(cbpos);
450474
BlockPos bp{pos.x, pos.y, pos.z};

src/legacy/api/EntityAPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ Local<Value> EntityClass::isOnHotBlock() {
292292
Actor* entity = get();
293293
if (!entity) return Local<Value>();
294294

295-
return Boolean::newBoolean(false); // todo: check IsOnHotBlockTest to get the correct value
295+
return Boolean::newBoolean(false); // TODO: check IsOnHotBlockTest to get the correct value
296296
}
297297
CATCH("Fail in isOnHotBlock!")
298298
}

src/legacy/api/EventAPI.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ bool LLSECallEventsOnHotUnload(ScriptEngine* engine) {
137137

138138
//////////////////// Events ////////////////////
139139

140-
// Todo
140+
// TODO:
141141
void EnableEventListener(int eventId) {
142142
using namespace ll::event;
143143
EventBus& bus = EventBus::getInstance();
@@ -626,7 +626,8 @@ void EnableEventListener(int eventId) {
626626
break;
627627

628628
case EVENT_TYPES::onLiquidFlow:
629-
lse::events::LiquidFlowEvent();
629+
// TODO:
630+
// lse::events::LiquidFlowEvent();
630631
break;
631632

632633
case EVENT_TYPES::onUseFrameBlock:

src/legacy/api/PlayerAPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ Local<Value> PlayerClass::isOnHotBlock() {
12331233
return Local<Value>();
12341234
}
12351235

1236-
return Boolean::newBoolean(false); // todo: check IsOnHotBlockTest to get the correct value
1236+
return Boolean::newBoolean(false); // TODO: check IsOnHotBlockTest to get the correct value
12371237
}
12381238
CATCH("Fail in isOnHotBlock!")
12391239
}

src/lse/events/EventHooks.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,6 @@ LL_TYPE_INSTANCE_HOOK(PlayerEatHook, HookPriority::Normal, Player, &Player::eat,
587587
}
588588

589589
LL_TYPE_INSTANCE_HOOK(ExplodeHook, HookPriority::Normal, Level, &Level::$explode, bool, ::Explosion& explosion) {
590-
// Todo: broken need to be fixed
591-
592590
IF_LISTENED(EVENT_TYPES::onEntityExplode) {
593591
if (explosion.mSourceID->rawID != ActorUniqueID::INVALID_ID().rawID) {
594592
if (!CallEvent(
@@ -762,29 +760,30 @@ LL_TYPE_INSTANCE_HOOK(
762760
origin(region, pos, strength, isFirstTime);
763761
}
764762

763+
// TODO: It is broken, need to be fixed
765764
LL_TYPE_INSTANCE_HOOK(
766765
LiquidFlowHook,
767766
HookPriority::Normal,
768767
LiquidBlockDynamic,
769-
&LiquidBlockDynamic::_spread,
768+
&LiquidBlockDynamic::_trySpreadTo,
770769
void,
771-
BlockSource& region,
772-
const ::BlockPos& pos,
773-
int depth,
774-
bool preserveExisting
770+
::BlockSource& region,
771+
::BlockPos const& pos,
772+
int neighbor,
773+
::BlockPos const& flowFromPos,
774+
uchar flowFromDirection
775775
) {
776776
IF_LISTENED(EVENT_TYPES::onLiquidFlow) {
777777
if (!CallEvent(
778778
EVENT_TYPES::onLiquidFlow,
779-
false,
780779
BlockClass::newBlock(pos, region.getDimensionId()),
781780
IntPos::newPos(pos, region.getDimensionId())
782781
)) {
783782
return;
784783
}
785784
}
786785
IF_LISTENED_END(EVENT_TYPES::onLiquidFlow);
787-
return origin(region, pos, depth, preserveExisting);
786+
return origin(region, pos, neighbor, flowFromPos, flowFromDirection);
788787
}
789788

790789
LL_TYPE_INSTANCE_HOOK(

0 commit comments

Comments
 (0)