Skip to content

Commit 9564218

Browse files
committed
chore: replace some code with Block::isAir and ItemStackBase::isEnchanted
1 parent 5a882fb commit 9564218

File tree

9 files changed

+9
-18
lines changed

9 files changed

+9
-18
lines changed

src/legacy/api/BlockAPI.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,7 @@ Local<Value> BlockClass::getThickness() {
197197

198198
Local<Value> BlockClass::isAir() {
199199
try {
200-
return Boolean::newBoolean(
201-
BlockHelper::isAir(*get())
202-
);
200+
return Boolean::newBoolean(get()->isAir());
203201
}
204202
CATCH("Fail in isAir!");
205203
}

src/legacy/api/EntityAPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ Local<Value> EntityClass::getBlockFromViewVector(const Arguments& args) {
14031403
}
14041404
Block const& bl = actor->getDimensionBlockSource().getBlock(bp);
14051405
BlockType const& legacy = bl.getBlockType();
1406-
if (lse::api::BlockHelper::isAir(bl)
1406+
if (bl.isAir()
14071407
|| (legacy.mProperties == BlockProperty::None && legacy.mMaterial.mType == MaterialType::Any)) {
14081408
return Local<Value>();
14091409
}

src/legacy/api/ItemAPI.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,7 @@ Local<Value> ItemClass::isDamaged() {
224224

225225
Local<Value> ItemClass::isEnchanted() {
226226
try {
227-
return Boolean::newBoolean(
228-
get()->mUserData && get()->mUserData->contains(ItemStackBase::TAG_ENCHANTS(), Tag::List)
229-
);
227+
return Boolean::newBoolean(get()->isEnchanted());
230228
}
231229
CATCH("Fail in isEnchanted!");
232230
}

src/legacy/api/PlayerAPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3275,7 +3275,7 @@ Local<Value> PlayerClass::getBlockFromViewVector(const Arguments& args) {
32753275
Block const& bl = player->getDimensionBlockSource().getBlock(bp);
32763276
BlockType const& legacy = bl.getBlockType();
32773277
// isEmpty()
3278-
if (lse::api::BlockHelper::isAir(bl)
3278+
if (bl.isAir()
32793279
|| (legacy.mProperties == BlockProperty::None && legacy.mMaterial.mType == MaterialType::Any)) {
32803280
return Local<Value>();
32813281
}

src/lse/api/helper/BlockHelper.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,4 @@ bool BlockHelper::isValidHeight(WeakRef<Dimension> dimension, std::variant<int,
1919

2020
return false;
2121
}
22-
23-
bool BlockHelper::isAir(Block const& block) {
24-
return block.getBlockType().mNameInfo->mFullName->mStrHash == BedrockBlockNames::Air().mStrHash;
25-
}
2622
} // namespace lse::api

src/lse/api/helper/BlockHelper.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ namespace lse::api {
44
class BlockHelper {
55
public:
66
static bool isValidHeight(WeakRef<Dimension> dimension, std::variant<int, float> height);
7-
static bool isAir(Block const& block);
87
};
98
} // namespace lse::api

src/lse/events/BlockEvents.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ LL_TYPE_INSTANCE_HOOK(
165165
uchar pistonMoveFacing
166166
) {
167167
IF_LISTENED(EVENT_TYPES::onPistonTryPush) {
168-
if (api::BlockHelper::isAir(region.getBlock(curPos))) {
168+
if (region.getBlock(curPos).isAir()) {
169169
return origin(region, curPos, curBranchFacing, pistonMoveFacing);
170170
}
171171
if (!CallEvent(
@@ -262,7 +262,7 @@ LL_TYPE_INSTANCE_HOOK(
262262
Actor* source
263263
) {
264264
IF_LISTENED(EVENT_TYPES::onBlockExploded) {
265-
if (api::BlockHelper::isAir(destroyedBlock)) {
265+
if (destroyedBlock.isAir()) {
266266
return origin(dimension, blockPos, destroyedBlock, source);
267267
}
268268
CallEvent(

src/lse/events/EntityEvents.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ LL_TYPE_INSTANCE_HOOK(
194194
IF_LISTENED(EVENT_TYPES::onProjectileHitBlock) {
195195
auto& region = owner.getDimensionBlockSourceConst();
196196
auto& block = region.getBlock(res.mBlock);
197-
if (res.mType == HitResultType::Tile && res.mBlock != BlockPos::ZERO() && !api::BlockHelper::isAir(block)) {
197+
if (res.mType == HitResultType::Tile && res.mBlock != BlockPos::ZERO() && !block.isAir()) {
198198
if (!CallEvent(
199199
EVENT_TYPES::onProjectileHitBlock,
200200
BlockClass::newBlock(block, res.mBlock, region),

xmake.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ add_rules("mode.debug", "mode.release")
33
add_repositories("levimc-repo https://github.com/LiteLDev/xmake-repo.git")
44

55
if is_config("target_type", "server") then
6-
add_requires("levilamina 34dc3a47d8c83aa0fc64be14b6bfde2e11d7711a", {configs = {target_type = "server"}})
6+
add_requires("levilamina 435ae9836047c827003bad585f1f452c24bda779", {configs = {target_type = "server"}})
77
else
8-
add_requires("levilamina 34dc3a47d8c83aa0fc64be14b6bfde2e11d7711a", {configs = {target_type = "client"}})
8+
add_requires("levilamina 435ae9836047c827003bad585f1f452c24bda779", {configs = {target_type = "client"}})
99
end
1010

1111
add_requires("levibuildscript")

0 commit comments

Comments
 (0)