Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/legacy/api/BaseAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#include "legacy/api/APIHelp.h"
#include "legacy/api/McAPI.h"
#include "legacy/main/Global.h"
#include "ll/api/Versions.h"
#include "mc/common/Common.h"
#include "mc/common/SharedConstants.h"

#include <mc/world/actor/ActorDamageSource.h>
#include <mc/world/level/BlockSource.h>
#include "mc/world/actor/ActorDamageSource.h"
#include "mc/world/level/BlockSource.h"

///////////////////// Enum //////////////////////
ClassDefine<void> DamageCauseEnumBuilder =
Expand Down Expand Up @@ -240,7 +240,7 @@ Local<Value> McClass::getBDSVersion(Arguments const&) {

Local<Value> McClass::getServerProtocolVersion(Arguments const&) {
try {
return Number::newNumber(SharedConstants::NetworkProtocolVersion());
return Number::newNumber(ll::getNetworkProtocolVersion());
}
CATCH_AND_THROW
}
55 changes: 42 additions & 13 deletions src/legacy/api/BlockAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
#include "ll/api/service/Bedrock.h"
#include "lse/api/helper/BlockHelper.h"
#include "mc/deps/core/utility/optional_ref.h"
#include "mc/deps/shared_types/v1_26_0/block/LiquidReaction.h"
#include "mc/world/level/BlockSource.h"
#include "mc/world/level/ChunkBlockPos.h"
#include "mc/world/level/block/BedrockBlockNames.h"
#include "mc/world/level/block/Block.h"
#include "mc/world/level/block/BlockChangeContext.h"
#include "mc/world/level/block/LiquidReaction.h"
#include "mc/world/level/block/VanillaBlockTags.h"
#include "mc/world/level/block/actor/BlockActor.h"
#include "mc/world/level/block/block_serialization_utils/BlockSerializationUtils.h"
Expand Down Expand Up @@ -281,7 +281,7 @@ Local<Value> BlockClass::isUnbreakable() const {
Local<Value> BlockClass::isWaterBlockingBlock() const {
try {
return Boolean::newBoolean(
block->mDirectData->mWaterDetectionRule->mOnLiquidTouches == LiquidReaction::Blocking
block->mDirectData->mWaterDetectionRule->mOnLiquidTouches == SharedTypes::v1_26_0::LiquidReaction::Blocking
);
}
CATCH_AND_THROW
Expand All @@ -308,7 +308,14 @@ Local<Value> BlockClass::setNbt(Arguments const& args) {
->getDimension(blockPos.dim)
.lock()
->getBlockSourceFromMainChunkSource()
.setBlock(blockPos.getBlockPos(), *bl, 3, nullptr, nullptr, BlockChangeContext(false));
.setBlock(
blockPos.getBlockPos(),
*bl,
3,
nullptr,
nullptr,
BlockChangeContext(StatelessBlockChangeContext::Commands)
);
}
preloadData(blockPos.getBlockPos(), blockPos.getDimensionId());
return Boolean::newBoolean(true);
Expand Down Expand Up @@ -381,7 +388,8 @@ Local<Value> BlockClass::removeBlockEntity(Arguments const&) const {
->getDimension(blockPos.dim)
.lock()
->getBlockSourceFromMainChunkSource()
.removeBlockEntity(blockPos.getBlockPos())
.getChunkAt(blockPos.getBlockPos())
->removeBlockEntity(blockPos.getBlockPos())
!= nullptr
);
}
Expand All @@ -398,8 +406,12 @@ Local<Value> BlockClass::destroyBlock(Arguments const& args) const {
BlockSource& bl =
ll::service::getLevel()->getDimension(blockPos.dim).lock()->getBlockSourceFromMainChunkSource();
return Boolean::newBoolean(
ll::service::getLevel()
->destroyBlock(bl, blockPos.getBlockPos(), args[0].asBoolean().value(), BlockChangeContext(false))
ll::service::getLevel()->destroyBlock(
bl,
blockPos.getBlockPos(),
args[0].asBoolean().value(),
BlockChangeContext(StatelessBlockChangeContext::Commands)
)
);
}
CATCH_AND_THROW
Expand Down Expand Up @@ -525,9 +537,14 @@ Local<Value> McClass::setBlock(Arguments const& args) {
}
BlockSource& bs =
ll::service::getLevel()->getDimension(pos.dim).lock()->getBlockSourceFromMainChunkSource();
return Boolean::newBoolean(
bs.setBlock(pos.getBlockPos(), bl, 3, nullptr, nullptr, BlockChangeContext(false))
);
return Boolean::newBoolean(bs.setBlock(
pos.getBlockPos(),
bl,
3,
nullptr,
nullptr,
BlockChangeContext(StatelessBlockChangeContext::Commands)
));
}
if (IsInstanceOf<NbtCompoundClass>(block)) {
// Nbt
Expand All @@ -538,17 +555,29 @@ Local<Value> McClass::setBlock(Arguments const& args) {
}
BlockSource& bs =
ll::service::getLevel()->getDimension(pos.dim).lock()->getBlockSourceFromMainChunkSource();
return Boolean::newBoolean(
bs.setBlock(pos.getBlockPos(), bl, 3, nullptr, nullptr, BlockChangeContext(false))
);
return Boolean::newBoolean(bs.setBlock(
pos.getBlockPos(),
bl,
3,
nullptr,
nullptr,
BlockChangeContext(StatelessBlockChangeContext::Commands)
));
}
// other block object
Block const* bl = BlockClass::extract(block);
if (!bl) {
throw WrongArgTypeException(__FUNCTION__);
}
BlockSource& bs = ll::service::getLevel()->getDimension(pos.dim).lock()->getBlockSourceFromMainChunkSource();
return Boolean::newBoolean(bs.setBlock(pos.getBlockPos(), *bl, 3, nullptr, nullptr, BlockChangeContext(false)));
return Boolean::newBoolean(bs.setBlock(
pos.getBlockPos(),
*bl,
3,
nullptr,
nullptr,
BlockChangeContext(StatelessBlockChangeContext::Commands)
));
}
CATCH_AND_THROW
}
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/api/BlockEntityAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "ll/api/service/Bedrock.h"
#include "lse/api/MoreGlobal.h"
#include "mc/dataloadhelper/DefaultDataLoadHelper.h"
#include "mc/nbt/CompoundTag.h"
#include "mc/deps/nbt/CompoundTag.h"
#include "mc/world/item/SaveContextFactory.h"
#include "mc/world/level/BlockSource.h"
#include "mc/world/level/block/actor/BlockActor.h"
Expand Down
10 changes: 5 additions & 5 deletions src/legacy/api/CommandAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,22 @@ Local<Value> convertResult(ParamStorageType const& result, CommandOrigin const&
auto dim = origin.getDimension();
return IntPos::newPos(
std::get<CommandPosition>(result.value())
.getBlockPos(CommandVersion::CurrentVersion(), origin, Vec3::ZERO()),
.getBlockPos(static_cast<int>(CurrentCmdVersion::Latest), origin, Vec3::ZERO()),
dim ? dim->getDimensionId().id : -1
);
}
if (result.hold(ParamKind::Kind::Vec3)) {
auto dim = origin.getDimension();
return FloatPos::newPos(
std::get<CommandPositionFloat>(result.value())
.getPosition(CommandVersion::CurrentVersion(), origin, Vec3::ZERO()),
.getPosition(static_cast<int>(CurrentCmdVersion::Latest), origin, Vec3::ZERO()),
dim ? dim->getDimensionId().id : -1
);
}
if (result.hold(ParamKind::Kind::Message)) {
return String::newString(
std::get<CommandMessage>(result.value())
.generateMessage(origin, CommandVersion::CurrentVersion())
.generateMessage(origin, static_cast<int>(CurrentCmdVersion::Latest))
.mMessage->c_str()
);
}
Expand Down Expand Up @@ -199,7 +199,7 @@ Local<Value> McClass::runcmd(Arguments const& args) {
CommandPermissionLevel::Owner,
0
),
CommandVersion::CurrentVersion()
static_cast<int>(CurrentCmdVersion::Latest)
);
try {
return Boolean::newBoolean(ll::service::getMinecraft()->mCommands->executeCommand(context, false).mSuccess);
Expand All @@ -217,7 +217,7 @@ Local<Value> McClass::runcmdEx(Arguments const& args) {
auto command = ll::service::getMinecraft()->mCommands->compileCommand(
args[0].asString().toString(),
origin,
static_cast<CurrentCmdVersion>(CommandVersion::CurrentVersion()),
static_cast<CurrentCmdVersion>(static_cast<int>(CurrentCmdVersion::Latest)),
[&](std::string const& err) { outputStr.append(err).append("\n"); }
);
Local<Object> resObj = Object::newObject();
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/api/CommandOriginAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "legacy/api/NbtAPI.h"
#include "legacy/api/PlayerAPI.h"
#include "magic_enum.hpp"
#include "mc/nbt/CompoundTag.h"
#include "mc/deps/nbt/CompoundTag.h"
#include "mc/server/commands/CommandOriginType.h"
#include "mc/world/actor/player/Player.h"
#include "mc/world/level/dimension/Dimension.h"
Expand Down
6 changes: 3 additions & 3 deletions src/legacy/api/CommandOutputAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Local<Value> CommandOutputClass::success(Arguments const& args) {
std::vector<CommandOutputParameter> param{};
auto paramArr = args[1].asArray();
for (int i = 0; i < paramArr.size(); ++i) {
param.push_back(CommandOutputParameter(paramArr.get(i).asString().toString().c_str()));
param.push_back(CommandOutputParameter({paramArr.get(i).asString().toString()}));
}
get()->success(msg, param);
send();
Expand All @@ -91,7 +91,7 @@ Local<Value> CommandOutputClass::addMessage(Arguments const& args) {
std::vector<CommandOutputParameter> param{};
auto paramArr = args[1].asArray();
for (int i = 0; i < paramArr.size(); ++i) {
param.push_back(CommandOutputParameter(paramArr.get(i).asString().toString().c_str()));
param.push_back(CommandOutputParameter({paramArr.get(i).asString().toString()}));
}
if (args.size() >= 3) {
CHECK_ARG_TYPE(args[2], ValueKind::kNumber);
Expand Down Expand Up @@ -120,7 +120,7 @@ Local<Value> CommandOutputClass::error(Arguments const& args) {
std::vector<CommandOutputParameter> param{};
auto paramArr = args[1].asArray();
for (int i = 0; i < paramArr.size(); ++i) {
param.push_back(CommandOutputParameter(paramArr.get(i).asString().toString().c_str()));
param.push_back(CommandOutputParameter({paramArr.get(i).asString().toString()}));
}
get()->error(msg, param);
send();
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/api/DeviceAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "legacy/api/APIHelp.h"
#include "ll/api/service/Bedrock.h"
#include "magic_enum.hpp"
#include "mc/certificates/WebToken.h"
#include "mc/deps/certificates/WebToken.h"
#include "mc/deps/input/InputMode.h"
#include "mc/deps/json/Value.h"
#include "mc/legacy/ActorRuntimeID.h"
Expand Down
17 changes: 10 additions & 7 deletions src/legacy/api/EntityAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,25 @@
#include "lse/api/MoreGlobal.h"
#include "lse/api/helper/AttributeHelper.h"
#include "mc/deps/core/math/Vec2.h"
#include "mc/deps/nbt/CompoundTag.h"
#include "mc/deps/shared_types/legacy/actor/ActorDamageCause.h"
#include "mc/deps/vanilla_components/ActorDataFlagComponent.h"
#include "mc/deps/vanilla_components/StateVectorComponent.h"
#include "mc/entity/components/AttributesComponent.h"
#include "mc/entity/components/InsideBlockComponent.h"
#include "mc/entity/components/IsOnHotBlockFlagComponent.h"
#include "mc/entity/components/TagsComponent.h"
#include "mc/entity/components/WasInWaterFlagComponent.h"
#include "mc/entity/utilities/ActorMobilityUtils.h"
#include "mc/legacy/ActorRuntimeID.h"
#include "mc/legacy/ActorUniqueID.h"
#include "mc/nbt/CompoundTag.h"
#include "mc/server/commands/CommandUtils.h"
#include "mc/util/BlockUtils.h"
#include "mc/world/SimpleContainer.h"
#include "mc/world/actor/ActorDamageByActorSource.h"
#include "mc/world/actor/ActorDamageSource.h"
#include "mc/world/actor/ActorDefinitionIdentifier.h"
#include "mc/world/actor/ActorHurtResult.h"
#include "mc/world/actor/ActorType.h"
#include "mc/world/actor/Mob.h"
#include "mc/world/actor/item/ItemActor.h"
Expand Down Expand Up @@ -527,7 +529,9 @@ Local<Value> EntityClass::getInAir() const {
Actor const* entity = get();
if (!entity) return {};

return Boolean::newBoolean(!entity->isOnGround() && !entity->isInWater());
return Boolean::newBoolean(
!entity->isOnGround() && !entity->getEntityContext().hasComponent<WasInWaterFlagComponent>()
);
}
CATCH_AND_THROW
}
Expand All @@ -537,7 +541,7 @@ Local<Value> EntityClass::getInWater() const {
Actor const* entity = get();
if (!entity) return {};

return Boolean::newBoolean(entity->isInWater());
return Boolean::newBoolean(entity->getEntityContext().hasComponent<WasInWaterFlagComponent>());
}
CATCH_AND_THROW
}
Expand Down Expand Up @@ -636,7 +640,7 @@ Local<Value> EntityClass::getDirection() const {
if (!entity) return {};

// getRotation()
Vec2 const vec = entity->mBuiltInComponents->mActorRotationComponent->mRotationDegree;
Vec2 const vec = entity->mBuiltInComponents->mActorRotationComponent->mRot;
return DirectionAngle::newAngle(vec.x, vec.y);
}
CATCH_AND_THROW
Expand Down Expand Up @@ -694,7 +698,7 @@ Local<Value> EntityClass::teleport(Arguments const& args) const {
}
if (!rotationIsValid) {
// getRotation()
ang = entity->mBuiltInComponents->mActorRotationComponent->mRotationDegree;
ang = entity->mBuiltInComponents->mActorRotationComponent->mRot;
}
entity->teleport(pos.getVec3(), pos.dim, ang);
return Boolean::newBoolean(true);
Expand Down Expand Up @@ -967,8 +971,7 @@ Local<Value> EntityClass::hurt(Arguments const& args) const {
ActorDamageByActorSource(*source, static_cast<SharedTypes::Legacy::ActorDamageCause>(type));
return Boolean::newBoolean(entity->_hurt(damageBySource, damage, true, false));
}
ActorDamageSource damageSource;
damageSource.mCause = static_cast<SharedTypes::Legacy::ActorDamageCause>(type);
ActorDamageSource damageSource(static_cast<SharedTypes::Legacy::ActorDamageCause>(type), {});
return Boolean::newBoolean(entity->_hurt(damageSource, damage, true, false));
}
CATCH_AND_THROW
Expand Down
8 changes: 5 additions & 3 deletions src/legacy/api/ItemAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ Local<Value> ItemClass::isArmorItem() const {

Local<Value> ItemClass::isBlock() const {
try {
return Boolean::newBoolean(get()->isBlock());
return Boolean::newBoolean(get()->getBlockType().get());
}
CATCH_AND_THROW
}
Expand Down Expand Up @@ -407,8 +407,10 @@ Local<Value> ItemClass::setDisplayName(Arguments const& args) const {
CHECK_ARG_TYPE(args[0], ValueKind::kString);

try {
Bedrock::Safety::RedactableString redactableString;
redactableString.mUnredactedString = args[0].asString().toString();
Bedrock::Safety::RedactableString redactableString(
args[0].asString().toString(),
args[0].asString().toString()
);
get()->setCustomName(redactableString);
return Boolean::newBoolean(true);
}
Expand Down
22 changes: 11 additions & 11 deletions src/legacy/api/NbtAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

#include "legacy/api/APIHelp.h"
#include "ll/api/utils/Base64Utils.h"
#include "mc/nbt/ByteArrayTag.h"
#include "mc/nbt/ByteTag.h"
#include "mc/nbt/CompoundTag.h"
#include "mc/nbt/DoubleTag.h"
#include "mc/nbt/EndTag.h"
#include "mc/nbt/FloatTag.h"
#include "mc/nbt/Int64Tag.h"
#include "mc/nbt/IntTag.h"
#include "mc/nbt/ListTag.h"
#include "mc/nbt/ShortTag.h"
#include "mc/nbt/StringTag.h"
#include "mc/deps/nbt/ByteArrayTag.h"
#include "mc/deps/nbt/ByteTag.h"
#include "mc/deps/nbt/CompoundTag.h"
#include "mc/deps/nbt/DoubleTag.h"
#include "mc/deps/nbt/EndTag.h"
#include "mc/deps/nbt/FloatTag.h"
#include "mc/deps/nbt/Int64Tag.h"
#include "mc/deps/nbt/IntTag.h"
#include "mc/deps/nbt/ListTag.h"
#include "mc/deps/nbt/ShortTag.h"
#include "mc/deps/nbt/StringTag.h"

#include <magic_enum.hpp>
#include <memory>
Expand Down
22 changes: 11 additions & 11 deletions src/legacy/api/NbtAPI.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#pragma once
#include "legacy/api/APIHelp.h"
#include "mc/nbt/ByteArrayTag.h"
#include "mc/nbt/DoubleTag.h"
#include "mc/nbt/Tag.h"

#include <mc/nbt/CompoundTag.h>
#include <mc/nbt/FloatTag.h>
#include <mc/nbt/Int64Tag.h>
#include <mc/nbt/IntTag.h>
#include <mc/nbt/ListTag.h>
#include <mc/nbt/ShortTag.h>
#include <mc/nbt/StringTag.h>
#include "mc/deps/nbt/ByteArrayTag.h"
#include "mc/deps/nbt/DoubleTag.h"
#include "mc/deps/nbt/Tag.h"

#include <mc/deps/nbt/CompoundTag.h>
#include <mc/deps/nbt/FloatTag.h>
#include <mc/deps/nbt/Int64Tag.h>
#include <mc/deps/nbt/IntTag.h>
#include <mc/deps/nbt/ListTag.h>
#include <mc/deps/nbt/ShortTag.h>
#include <mc/deps/nbt/StringTag.h>
#include <memory>

// NBT Static
Expand Down
Loading
Loading