Skip to content

Commit

Permalink
refactor: support LeviLamina 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed Dec 31, 2024
1 parent 21db327 commit e4f80be
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 46 deletions.
9 changes: 5 additions & 4 deletions src/LegacyParticleAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ LL_AUTO_TYPE_INSTANCE_HOOK(

namespace legacy_particleapi {

static std::unique_ptr<LegacyParticleAPI> instance;

LegacyParticleAPI& LegacyParticleAPI::getInstance() { return *instance; }
LegacyParticleAPI& LegacyParticleAPI::getInstance() {
static LegacyParticleAPI instance;
return instance;
}

bool LegacyParticleAPI::load() {
ResourceInitHook::hook();
Expand All @@ -35,4 +36,4 @@ bool LegacyParticleAPI::disable() { return true; }

} // namespace legacy_particleapi

LL_REGISTER_MOD(legacy_particleapi::LegacyParticleAPI, legacy_particleapi::instance);
LL_REGISTER_MOD(legacy_particleapi::LegacyParticleAPI, legacy_particleapi::LegacyParticleAPI::getInstance());
4 changes: 1 addition & 3 deletions src/LegacyParticleAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class LegacyParticleAPI {
public:
static LegacyParticleAPI& getInstance();

LegacyParticleAPI(ll::mod::NativeMod& self) : mSelf(self) {}
LegacyParticleAPI() : mSelf(*ll::mod::NativeMod::current()) {}

[[nodiscard]] ll::mod::NativeMod& getSelf() const { return mSelf; }

Expand All @@ -19,8 +19,6 @@ class LegacyParticleAPI {

bool disable();

// bool unload();

private:
ll::mod::NativeMod& mSelf;
};
Expand Down
8 changes: 4 additions & 4 deletions src/ParticleAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
//
#include "ParticleAPI.h"
#include "ll/api/service/Bedrock.h"
#include "mc/deps/core/mce/Color.h"
#include "mc/deps/core/math/Color.h"
#include "mc/network/packet/SpawnParticleEffectPacket.h"
#include "mc/world/actor/player/Player.h"
#include "mc/world/level/Level.h"
#include "mc/world/level/dimension/Dimension.h"
#include "mc/world/phys/AABB.h"

#include "mc/util/MolangVariableMap.h"

namespace {
template <typename T>
Expand Down Expand Up @@ -79,8 +79,8 @@ static char getParticleColorType(ParticleCUI::ColorPalette const& p) { return pa

extern "C" {
void PTAPI_spawnParticle(int displayRadius, Vec3 const& pos, std::string const& particleName, int dimId) {
ll::service::getLevel()->getDimension(dimId)->forEachPlayer([&](Player& player) {
if (displayRadius == UINT_MAX || player.getPosition().distanceTo(pos) < displayRadius) {
ll::service::getLevel()->forEachPlayer([&](Player& player) {
if (player.getDimensionId() == dimId && displayRadius == UINT_MAX || player.getPosition().distanceTo(pos) < displayRadius) {
SpawnParticleEffectPacket pkt(pos, particleName, dimId, player.getMolangVariables());
player.sendNetworkPacket(pkt);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ParticleAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
*/
#pragma once
#include "mc/math/Vec3.h"
#include "mc/deps/core/math/Vec3.h"
#include "mc/world/level/BlockPos.h"
#include "mc/world/level/levelgen/structure/BoundingBox.h"
#include "mc/world/phys/AABB.h"
Expand Down
65 changes: 31 additions & 34 deletions xmake.lua
Original file line number Diff line number Diff line change
@@ -1,44 +1,41 @@
add_rules("mode.debug", "mode.release", "mode.releasedbg")
add_rules("mode.debug", "mode.release")

add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git")

if is_config("target_type", "server") then
add_requires("levilamina develop", {configs = {target_type = "server"}})
else
add_requires("levilamina develop", {configs = {target_type = "client"}})
end

add_requires("levibuildscript")

if not has_config("vs_runtime") then
set_runtimes("MD")
end

add_requires("levilamina 0.13.5")
option("target_type")
set_default("server")
set_showmenu(true)
set_values("server", "client")
option_end()

target("LegacyParticleAPI")
add_cxflags(
"/EHa",
"/utf-8"
)
add_defines(
"PARTICLEAPI_EXPORTS"
)
add_files(
"src/**.cpp"
)
add_includedirs(
"src"
)
add_packages(
"levilamina"
)
add_shflags(
"/DELAYLOAD:bedrock_server.dll"
)
target("legacy-particle-api")
add_rules("@levibuildscript/linkrule")
add_rules("@levibuildscript/modpacker")
add_cxflags( "/EHa", "/utf-8", "/W4", "/w44265", "/w44289", "/w44296", "/w45263", "/w44738", "/w45204")
add_defines("NOMINMAX", "UNICODE", "PARTICLEAPI_EXPORTS")
add_packages("levilamina")
set_exceptions("none")
set_kind("shared")
set_languages("cxx20")

after_build(function (target)
local plugin_packer = import("scripts.after_build")

local plugin_define = {
pluginName = target:name(),
pluginFile = path.filename(target:targetfile()),
}

plugin_packer.pack_plugin(target,plugin_define)
end)
set_languages("c++20")
set_symbols("debug")
add_files("src/**.cpp")
add_includedirs("src")
-- if is_config("target_type", "server") then
-- add_includedirs("src-server")
-- add_files("src-server/**.cpp")
-- else
-- add_includedirs("src-client")
-- add_files("src-client/**.cpp")
-- end

0 comments on commit e4f80be

Please sign in to comment.