Skip to content

Commit

Permalink
update: 0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
KobeBryant114514 authored Jan 19, 2024
2 parents b1df6e7 + 0f10bf9 commit 6dde45e
Show file tree
Hide file tree
Showing 25 changed files with 351 additions and 86 deletions.
Binary file modified GMLIB/GMLIB.dll
Binary file not shown.
15 changes: 15 additions & 0 deletions include/GMLIB/Event/Entity/ItemActorEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once
#include "GMLIB/GMLIB.h"
#include <ll/api/event/entity/ActorEvent.h>

namespace GMLIB::Event::EntityEvent {

class ItemActorEvent : public ll::event::entity::ActorEvent {
protected:
constexpr explicit ItemActorEvent(ItemActor& itemActor) : ActorEvent(itemActor) {}

public:
GMLIB_API ItemActor& getItemActor() const;
};

} // namespace GMLIB::Event::EntityEvent
67 changes: 67 additions & 0 deletions include/GMLIB/Event/Entity/ItemActorSpawnEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#pragma once
#include "GMLIB/Event/Entity/ItemActorEvent.h"
#include "GMLIB/GMLIB.h"
#include <ll/api/event/entity/ActorEvent.h>

namespace GMLIB::Event::EntityEvent {

class ItemActorSpawnBeforeEvent : public ll::event::Cancellable<ll::event::Event> {
BlockSource const& mBlockSource;
Vec3& mPosition;
ItemStack& mItem;
Actor* mSpawner = nullptr;
int mThrowTime;

public:
constexpr explicit ItemActorSpawnBeforeEvent(
BlockSource& blockSource,
Vec3& position,
ItemStack& item,
Actor* spawner,
int throwTime
)
: Cancellable(),
mBlockSource(blockSource),
mPosition(position),
mItem(item),
mSpawner(spawner),
mThrowTime(throwTime) {}

GMLIB_API BlockSource const& getBlockSource() const;
GMLIB_API Vec3 const& getPosition() const;
GMLIB_API ItemStack const& getItem() const;
GMLIB_API Actor* const getSpawner() const;
GMLIB_API int const& getThrowTime() const;
};

class ItemActorSpawnAfterEvent : public ItemActorEvent {
BlockSource const& mBlockSource;
Vec3& mPosition;
ItemStack& mItem;
Actor* mSpawner = nullptr;
int mThrowTime;

public:
constexpr explicit ItemActorSpawnAfterEvent(
ItemActor& itemActor,
BlockSource& blockSource,
Vec3& position,
ItemStack& item,
Actor* spawner,
int throwTime
)
: ItemActorEvent(itemActor),
mBlockSource(blockSource),
mPosition(position),
mItem(item),
mSpawner(spawner),
mThrowTime(throwTime) {}

GMLIB_API BlockSource const& getBlockSource() const;
GMLIB_API Vec3 const& getPosition() const;
GMLIB_API ItemStack const& getItem() const;
GMLIB_API Actor* const getSpawner() const;
GMLIB_API int const& getThrowTime() const;
};

} // namespace GMLIB::Event::EntityEvent
27 changes: 27 additions & 0 deletions include/GMLIB/Event/Entity/MobPickupItemEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#include "GMLIB/GMLIB.h"
#include <ll/api/event/entity/MobEvent.h>

