Skip to content

Commit cfd5c3f

Browse files
committed
feat: support LeviLamina 1.6.0
1 parent 5bdf533 commit cfd5c3f

18 files changed

+187
-215
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.15.0] - 2025-10-02
11+
12+
### Changed
13+
14+
- Supported LeviLamina 1.6.0 @ShrBox
15+
1016
## [0.14.0] - 2025-09-23
1117

1218
### Changed
@@ -1015,7 +1021,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10151021
[#310]: https://github.com/LiteLDev/LegacyScriptEngine/issues/310
10161022
[#323]: https://github.com/LiteLDev/LegacyScriptEngine/issues/323
10171023

1018-
[Unreleased]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.14.0...HEAD
1024+
[Unreleased]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.15.0...HEAD
1025+
[0.15.0]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.14.0...v0.15.0
10191026
[0.14.0]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.13.2...v0.14.0
10201027
[0.13.2]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.13.1...v0.13.2
10211028
[0.13.1]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.13.0...v0.13.1

src/legacy/api/BlockAPI.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@
1515
#include "mc/world/level/ChunkBlockPos.h"
1616
#include "mc/world/level/block/BedrockBlockNames.h"
1717
#include "mc/world/level/block/Block.h"
18-
#include "mc/world/level/block/DetectionRule.h"
1918
#include "mc/world/level/block/LiquidReaction.h"
19+
#include "mc/world/level/block/VanillaBlockTags.h"
2020
#include "mc/world/level/block/actor/BlockActor.h"
2121
#include "mc/world/level/block/block_serialization_utils/BlockSerializationUtils.h"
22-
#include "mc/world/level/block/components/BlockComponentDirectData.h"
2322
#include "mc/world/level/chunk/LevelChunk.h"
24-
#include "mc/world/level/dimension/Dimension.h"
25-
#include "mc/world/level/dimension/DimensionHeightRange.h"
2623

2724
#include <exception>
2825

@@ -200,7 +197,9 @@ Local<Value> BlockClass::getThickness() {
200197

201198
Local<Value> BlockClass::isAir() {
202199
try {
203-
return Boolean::newBoolean(block->isAir());
200+
return Boolean::newBoolean(
201+
BlockHelper::isAir(*get())
202+
);
204203
}
205204
CATCH("Fail in isAir!");
206205
}
@@ -214,21 +213,21 @@ Local<Value> BlockClass::isBounceBlock() {
214213

215214
Local<Value> BlockClass::isButtonBlock() {
216215
try {
217-
return Boolean::newBoolean(block->isButtonBlock());
216+
return Boolean::newBoolean(block->getBlockType().isButtonBlock());
218217
}
219218
CATCH("Fail in isButtonBlock!");
220219
}
221220

222221
Local<Value> BlockClass::isCropBlock() {
223222
try {
224-
return Boolean::newBoolean(block->isCropBlock());
223+
return Boolean::newBoolean(block->hasTag(VanillaBlockTags::Crop()));
225224
}
226225
CATCH("Fail in isCropBlock!");
227226
}
228227

229228
Local<Value> BlockClass::isDoorBlock() {
230229
try {
231-
return Boolean::newBoolean(block->isDoorBlock());
230+
return Boolean::newBoolean(block->getBlockType().isDoorBlock());
232231
}
233232
CATCH("Fail in isDoorBlock!");
234233
}
@@ -270,7 +269,7 @@ Local<Value> BlockClass::isStemBlock() {
270269

271270
Local<Value> BlockClass::isSlabBlock() {
272271
try {
273-
return Boolean::newBoolean(block->isSlabBlock());
272+
return Boolean::newBoolean(block->getBlockType().isSlabBlock());
274273
}
275274
CATCH("Fail in isSlabBlock!");
276275
}
@@ -397,16 +396,14 @@ Local<Value> BlockClass::getBlockEntity(const Arguments&) {
397396

398397
Local<Value> BlockClass::removeBlockEntity(const Arguments&) {
399398
try {
400-
auto chunk = ll::service::getLevel()
401-
->getDimension(blockPos.dim)
402-
.lock()
403-
->getBlockSourceFromMainChunkSource()
404-
.getChunkAt(blockPos.getBlockPos());
405-
if (chunk) {
406-
return Boolean::newBoolean(chunk->removeBlockEntity(blockPos.getBlockPos()) != nullptr);
407-
} else {
408-
return Boolean::newBoolean(false);
409-
}
399+
return Boolean::newBoolean(
400+
ll::service::getLevel()
401+
->getDimension(blockPos.dim)
402+
.lock()
403+
->getBlockSourceFromMainChunkSource()
404+
.removeBlockEntity(blockPos.getBlockPos())
405+
!= nullptr
406+
);
410407
}
411408
CATCH("Fail in removeBlockEntity!");
412409
}
@@ -532,7 +529,8 @@ Local<Value> McClass::setBlock(const Arguments& args) {
532529
}
533530

534531
if (block.isString()) {
535-
optional_ref<const Block> bl = Block::tryGetFromRegistry(block.asString().toString(), tileData);
532+
optional_ref<const Block> bl =
533+
Block::tryGetFromRegistry(HashedString(block.asString().toString()), tileData);
536534
if (!bl.has_value()) {
537535
return Boolean::newBoolean(false);
538536
}

src/legacy/api/CommandAPI.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include "magic_enum.hpp"
2222
#include "mc/_HeaderOutputPredefine.h"
2323
#include "mc/deps/core/utility/MCRESULT.h"
24-
#include "mc/deps/json/Value.h"
2524
#include "mc/deps/json/FastWriter.h"
25+
#include "mc/deps/json/Value.h"
2626
#include "mc/locale/I18n.h"
2727
#include "mc/locale/Localization.h"
2828
#include "mc/server/commands/CommandBlockName.h"
@@ -35,9 +35,7 @@
3535
#include "mc/server/commands/GenerateMessageResult.h"
3636
#include "mc/server/commands/MinecraftCommands.h"
3737
#include "mc/server/commands/ServerCommandOrigin.h"
38-
#include "mc/util/JsonHelpers.h"
3938
#include "mc/world/Minecraft.h"
40-
#include "mc/world/item/ItemInstance.h"
4139
#include "mc/world/item/ItemStack.h"
4240
#include "mc/world/level/dimension/Dimension.h"
4341

@@ -96,9 +94,9 @@ Local<Value> convertResult(ParamStorageType const& result, CommandOrigin const&
9694
} else if (result.hold(ParamKind::Kind::Item)) {
9795
return ItemClass::newItem(
9896
new ItemStack(
99-
std::get<CommandItem>(result.value())
100-
.createInstance(1, 1, output, true)
101-
.value_or(ItemInstance::EMPTY_ITEM())
97+
ll::service::getLevel()->getItemRegistry().getNameFromLegacyID(
98+
std::get<CommandItem>(result.value()).mId
99+
)
102100
),
103101
false
104102
); // Not managed by BDS, pointer will be saved as unique_ptr
@@ -490,7 +488,8 @@ Local<Value> CommandClass::optional(const Arguments& args) {
490488
// vector<index>
491489
Local<Value> CommandClass::addOverload(const Arguments& args) {
492490
try {
493-
auto overloadFunc = [e(EngineScope::currentEngine()
491+
auto overloadFunc = [e(
492+
EngineScope::currentEngine()
494493
)](RuntimeOverload& cmd, std::string const& commandName, std::string const& paramName) {
495494
auto& paramList = getEngineData(e)->plugin->registeredCommands[commandName];
496495
for (auto& info : paramList) {
@@ -513,8 +512,8 @@ Local<Value> CommandClass::addOverload(const Arguments& args) {
513512
};
514513
auto delayRegFunc = [this, &overloadFunc](std::vector<std::string>& paramNames) {
515514
ll::coro::keepThis(
516-
[paramNames, commandName(commandName), overloadFunc, e(EngineScope::currentEngine())](
517-
) -> ll::coro::CoroTask<> {
515+
[paramNames, commandName(commandName), overloadFunc, e(EngineScope::currentEngine())]()
516+
-> ll::coro::CoroTask<> {
518517
auto cmd = ll::command::CommandRegistrar::getInstance()
519518
.getOrCreateCommand(commandName)
520519
.runtimeOverload(getEngineData(e)->plugin);

src/legacy/api/EntityAPI.cpp

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
#include "ll/api/service/Bedrock.h"
1313
#include "lse/api/MoreGlobal.h"
1414
#include "lse/api/helper/AttributeHelper.h"
15+
#include "lse/api/helper/BlockHelper.h"
1516
#include "mc/deps/core/math/Vec2.h"
1617
#include "mc/deps/shared_types/legacy/actor/ActorDamageCause.h"
18+
#include "mc/deps/vanilla_components/ActorDataFlagComponent.h"
1719
#include "mc/deps/vanilla_components/StateVectorComponent.h"
18-
#include "mc/entity/components/ActorRotationComponent.h"
1920
#include "mc/entity/components/InsideBlockComponent.h"
2021
#include "mc/entity/components/IsOnHotBlockFlagComponent.h"
2122
#include "mc/entity/components/TagsComponent.h"
@@ -316,7 +317,9 @@ Local<Value> EntityClass::isDancing() {
316317
Actor* entity = get();
317318
if (!entity) return Local<Value>();
318319

319-
return Boolean::newBoolean(entity->isDancing());
320+
return Boolean::newBoolean(
321+
SynchedActorDataAccess::getActorFlag(entity->getEntityContext(), ActorFlags::Dancing)
322+
);
320323
}
321324
CATCH("Fail in isDancing!")
322325
}
@@ -356,7 +359,8 @@ Local<Value> EntityClass::isMoving() {
356359
Actor* entity = get();
357360
if (!entity) return Local<Value>();
358361

359-
return Boolean::newBoolean(SynchedActorDataAccess::getActorFlag(entity->getEntityContext(), ActorFlags::Moving)
362+
return Boolean::newBoolean(
363+
SynchedActorDataAccess::getActorFlag(entity->getEntityContext(), ActorFlags::Moving)
360364
);
361365
}
362366
CATCH("Fail in isMoving!")
@@ -397,7 +401,7 @@ Local<Value> EntityClass::getPos() {
397401
Actor* entity = get();
398402
if (!entity) return Local<Value>();
399403

400-
return FloatPos::newPos(entity->getPosition(), entity->getDimensionId());
404+
return FloatPos::newPos(entity->getPosition(), entity->getDimension().mId->id);
401405
}
402406
CATCH("Fail in GetEntityPos!")
403407
}
@@ -407,7 +411,7 @@ Local<Value> EntityClass::getPosDelta() {
407411
Actor* entity = get();
408412
if (!entity) return Local<Value>();
409413

410-
return FloatPos::newPos(entity->getPosDelta(), entity->getDimensionId());
414+
return FloatPos::newPos(entity->getPosDelta(), entity->getDimension().mId->id);
411415
}
412416
CATCH("Fail in GetEntityPosDelta!")
413417
}
@@ -446,7 +450,7 @@ Local<Value> EntityClass::getFeetPos() {
446450
Actor* entity = get();
447451
if (!entity) return Local<Value>();
448452

449-
return FloatPos::newPos(entity->getFeetPos(), entity->getDimensionId());
453+
return FloatPos::newPos(entity->getFeetPos(), entity->getDimension().mId->id);
450454
}
451455
CATCH("Fail in GetEntityFeetPos!")
452456
}
@@ -456,7 +460,7 @@ Local<Value> EntityClass::getBlockPos() {
456460
Actor* entity = get();
457461
if (!entity) return Local<Value>();
458462

459-
return IntPos::newPos(entity->getFeetBlockPos(), entity->getDimensionId());
463+
return IntPos::newPos(entity->getFeetBlockPos(), entity->getDimension().mId->id);
460464
}
461465
CATCH("Fail in GetEntityBlockPos!")
462466
}
@@ -742,7 +746,7 @@ Local<Value> EntityClass::distanceTo(const Arguments& args) {
742746
pos.x = targetActorPos.x;
743747
pos.y = targetActorPos.y;
744748
pos.z = targetActorPos.z;
745-
pos.dim = targetActor->getDimensionId();
749+
pos.dim = targetActor->getDimension().mId->id;
746750
} else {
747751
LOG_WRONG_ARG_TYPE(__FUNCTION__);
748752
return Local<Value>();
@@ -763,9 +767,9 @@ Local<Value> EntityClass::distanceTo(const Arguments& args) {
763767
return Local<Value>();
764768
}
765769

766-
if (actor->getDimensionId().id != pos.dim) return Number::newNumber(INT_MAX);
770+
if (actor->getDimension().mId->id != pos.dim) return Number::newNumber(INT_MAX);
767771

768-
return Number::newNumber(actor->distanceTo(pos.getVec3()));
772+
return Number::newNumber(actor->getPosition().distanceTo(pos.getVec3()));
769773
}
770774
CATCH("Fail in distanceTo!")
771775
}
@@ -805,7 +809,7 @@ Local<Value> EntityClass::distanceToSqr(const Arguments& args) {
805809
pos.x = targetActorPos.x;
806810
pos.y = targetActorPos.y;
807811
pos.z = targetActorPos.z;
808-
pos.dim = targetActor->getDimensionId();
812+
pos.dim = targetActor->getDimension().mId->id;
809813
} else {
810814
LOG_WRONG_ARG_TYPE(__FUNCTION__);
811815
return Local<Value>();
@@ -826,9 +830,9 @@ Local<Value> EntityClass::distanceToSqr(const Arguments& args) {
826830
return Local<Value>();
827831
}
828832

829-
if (actor->getDimensionId().id != pos.dim) return Number::newNumber(INT_MAX);
833+
if (actor->getDimension().mId->id != pos.dim) return Number::newNumber(INT_MAX);
830834

831-
return Number::newNumber(actor->distanceToSqr(pos.getVec3()));
835+
return Number::newNumber(actor->getPosition().distanceToSqr(pos.getVec3()));
832836
}
833837
CATCH("Fail in distanceToSqr!")
834838
}
@@ -913,7 +917,7 @@ Local<Value> EntityClass::getBlockStandingOn(const Arguments&) {
913917
Actor* entity = get();
914918
if (!entity) return Local<Value>();
915919

916-
return BlockClass::newBlock(entity->getBlockPosCurrentlyStandingOn(nullptr), entity->getDimensionId());
920+
return BlockClass::newBlock(entity->getBlockPosCurrentlyStandingOn(nullptr), entity->getDimension().mId->id);
917921
}
918922
CATCH("Fail in getBlockStandingOn!");
919923
}
@@ -1379,7 +1383,7 @@ Local<Value> EntityClass::getBlockFromViewVector(const Arguments& args) {
13791383
if (solidOnly && !block.mCachedComponentData->mIsSolid) {
13801384
return false;
13811385
}
1382-
if (fullOnly && !block.isSlabBlock()) {
1386+
if (fullOnly && !block.getBlockType().isSlabBlock()) {
13831387
return false;
13841388
}
13851389
if (!includeLiquid && BlockUtils::isLiquidSource(block)) {
@@ -1397,12 +1401,13 @@ Local<Value> EntityClass::getBlockFromViewVector(const Arguments& args) {
13971401
} else {
13981402
bp = res.mBlock;
13991403
}
1400-
Block const& bl = actor->getDimensionBlockSource().getBlock(bp);
1404+
Block const& bl = actor->getDimensionBlockSource().getBlock(bp);
14011405
BlockType const& legacy = bl.getBlockType();
1402-
if (bl.isAir() || (legacy.mProperties == BlockProperty::None && legacy.mMaterial.mType == MaterialType::Any)) {
1406+
if (lse::api::BlockHelper::isAir(bl)
1407+
|| (legacy.mProperties == BlockProperty::None && legacy.mMaterial.mType == MaterialType::Any)) {
14031408
return Local<Value>();
14041409
}
1405-
return BlockClass::newBlock(bl, bp, actor->getDimensionId());
1410+
return BlockClass::newBlock(bl, bp, actor->getDimension().mId);
14061411
}
14071412
CATCH("Fail in getBlockFromViewVector!");
14081413
}
@@ -1795,16 +1800,18 @@ Local<Value> McClass::explode(const Arguments& args) {
17951800
bool isDestroy = args[beginIndex + 2].asBoolean().value();
17961801
bool isFire = args[beginIndex + 3].asBoolean().value();
17971802

1798-
return Boolean::newBoolean(ll::service::getLevel()->explode(
1799-
ll::service::getLevel()->getDimension(pos.dim).lock()->getBlockSourceFromMainChunkSource(),
1800-
source.value_or(nullptr),
1801-
pos.getVec3(),
1802-
radius,
1803-
isFire,
1804-
isDestroy,
1805-
FLT_MAX,
1806-
false
1807-
));
1803+
return Boolean::newBoolean(
1804+
ll::service::getLevel()->explode(
1805+
ll::service::getLevel()->getDimension(pos.dim).lock()->getBlockSourceFromMainChunkSource(),
1806+
source.value_or(nullptr),
1807+
pos.getVec3(),
1808+
radius,
1809+
isFire,
1810+
isDestroy,
1811+
FLT_MAX,
1812+
false
1813+
)
1814+
);
18081815
} else {
18091816
CHECK_ARG_TYPE(args[beginIndex + 1], ValueKind::kNumber);
18101817
CHECK_ARG_TYPE(args[beginIndex + 2], ValueKind::kNumber);
@@ -1816,16 +1823,18 @@ Local<Value> McClass::explode(const Arguments& args) {
18161823
bool isDestroy = args[beginIndex + 3].asBoolean().value();
18171824
bool isFire = args[beginIndex + 4].asBoolean().value();
18181825

1819-
return Boolean::newBoolean(ll::service::getLevel()->explode(
1820-
ll::service::getLevel()->getDimension(pos.dim).lock()->getBlockSourceFromMainChunkSource(),
1821-
source.value_or(nullptr),
1822-
pos.getVec3(),
1823-
radius,
1824-
isFire,
1825-
isDestroy,
1826-
maxResistance,
1827-
false
1828-
));
1826+
return Boolean::newBoolean(
1827+
ll::service::getLevel()->explode(
1828+
ll::service::getLevel()->getDimension(pos.dim).lock()->getBlockSourceFromMainChunkSource(),
1829+
source.value_or(nullptr),
1830+
pos.getVec3(),
1831+
radius,
1832+
isFire,
1833+
isDestroy,
1834+
maxResistance,
1835+
false
1836+
)
1837+
);
18291838
}
18301839
}
18311840
CATCH("Fail in Explode!");

0 commit comments

Comments
 (0)