Skip to content

Commit b568074

Browse files
committed
fix: fix EntityAPI completely
1 parent cacd581 commit b568074

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/legacy/api/EntityAPI.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "mc/legacy/ActorUniqueID.h"
2525
#include "mc/nbt/CompoundTag.h"
2626
#include "mc/server/commands/CommandUtils.h"
27+
#include "mc/util/BlockUtils.h"
2728
#include "mc/util/IDType.h"
2829
#include "mc/world/SimpleContainer.h"
2930
#include "mc/world/actor/ActorDamageByActorSource.h"
@@ -48,6 +49,7 @@
4849
#include "mc/world/level/Spawner.h"
4950
#include "mc/world/level/biome/Biome.h"
5051
#include "mc/world/level/block/Block.h"
52+
#include "mc/world/level/block/CachedComponentData.h"
5153
#include "mc/world/level/block/VanillaBlockTypeIds.h"
5254
#include "mc/world/level/dimension/Dimension.h"
5355
#include "mc/world/level/material/Material.h"
@@ -1397,13 +1399,13 @@ Local<Value> EntityClass::getBlockFromViewVector(const Arguments& args) {
13971399
false,
13981400
true,
13991401
[&solidOnly, &fullOnly, &includeLiquid](BlockSource const&, Block const& block, bool) {
1400-
if (solidOnly && !block.isSolid()) {
1402+
if (solidOnly && !block.mCachedComponentData->mUnkd6c5eb.as<bool>()) {
14011403
return false;
14021404
}
14031405
if (fullOnly && !block.isSlabBlock()) {
14041406
return false;
14051407
}
1406-
if (!includeLiquid && block.getMaterial().isLiquid()) {
1408+
if (!includeLiquid && BlockUtils::isLiquidSource(block)) {
14071409
return false;
14081410
}
14091411
return true;
@@ -1418,8 +1420,9 @@ Local<Value> EntityClass::getBlockFromViewVector(const Arguments& args) {
14181420
} else {
14191421
bp = res.mBlock;
14201422
}
1421-
Block const& bl = actor->getDimensionBlockSource().getBlock(bp);
1422-
if (bl.isAir() || bl.isEmpty()) {
1423+
Block const& bl = actor->getDimensionBlockSource().getBlock(bp);
1424+
BlockLegacy const& legacy = bl.getLegacyBlock();
1425+
if (bl.isAir() || (legacy.mProperties == BlockProperty::None && legacy.mMaterial.mType == MaterialType::Any)) {
14231426
return Local<Value>();
14241427
}
14251428
return BlockClass::newBlock(bl, bp, actor->getDimensionId());
@@ -1465,10 +1468,8 @@ Local<Value> EntityClass::getAllEffects() {
14651468
return Local<Value>();
14661469
}
14671470
Local<Array> effectList = Array::newArray();
1468-
for (unsigned int i = 0; i <= 30; i++) {
1469-
if (actor->getEffect(i)) {
1470-
effectList.add(Number::newNumber((int)i));
1471-
}
1471+
for (auto& effect : actor->_getAllEffectsNonConst()) {
1472+
effectList.add(Number::newNumber((long long)effect.mId));
14721473
}
14731474
return effectList;
14741475
}
@@ -1486,12 +1487,14 @@ Local<Value> EntityClass::addEffect(const Arguments& args) {
14861487
if (!actor) {
14871488
return Boolean::newBoolean(false);
14881489
}
1489-
unsigned int id = args[0].asNumber().toInt32();
1490-
EffectDuration duration{};
1491-
duration.mValue = args[1].asNumber().toInt32();
1490+
unsigned int id = args[0].asNumber().toInt32();
1491+
EffectDuration duration{args[1].asNumber().toInt32()};
14921492
int level = args[2].asNumber().toInt32();
14931493
bool showParticles = args[3].asBoolean().value();
1494-
MobEffectInstance effect = MobEffectInstance(id, duration, level, false, showParticles, false);
1494+
MobEffectInstance effect(id);
1495+
effect.mDuration = duration;
1496+
effect.mAmplifier = level;
1497+
effect.mEffectVisible = showParticles;
14951498
actor->addEffect(effect);
14961499
return Boolean::newBoolean(true);
14971500
}
@@ -1518,7 +1521,7 @@ Local<Value> McClass::getAllEntities(const Arguments&) {
15181521
auto& entityList = ll::service::getLevel()->getEntities();
15191522
auto arr = Array::newArray();
15201523
for (auto& i : entityList) {
1521-
if (i._hasValue() && i.tryUnwrap().has_value()) {
1524+
if (i.has_value() && i.tryUnwrap().has_value()) {
15221525
arr.add(EntityClass::newEntity(&i.tryUnwrap().get()));
15231526
}
15241527
}
@@ -1596,11 +1599,11 @@ Local<Value> McClass::getEntities(const Arguments& args) {
15961599

15971600
auto arr = Array::newArray();
15981601
auto dimension = ll::service::getLevel()->getDimension(dim);
1599-
if (!dimension) {
1602+
if (!dimension.lock()) {
16001603
LOG_ERROR_WITH_SCRIPT_INFO(__FUNCTION__, "Wrong Dimension!");
16011604
return Local<Value>();
16021605
}
1603-
BlockSource& bs = dimension->getBlockSourceFromMainChunkSource();
1606+
BlockSource& bs = dimension.lock()->getBlockSourceFromMainChunkSource();
16041607
auto entityList = bs.getEntities(aabb, dis);
16051608
for (auto i : entityList) {
16061609
arr.add(EntityClass::newEntity(i));
@@ -1680,7 +1683,7 @@ Local<Value> McClass::cloneMob(const Arguments& args) {
16801683
}
16811684
ActorDefinitionIdentifier id(ac->getTypeName());
16821685
Mob* entity = ll::service::getLevel()->getSpawner().spawnMob(
1683-
ll::service::getLevel()->getDimension(pos.dim)->getBlockSourceFromMainChunkSource(),
1686+
ll::service::getLevel()->getDimension(pos.dim).lock()->getBlockSourceFromMainChunkSource(),
16841687
id,
16851688
nullptr,
16861689
pos.getVec3(),
@@ -1743,7 +1746,7 @@ Local<Value> McClass::spawnMob(const Arguments& args) {
17431746

17441747
ActorDefinitionIdentifier id(name);
17451748
Mob* entity = ll::service::getLevel()->getSpawner().spawnMob(
1746-
ll::service::getLevel()->getDimension(pos.dim)->getBlockSourceFromMainChunkSource(),
1749+
ll::service::getLevel()->getDimension(pos.dim).lock()->getBlockSourceFromMainChunkSource(),
17471750
id,
17481751
nullptr,
17491752
pos.getVec3(),
@@ -1824,7 +1827,7 @@ Local<Value> McClass::explode(const Arguments& args) {
18241827

18251828
return Boolean::newBoolean(
18261829
ll::service::getLevel()->explode(
1827-
ll::service::getLevel()->getDimension(pos.dim)->getBlockSourceFromMainChunkSource(),
1830+
ll::service::getLevel()->getDimension(pos.dim).lock()->getBlockSourceFromMainChunkSource(),
18281831
source.value_or(nullptr),
18291832
pos.getVec3(),
18301833
radius,
@@ -1847,7 +1850,7 @@ Local<Value> McClass::explode(const Arguments& args) {
18471850

18481851
return Boolean::newBoolean(
18491852
ll::service::getLevel()->explode(
1850-
ll::service::getLevel()->getDimension(pos.dim)->getBlockSourceFromMainChunkSource(),
1853+
ll::service::getLevel()->getDimension(pos.dim).lock()->getBlockSourceFromMainChunkSource(),
18511854
source.value_or(nullptr),
18521855
pos.getVec3(),
18531856
radius,

0 commit comments

Comments
 (0)