adapt: adapt LeviLamina 1.0.0-rc.3

This commit is contained in:
子沐呀
2025-01-12 20:32:24 +08:00
Unverified
parent 6e57f87129
commit 846575f83d
13 changed files with 77 additions and 131 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ public:
auto nextId = getNextId();
cretateBinaryStream(nextId);
if(auto bs = getBinaryStream(nextId); bs !=nullptr){
*getBinaryStream(nextId)->mBuffer = *getBinaryStream(id)->mBuffer;
getBinaryStream(nextId)->mBuffer = getBinaryStream(id)->mBuffer;
}
return nextId;
}
+39 -28
View File
@@ -1,3 +1,4 @@
#include "GMLIB/Mod/CustomRecipe/CustomRecipe.h"
#include "Global.h"
#include <regex>
@@ -7,7 +8,7 @@ bool isInteger(const std::string& str) {
}
ActorUniqueID parseScriptUniqueID(std::string const& uniqueId) {
return isInteger(uniqueId) ? ActorUniqueID(std::stoll(uniqueId)) : ActorUniqueID::INVALID_ID;
return isInteger(uniqueId) ? ActorUniqueID(std::stoll(uniqueId)) : ActorUniqueID::INVALID_ID();
}
void Export_Compatibility_API() {
@@ -394,7 +395,7 @@ void Export_Compatibility_API() {
RemoteCall::exportAs("GMLIB_API", "getAllScoreboardEntities", []() -> std::vector<std::string> {
std::vector<std::string> result;
for (auto& uniqueId : GMLIB_Scoreboard::getInstance()->getAllEntities()) {
result.push_back(std::to_string(uniqueId.id));
result.push_back(std::to_string(uniqueId.rawID));
}
return result;
});
@@ -418,7 +419,7 @@ void Export_Compatibility_API() {
for (auto& uniqueId : GMLIB_Scoreboard::getInstance()->getAllEntities()) {
result.push_back({
{"Type", "Entity" },
{"UniqueId", std::to_string(uniqueId.id)}
{"UniqueId", std::to_string(uniqueId.rawID)}
});
}
return result;
@@ -431,7 +432,7 @@ void Export_Compatibility_API() {
return ll::service::getLevel()->getPlayer(parseScriptUniqueID(uniqueId));
});
RemoteCall::exportAs("GMLIB_API", "getEntityFromUniqueId", [](std::string const& uniqueId) -> Actor* {
return ll::service::getLevel()->fetchEntity(parseScriptUniqueID(uniqueId));
return ll::service::getLevel()->fetchEntity(parseScriptUniqueID(uniqueId), false);
});
RemoteCall::exportAs("GMLIB_API", "getWorldSpawn", []() -> std::pair<BlockPos, int> {
return {GMLIB_Level::getInstance()->getWorldSpawn(), 0};
@@ -555,10 +556,7 @@ void Export_Compatibility_API() {
return item->canDestroySpecial(*block);
});
RemoteCall::exportAs("GMLIB_API", "blockCanDropWithAnyTool", [](Block const* block) -> bool {
return block->canDropWithAnyTool();
});
RemoteCall::exportAs("GMLIB_API", "blockIsAlwaysDestroyable", [](Block const* block) -> bool {
return block->getMaterial().isAlwaysDestroyable();
return !block->requiresCorrectToolForDrops();
});
RemoteCall::exportAs(
"GMLIB_API",
@@ -583,7 +581,7 @@ void Export_Compatibility_API() {
"getBlockLightEmission",
[](std::string const& blockName, short legacyData) -> char {
return Block::tryGetFromRegistry(blockName)
.transform([](const Block& block) -> char { return (char)block.getLightEmission().value; })
.transform([](const Block& block) -> char { return (char)block.getLightEmission().mValue; })
.value_or(-1);
}
);
@@ -622,13 +620,6 @@ void Export_Compatibility_API() {
return result;
}
);
RemoteCall::exportAs("GMLIB_API", "getLegalEnchants", [](ItemStack const* item) -> std::vector<std::string> {
std::vector<std::string> result;
for (auto& enchant : EnchantUtils::getLegalEnchants(item->getItem())) {
result.push_back(Enchant::getEnchant((Enchant::Type)enchant)->getStringId());
}
return result;
});
RemoteCall::exportAs("GMLIB_API", "getEnchantTypeNameFromId", [](int id) -> std::string {
if (auto enchant = Enchant::getEnchant((Enchant::Type)id)) {
return std::string(enchant->getStringId());
@@ -669,10 +660,10 @@ void Export_Compatibility_API() {
[](Player* player, ItemStack const* item, bool randomly) -> bool { return player->drop(*item, randomly); }
);
RemoteCall::exportAs("GMLIB_API", "getPlayerRuntimeId", [](Player* player) -> uint64 {
return player->getRuntimeID().id;
return player->getRuntimeID().rawID;
});
RemoteCall::exportAs("GMLIB_API", "getEntityRuntimeId", [](Actor* entity) -> uint64 {
return entity->getRuntimeID().id;
return entity->getRuntimeID().rawID;
});
RemoteCall::exportAs("GMLIB_API", "getEntityNameTag", [](Actor* entity) -> std::string {
return entity->getNameTag();
@@ -730,7 +721,7 @@ void Export_Compatibility_API() {
}
);
RemoteCall::exportAs("GMLIB_API", "getPlayerHungry", [](Player* player) -> float {
return player->getMutableAttribute(Player::HUNGER)->getCurrentValue();
return player->getMutableAttribute(Player::HUNGER())->getCurrentValue();
});
RemoteCall::exportAs("GMLIB_API", "getPlayerArmorCoverPercentage", [](Player* player) -> float {
return player->getArmorCoverPercentage();
@@ -739,7 +730,7 @@ void Export_Compatibility_API() {
return player->getArmorValue();
});
RemoteCall::exportAs("GMLIB_API", "getEntityOwnerUniqueId", [](Actor* entity) -> int64 {
return entity->getOwnerId().id;
return entity->getOwnerId().rawID;
});
RemoteCall::exportAs("GMLIB_API", "getItemCategoryName", [](ItemStack const* item) -> std::string {
return item->getCategoryName();
@@ -757,7 +748,7 @@ void Export_Compatibility_API() {
return false;
});
RemoteCall::exportAs("GMLIB_API", "setPlayerUIItem", [](Player* player, int slot, ItemStack const* item) -> void {
player->setPlayerUIItem((PlayerUISlot)slot, *item);
player->setPlayerUIItem((PlayerUISlot)slot, *item, false);
});
RemoteCall::exportAs("GMLIB_API", "getPlayerUIItem", [](Player* player, int slot) -> ItemStack* {
return const_cast<ItemStack*>(&player->getPlayerUIItem((PlayerUISlot)slot));
@@ -792,25 +783,25 @@ void Export_Compatibility_API() {
});
RemoteCall::exportAs("GMLIB_API", "getEntityEffectDuration", [](Actor* entity, int effectId) -> int {
if (auto effect = entity->getEffect(effectId)) {
return effect->mDuration;
return effect->mDuration->mValue;
}
return 0;
});
RemoteCall::exportAs("GMLIB_API", "getEntityEffectDurationEasy", [](Actor* entity, int effectId) -> int {
if (auto effect = entity->getEffect(effectId)) {
return effect->mDurationEasy;
return effect->mDurationEasy->transform([](auto&& duration) -> int { return duration.mValue; }).value_or(0);
}
return 0;
});
RemoteCall::exportAs("GMLIB_API", "getEntityEffectDurationHard", [](Actor* entity, int effectId) -> int {
if (auto effect = entity->getEffect(effectId)) {
return effect->mDurationHard;
return effect->mDurationHard->transform([](auto&& duration) -> int { return duration.mValue; }).value_or(0);
}
return 0;
});
RemoteCall::exportAs("GMLIB_API", "getEntityEffectDurationNormal", [](Actor* entity, int effectId) -> int {
if (auto effect = entity->getEffect(effectId)) {
return effect->mDurationNormal;
return effect->mDurationNormal->transform([](auto&& duration) -> int { return duration.mValue; }).value_or(0);
}
return 0;
});
@@ -857,7 +848,13 @@ void Export_Compatibility_API() {
std::vector<Recipes::Type> types;
char rt = 'A';
for (auto& ing : ingredients) {
types.emplace_back(ing, rt++, 1, 0);
auto ingredient = RecipeIngredient{ing, 0,1};
types.push_back(Recipes::Type{
(Item*)ingredient.getItem(),
ingredient.getBlock(),
ingredient,
rt++
});
}
GMLIB::Mod::CustomRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, *result);
}
@@ -873,9 +870,23 @@ void Export_Compatibility_API() {
std::vector<Recipes::Type> types;
char rt = 'A';
for (auto& ing : ingredients) {
types.emplace_back(ing, rt++, 1, 0);
auto ingredient = RecipeIngredient{ing, 0, 1};
types.push_back(Recipes::Type{(Item*)ingredient.getItem(), ingredient.getBlock(), ingredient, rt++});
}
GMLIB::Mod::CustomRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, *result);
auto tmp = RecipeUnlockingRequirement();
tmp.mContext = RecipeUnlockingRequirement::UnlockingContext::AlwaysUnlocked;
ll::service::bedrock::getLevel()->getRecipes().addShapedRecipe(
recipe_id,
ItemInstance(*result),
shape,
types,
{"crafting_table"},
50,
nullptr,
tmp,
SemVersion(1, 20, 80, "", ""),
true
);
}
);
RemoteCall::exportAs("GMLIB_API", "entityIsType", [](Actor* entity, int type) -> bool {
+7 -8
View File
@@ -1,12 +1,10 @@
#include "Entry.h"
#include "Global.h"
ll::Logger logger(PLUGIN_NAME);
namespace gmlib {
std::unique_ptr<LegacyRemoteCallApi>& LegacyRemoteCallApi::getInstance() {
static std::unique_ptr<LegacyRemoteCallApi> instance;
LegacyRemoteCallApi& LegacyRemoteCallApi::getInstance() {
static LegacyRemoteCallApi instance;
return instance;
}
@@ -18,14 +16,15 @@ bool LegacyRemoteCallApi::load() {
Export_Event_API();
Export_BinaryStream_API();
// Export_Form_API();
logger.info("GMLIB-LegacyRemoteCallApi Loaded!");
logger.info(
auto logger = ll::io::LoggerRegistry::getInstance().getOrCreate(PLUGIN_NAME);
logger->info("GMLIB-LegacyRemoteCallApi Loaded!");
logger->info(
"Loaded Version: {} with {}",
fmt::format(fg(fmt::color::pink), "GMLIB-" + GMLIB::Version::getLibVersionString()),
fmt::format(fg(fmt::color::light_green), "GMLIB-LegacyRemoteCallApi-" + LIB_VERSION.asString())
);
logger.info("Author: GroupMountain");
logger.info("Repository: https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi");
logger->info("Author: GroupMountain");
logger->info("Repository: https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi");
return true;
}
+2 -3
View File
@@ -1,5 +1,4 @@
#pragma once
#include <span>
#include <ll/api/mod/NativeMod.h>
#include <ll/api/mod/RegisterHelper.h>
@@ -8,9 +7,9 @@ namespace gmlib {
class LegacyRemoteCallApi {
public:
static std::unique_ptr<LegacyRemoteCallApi>& getInstance();
static LegacyRemoteCallApi& getInstance();
LegacyRemoteCallApi(ll::mod::NativeMod& self) : mSelf(self) {}
LegacyRemoteCallApi() : mSelf(*ll::mod::NativeMod::current()) {}
[[nodiscard]] ll::mod::NativeMod& getSelf() const { return mSelf; }
+14 -14
View File
@@ -140,7 +140,7 @@ void Export_Event_API() {
(ItemStack * item, std::pair<Vec3, int> position, int64 spawnerUniqueId, bool isCancelled),
(&event.getItem(),
{event.getPosition(), event.getBlockSource().getDimensionId().id},
event.getSpawner().has_value() ? event.getSpawner()->getOrCreateUniqueID().id : -1,
event.getSpawner().has_value() ? event.getSpawner()->getOrCreateUniqueID().rawID : -1,
event.isCancelled()),
event.setCancelled(result);
);
@@ -151,7 +151,7 @@ void Export_Event_API() {
(Actor * item, std::pair<Vec3, int> position, int64 spawnerUniqueId),
(&event.self(),
{event.getPosition(), event.getBlockSource().getDimensionId().id},
event.getSpawner().has_value() ? event.getSpawner()->getOrCreateUniqueID().id : -1),
event.getSpawner().has_value() ? event.getSpawner()->getOrCreateUniqueID().rawID : -1),
,
);
}
@@ -221,7 +221,7 @@ void Export_Event_API() {
Actor* source = nullptr;
if (damageSource.isEntitySource()) {
auto uniqueId = damageSource.getDamagingEntityUniqueID();
source = ll::service::getLevel()->fetchEntity(uniqueId);
source = ll::service::getLevel()->fetchEntity(uniqueId, false);
if (source->getOwner()) source = source->getOwner();
}
);
@@ -254,7 +254,7 @@ void Export_Event_API() {
GMLIB::Event::EntityEvent::ProjectileCreateBeforeEvent,
(Actor * mob, int64 uniqueId, bool isCancelled),
(&event.self(),
event.getShooter() ? event.getShooter()->getOrCreateUniqueID().id : -1,
event.getShooter() ? event.getShooter()->getOrCreateUniqueID().rawID : -1,
event.isCancelled()),
event.setCancelled(result);
);
@@ -263,7 +263,7 @@ void Export_Event_API() {
REGISTER_EVENT_LISTEN(
GMLIB::Event::EntityEvent::ProjectileCreateAfterEvent,
(Actor * mob, int64 uniqueId),
(&event.self(), event.getShooter() ? event.getShooter()->getOrCreateUniqueID().id : -1),
(&event.self(), event.getShooter() ? event.getShooter()->getOrCreateUniqueID().rawID : -1),
);
}
case doHash("gmlib::SpawnWanderingTraderBeforeEvent"): {
@@ -299,10 +299,10 @@ void Export_Event_API() {
(Player*)&event.self(),
magic_enum::enum_name(requestAction.mActionType).data(),
(int)requestAction.mAmount,
magic_enum::enum_name(requestAction.mSrc.mOpenContainerNetId).data(),
(int)requestAction.mSrc.mSlot,
magic_enum::enum_name(requestAction.mDst.mOpenContainerNetId).data(),
(int)requestAction.mDst.mSlot,
magic_enum::enum_name(requestAction.mSrc->mFullContainerName.mName).data(),
(int)requestAction.mSrc->mSlot,
magic_enum::enum_name(requestAction.mDst->mFullContainerName.mName).data(),
(int)requestAction.mDst->mSlot,
event.isCancelled()
),
event.setCancelled(result);,
@@ -327,10 +327,10 @@ void Export_Event_API() {
(Player*)&event.self(),
magic_enum::enum_name(requestAction.mActionType).data(),
(int)requestAction.mAmount,
magic_enum::enum_name(requestAction.mSrc.mOpenContainerNetId).data(),
(int)requestAction.mSrc.mSlot,
magic_enum::enum_name(requestAction.mDst.mOpenContainerNetId).data(),
(int)requestAction.mDst.mSlot
magic_enum::enum_name(requestAction.mSrc->mFullContainerName.mName).data(),
(int)requestAction.mSrc->mSlot,
magic_enum::enum_name(requestAction.mDst->mFullContainerName.mName).data(),
(int)requestAction.mDst->mSlot
),
,
auto& requestAction = (ItemStackRequestActionTransferBase&)event.getRequestAction();
@@ -342,7 +342,7 @@ void Export_Event_API() {
GMLIB::Event::PacketEvent::ContainerClosePacketSendAfterEvent,
(Player * player, int containerId, bool serverInitiatedClose, bool),
(event.getServerNetworkHandler()
.getServerPlayer(event.getNetworkIdentifier(), event.getPacket().mClientSubId),
._getServerPlayer(event.getNetworkIdentifier(), event.getPacket().mClientSubId),
(int)event.getPacket().mContainerId,
event.getPacket().mServerInitiatedClose,
false),
-2
View File
@@ -11,8 +11,6 @@
#define LIB_VERSION GMLIB::Version(LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH)
extern ll::Logger logger;
extern void Export_Legacy_GMLib_ModAPI();
extern void Export_Legacy_GMLib_ServerAPI();
extern void Export_Compatibility_API();
+3 -3
View File
@@ -149,7 +149,7 @@ void Export_Legacy_GMLib_ModAPI() {
if (set.contains((AllExperiments)experiment_id)) {
GMLIB_Level::addExperimentsRequire((AllExperiments)experiment_id);
} else {
ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
ll::io::LoggerRegistry::getInstance().getOrCreate("Server")->error("Experiment ID '{}' does not exist!", experiment_id);
}
});
RemoteCall::exportAs("GMLib_ModAPI", "setExperimentEnabled", [](int experiment_id, bool value) -> void {
@@ -158,7 +158,7 @@ void Export_Legacy_GMLib_ModAPI() {
std::unordered_set<AllExperiments> set(list.begin(), list.end());
if (set.contains((AllExperiments)experiment_id)) {
GMLIB_Level::getInstance()->setExperimentEnabled(((AllExperiments)experiment_id), value);
} else ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
} else ll::io::LoggerRegistry::getInstance().getOrCreate("Server")->error("Experiment ID '{}' does not exist!", experiment_id);
}
});
RemoteCall::exportAs("GMLib_ModAPI", "getExperimentEnabled", [](int experiment_id) -> bool {
@@ -168,7 +168,7 @@ void Export_Legacy_GMLib_ModAPI() {
if (set.contains((AllExperiments)experiment_id)) {
return GMLIB_Level::getInstance()->getExperimentEnabled(((AllExperiments)experiment_id));
}
ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
ll::io::LoggerRegistry::getInstance().getOrCreate("Server")->error("Experiment ID '{}' does not exist!", experiment_id);
}
return false;
});
+1 -1
View File
@@ -4,4 +4,4 @@
#define LL_MEMORY_OPERATORS
#include <ll/api/memory/MemoryOperators.h>
#include <ll/api/memory/MemoryOperators.h>