Skip to content

Commit 44b413f

Browse files
committed
feat: adapt to LeviLamina 0.12.x(WIP)
1 parent 7d48c97 commit 44b413f

15 files changed

+75
-76
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "native",
55
"description": "A plugin engine for running LLSE plugins on LeviLamina",
66
"author": "LiteLDev",
7-
"version": "0.6.4",
7+
"version": "0.7.0",
88
"dependencies": [
99
{
1010
"name": "LegacyMoney"

src/legacy/api/BlockEntityAPI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ Local<Value> BlockEntityClass::setNbt(const Arguments& args) {
9494
try {
9595
auto nbt = NbtCompoundClass::extract(args[0]);
9696
if (!nbt) return Local<Value>(); // Null
97-
void* helper = LL_RESOLVE_SYMBOL("??_7DefaultDataLoadHelper@@6B@");
98-
blockEntity->load(*ll::service::getLevel(), *nbt, (DataLoadHelper&)helper);
97+
DefaultDataLoadHelper helper;
98+
blockEntity->load(*ll::service::getLevel(), *nbt, helper);
9999
return Boolean::newBoolean(true);
100100
}
101101
CATCH("Fail in setNbt!")

src/legacy/api/CommandAPI.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "mc/deps/json/JsonHelpers.h"
2727
#include "mc/enums/CurrentCmdVersion.h"
2828
#include "mc/locale/I18n.h"
29+
#include "mc/locale/Localization.h"
2930
#include "mc/server/ServerLevel.h"
3031
#include "mc/server/commands/BlockStateCommandParam.h"
3132
#include "mc/server/commands/CommandBlockName.h"
@@ -182,6 +183,8 @@ Local<Value> McClass::runcmd(const Arguments& args) {
182183
CATCH("Fail in RunCmd!")
183184
}
184185

186+
I18n* getI18n(); // Stupid Mojang
187+
185188
Local<Value> McClass::runcmdEx(const Arguments& args) {
186189
CHECK_ARGS_COUNT(args, 1)
187190
CHECK_ARG_TYPE(args[0], ValueKind::kString)
@@ -200,7 +203,9 @@ Local<Value> McClass::runcmdEx(const Arguments& args) {
200203
if (command) {
201204
command->run(origin, output);
202205
for (auto msg : output.getMessages()) {
203-
outputStr = outputStr.append(I18n::get(msg.getMessageId(), msg.getParams())).append("\n");
206+
std::string temp;
207+
getI18n()->getCurrentLanguage()->get(msg.getMessageId(), temp, msg.getParams());
208+
outputStr += temp.append("\n");
204209
}
205210
if (output.getMessages().size()) {
206211
outputStr.pop_back();

src/legacy/api/EntityAPI.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,25 @@
1010
#include "api/NbtAPI.h"
1111
#include "api/PlayerAPI.h"
1212
#include "ll/api/base/StdInt.h"
13+
#include "ll/api/memory/Memory.h"
1314
#include "ll/api/service/Bedrock.h"
1415
#include "mc/common/HitDetection.h"
1516
#include "mc/dataloadhelper/DataLoadHelper.h"
1617
#include "mc/entity/utilities/ActorDamageCause.h"
1718
#include "mc/entity/utilities/ActorType.h"
1819
#include "mc/enums/FacingID.h"
20+
#include "mc/world/SimpleContainer.h"
1921
#include "mc/world/actor/ActorDefinitionIdentifier.h"
2022
#include "mc/world/effect/MobEffectInstance.h"
2123
#include "mc/world/level/Spawner.h"
2224
#include "mc/world/level/block/Block.h"
2325

2426
#include <magic_enum.hpp>
2527
#include <mc/entity/EntityContext.h>
28+
#include <mc/entity/utilities/ActorEquipment.h>
2629
#include <mc/entity/utilities/ActorMobilityUtils.h>
2730
#include <mc/nbt/CompoundTag.h>
2831
#include <mc/server/ServerPlayer.h>
29-
#include <mc/world/SimpleContainer.h>
3032
#include <mc/world/actor/Mob.h>
3133
#include <mc/world/actor/SynchedActorData.h>
3234
#include <mc/world/actor/SynchedActorDataEntityWrapper.h>
@@ -943,7 +945,7 @@ Local<Value> EntityClass::getArmor(const Arguments& args) {
943945
Actor* entity = get();
944946
if (!entity) return Local<Value>();
945947

946-
return ContainerClass::newContainer(&entity->getArmorContainer());
948+
return ContainerClass::newContainer(&ActorEquipment::getArmorContainer(entity->getEntityContext()));
947949
}
948950
CATCH("Fail in getArmor!");
949951
}
@@ -968,9 +970,7 @@ Local<Value> EntityClass::hasContainer(const Arguments& args) {
968970
if (!entity) return Local<Value>();
969971

970972
Vec3 pos = entity->getPosition();
971-
return Boolean::newBoolean(
972-
entity->getDimension().getBlockSourceFromMainChunkSource().tryGetContainer(BlockPos(pos)) ? true : false
973-
);
973+
return Boolean::newBoolean(entity->getDimensionBlockSource().tryGetContainer(BlockPos(pos)) ? true : false);
974974
}
975975
CATCH("Fail in hasContainer!");
976976
}
@@ -980,9 +980,8 @@ Local<Value> EntityClass::getContainer(const Arguments& args) {
980980
Actor* entity = get();
981981
if (!entity) return Local<Value>();
982982

983-
Vec3 pos = entity->getPosition();
984-
Container* container =
985-
entity->getDimension().getBlockSourceFromMainChunkSource().tryGetContainer(BlockPos(pos));
983+
Vec3 pos = entity->getPosition();
984+
Container* container = entity->getDimensionBlockSource().tryGetContainer(BlockPos(pos));
986985
return container ? ContainerClass::newContainer(container) : Local<Value>();
987986
}
988987
CATCH("Fail in getContainer!");
@@ -1307,7 +1306,7 @@ Local<Value> EntityClass::setNbt(const Arguments& args) {
13071306
auto nbt = NbtCompoundClass::extract(args[0]);
13081307
if (!nbt) return Local<Value>(); // Null
13091308

1310-
DefaultDataLoadHelper helper = DefaultDataLoadHelper();
1309+
DefaultDataLoadHelper helper;
13111310
return Boolean::newBoolean(entity->load(*nbt, helper));
13121311
}
13131312
CATCH("Fail in setNbt!")

src/legacy/api/GlobalNativePointer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Local<Value> GlobalNativePointer::getScoreboardPtr(const Arguments& args) {
4141
}
4242

4343
Local<Value> GlobalNativePointer::getAllowListFilePtr(const Arguments& args) {
44-
return NativePointer::newNativePointer(AllowListCommand::$mAllowListFile());
44+
return NativePointer::newNativePointer(AllowListCommand::mAllowListFile);
4545
}
4646

4747
Local<Value> GlobalNativePointer::getPropertiesSettingsPtr(const Arguments& args) {

src/legacy/api/LoggerAPI.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "api/APIHelp.h"
44
#include "api/PlayerAPI.h"
55
#include "engine/EngineOwnData.h"
6+
#include "ll/api/Logger.h"
67
#include "mc/world/actor/player/Player.h"
78
#include "utils/Utils.h"
89

@@ -42,7 +43,7 @@ string& StrReplace(string& str, const string& to_replaced, const string& new_str
4243
}
4344
////////////////// Helper //////////////////
4445

45-
void inline LogDataHelper(ll::Logger::OutputStream* outStream, const Arguments& args) {
46+
void inline LogDataHelper(ll::OutputStream* outStream, const Arguments& args) {
4647
std::string res;
4748
for (int i = 0; i < args.size(); ++i) res += ValueToString(args[i]);
4849
(*outStream)(res);

src/legacy/api/PlayerAPI.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include "mc/world/ActorUniqueID.h"
6363
#include "mc/world/Container.h"
6464
#include "mc/world/Minecraft.h"
65+
#include "mc/world/SimpleContainer.h"
6566
#include "mc/world/actor/player/EnderChestContainer.h"
6667
#include "mc/world/actor/player/PlayerScoreSetFunction.h"
6768
#include "mc/world/actor/player/PlayerUISlot.h"
@@ -79,6 +80,7 @@
7980

8081
#include <algorithm>
8182
#include <mc/entity/EntityContext.h>
83+
#include <mc/entity/utilities/ActorEquipment.h>
8284
#include <mc/entity/utilities/ActorMobilityUtils.h>
8385
#include <mc/nbt/CompoundTag.h>
8486
#include <mc/world/SimpleContainer.h>
@@ -370,7 +372,8 @@ Local<Value> McClass::setPlayerNbt(const Arguments& args) {
370372
auto tag = NbtCompoundClass::extract(args[1]);
371373
Player* player = ll::service::getLevel()->getPlayer(uuid);
372374
if (player) {
373-
player->load(*tag);
375+
DefaultDataLoadHelper defaultDataLoadHelper;
376+
player->load(*tag, defaultDataLoadHelper);
374377
return Boolean::newBoolean(true);
375378
} else {
376379
DBStorage* db = MoreGlobal::db;
@@ -414,8 +417,8 @@ Local<Value> McClass::setPlayerNbtTags(const Arguments& args) {
414417
}
415418
}
416419
}
417-
418-
player->load(playerNbt);
420+
DefaultDataLoadHelper defaultDataLoadHelper;
421+
player->load(playerNbt, defaultDataLoadHelper);
419422
player->refreshInventory();
420423
return Boolean::newBoolean(true);
421424
}
@@ -1626,7 +1629,7 @@ Local<Value> PlayerClass::getArmor(const Arguments& args) {
16261629
Player* player = get();
16271630
if (!player) return Local<Value>();
16281631

1629-
return ContainerClass::newContainer(&player->getArmorContainer());
1632+
return ContainerClass::newContainer(&ActorEquipment::getArmorContainer(player->getEntityContext()));
16301633
}
16311634
CATCH("Fail in getArmor!");
16321635
}
@@ -2840,26 +2843,26 @@ Local<Value> PlayerClass::clearItem(const Arguments& args) {
28402843
player->getInventory().removeItem(slot, clearCount);
28412844
}
28422845
}
2843-
auto& handSlots = player->getHandContainer().getSlots();
2846+
auto& handSlots = ActorEquipment::getHandContainer(player->getEntityContext()).getSlots();
28442847
for (unsigned short slot = 0; slot < handSlots.size(); ++slot) {
28452848
if (handSlots[slot]->getTypeName() == args[0].asString().toString()) {
28462849
if (handSlots[slot]->mCount < clearCount) {
28472850
result += handSlots[slot]->mCount;
28482851
} else {
28492852
result += clearCount;
28502853
}
2851-
player->getHandContainer().removeItem(slot, clearCount);
2854+
ActorEquipment::getHandContainer(player->getEntityContext()).removeItem(slot, clearCount);
28522855
}
28532856
}
2854-
auto& armorSlots = player->getArmorContainer().getSlots();
2857+
auto& armorSlots = ActorEquipment::getArmorContainer(player->getEntityContext()).getSlots();
28552858
for (unsigned short slot = 0; slot < armorSlots.size(); ++slot) {
28562859
if (armorSlots[slot]->getTypeName() == args[0].asString().toString()) {
28572860
if (armorSlots[slot]->mCount < clearCount) {
28582861
result += armorSlots[slot]->mCount;
28592862
} else {
28602863
result += clearCount;
28612864
}
2862-
player->getArmorContainer().removeItem(slot, clearCount);
2865+
ActorEquipment::getArmorContainer(player->getEntityContext()).removeItem(slot, clearCount);
28632866
}
28642867
}
28652868
player->refreshInventory();
@@ -3212,8 +3215,8 @@ Local<Value> PlayerClass::getAllItems(const Arguments& args) {
32123215
const ItemStack& hand = player->getCarriedItem();
32133216
const ItemStack& offHand = player->getOffhandSlot();
32143217
std::vector<const ItemStack*> inventory = player->getInventory().getSlots();
3215-
std::vector<const ItemStack*> armor = player->getArmorContainer().getSlots();
3216-
std::vector<const ItemStack*> endChest = player->getEnderChestContainer()->getSlots();
3218+
std::vector<const ItemStack*> armor = ActorEquipment::getArmorContainer(player->getEntityContext()).getSlots();
3219+
std::vector<const ItemStack*> endChest = player->getEnderChestContainer()->getSlots();
32173220

32183221
Local<Object> result = Object::newObject();
32193222

src/lse/PluginManager.cpp

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "legacy/api/EventAPI.h"
66
#include "legacy/engine/EngineManager.h"
77
#include "legacy/engine/EngineOwnData.h"
8+
#include "ll/api/Expected.h"
89

910
#include <ScriptX/ScriptX.h>
1011
#include <exception>
@@ -60,7 +61,7 @@ namespace lse {
6061

6162
PluginManager::PluginManager() : ll::plugin::PluginManager(PluginManagerName) {}
6263

63-
auto PluginManager::load(ll::plugin::Manifest manifest) -> bool {
64+
ll::Expected<> PluginManager::load(ll::plugin::Manifest manifest) {
6465
auto& logger = getSelfPluginInstance().getLogger();
6566
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON
6667
std::filesystem::path dirPath = ll::plugin::getPluginsRoot() / manifest.name; // Plugin path
@@ -207,8 +208,7 @@ auto PluginManager::load(ll::plugin::Manifest manifest) -> bool {
207208
plugin->onEnable([](ll::plugin::Plugin& plugin) { return true; });
208209
plugin->onDisable([](ll::plugin::Plugin& plugin) { return true; });
209210
} catch (const Exception& e) {
210-
EngineScope engineScope(scriptEngine);
211-
logger.error("Failed to load plugin {0}: {1}\n{2}", manifest.name, e.message(), e.stacktrace());
211+
EngineScope engineScope(scriptEngine);
212212
ExitEngineScope exit;
213213
LLSERemoveTimeTaskData(&scriptEngine);
214214
LLSERemoveAllEventListeners(&scriptEngine);
@@ -220,23 +220,23 @@ auto PluginManager::load(ll::plugin::Manifest manifest) -> bool {
220220

221221
EngineManager::unregisterEngine(&scriptEngine);
222222

223-
return false;
223+
return ll::makeStringError(
224+
"Failed to load plugin {0}: {1}\n{2}"_tr(manifest.name, e.message(), e.stacktrace())
225+
);
224226
}
225227

226-
if (!addPlugin(manifest.name, plugin)) {
227-
throw std::runtime_error("Failed to register plugin {}"_tr(manifest.name));
228-
}
228+
addPlugin(manifest.name, plugin);
229229

230-
return true;
230+
return {};
231231

232232
} catch (const std::exception& e) {
233233
logger.error("Failed to load plugin {0}: {1}", manifest.name, e.what());
234234
}
235235

236-
return true;
236+
return {};
237237
}
238238

239-
auto PluginManager::unload(std::string_view name) -> bool {
239+
ll::Expected<> PluginManager::unload(std::string_view name) {
240240
auto& logger = getSelfPluginInstance().getLogger();
241241

242242
try {
@@ -254,21 +254,12 @@ auto PluginManager::unload(std::string_view name) -> bool {
254254
LLSERemoveAllExportedFuncs(&scriptEngine);
255255

256256
scriptEngine.getData().reset();
257-
258257
EngineManager::unregisterEngine(&scriptEngine);
259-
260258
scriptEngine.destroy(); // TODO: use unique_ptr to manage the engine.
261-
262-
if (!erasePlugin(name)) {
263-
throw std::runtime_error(fmt::format("Failed to unregister plugin {}", name));
264-
return false;
265-
}
266-
267-
return true;
268-
259+
erasePlugin(name);
260+
return {};
269261
} catch (const std::exception& e) {
270-
logger.error("Failed to unload plugin {}: {}", name, e.what());
271-
return false;
262+
return ll::makeStringError("Failed to unload plugin {}: {}"_tr(name, e.what()));
272263
}
273264
}
274265

src/lse/PluginManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class PluginManager : public ll::plugin::PluginManager {
1818
~PluginManager() override = default;
1919

2020
private:
21-
auto load(ll::plugin::Manifest manifest) -> bool override;
22-
auto unload(std::string_view name) -> bool override;
21+
ll::Expected<> load(ll::plugin::Manifest manifest) override;
22+
ll::Expected<> unload(std::string_view name) override;
2323
};
2424

2525
} // namespace lse

tooth.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"tooth": "github.com/LiteLDev/LegacyScriptEngine",
4-
"version": "0.6.4",
4+
"version": "0.7.0",
55
"info": {
66
"name": "LegacyScriptEngine",
77
"description": "A plugin engine for running LLSE plugins on LeviLamina",
@@ -12,7 +12,7 @@
1212
]
1313
},
1414
"dependencies": {
15-
"gitea.litebds.com/LiteLDev/legacy-script-engine-lua": "0.6.4",
16-
"gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs": "0.6.4"
15+
"gitea.litebds.com/LiteLDev/legacy-script-engine-lua": "0.7.0",
16+
"gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs": "0.7.0"
1717
}
1818
}

0 commit comments

Comments
 (0)