Skip to content

Commit

Permalink
Add Actor::getBiomeId Actor::getBiomeName LiteLDev#883
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamguxiang committed Nov 4, 2022
1 parent 98c777c commit 1e688bb
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 0 deletions.
3 changes: 3 additions & 0 deletions LiteLoader/include/llapi/mc/Actor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Vec2;
class BlockInstance;
class ItemStack;
class BlockSource;
class Biome;

enum class FaceID : char;

#undef BEFORE_EXTRA
Expand Down Expand Up @@ -71,6 +73,7 @@ class Actor {
LIAPI bool refreshActorData();
LIAPI bool addEffect(MobEffect::EffectType type, int tick, int level, bool ambient = false, bool showParticles = true, bool showAnimation = false);
LIAPI float quickEvalMolangScript(const string& expression);
LIAPI Biome* getBiome();
//LIAPI Json::Value quickEvalMolangScriptAsJson(const string& expression);

inline Vec3 getPos()
Expand Down
1 change: 1 addition & 0 deletions LiteLoader/include/llapi/mc/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Container;
class CompoundTag;
class LayeredAbilities;

class Biome;
#include "UserEntityIdentifierComponent.hpp"
#include "ScorePacketInfo.hpp"
#include "DataItem.hpp"
Expand Down
5 changes: 5 additions & 0 deletions LiteLoader/src/llapi/mc/ActorAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,8 @@ bool Actor::hasTag(const string& tag) {
auto tags = getAllTags();
return std::find(tags.begin(), tags.end(), tag) != tags.end();
}

Biome* Actor::getBiome() {
auto bs = getBlockSource();
return const_cast<Biome*>(&bs->getConstBiome(getPos().toBlockPos()));
}
4 changes: 4 additions & 0 deletions LiteLoader/src/llapi/mc/PlayerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
#include "llapi/mc/UpdateAdventureSettingsPacket.hpp"
#include "llapi/mc/AdventureSettings.hpp"

#include "llapi/mc/Biome.hpp"
#include "llapi/mc/BlockSource.hpp"
#include "llapi/mc/ChunkPos.hpp"

using ll::logger;

NetworkIdentifier* Player::getNetworkIdentifier() {
Expand Down
25 changes: 25 additions & 0 deletions ScriptEngine/src/api/EntityAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <llapi/mc/SharedAttributes.hpp>
#include <llapi/mc/Attribute.hpp>
#include <llapi/mc/AttributeInstance.hpp>
#include <llapi/mc/Biome.hpp>
#include <magic_enum/magic_enum.hpp>

using magic_enum::enum_integer;
Expand Down Expand Up @@ -68,6 +69,8 @@ ClassDefine<EntityClass> EntityClassBuilder =
.instanceProperty("isAngry", &EntityClass::isAngry)
.instanceProperty("isBaby", &EntityClass::isBaby)
.instanceProperty("isMoving", &EntityClass::isMoving)
.instanceProperty("getBiomeName", &EntityClass::getBiomeName)
.instanceProperty("getBiomeId", &EntityClass::getBiomeId)

.instanceFunction("teleport", &EntityClass::teleport)
.instanceFunction("kill", &EntityClass::kill)
Expand Down Expand Up @@ -1210,6 +1213,28 @@ Local<Value> EntityClass::quickEvalMolangScript(const Arguments& args) {
CATCH("Fail in quickEvalMolangScript!");
}

Local<Value> EntityClass::getBiomeId() {
try {
Actor* actor = get();
if (!actor)
return Local<Value>();
auto bio = actor->getBiome();
return Number::newNumber(bio->getId());
}
CATCH("Fail in getBiomeId!");
}

Local<Value> EntityClass::getBiomeName() {
try {
Actor* actor = get();
if (!actor)
return Local<Value>();
auto bio = actor->getBiome();
return String::newString(bio->getName());
}
CATCH("Fail in getBiomeName!");
}

Local<Value> McClass::getAllEntities(const Arguments& args) {
try {
auto entityList = Level::getAllEntities();
Expand Down
2 changes: 2 additions & 0 deletions ScriptEngine/src/api/EntityAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class EntityClass : public ScriptClass {
Local<Value> getInWaterOrRain();
Local<Value> getInWorld();
Local<Value> getSpeed();
Local<Value> getBiomeName();
Local<Value> getBiomeId();
Local<Value> getDirection();
Local<Value> getUniqueID();
Local<Value> isInvisible();
Expand Down
25 changes: 25 additions & 0 deletions ScriptEngine/src/api/PlayerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <llapi/mc/Command.hpp>
#include <llapi/mc/SynchedActorDataEntityWrapper.hpp>
#include <llapi/PlayerInfoAPI.h>
#include <llapi/mc/Biome.hpp>
#include "main/SafeGuardRecord.h"
#include <string>
#include <vector>
Expand Down Expand Up @@ -170,6 +171,8 @@ ClassDefine<PlayerClass> PlayerClassBuilder =
.instanceFunction("setTotalExperience", &PlayerClass::setTotalExperience)
.instanceFunction("getXpNeededForNextLevel", &PlayerClass::getXpNeededForNextLevel)
.instanceFunction("setAbility", &PlayerClass::setAbility)
.instanceFunction("getBiomeId", &PlayerClass::getBiomeId)
.instanceFunction("getBiomeName", &PlayerClass::getBiomeName)

.instanceFunction("sendSimpleForm", &PlayerClass::sendSimpleForm)
.instanceFunction("sendModalForm", &PlayerClass::sendModalForm)
Expand Down Expand Up @@ -2795,4 +2798,26 @@ Local<Value> PlayerClass::setAbility(const Arguments& args) {
return Boolean::newBoolean(true);
}
CATCH("Fail in setAbility!");
}

Local<Value> PlayerClass::getBiomeId() {
try {
Player* player = get();
if (!player)
return Local<Value>();
auto bio = player->getBiome();
return Number::newNumber(bio->getId());
}
CATCH("Fail in getBiomeId!");
}

Local<Value> PlayerClass::getBiomeName() {
try {
Player* player = get();
if (!player)
return Local<Value>();
auto bio = player->getBiome();
return String::newString(bio->getName());
}
CATCH("Fail in getBiomeName!");
}
2 changes: 2 additions & 0 deletions ScriptEngine/src/api/PlayerAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class PlayerClass : public ScriptClass {
Local<Value> getDirection();
Local<Value> getUniqueID();
Local<Value> getLangCode();
Local<Value> getBiomeName();
Local<Value> getBiomeId();
Local<Value> isLoading();
Local<Value> isInvisible();
Local<Value> isInsidePortal();
Expand Down

0 comments on commit 1e688bb

Please sign in to comment.