Skip to content

Commit e4bc275

Browse files
committed
refactor: add compability for mc.explode
1 parent cb0cf4a commit e4bc275

File tree

1 file changed

+52
-26
lines changed

1 file changed

+52
-26
lines changed

src/legacy/api/EntityAPI.cpp

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "mc/world/level/Spawner.h"
2525
#include "mc/world/level/block/Block.h"
2626

27+
#include <climits>
2728
#include <magic_enum.hpp>
2829
#include <mc/deps/core/string/HashedString.h>
2930
#include <mc/entity/EntityContext.h>
@@ -1756,12 +1757,14 @@ Local<Value> McClass::spawnMob(const Arguments& args) {
17561757
}
17571758

17581759
Local<Value> McClass::explode(const Arguments& args) {
1759-
CHECK_ARGS_COUNT(args, 6);
1760+
CHECK_ARGS_COUNT(args, 5);
17601761

17611762
try {
17621763
FloatVec4 pos;
17631764
int beginIndex;
1764-
if (args.size() == 6) {
1765+
switch (args.size()) {
1766+
case 5:
1767+
case 6:
17651768
// PosObj
17661769
beginIndex = 1;
17671770

@@ -1786,7 +1789,9 @@ Local<Value> McClass::explode(const Arguments& args) {
17861789
LOG_WRONG_ARG_TYPE();
17871790
return Local<Value>();
17881791
}
1789-
} else if (args.size() == 9) {
1792+
break;
1793+
case 8:
1794+
case 9:
17901795
// Number Pos
17911796
beginIndex = 4;
17921797
CHECK_ARG_TYPE(args[0], ValueKind::kNumber);
@@ -1799,34 +1804,55 @@ Local<Value> McClass::explode(const Arguments& args) {
17991804
args[2].asNumber().toFloat(),
18001805
args[3].toInt()
18011806
};
1802-
} else {
1807+
break;
1808+
default:
18031809
LOG_WRONG_ARGS_COUNT();
18041810
return Local<Value>();
1811+
break;
18051812
}
1806-
18071813
auto source = EntityClass::extract(args[beginIndex + 0]); // Can be nullptr
18081814

1809-
CHECK_ARG_TYPE(args[beginIndex + 1], ValueKind::kNumber);
1810-
CHECK_ARG_TYPE(args[beginIndex + 2], ValueKind::kNumber);
1811-
CHECK_ARG_TYPE(args[beginIndex + 3], ValueKind::kBoolean);
1812-
CHECK_ARG_TYPE(args[beginIndex + 4], ValueKind::kBoolean);
1813-
1814-
float maxResistance = args[beginIndex + 1].asNumber().toFloat();
1815-
float radius = args[beginIndex + 2].asNumber().toFloat();
1816-
bool isDestroy = args[beginIndex + 3].asBoolean().value();
1817-
bool isFire = args[beginIndex + 4].asBoolean().value();
1818-
1819-
ll::service::getLevel()->explode(
1820-
ll::service::getLevel()->getDimension(pos.dim)->getBlockSourceFromMainChunkSource(),
1821-
source,
1822-
pos.getVec3(),
1823-
radius,
1824-
isFire,
1825-
isDestroy,
1826-
maxResistance,
1827-
false
1828-
);
1829-
return Boolean::newBoolean(true);
1815+
if (args.size() == 5 || args.size() == 8) {
1816+
CHECK_ARG_TYPE(args[beginIndex + 1], ValueKind::kNumber);
1817+
CHECK_ARG_TYPE(args[beginIndex + 3], ValueKind::kBoolean);
1818+
CHECK_ARG_TYPE(args[beginIndex + 4], ValueKind::kBoolean);
1819+
1820+
float radius = args[beginIndex + 1].asNumber().toFloat();
1821+
bool isDestroy = args[beginIndex + 2].asBoolean().value();
1822+
bool isFire = args[beginIndex + 3].asBoolean().value();
1823+
1824+
return Boolean::newBoolean(ll::service::getLevel()->explode(
1825+
ll::service::getLevel()->getDimension(pos.dim)->getBlockSourceFromMainChunkSource(),
1826+
source,
1827+
pos.getVec3(),
1828+
radius,
1829+
isFire,
1830+
isDestroy,
1831+
FLT_MAX,
1832+
false
1833+
));
1834+
} else {
1835+
CHECK_ARG_TYPE(args[beginIndex + 1], ValueKind::kNumber);
1836+
CHECK_ARG_TYPE(args[beginIndex + 2], ValueKind::kNumber);
1837+
CHECK_ARG_TYPE(args[beginIndex + 3], ValueKind::kBoolean);
1838+
CHECK_ARG_TYPE(args[beginIndex + 4], ValueKind::kBoolean);
1839+
1840+
float maxResistance = args[beginIndex + 1].asNumber().toFloat();
1841+
float radius = args[beginIndex + 2].asNumber().toFloat();
1842+
bool isDestroy = args[beginIndex + 3].asBoolean().value();
1843+
bool isFire = args[beginIndex + 4].asBoolean().value();
1844+
1845+
return Boolean::newBoolean(ll::service::getLevel()->explode(
1846+
ll::service::getLevel()->getDimension(pos.dim)->getBlockSourceFromMainChunkSource(),
1847+
source,
1848+
pos.getVec3(),
1849+
radius,
1850+
isFire,
1851+
isDestroy,
1852+
maxResistance,
1853+
false
1854+
));
1855+
}
18301856
}
18311857
CATCH("Fail in Explode!");
18321858
}

0 commit comments

Comments
 (0)