namespace GMLIB::Event::EntityEvent {

class MobPickupItemBeforeEvent : public ll::event::Cancellable<ll::event::entity::MobEvent> {
ItemActor& mItemActor;

public:
constexpr explicit MobPickupItemBeforeEvent(Mob& mob, ItemActor& itemActor)
: Cancellable(mob),
mItemActor(itemActor) {}

GMLIB_API ItemActor const& getItemActor() const;
};

class MobPickupItemAfterEvent : public ll::event::entity::MobEvent {
ItemActor& mItemActor;

public:
constexpr explicit MobPickupItemAfterEvent(Mob& mob, ItemActor& itemActor) : MobEvent(mob), mItemActor(itemActor) {}

GMLIB_API ItemActor const& getItemActor() const;
};

} // namespace GMLIB::Event::EntityEvent
2 changes: 1 addition & 1 deletion include/GMLIB/Server/ActorAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GMLIB_Actor : public Actor {

GMLIB_API std::unique_ptr<CompoundTag> getNbt();

GMLIB_API bool setNbt(CompoundTag* nbt);
GMLIB_API bool setNbt(CompoundTag& nbt);

GMLIB_API void addEffect(
MobEffect::EffectType effectType,
Expand Down
10 changes: 5 additions & 5 deletions include/GMLIB/Server/CompoundTagAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class GMLIB_CompoundTag : public CompoundTag {
GMLIB_API static std::unique_ptr<CompoundTag> getFromBlock(Block* block);

public:
GMLIB_API bool setToActor(Actor* ac, CompoundTag* nbt);
GMLIB_API bool setToActor(Actor* ac);

GMLIB_API bool setToPlayer(Player* pl, CompoundTag* nbt);
GMLIB_API bool setToPlayer(Player* pl);

GMLIB_API void setToBlockActor(BlockActor* blac, CompoundTag* nbt);
GMLIB_API void setToBlockActor(BlockActor* blac);

GMLIB_API void setToItemStack(ItemStack* item, CompoundTag* nbt);
GMLIB_API void setToItemStack(ItemStack* item);

GMLIB_API void setToBlock(Block* block, CompoundTag* nbt);
GMLIB_API void setToBlock(Block* block);
};
2 changes: 1 addition & 1 deletion include/GMLIB/Server/ItemStackAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class GMLIB_ItemStack : public ItemStack {
public:
GMLIB_API std::unique_ptr<CompoundTag> getNbt();

GMLIB_API void setNbt(CompoundTag* nbt);
GMLIB_API void setNbt(CompoundTag& nbt);

GMLIB_API void setItem(std::string name, int count = 1, short auxValue = 0);

Expand Down
21 changes: 19 additions & 2 deletions include/GMLIB/Server/LevelAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,13 @@ class GMLIB_Level : public Level {

GMLIB_API bool setBlock(std::string name, short aux, BlockPos& pos, DimensionType dimId);

GMLIB_API int
fillBlocks(BlockPos startpos, BlockPos endpos, DimensionType dimId, Block* block, FillMode mode = FillMode::Replace);
GMLIB_API int fillBlocks(
BlockPos startpos,
BlockPos endpos,
DimensionType dimId,
Block* block,
FillMode mode = FillMode::Replace
);

GMLIB_API int fillBlocks(
BlockPos startpos,
Expand All @@ -127,4 +132,16 @@ class GMLIB_Level : public Level {
std::string newName,
unsigned short newTileData
);

GMLIB_API double getServerMspt();

GMLIB_API float getServerAverageTps();

GMLIB_API float getServerCurrentTps();

GMLIB_API void setFreezeTick(bool freeze = true);

GMLIB_API bool isTickFreezed();

GMLIB_API void setTickScale(float scale = 1.0f);
};
22 changes: 11 additions & 11 deletions include/GMLIB/Server/PlayerAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ class GMLIB_Player : public Player {

GMLIB_API static std::unique_ptr<CompoundTag> getOfflineNbt(std::string serverid);

GMLIB_API static bool setOfflineNbt(std::string serverid, CompoundTag* nbt);
GMLIB_API static bool setOfflineNbt(std::string serverid, CompoundTag& nbt);

GMLIB_API static std::unique_ptr<CompoundTag> getPlayerNbt(mce::UUID uuid);

GMLIB_API static bool setPlayerNbt(mce::UUID const& uuid, CompoundTag* nbt);
GMLIB_API static bool setPlayerNbt(mce::UUID const& uuid, CompoundTag& nbt);

GMLIB_API static bool
setPlayerNbtTags(mce::UUID const& uuid, CompoundTag* nbt, const std::vector<std::string>& tags);
setPlayerNbtTags(mce::UUID const& uuid, CompoundTag& nbt, const std::vector<std::string>& tags);

GMLIB_API static bool deletePlayerNbt(std::string serverid);
GMLIB_API static bool deleteOfflinePlayerNbt(std::string serverid);

GMLIB_API static bool deletePlayerNbt(mce::UUID& uuid);

Expand Down Expand Up @@ -60,7 +60,7 @@ class GMLIB_Player : public Player {
public:
GMLIB_API std::unique_ptr<CompoundTag> getNbt();

GMLIB_API bool setNbt(CompoundTag* nbt);
GMLIB_API bool setNbt(CompoundTag& nbt);

GMLIB_API std::optional<int> getScore(std::string objective);

Expand All @@ -73,12 +73,12 @@ class GMLIB_Player : public Player {

GMLIB_API bool resetScore();

// Broken
// GMLIB_API void setClientSidebar(
// const std::string title,
// const std::vector<std::pair<std::string, int>>& data,
// ObjectiveSortOrder sortOrder = ObjectiveSortOrder::Ascending
// );

GMLIB_API void setClientSidebar(
const std::string title,
const std::vector<std::pair<std::string, int>>& data,
ObjectiveSortOrder sortOrder = ObjectiveSortOrder::Ascending
);

GMLIB_API void removeClientSidebar();

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"type": "native",
"author": "GroupMountain",
"description": "Group Mountain Library",
"version": "0.5.0"
"version": "0.5.1"
}
8 changes: 8 additions & 0 deletions src/Event/Actor/ItemActorEvent.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "Global.h"
#include <GMLIB/Event/entity/ItemActorEvent.h>

namespace GMLIB::Event::EntityEvent {

ItemActor& ItemActorEvent::getItemActor() const { return static_cast<ItemActor&>(ActorEvent::self()); }

} // namespace GMLIB::Event::EntityEvent
43 changes: 43 additions & 0 deletions src/Event/Actor/ItemActorSpawnEvent.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "Global.h"
#include <GMLIB/Event/entity/ItemActorSpawnEvent.h>

namespace GMLIB::Event::EntityEvent {

BlockSource const& ItemActorSpawnBeforeEvent::getBlockSource() const { return mBlockSource; }
Vec3 const& ItemActorSpawnBeforeEvent::getPosition() const { return mPosition; }
ItemStack const& ItemActorSpawnBeforeEvent::getItem() const { return mItem; }
Actor* const ItemActorSpawnBeforeEvent::getSpawner() const { return mSpawner; }
int const& ItemActorSpawnBeforeEvent::getThrowTime() const { return mThrowTime; }

BlockSource const& ItemActorSpawnAfterEvent::getBlockSource() const { return mBlockSource; }
Vec3 const& ItemActorSpawnAfterEvent::getPosition() const { return mPosition; }
ItemStack const& ItemActorSpawnAfterEvent::getItem() const { return mItem; }
Actor* const ItemActorSpawnAfterEvent::getSpawner() const { return mSpawner; }
int const& ItemActorSpawnAfterEvent::getThrowTime() const { return mThrowTime; }

LL_AUTO_TYPE_INSTANCE_HOOK(
ItemSpawnEventHook,
ll::memory::HookPriority::Normal,
Spawner,
"?spawnItem@Spawner@@QEAAPEAVItemActor@@AEAVBlockSource@@AEBVItemStack@@PEAVActor@@AEBVVec3@@H@Z",
ItemActor*,
class BlockSource& region,
class ItemStack& item,
class Actor* spawner,
class Vec3& pos,
int throwTime
) {
auto beforeEvent = ItemActorSpawnBeforeEvent(region, pos, item, spawner, throwTime);
ll::event::EventBus::getInstance().publish(beforeEvent);
if (beforeEvent.isCancelled()) {
return nullptr;
}
auto result = origin(region, item, spawner, pos, throwTime);
if (result) {
auto afterEvent = ItemActorSpawnAfterEvent(*result, region, pos, item, spawner, throwTime);
ll::event::EventBus::getInstance().publish(afterEvent);
}
return result;
}

} // namespace GMLIB::Event::EntityEvent
29 changes: 29 additions & 0 deletions src/Event/Actor/MobPickupItemEvent.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "Global.h"
#include <GMLIB/Event/entity/MobPickupItemEvent.h>

namespace GMLIB::Event::EntityEvent {

ItemActor const& MobPickupItemBeforeEvent::getItemActor() const { return mItemActor; }

ItemActor const& MobPickupItemAfterEvent::getItemActor() const { return mItemActor; }

LL_AUTO_TYPE_INSTANCE_HOOK(
MobPickupItemEventHook,
ll::memory::HookPriority::Normal,
PickupItemsGoal,
"?_pickItemUp@PickupItemsGoal@@AEAAXPEAVItemActor@@@Z",
void,
class ItemActor& item
) {
auto mob = ll::memory::dAccess<Mob*>(this, 112); // IDA: PickupItemsGoal::PickupItemsGoal()
auto beforeEvent = MobPickupItemBeforeEvent(*mob, item);
ll::event::EventBus::getInstance().publish(beforeEvent);
if (beforeEvent.isCancelled()) {
return;
}
origin(item);
auto afterEvent = MobPickupItemAfterEvent(*mob, item);
ll::event::EventBus::getInstance().publish(afterEvent);
}

} // namespace GMLIB::Event::EntityEvent
16 changes: 8 additions & 8 deletions src/Event/Level/WeatherUpdateEvent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

namespace GMLIB::Event::LevelEvent {

GMLIB_API int const& WeatherUpdateBeforeEvent::getRainingLastTick() const { return mRainingLastTick; }
GMLIB_API int const& WeatherUpdateBeforeEvent::getLightningLastTick() const { return mLightningLastTick; }
GMLIB_API int const& WeatherUpdateBeforeEvent::getRainLevel() const { return mRainLevel; }
GMLIB_API int const& WeatherUpdateBeforeEvent::getLightningLevel() const { return mLightningLevel; }
int const& WeatherUpdateBeforeEvent::getRainingLastTick() const { return mRainingLastTick; }
int const& WeatherUpdateBeforeEvent::getLightningLastTick() const { return mLightningLastTick; }
int const& WeatherUpdateBeforeEvent::getRainLevel() const { return mRainLevel; }
int const& WeatherUpdateBeforeEvent::getLightningLevel() const { return mLightningLevel; }

GMLIB_API int const& WeatherUpdateAfterEvent::getRainingLastTick() const { return mRainingLastTick; }
GMLIB_API int const& WeatherUpdateAfterEvent::getLightningLastTick() const { return mLightningLastTick; }
GMLIB_API int const& WeatherUpdateAfterEvent::getRainLevel() const { return mRainLevel; }
GMLIB_API int const& WeatherUpdateAfterEvent::getLightningLevel() const { return mLightningLevel; }
int const& WeatherUpdateAfterEvent::getRainingLastTick() const { return mRainingLastTick; }
int const& WeatherUpdateAfterEvent::getLightningLastTick() const { return mLightningLastTick; }
int const& WeatherUpdateAfterEvent::getRainLevel() const { return mRainLevel; }
int const& WeatherUpdateAfterEvent::getLightningLevel() const { return mLightningLevel; }

LL_AUTO_TYPE_INSTANCE_HOOK(
WeatherUpdateEventHook,
Expand Down
14 changes: 7 additions & 7 deletions src/Event/Player/PlayerSleepEvent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

namespace GMLIB::Event::PlayerEvent {

GMLIB_API BlockPos const& PlayerStartSleepBeforeEvent::getPosition() const { return mBlockPos; }
BlockPos const& PlayerStartSleepBeforeEvent::getPosition() const { return mBlockPos; }

GMLIB_API BlockPos const& PlayerStartSleepAfterEvent::getPosition() const { return mBlockPos; }
GMLIB_API bool const& PlayerStartSleepAfterEvent::getResult() const { return mResult; }
BlockPos const& PlayerStartSleepAfterEvent::getPosition() const { return mBlockPos; }
bool const& PlayerStartSleepAfterEvent::getResult() const { return mResult; }

GMLIB_API bool const& PlayerStopSleepBeforeEvent::isForcefulWakeUp() const { return mForcefulWakeUp; }
GMLIB_API bool const& PlayerStopSleepBeforeEvent::isUpdateLevelList() const { return mUpdateLevelList; }
bool const& PlayerStopSleepBeforeEvent::isForcefulWakeUp() const { return mForcefulWakeUp; }
bool const& PlayerStopSleepBeforeEvent::isUpdateLevelList() const { return mUpdateLevelList; }

GMLIB_API bool const& PlayerStopSleepAfterEvent::isForcefulWakeUp() const { return mForcefulWakeUp; }
GMLIB_API bool const& PlayerStopSleepAfterEvent::isUpdateLevelList() const { return mUpdateLevelList; }
bool const& PlayerStopSleepAfterEvent::isForcefulWakeUp() const { return mForcefulWakeUp; }
bool const& PlayerStopSleepAfterEvent::isUpdateLevelList() const { return mUpdateLevelList; }

LL_AUTO_TYPE_INSTANCE_HOOK(
PlayerStartSleepEventHook,
Expand Down
5 changes: 4 additions & 1 deletion src/GMLIB.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ void loadLib() {
printLibInfo();
}

void enableLib() { initExperiments(&ll::service::bedrock::getLevel()->getLevelData()); }
void enableLib() {
initExperiments(&ll::service::bedrock::getLevel()->getLevelData());
CaculateTPS();
}

void disableLib() {}

Expand Down
4 changes: 3 additions & 1 deletion src/Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include "include_all.h"

extern ll::Logger logger;
extern void initExperiments(LevelData* leveldat);

extern void initExperiments(LevelData* leveldat);
extern void CaculateTPS();

class DBStorage;

Expand Down
Loading

0 comments on commit 6dde45e

Please sign in to comment.