Skip to content

Commit e9855e5

Browse files
authored
fix: fix some issue (#333)
Added the maxCount attribute to the Item class Fixed the Vec3 parameter of the command Fixed the objectificationMoneyHistory function of money Fixed the Player::giveItem method Fixed the NbtCompound::toObject method Fixed the syntax error output of runcmdEx Fixed the asynchronous output of commands Fixed the hurt method of the Actor class
1 parent 7fde5dc commit e9855e5

File tree

16 files changed

+163
-110
lines changed

16 files changed

+163
-110
lines changed

CHANGELOG.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.16.1] - 2025-11-12
11+
12+
### Added
13+
14+
- Added the maxCount attribute to the Item class @zimuya4153
15+
16+
### Fixed
17+
18+
- Fixed the Vec3 parameter of the command @zimuya4153
19+
- Fixed the objectificationMoneyHistory function of money [#332] @zimuya4153
20+
- Fixed the Player::giveItem method [#326] @zimuya4153
21+
- Fixed the NbtCompound::toObject method [#315] [#317] @zimuya4153
22+
- Fixed the syntax error output of runcmdEx @zimuya4153
23+
- Fixed the asynchronous output of commands [#322] @zimuya4153
24+
- Fixed the hurt method of the Actor class [#330] @zimuya4153
25+
1026
## [0.16.0] - 2025-11-04
1127

1228
### Changed
@@ -1026,9 +1042,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10261042
[#303]: https://github.com/LiteLDev/LegacyScriptEngine/issues/303
10271043
[#309]: https://github.com/LiteLDev/LegacyScriptEngine/issues/309
10281044
[#310]: https://github.com/LiteLDev/LegacyScriptEngine/issues/310
1045+
[#315]: https://github.com/LiteLDev/LegacyScriptEngine/issues/315
1046+
[#317]: https://github.com/LiteLDev/LegacyScriptEngine/issues/317
1047+
[#322]: https://github.com/LiteLDev/LegacyScriptEngine/issues/322
10291048
[#323]: https://github.com/LiteLDev/LegacyScriptEngine/issues/323
1049+
[#326]: https://github.com/LiteLDev/LegacyScriptEngine/issues/326
1050+
[#330]: https://github.com/LiteLDev/LegacyScriptEngine/issues/330
1051+
[#332]: https://github.com/LiteLDev/LegacyScriptEngine/issues/332
10301052

1031-
[Unreleased]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.16.0...HEAD
1053+
[Unreleased]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.16.1...HEAD
1054+
[0.16.1]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.16.0...v0.16.1
10321055
[0.16.0]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.15.0...v0.16.0
10331056
[0.15.0]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.14.0...v0.15.0
10341057
[0.14.0]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.13.2...v0.14.0

docs/apis/GameAPI/Item.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Every item object contains some fixed object properties. For a specific item obj
6565
| it.type | Item Standard Type Name | `String` |
6666
| it.id | Item's in-game ID | `Integer` |
6767
| it.count | Item's count | `Integer` |
68+
| it.count | Item's max count (Added in 0.16.1) | `Integer` |
6869
| it.aux | Item's data value (for example, wool color or wood type) | `Integer` |
6970
| it.lore | Item Lore | `Array<String, String...>` |
7071
| it.damage | Item Consumed Damage | `Integer` |

docs/apis/GameAPI/Item.zh.md

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,33 +60,34 @@
6060

6161
每一个物品对象都包含一些固定的对象属性。对于某个特定的物品对象`it`,有以下这些属性
6262

63-
| 属性 | 含义 | 类型 |
64-
|---------------------|---------------------------------|----------------------------|
65-
| it.name | 游戏内显示的物品名称 | `String` |
66-
| it.type | 物品标准类型名 | `String` |
67-
| it.id | 物品的游戏内id | `Integer` |
68-
| it.count | 这个物品对象堆叠的个数 | `Integer` |
69-
| it.aux | 物品附加值(如羊毛颜色) | `Integer` |
70-
| it.damage | 物品已消耗耐久 | `Integer` |
71-
| it.attackDamage | 物品攻击伤害 | `Integer` |
72-
| it.maxDamage | 物品最大耐久 | `Integer` |
73-
| it.lore | 物品Lore | `Array<String, String...>` |
74-
| it.isArmorItem | 物品是否为盔甲 | `Boolean` |
75-
| it.isBlock | 物品是否为方块 | `Boolean` |
76-
| it.isDamageableItem | 物品是否可被破坏 | `Boolean` |
77-
| it.isDamaged | 物品耐久是否被消耗 | `Boolean` |
78-
| it.isEnchanted | 物品是否已被附魔 | `Boolean` |
79-
| it.isEnchantingBook | 物品是否为附魔书 | `Boolean` |
80-
| it.isFireResistant | 物品是否防火 | `Boolean` |
81-
| it.isFullStack | 物品是否已堆叠到最大堆叠数 | `Boolean` |
82-
| it.isGlint | 物品是否闪烁 | `Boolean` |
83-
| it.isHorseArmorItem | 物品是否为马铠 | `Boolean` |
84-
| it.isLiquidClipItem | Whether the item is liquid clip | `Boolean` |
85-
| it.isMusicDiscItem | 物品是否为唱片 | `Boolean` |
86-
| it.isOffhandItem | 物品是否可设置到副手 | `Boolean` |
87-
| it.isPotionItem | 物品是否为药水 | `Boolean` |
88-
| it.isStackable | 物品是否可堆叠 | `Boolean` |
89-
| it.isWearableItem | 物品是否可穿戴 | `Boolean` |
63+
| 属性 | 含义 | 类型 |
64+
| ------------------- | ---------------------------------------------- | -------------------------- |
65+
| it.name | 游戏内显示的物品名称 | `String` |
66+
| it.type | 物品标准类型名 | `String` |
67+
| it.id | 物品的游戏内 id | `Integer` |
68+
| it.count | 这个物品对象堆叠的个数 | `Integer` |
69+
| it.maxCount | 这个物品对象堆叠的最大个数(在 0.16.1 时被加入) | `Integer` |
70+
| it.aux | 物品附加值(如羊毛颜色) | `Integer` |
71+
| it.damage | 物品已消耗耐久 | `Integer` |
72+
| it.attackDamage | 物品攻击伤害 | `Integer` |
73+
| it.maxDamage | 物品最大耐久 | `Integer` |
74+
| it.lore | 物品 Lore | `Array<String, String...>` |
75+
| it.isArmorItem | 物品是否为盔甲 | `Boolean` |
76+
| it.isBlock | 物品是否为方块 | `Boolean` |
77+
| it.isDamageableItem | 物品是否可被破坏 | `Boolean` |
78+
| it.isDamaged | 物品耐久是否被消耗 | `Boolean` |
79+
| it.isEnchanted | 物品是否已被附魔 | `Boolean` |
80+
| it.isEnchantingBook | 物品是否为附魔书 | `Boolean` |
81+
| it.isFireResistant | 物品是否防火 | `Boolean` |
82+
| it.isFullStack | 物品是否已堆叠到最大堆叠数 | `Boolean` |
83+
| it.isGlint | 物品是否闪烁 | `Boolean` |
84+
| it.isHorseArmorItem | 物品是否为马铠 | `Boolean` |
85+
| it.isLiquidClipItem | Whether the item is liquid clip | `Boolean` |
86+
| it.isMusicDiscItem | 物品是否为唱片 | `Boolean` |
87+
| it.isOffhandItem | 物品是否可设置到副手 | `Boolean` |
88+
| it.isPotionItem | 物品是否为药水 | `Boolean` |
89+
| it.isStackable | 物品是否可堆叠 | `Boolean` |
90+
| it.isWearableItem | 物品是否可穿戴 | `Boolean` |
9091

9192
这些对象属性都是只读的,无法被修改
9293

src/legacy/api/CommandAPI.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Local<Value> convertResult(ParamStorageType const& result, CommandOrigin const&
122122
} else if (result.hold(ParamKind::Kind::Vec3)) {
123123
auto dim = origin.getDimension();
124124
return FloatPos::newPos(
125-
std::get<CommandPosition>(result.value())
125+
std::get<CommandPositionFloat>(result.value())
126126
.getPosition(CommandVersion::CurrentVersion(), origin, Vec3::ZERO()),
127127
dim ? dim->getDimensionId().id : -1
128128
);
@@ -222,6 +222,7 @@ Local<Value> McClass::runcmdEx(const Arguments& args) {
222222
outputStr.pop_back();
223223
}
224224
resObj.set("success", false);
225+
resObj.set("output", outputStr);
225226
return resObj;
226227
}
227228
CATCH("Fail in RunCmdEx!")
@@ -361,8 +362,8 @@ void onExecute(CommandOrigin const& origin, CommandOutput& output, RuntimeComman
361362
try {
362363
Local<Object> args = Object::newObject();
363364
auto cmd = CommandClass::newCommand(commandName);
364-
auto ori = CommandOriginClass::newCommandOrigin(&origin);
365-
auto outp = CommandOutputClass::newCommandOutput(&output);
365+
auto * ori = new CommandOriginClass(origin.clone());
366+
auto* outp = new CommandOutputClass(std::make_shared<CommandOutput>(output), ori->ptr);
366367

367368
auto& registeredCommands = getEngineOwnData()->plugin->registeredCommands;
368369
if (registeredCommands.find(commandName) == registeredCommands.end()) {
@@ -395,6 +396,9 @@ void onExecute(CommandOrigin const& origin, CommandOutput& output, RuntimeComman
395396
}
396397
}
397398
localShareData->commandCallbacks[commandName].func.get().call({}, cmd, ori, outp, args);
399+
std::swap(output.mMessages, outp->output->mMessages);
400+
output.mSuccessCount = outp->output->mSuccessCount;
401+
outp->isAsync = true;
398402
}
399403
CATCH_WITHOUT_RETURN("Fail in executing command \"" + commandName + "\"!")
400404
}

src/legacy/api/CommandOriginAPI.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,9 @@ ClassDefine<CommandOriginClass> CommandOriginClassBuilder =
3232

3333
//////////////////// APIs ////////////////////
3434

35-
CommandOriginClass::CommandOriginClass(CommandOrigin const* p)
35+
CommandOriginClass::CommandOriginClass(std::shared_ptr<CommandOrigin> p)
3636
: ScriptClass(ScriptClass::ConstructFromCpp<CommandOriginClass>{}),
37-
ptr(p) {};
38-
39-
Local<Object> CommandOriginClass::newCommandOrigin(CommandOrigin const* p) {
40-
auto newp = new CommandOriginClass(p);
41-
return newp->getScriptObject();
42-
}
37+
ptr(std::move(p)) {};
4338

4439
Local<Value> CommandOriginClass::getOriginType() {
4540
try {

src/legacy/api/CommandOriginAPI.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@ extern ClassDefine<void> OriginTypeStaticBuilder;
77
extern ClassDefine<CommandOriginClass> CommandOriginClassBuilder;
88

99
class CommandOriginClass : public ScriptClass {
10-
CommandOrigin const* ptr;
11-
inline CommandOrigin const* get() { return ptr; }
10+
public:
11+
std::shared_ptr<CommandOrigin> ptr;
12+
inline CommandOrigin* get() { return ptr.get(); }
1213

1314
public:
14-
CommandOriginClass(CommandOrigin const* p);
15-
static Local<Object> newCommandOrigin(CommandOrigin const* p);
16-
Local<Value> getOriginType();
17-
Local<Value> getOriginTypeName();
18-
Local<Value> getOriginName();
19-
Local<Value> getBlockPosition();
20-
Local<Value> getPosition();
21-
Local<Value> getEntity();
22-
Local<Value> getPlayer();
23-
Local<Value> getNbt(const Arguments& args);
24-
Local<Value> toString();
15+
CommandOriginClass(std::shared_ptr<CommandOrigin> p);
16+
static std::shared_ptr<CommandOrigin> extract(Local<Value> v);
17+
Local<Value> getOriginType();
18+
Local<Value> getOriginTypeName();
19+
Local<Value> getOriginName();
20+
Local<Value> getBlockPosition();
21+
Local<Value> getPosition();
22+
Local<Value> getEntity();
23+
Local<Value> getPlayer();
24+
Local<Value> getNbt(const Arguments& args);
25+
Local<Value> toString();
2526
};

src/legacy/api/CommandOutputAPI.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include "api/CommandOutputAPI.h"
22

3+
#include "ll/api/service/Bedrock.h"
34
#include "mc/server/commands/CommandOutputMessageType.h"
5+
#include "mc/server/commands/CommandPropertyBag.h"
6+
#include "mc/server/commands/MinecraftCommands.h"
7+
#include "mc/world/Minecraft.h"
48

59
//////////////////// Class Definition ////////////////////
610

@@ -20,14 +24,11 @@ ClassDefine<CommandOutputClass> CommandOutputClassBuilder =
2024

2125
//////////////////// APIs ////////////////////
2226

23-
CommandOutputClass::CommandOutputClass(CommandOutput* p)
27+
CommandOutputClass::CommandOutputClass(std::shared_ptr<CommandOutput> out, std::shared_ptr<CommandOrigin> ori)
2428
: ScriptClass(ScriptClass::ConstructFromCpp<CommandOutputClass>{}),
25-
ptr(p) {};
26-
27-
Local<Object> CommandOutputClass::newCommandOutput(CommandOutput* p) {
28-
auto newp = new CommandOutputClass(p);
29-
return newp->getScriptObject();
30-
}
29+
output(std::move(out)),
30+
origin(std::move(ori)),
31+
isAsync(false) {};
3132

3233
Local<Value> CommandOutputClass::empty() {
3334
try {
@@ -68,9 +69,11 @@ Local<Value> CommandOutputClass::success(const Arguments& args) {
6869
param.push_back(CommandOutputParameter(paramArr.get(i).asString().toString().c_str()));
6970
}
7071
get()->success(msg, param);
72+
send();
7173
return Boolean::newBoolean(true);
7274
}
7375
get()->success(msg);
76+
send();
7477
return Boolean::newBoolean(true);
7578
}
7679
CATCH("Fail in success!");
@@ -90,12 +93,15 @@ Local<Value> CommandOutputClass::addMessage(const Arguments& args) {
9093
if (args.size() >= 3) {
9194
CHECK_ARG_TYPE(args[2], ValueKind::kNumber);
9295
get()->addMessage(msg, param, (CommandOutputMessageType)args[2].asNumber().toInt32());
96+
send();
9397
return Boolean::newBoolean(true);
9498
}
9599
get()->addMessage(msg, param, (CommandOutputMessageType)0);
100+
send();
96101
return Boolean::newBoolean(true);
97102
}
98103
get()->addMessage(msg, {}, CommandOutputMessageType::Success);
104+
send();
99105
return Boolean::newBoolean(true);
100106
}
101107
CATCH("Fail in addMessage!");
@@ -114,14 +120,26 @@ Local<Value> CommandOutputClass::error(const Arguments& args) {
114120
param.push_back(CommandOutputParameter(paramArr.get(i).asString().toString().c_str()));
115121
}
116122
get()->error(msg, param);
123+
send();
117124
return Boolean::newBoolean(true);
118125
}
119126
get()->error(msg);
127+
send();
120128
return Boolean::newBoolean(true);
121129
}
122130
CATCH("Fail in error!");
123131
};
124132

133+
void CommandOutputClass::send() {
134+
try {
135+
if (!isAsync) return;
136+
ll::service::getMinecraft()->mCommands->handleOutput(*origin, *output);
137+
output->mSuccessCount = 0;
138+
output->mMessages.clear();
139+
}
140+
CATCH_WITHOUT_RETURN("Fail in sendCommandOutput!");
141+
}
142+
125143
Local<Value> CommandOutputClass::toString(const Arguments&) {
126144
try {
127145
return String::newString("<CommandOutput>");

src/legacy/api/CommandOutputAPI.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ class CommandOutputClass;
66
extern ClassDefine<CommandOutputClass> CommandOutputClassBuilder;
77

88
class CommandOutputClass : public ScriptClass {
9-
CommandOutput* ptr;
10-
inline CommandOutput* get() { return ptr; }
9+
public:
10+
std::shared_ptr<CommandOutput> output;
11+
std::shared_ptr<CommandOrigin> origin;
12+
bool isAsync;
13+
inline CommandOutput* get() { return output.get(); }
1114

1215
public:
13-
CommandOutputClass(CommandOutput* p);
14-
static Local<Object> newCommandOutput(CommandOutput* p);
16+
CommandOutputClass(std::shared_ptr<CommandOutput> output, std::shared_ptr<CommandOrigin> origin = {});
1517

1618
Local<Value> empty();
1719

@@ -23,6 +25,8 @@ class CommandOutputClass : public ScriptClass {
2325

2426
Local<Value> error(const Arguments& args);
2527

28+
void send();
29+
2630
// Local<Value> setHasPlayerText()
2731
//{
2832
// try

src/legacy/api/DataAPI.cpp

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "mc/deps/crypto/hash/Hash.h"
1212
#include "utils/JsonHelper.h"
1313

14+
#include <ctre/ctre.hpp>
1415
#include <fstream>
1516
#include <string>
1617
#include <vector>
@@ -632,37 +633,24 @@ Local<Value> MoneyClass::trans(const Arguments& args) {
632633
}
633634

634635
Local<Array> objectificationMoneyHistory(const string& res) {
635-
std::vector<std::string_view> listV = ll::string_utils::splitByPattern(res, "\n");
636-
std::vector<std::string> list = std::vector<std::string>(listV.begin(), listV.end());
637-
// from -> to money time (note)
638-
639636
Local<Array> arr = Array::newArray();
640-
641-
string from, to, time1, time2, note, tmp;
642-
long long money;
643-
for (auto& str : list) {
644-
if (str.back() == '\n') str.pop_back();
645-
646-
std::istringstream sin(str);
647-
Local<Object> obj = Object::newObject();
648-
649-
note.clear();
650-
sin >> from >> tmp >> to >> money >> time1 >> time2;
651-
sin.get();
652-
getline(sin, note);
653-
if (note.front() == '(') note.erase(0, 1);
654-
if (note.back() == '\n') note.pop_back();
655-
if (note.back() == ')') note.pop_back();
656-
657-
time1 += " " + time2;
658-
659-
obj.set("from", String::newString(from));
660-
obj.set("to", String::newString(to));
661-
obj.set("money", Number::newNumber(money));
662-
obj.set("time", String::newString(time1));
663-
obj.set("note", String::newString(note));
664-
arr.add(obj);
665-
}
637+
ll::string_utils::splitByPattern(
638+
[&](std::string_view str) -> bool {
639+
auto [whole, fromName, toName, money, time, note] =
640+
ctre::match<R"(^(.*) -> (.*) (\d+) (\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}) \((.*)\)$)">(str);
641+
if (time.empty()) return true;
642+
Local<Object> obj = Object::newObject();
643+
obj.set("from", String::newString(fromName));
644+
obj.set("to", String::newString(toName));
645+
obj.set("money", Number::newNumber(money.to_number<llong>()));
646+
obj.set("time", String::newString(time));
647+
obj.set("note", String::newString(note));
648+
arr.add(obj);
649+
return true;
650+
},
651+
res,
652+
"\n"
653+
);
666654
return arr;
667655
}
668656

src/legacy/api/EntityAPI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,12 +981,12 @@ Local<Value> EntityClass::hurt(const Arguments& args) {
981981
type = args[1].asNumber().toInt32();
982982
}
983983
if (args.size() == 3) {
984-
std::optional<Actor*> source = EntityClass::tryExtractActor(args[2]);
984+
Actor* source = EntityClass::tryExtractActor(args[2]);
985985
if (!source) {
986986
return Boolean::newBoolean(false);
987987
}
988988
ActorDamageByActorSource damageBySource =
989-
ActorDamageByActorSource(*source.value(), (SharedTypes::Legacy::ActorDamageCause)type);
989+
ActorDamageByActorSource(*source, (SharedTypes::Legacy::ActorDamageCause)type);
990990
return Boolean::newBoolean(entity->_hurt(damageBySource, damage, true, false));
991991
}
992992
ActorDamageSource damageSource;

0 commit comments

Comments
 (0)