Skip to content

Commit c19b649

Browse files
committed
chore: fix some compile warnings
1 parent 237d48e commit c19b649

File tree

17 files changed

+85
-131
lines changed

17 files changed

+85
-131
lines changed

.clangd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ CompileFlags:
88
Add:
99
- "-ferror-limit=0"
1010
- '-D__FUNCTION__="dummy"'
11+
- "-Wimplicit-fallthrough"

src/legacy/api/APIHelp.h

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,6 @@ std::string ValueToJson(Local<Value> v, int formatIndent = -1);
244244
// Limitation: enum values must be in range of [-128, 128)
245245
template <typename Type>
246246
struct EnumDefineBuilder {
247-
template <Type val>
248-
inline static Local<Value> serialize() {
249-
return Number::newNumber(static_cast<int>(val));
250-
}
251-
252247
inline static Local<Value> keys() {
253248
try {
254249
auto arr = Array::newArray();
@@ -266,7 +261,7 @@ struct EnumDefineBuilder {
266261
try {
267262
auto obj = Object::newObject();
268263
for (auto& [value, name] : magic_enum::enum_entries<Type>()) {
269-
obj.set(String::newString(name), Number::newNumber((int)value));
264+
obj.set(String::newString(name), Number::newNumber(static_cast<int64_t>(value)));
270265
}
271266
return obj;
272267
} catch (const std::exception&) {
@@ -299,37 +294,18 @@ struct EnumDefineBuilder {
299294
return Local<Value>();
300295
}
301296

302-
template <
303-
Type val,
304-
std::enable_if_t<std::is_enum_v<Type>, char> max = static_cast<char>(*magic_enum::enum_values<Type>().rbegin())>
305-
inline static void buildBuilder(script::ClassDefineBuilder<void>& builder) {
306-
if constexpr (static_cast<char>(val) > max) return;
307-
if constexpr (!magic_enum::enum_name(val).empty()) {
308-
fmt::print("{} = {},\n", magic_enum::enum_name(val), static_cast<int>(val));
309-
builder.property(magic_enum::enum_name(val).data(), &serialize<val>);
310-
}
311-
buildBuilder<static_cast<Type>((static_cast<char>(val) + 1)), max>(builder);
312-
}
313-
314-
template <
315-
std::enable_if_t<std::is_enum_v<Type>, char> max = static_cast<char>(*magic_enum::enum_values<Type>().rbegin())>
316297
inline static ClassDefine<void> build(std::string const& enumName) {
317298
script::ClassDefineBuilder<void> builder = defineClass(enumName);
318-
// fmt::print("枚举 {} 可能取值:\n", enumName);
319-
// buildBuilder<*magic_enum::enum_values<Type>().begin(), max>(builder);
320299

321300
for (auto& [val, name] : magic_enum::enum_entries<Type>()) {
322-
// fmt::print("{} = {},\n", name, static_cast<int>(val));
323-
auto _val = val;
324-
auto _name = name;
325-
builder.property(std::string(name), [=]() -> Local<Value> {
301+
builder.property(std::string(name), [enumName, val, name{std::string{name}}]() -> Local<Value> {
326302
try {
327-
return Number::newNumber(static_cast<int>(_val));
303+
return Number::newNumber(static_cast<int64_t>(val));
328304
} catch (const std::exception&) {
329305
lse::LegacyScriptEngine::getInstance().getSelf().getLogger().error(
330306
"Error in get {}.{}",
331307
enumName,
332-
_name
308+
name
333309
);
334310
}
335311
return Local<Value>();

src/legacy/api/BaseAPI.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#pragma once
22

3-
#include "api/APIHelp.h"
3+
#include "api/APIHelp.h" // IWYU pragma: keep
44
#include "main/Global.h"
55

6-
#include <string>
76
class BlockSource;
87

98
///////////////////// Enum //////////////////////
@@ -13,7 +12,7 @@ extern ClassDefine<void> ActorDamageCauseEnumBuilder;
1312
//////////////////// Classes ////////////////////
1413
class IntPos : public IntVec4, public ScriptClass {
1514
public:
16-
explicit IntPos(const Local<Object>& scriptObj) : ScriptClass(scriptObj) {}
15+
explicit IntPos(const Local<Object>& scriptObj) : IntVec4(), ScriptClass(scriptObj) {}
1716
static IntPos* create(const Arguments& args);
1817

1918
static Local<Object> newPos(int x, int y, int z, int dim = -1);
@@ -38,7 +37,7 @@ extern ClassDefine<IntPos> IntPosBuilder;
3837

3938
class FloatPos : public FloatVec4, public ScriptClass {
4039
public:
41-
explicit FloatPos(const Local<Object>& scriptObj) : ScriptClass(scriptObj) {}
40+
explicit FloatPos(const Local<Object>& scriptObj) : FloatVec4(), ScriptClass(scriptObj) {}
4241
static FloatPos* create(const Arguments& args);
4342

4443
static Local<Object> newPos(double x, double y, double z, int dim = -1);
@@ -62,18 +61,18 @@ extern ClassDefine<FloatPos> FloatPosBuilder;
6261

6362
class DirectionAngle : public ScriptClass {
6463
public:
65-
double pitch = 0, yaw = 0;
64+
float pitch = 0, yaw = 0;
6665

6766
explicit DirectionAngle(const Local<Object>& scriptObj) : ScriptClass(scriptObj) {}
6867
static DirectionAngle* create(const Arguments& args);
6968
static DirectionAngle* extract(Local<Value> value);
7069

71-
static Local<Object> newAngle(float pitch, float yaw);
72-
Local<Value> getPitch() { return Number::newNumber(pitch); }
73-
Local<Value> getYaw() { return Number::newNumber(yaw); }
74-
void setPitch(const Local<Value>& value) { pitch = value.asNumber().toDouble(); }
75-
void setYaw(const Local<Value>& value) { yaw = value.asNumber().toDouble(); }
76-
Local<Value> toString();
70+
static Local<Object> newAngle(float pitch, float yaw);
71+
[[nodiscard]] Local<Value> getPitch() const { return Number::newNumber(pitch); }
72+
[[nodiscard]] Local<Value> getYaw() const { return Number::newNumber(yaw); }
73+
void setPitch(const Local<Value>& value) { pitch = value.asNumber().toFloat(); }
74+
void setYaw(const Local<Value>& value) { yaw = value.asNumber().toFloat(); }
75+
Local<Value> toString();
7776

7877
Local<Value> toFacing();
7978
};

src/legacy/api/BlockAPI.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,8 @@ Local<Value> McClass::spawnParticle(const Arguments& args) {
581581
IntPos* posObj = IntPos::extractPos(args[0]);
582582
if (posObj->dim < 0) return Boolean::newBoolean(false);
583583
else {
584-
pos.x = posObj->x;
585-
pos.y = posObj->y;
586-
pos.z = posObj->z;
587-
pos.dim = posObj->dim;
588-
type = args[1];
584+
pos = *posObj;
585+
type = args[1];
589586
}
590587
} else if (IsInstanceOf<FloatPos>(args[0])) {
591588
// FloatPos

src/legacy/api/CommandAPI.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "ll/api/coro/CoroTask.h"
1818
#include "ll/api/service/Bedrock.h"
1919
#include "ll/api/service/GamingStatus.h"
20+
#include "ll/api/thread/ServerThreadExecutor.h"
2021
#include "magic_enum.hpp"
2122
#include "mc/_HeaderOutputPredefine.h"
2223
#include "mc/deps/core/utility/MCRESULT.h"
@@ -37,7 +38,6 @@
3738
#include "mc/world/item/ItemInstance.h"
3839
#include "mc/world/item/ItemStack.h"
3940
#include "mc/world/level/dimension/Dimension.h"
40-
#include "ll/api/thread/ServerThreadExecutor.h"
4141

4242
#include <string>
4343
#include <vector>
@@ -495,15 +495,15 @@ Local<Value> CommandClass::addOverload(const Arguments& args) {
495495
if (info.name == paramName || info.enumName == paramName || info.identifier == paramName) {
496496
if (info.optional) {
497497
if (info.type == ParamKind::Kind::Enum || info.type == ParamKind::Kind::SoftEnum) {
498-
cmd.optional(info.enumName, info.type, info.enumName).option(info.option);
498+
(void)cmd.optional(info.enumName, info.type, info.enumName).option(info.option);
499499
} else {
500-
cmd.optional(info.name, info.type).option(info.option);
500+
(void)cmd.optional(info.name, info.type).option(info.option);
501501
}
502502
} else {
503503
if (info.type == ParamKind::Kind::Enum || info.type == ParamKind::Kind::SoftEnum) {
504-
cmd.required(info.enumName, info.type, info.enumName).option(info.option);
504+
(void)cmd.required(info.enumName, info.type, info.enumName).option(info.option);
505505
} else {
506-
cmd.required(info.name, info.type).option(info.option);
506+
(void)cmd.required(info.name, info.type).option(info.option);
507507
}
508508
}
509509
}

src/legacy/api/DataAPI.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ Local<Value> ConfIniClass::getFloat(const Arguments& args) {
457457
return Number::newNumber(iniConf->getFloat(
458458
args[0].asString().toString(),
459459
args[1].asString().toString(),
460-
args.size() >= 3 ? args[2].asNumber().toFloat() : 0.0
460+
args.size() >= 3 ? args[2].asNumber().toFloat() : 0.0f
461461
));
462462
}
463463
CATCH("Fail in ConfIniGetFloat!");
@@ -884,7 +884,7 @@ Local<Value> DataClass::toMD5(const Arguments& args) {
884884
LOG_WRONG_ARG_TYPE(__FUNCTION__);
885885
return Local<Value>();
886886
}
887-
return String::newString(Crypto::Hash::hash(Crypto::Hash::HashType::Md5, data.data(), data.size()));
887+
return String::newString(Crypto::Hash::hash(Crypto::Hash::HashType::Md5, data.data(), (uint)data.size()));
888888
}
889889
CATCH("Fail in ToMD5!");
890890
}
@@ -902,7 +902,7 @@ Local<Value> DataClass::toSHA1(const Arguments& args) {
902902
LOG_WRONG_ARG_TYPE(__FUNCTION__);
903903
return Local<Value>();
904904
}
905-
return String::newString(Crypto::Hash::hash(Crypto::Hash::HashType::Md5, data.data(), data.size()));
905+
return String::newString(Crypto::Hash::hash(Crypto::Hash::HashType::Md5, data.data(), (uint)data.size()));
906906
}
907907
CATCH("Fail in ToSHA1!");
908908
}

src/legacy/api/EntityAPI.cpp

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ Local<Value> EntityClass::getInClouds() {
547547
Actor* entity = get();
548548
if (!entity) return Local<Value>();
549549

550-
short cloudHeight = entity->getDimension().getCloudHeight();
550+
float cloudHeight = entity->getDimension().getCloudHeight();
551551
float y = entity->getPosition().y;
552552
return Boolean::newBoolean(y > cloudHeight && y < cloudHeight + 4.0f);
553553
}
@@ -658,10 +658,7 @@ Local<Value> EntityClass::teleport(const Arguments& args) {
658658
IntPos* posObj = IntPos::extractPos(args[0]);
659659
if (posObj->dim < 0) return Boolean::newBoolean(false);
660660
else {
661-
pos.x = posObj->x;
662-
pos.y = posObj->y;
663-
pos.z = posObj->z;
664-
pos.dim = posObj->dim;
661+
pos = *posObj;
665662
}
666663
} else if (IsInstanceOf<FloatPos>(args[0])) {
667664
// FloatPos
@@ -726,10 +723,7 @@ Local<Value> EntityClass::distanceTo(const Arguments& args) {
726723
IntPos* posObj = IntPos::extractPos(args[0]);
727724
if (posObj->dim < 0) return Local<Value>();
728725
else {
729-
pos.x = posObj->x;
730-
pos.y = posObj->y;
731-
pos.z = posObj->z;
732-
pos.dim = posObj->dim;
726+
pos = *posObj;
733727
}
734728
} else if (IsInstanceOf<FloatPos>(args[0])) {
735729
// FloatPos
@@ -792,10 +786,7 @@ Local<Value> EntityClass::distanceToSqr(const Arguments& args) {
792786
IntPos* posObj = IntPos::extractPos(args[0]);
793787
if (posObj->dim < 0) return Local<Value>();
794788
else {
795-
pos.x = posObj->x;
796-
pos.y = posObj->y;
797-
pos.z = posObj->z;
798-
pos.dim = posObj->dim;
789+
pos = *posObj;
799790
}
800791
} else if (IsInstanceOf<FloatPos>(args[0])) {
801792
// FloatPos
@@ -1636,10 +1627,7 @@ Local<Value> McClass::cloneMob(const Arguments& args) {
16361627
IntPos* posObj = IntPos::extractPos(args[1]);
16371628
if (posObj->dim < 0) return Boolean::newBoolean(false);
16381629
else {
1639-
pos.x = posObj->x;
1640-
pos.y = posObj->y;
1641-
pos.z = posObj->z;
1642-
pos.dim = posObj->dim;
1630+
pos = *posObj;
16431631
}
16441632
} else if (IsInstanceOf<FloatPos>(args[1])) {
16451633
// FloatPos
@@ -1698,10 +1686,7 @@ Local<Value> McClass::spawnMob(const Arguments& args) {
16981686
IntPos* posObj = IntPos::extractPos(args[1]);
16991687
if (posObj->dim < 0) return Boolean::newBoolean(false);
17001688
else {
1701-
pos.x = posObj->x;
1702-
pos.y = posObj->y;
1703-
pos.z = posObj->z;
1704-
pos.dim = posObj->dim;
1689+
pos = *posObj;
17051690
}
17061691
} else if (IsInstanceOf<FloatPos>(args[1])) {
17071692
// FloatPos
@@ -1764,10 +1749,7 @@ Local<Value> McClass::explode(const Arguments& args) {
17641749
IntPos* posObj = IntPos::extractPos(args[0]);
17651750
if (posObj->dim < 0) return Boolean::newBoolean(false);
17661751
else {
1767-
pos.x = posObj->x;
1768-
pos.y = posObj->y;
1769-
pos.z = posObj->z;
1770-
pos.dim = posObj->dim;
1752+
pos = *posObj;
17711753
}
17721754
} else if (IsInstanceOf<FloatPos>(args[0])) {
17731755
// FloatPos

src/legacy/api/EventAPI.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111
#include "engine/EngineOwnData.h"
1212
#include "engine/GlobalShareData.h"
1313
#include "legacy/engine/LocalShareData.h"
14-
#include "legacy/main/BuiltinCommands.h"
1514
#include "ll/api/chrono/GameChrono.h"
1615
#include "ll/api/coro/CoroTask.h"
1716
#include "ll/api/event/EventBus.h"
1817
#include "ll/api/event/command/ExecuteCommandEvent.h"
19-
#include "ll/api/event/entity/ActorHurtEvent.h"
2018
#include "ll/api/event/entity/MobDieEvent.h"
2119
#include "ll/api/event/player/PlayerAddExperienceEvent.h"
2220
#include "ll/api/event/player/PlayerAttackEvent.h"
@@ -40,15 +38,13 @@
4038
#include "ll/api/event/world/FireSpreadEvent.h"
4139
#include "ll/api/event/world/SpawnMobEvent.h"
4240
#include "ll/api/service/Bedrock.h"
43-
#include "ll/api/service/GamingStatus.h"
4441
#include "ll/api/thread/ServerThreadExecutor.h"
4542
#include "lse/Entry.h"
4643
#include "lse/events/BlockEvents.h"
4744
#include "lse/events/EntityEvents.h"
4845
#include "lse/events/OtherEvents.h"
4946
#include "lse/events/PlayerEvents.h"
5047
#include "main/Global.h"
51-
#include "mc/legacy/ActorUniqueID.h"
5248
#include "mc/server/commands/CommandOriginType.h"
5349
#include "mc/world/actor/player/Player.h"
5450
#include "mc/world/attribute/AttributeInstance.h"
@@ -65,7 +61,6 @@
6561
#endif
6662

6763
#include <list>
68-
#include <shared_mutex>
6964
#include <string>
7065

7166
//////////////////// Listeners ////////////////////
@@ -202,6 +197,7 @@ void EnableEventListener(int eventId) {
202197
}
203198
IF_LISTENED_END(EVENT_TYPES::onChat);
204199
});
200+
break;
205201

206202
case EVENT_TYPES::onChangeDim:
207203
lse::events::player::ChangeDimensionEvent();
@@ -520,9 +516,7 @@ void EnableEventListener(int eventId) {
520516
break;
521517

522518
case EVENT_TYPES::onEntityExplode:
523-
lse::events::block::ExplodeEvent();
524-
break;
525-
519+
[[fallthrough]];
526520
case EVENT_TYPES::onBlockExplode:
527521
lse::events::block::ExplodeEvent();
528522
break;
@@ -618,15 +612,14 @@ void EnableEventListener(int eventId) {
618612
}
619613
IF_LISTENED_END(EVENT_TYPES::onBlockInteracted);
620614
});
615+
break;
621616

622617
case EVENT_TYPES::onFarmLandDecay:
623618
lse::events::block::FarmDecayEvent();
624619
break;
625620

626621
case EVENT_TYPES::onPistonTryPush:
627-
lse::events::block::PistonPushEvent();
628-
break;
629-
622+
[[fallthrough]];
630623
case EVENT_TYPES::onPistonPush:
631624
lse::events::block::PistonPushEvent();
632625
break;

src/legacy/api/GuiAPI.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ Local<Value> SimpleFormClass::addLabel(const Arguments& args) {
143143
}
144144

145145
Local<Value> SimpleFormClass::addDivider(const Arguments& args) {
146-
CHECK_ARGS_COUNT(args, 0);
147-
148146
try {
149147
form.appendDivider();
150148
return this->getScriptObject();
@@ -245,8 +243,6 @@ Local<Value> CustomFormClass::addLabel(const Arguments& args) {
245243
}
246244

247245
Local<Value> CustomFormClass::addDivider(const Arguments& args) {
248-
CHECK_ARGS_COUNT(args, 0)
249-
250246
try {
251247
form.appendDivider();
252248
return this->getScriptObject();

src/legacy/api/ItemAPI.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,7 @@ Local<Value> McClass::spawnItem(const Arguments& args) {
491491
IntPos* posObj = IntPos::extractPos(args[1]);
492492
if (posObj->dim < 0) return Boolean::newBoolean(false);
493493
else {
494-
pos.x = posObj->x;
495-
pos.y = posObj->y;
496-
pos.z = posObj->z;
497-
pos.dim = posObj->dim;
494+
pos = *posObj;
498495
}
499496
} else if (IsInstanceOf<FloatPos>(args[1])) {
500497
// FloatPos

0 commit comments

Comments
 (0)