Skip to content

Commit

Permalink
Release 0.8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
KobeBryant114514 authored Feb 17, 2024
2 parents e51b04b + 77842b0 commit ceb9f20
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 16 deletions.
8 changes: 4 additions & 4 deletions include/GMLIB/Server/FloatingTextAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class FloatingText {
GMLIB_API virtual ~FloatingText();

public:
GMLIB_API int64_t getFloatingTextRuntimeId();

GMLIB_API void sendToClient(Player* pl);

GMLIB_API void sendToAllClients();
Expand All @@ -37,7 +35,9 @@ class FloatingText {

GMLIB_API void setText(std::string newText);

GMLIB_API int64 getRuntimeID();
GMLIB_API void setPosition(Vec3& pos, DimensionType dimid);

GMLIB_API int64_t getRuntimeID();

GMLIB_API std::string getText();

Expand All @@ -46,4 +46,4 @@ class FloatingText {
GMLIB_API DimensionType getDimensionId();
};

}
} // namespace GMLIB::Server
4 changes: 4 additions & 0 deletions include/GMLIB/Server/LevelAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class GMLIB_Level : public Level {

GMLIB_API static std::map<int, std::string> getAllExperimentsTranslateKeys();

GMLIB_API static void broadcast(std::string_view message);

GMLIB_API static void broadcastToast(std::string_view title, std::string_view message);

public:
GMLIB_API BlockSource* getBlockSource(DimensionType dimid);

Expand Down
2 changes: 2 additions & 0 deletions include/GMLIB/Server/PlayerAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ class GMLIB_Player : public Player {

GMLIB_API void setClientWeather(WeatherType weather);

GMLIB_API void sendToast(std::string_view title, std::string_view message);

GMLIB_API void addEffect(
MobEffect::EffectType effectType,
int duration = 600,
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.8.2"
"version": "0.8.3"
}
4 changes: 2 additions & 2 deletions src/Server/ActorAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ GMLIB_Actor* GMLIB_Actor::shootProjectile(std::string typeName, float speed, flo
}

int64_t GMLIB_Actor::getNextActorUniqueID() {
auto res = ll::service::getLevel()->getRandom().nextLong();
auto res = Random::getThreadLocal().nextLong();
while (ll::service::getLevel()->fetchEntity(ActorUniqueID(res)) != nullptr) {
res = ll::service::getLevel()->getRandom().nextLong();
res = Random::getThreadLocal().nextLong();
}
return res;
}
Expand Down
25 changes: 19 additions & 6 deletions src/Server/FloatingTextAPI.cc
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
#include "Global.h"
#include "mc/world/item/NetworkItemStackDescriptor.h"
#include <GMLIB/Server/ActorAPI.h>
#include <GMLIB/Server/BinaryStreamAPI.h>
#include <GMLIB/Server/FloatingTextAPI.h>
#include <GMLIB/Server/LevelAPI.h>
#include <GMLIB/Server/NetworkPacketAPI.h>
#include <mc/network/packet/AddItemActorPacket.h>
#include <mc/network/packet/RemoveActorPacket.h>
#include <mc/network/packet/SetActorDataPacket.h>
#include <mc/util/Random.h>

namespace GMLIB::Server {

std::unordered_map<int64, FloatingText*> mRuntimeFloatingTextList;

int getNextFloatingTextId() {
auto id = Random::getThreadLocal().nextInt(0, 2147473647);
while (ll::service::getLevel()->fetchEntity(ActorUniqueID(id))) {
id = Random::getThreadLocal().nextInt(0, 2147473647);
}
return id;
}

FloatingText::FloatingText(std::string text, Vec3 position, DimensionType dimensionId)
: mText(text),
mPosition(position),
mDimensionId(dimensionId) {
mRuntimeId = GMLIB_Actor::getNextActorUniqueID();
mRuntimeId = getNextFloatingTextId();
mRuntimeFloatingTextList.insert({mRuntimeId, this});
}

Expand All @@ -24,9 +34,12 @@ FloatingText::~FloatingText() {
mRuntimeFloatingTextList.erase(mRuntimeId);
}

int64_t FloatingText::getFloatingTextRuntimeId() { return mRuntimeId; }
void FloatingText::setPosition(Vec3& pos, DimensionType dimid) {
mPosition = pos;
mDimensionId = dimid;
}

GMLIB::Server::NetworkPacket<15> createFloatingTextPacket(FloatingText* ft) {
GMLIB::Server::NetworkPacket<15> createAddFloatingTextPacket(FloatingText* ft) {
auto item = std::make_unique<ItemStack>(ItemStack{"minecraft:air"});
auto nisd = NetworkItemStackDescriptor(*item);
GMLIB_BinaryStream bs;
Expand All @@ -50,13 +63,13 @@ GMLIB::Server::NetworkPacket<15> createFloatingTextPacket(FloatingText* ft) {

void FloatingText::sendToClient(Player* pl) {
if (!pl->isSimulatedPlayer() && pl->getDimensionId() == mDimensionId) {
auto pkt = createFloatingTextPacket(this);
auto pkt = createAddFloatingTextPacket(this);
pkt.sendTo(*pl);
}
}

void FloatingText::sendToAllClients() {
auto pkt = createFloatingTextPacket(this);
auto pkt = createAddFloatingTextPacket(this);
ll::service::getLevel()->forEachPlayer([&](Player& pl) -> bool {
if (!pl.isSimulatedPlayer() && pl.getDimensionId() == mDimensionId) {
pkt.sendTo(pl);
Expand Down
9 changes: 9 additions & 0 deletions src/Server/LevelAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <mc/network/packet/ResourcePacksInfoPacket.h>
#include <mc/network/packet/SetTimePacket.h>
#include <mc/network/packet/StartGamePacket.h>
#include <mc/network/packet/TextPacket.h>
#include <mc/network/packet/ToastRequestPacket.h>
#include <mc/server/commands/edu/AbilityCommand.h>
#include <mc/server/common/commands/ChangeSettingCommand.h>
#include <mc/util/Random.h>
Expand Down Expand Up @@ -348,6 +350,13 @@ void GMLIB_Level::setClientWeather(WeatherType weather) {
}
}

void GMLIB_Level::broadcast(std::string_view message) { TextPacket::createRawMessage(message).sendToClients(); }

void GMLIB_Level::broadcastToast(std::string_view title, std::string_view message) {
auto pkt = ToastRequestPacket(std::string(title), std::string(message));
pkt.sendToClients();
}

std::optional<bool> GMLIB_Level::getGameruleBool(GameRuleId id) {
auto rule = ll::service::bedrock::getLevel()->getGameRules().getRule(id);
if (rule) {
Expand Down
6 changes: 6 additions & 0 deletions src/Server/PlayerAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <mc/network/packet/ScorePacketInfo.h>
#include <mc/network/packet/SetDisplayObjectivePacket.h>
#include <mc/network/packet/SetScorePacket.h>
#include <mc/network/packet/ToastRequestPacket.h>
#include <mc/network/packet/UpdatePlayerGameTypePacket.h>
#include <mc/world/attribute/AttributeInstance.h>
#include <mc/world/attribute/SharedAttributes.h>
Expand Down Expand Up @@ -330,6 +331,11 @@ void GMLIB_Player::updateClientBossbar(

void GMLIB_Player::setClientWeather(WeatherType weather) { return GMLIB_Level::setClientWeather(weather, this); }

void GMLIB_Player::sendToast(std::string_view title, std::string_view message) {
auto pkt = ToastRequestPacket(std::string(title), std::string(message));
pkt.sendTo(*this);
}

void GMLIB_Player::addEffect(
MobEffect::EffectType effectType,
int duration,
Expand Down
2 changes: 1 addition & 1 deletion src/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#define LIB_VERSION_MAJOR 0
#define LIB_VERSION_MINOR 8
#define LIB_VERSION_REVISION 2
#define LIB_VERSION_REVISION 3
#define LIB_VERSION_PRERELEASE ""
#define LIB_VERSION_BUILD_META ""

Expand Down
4 changes: 2 additions & 2 deletions tooth.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"format_version": 2,
"tooth": "github.com/GroupMountain/GMLIB",
"version": "0.8.2",
"version": "0.8.3",
"info": {
"name": "GMLIB",
"description": "Group Mountain Library",
Expand All @@ -12,7 +12,7 @@
"Library"
]
},
"asset_url": "https://github.com/GroupMountain/GMLIB/releases/download/v0.8.2/GMLIB-windows-x64.zip",
"asset_url": "https://github.com/GroupMountain/GMLIB/releases/download/v0.8.3/GMLIB-windows-x64.zip",
"files": {
"place": [
{
Expand Down

0 comments on commit ceb9f20

Please sign in to comment.