feat: Initialize the mod
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#include <gmlib/mod/item/CustomItemRegistry.h>
|
||||
#include <gmlib/mod/item/base/ICustomItem.h>
|
||||
#include <ll/api/base/Containers.h>
|
||||
#include <ll/api/thread/ServerThreadExecutor.h>
|
||||
#include <mc/deps/core/math/Vec3.h>
|
||||
#include <mc/deps/core/string/HashedString.h>
|
||||
#include <mc/world/actor/player/Player.h>
|
||||
#include <mc/world/level/BlockSource.h>
|
||||
#include <mc/world/level/block/Block.h>
|
||||
#include <mc/world/gamemode/InteractionResult.h>
|
||||
#include <mc/world/item/VanillaItemNames.h>
|
||||
#include <mc/world/level/BlockPos.h>
|
||||
|
||||
namespace DebugStick {
|
||||
|
||||
class DebugStickItem : public gmlib::mod::ICustomItem {
|
||||
public:
|
||||
DebugStickItem() : ICustomItem(VanillaItemNames::DebugStick()){}
|
||||
|
||||
uint8_t getItemMaxStackSize() const override { return 1; }
|
||||
|
||||
gmlib::mod::ItemIcon getIcon() const override { return "stick"; }
|
||||
|
||||
std::string getDisplayName() const override { return "item.debug_stick.name"; }
|
||||
|
||||
bool isFoil() const override { return true; }
|
||||
|
||||
Rarity getBaseRarity() const override { return Rarity::Epic; }
|
||||
|
||||
InteractionResult _useOn(ItemStack&, Actor& entity, BlockPos pos, uchar, Vec3 const&) const override {
|
||||
static ll::DenseMap<Player*, std::shared_ptr<ll::data::CancellableCallback>> mTimer;
|
||||
if (!entity.isPlayer()) return {InteractionResult::Result::Fail};
|
||||
auto& player = static_cast<Player&>(entity);
|
||||
if (auto it = mTimer.find(&player); it != mTimer.end() && it->second) {
|
||||
it->second->cancel();
|
||||
}
|
||||
mTimer[&player] = ll::thread::ServerThreadExecutor::getDefault().executeAfter(
|
||||
[&player, pos]() -> void { //
|
||||
auto& region = player.getDimensionBlockSource();
|
||||
auto& oldBlock = region.getBlock(pos);
|
||||
auto* newBlock = oldBlock.getLegacyBlock().getNextBlockPermutation(oldBlock);
|
||||
if (newBlock) region.setBlock(pos, *newBlock, 3, nullptr, &player);
|
||||
},
|
||||
std::chrono::milliseconds(50)
|
||||
);
|
||||
return {InteractionResult::Result::Swing};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace DebugStick
|
||||
|
||||
inline static auto GMLIB_CUSTOM_ITEM_DebugStickItem = []() -> bool {
|
||||
gmlib::mod::CustomItemRegistry::getInstance().registerItem<DebugStick::DebugStickItem>();
|
||||
return true;
|
||||
}();
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "Entry.h"
|
||||
#include <gmlib/gm/i18n/ResourceI18n.h>
|
||||
#include <ll/api/mod/RegisterHelper.h>
|
||||
|
||||
namespace DebugStick {
|
||||
|
||||
Entry& Entry::getInstance() {
|
||||
static Entry instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool Entry::load() {
|
||||
auto version = getSelf().getManifest().version.value_or(ll::data::Version{0, 0, 0});
|
||||
auto resource = gmlib::i18n::ResourceI18n(
|
||||
getSelf().getModDir(),
|
||||
getSelf().getName(),
|
||||
version.major,
|
||||
version.minor,
|
||||
version.patch
|
||||
);
|
||||
resource.addLanguagesFromDirectory(getSelf().getLangDir());
|
||||
resource.loadAllLanguages();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Entry::enable() { return true; }
|
||||
|
||||
bool Entry::disable() { return true; }
|
||||
|
||||
bool Entry::unload() { return true; }
|
||||
|
||||
} // namespace DebugStick
|
||||
|
||||
LL_REGISTER_MOD(DebugStick::Entry, DebugStick::Entry::getInstance());
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include <ll/api/mod/NativeMod.h>
|
||||
|
||||
namespace DebugStick {
|
||||
|
||||
class Entry {
|
||||
|
||||
public:
|
||||
static Entry& getInstance();
|
||||
|
||||
Entry() : mSelf(*ll::mod::NativeMod::current()) {}
|
||||
|
||||
[[nodiscard]] ll::mod::NativeMod& getSelf() const { return mSelf; }
|
||||
|
||||
bool load();
|
||||
bool enable();
|
||||
bool disable();
|
||||
bool unload();
|
||||
|
||||
private:
|
||||
ll::mod::NativeMod& mSelf;
|
||||
};
|
||||
|
||||
} // namespace DebugStick
|
||||
@@ -0,0 +1,2 @@
|
||||
#define LL_MEMORY_OPERATORS
|
||||
#include <ll/api/memory/MemoryOperators.h>
|
||||
@@ -1,6 +0,0 @@
|
||||
// This file will make your mod use LeviLamina's memory operators by default.
|
||||
// This improves the memory management of your mod and is recommended to use.
|
||||
|
||||
#define LL_MEMORY_OPERATORS
|
||||
|
||||
#include "ll/api/memory/MemoryOperators.h" // IWYU pragma: keep
|
||||
@@ -1,32 +0,0 @@
|
||||
#include "mod/MyMod.h"
|
||||
|
||||
#include "ll/api/mod/RegisterHelper.h"
|
||||
|
||||
namespace my_mod {
|
||||
|
||||
MyMod& MyMod::getInstance() {
|
||||
static MyMod instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool MyMod::load() {
|
||||
getSelf().getLogger().debug("Loading...");
|
||||
// Code for loading the mod goes here.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MyMod::enable() {
|
||||
getSelf().getLogger().debug("Enabling...");
|
||||
// Code for enabling the mod goes here.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MyMod::disable() {
|
||||
getSelf().getLogger().debug("Disabling...");
|
||||
// Code for disabling the mod goes here.
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace my_mod
|
||||
|
||||
LL_REGISTER_MOD(my_mod::MyMod, my_mod::MyMod::getInstance());
|
||||
@@ -1,33 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "ll/api/mod/NativeMod.h"
|
||||
|
||||
namespace my_mod {
|
||||
|
||||
class MyMod {
|
||||
|
||||
public:
|
||||
static MyMod& getInstance();
|
||||
|
||||
MyMod() : mSelf(*ll::mod::NativeMod::current()) {}
|
||||
|
||||
[[nodiscard]] ll::mod::NativeMod& getSelf() const { return mSelf; }
|
||||
|
||||
/// @return True if the mod is loaded successfully.
|
||||
bool load();
|
||||
|
||||
/// @return True if the mod is enabled successfully.
|
||||
bool enable();
|
||||
|
||||
/// @return True if the mod is disabled successfully.
|
||||
bool disable();
|
||||
|
||||
// TODO: Implement this method if you need to unload the mod.
|
||||
// /// @return True if the mod is unloaded successfully.
|
||||
// bool unload();
|
||||
|
||||
private:
|
||||
ll::mod::NativeMod& mSelf;
|
||||
};
|
||||
|
||||
} // namespace my_mod
|
||||
Reference in New Issue
Block a user