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
25 changes: 24 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.16.1] - 2025-11-12

### Added

- Added the maxCount attribute to the Item class @zimuya4153

### Fixed

- Fixed the Vec3 parameter of the command @zimuya4153
- Fixed the objectificationMoneyHistory function of money [#332] @zimuya4153
- Fixed the Player::giveItem method [#326] @zimuya4153
- Fixed the NbtCompound::toObject method [#315] [#317] @zimuya4153
- Fixed the syntax error output of runcmdEx @zimuya4153
- Fixed the asynchronous output of commands [#322] @zimuya4153
- Fixed the hurt method of the Actor class [#330] @zimuya4153

## [0.16.0] - 2025-11-04

### Changed
Expand Down Expand Up @@ -1026,9 +1042,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#303]: https://github.com/LiteLDev/LegacyScriptEngine/issues/303
[#309]: https://github.com/LiteLDev/LegacyScriptEngine/issues/309
[#310]: https://github.com/LiteLDev/LegacyScriptEngine/issues/310
[#315]: https://github.com/LiteLDev/LegacyScriptEngine/issues/315
[#317]: https://github.com/LiteLDev/LegacyScriptEngine/issues/317
[#322]: https://github.com/LiteLDev/LegacyScriptEngine/issues/322
[#323]: https://github.com/LiteLDev/LegacyScriptEngine/issues/323
[#326]: https://github.com/LiteLDev/LegacyScriptEngine/issues/326
[#330]: https://github.com/LiteLDev/LegacyScriptEngine/issues/330
[#332]: https://github.com/LiteLDev/LegacyScriptEngine/issues/332

[Unreleased]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.16.0...HEAD
[Unreleased]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.16.1...HEAD
[0.16.1]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.16.0...v0.16.1
[0.16.0]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.15.0...v0.16.0
[0.15.0]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.14.0...v0.15.0
[0.14.0]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.13.2...v0.14.0
Expand Down
1 change: 1 addition & 0 deletions docs/apis/GameAPI/Item.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Every item object contains some fixed object properties. For a specific item obj
| it.type | Item Standard Type Name | `String` |
| it.id | Item's in-game ID | `Integer` |
| it.count | Item's count | `Integer` |
| it.count | Item's max count (Added in 0.16.1) | `Integer` |
| it.aux | Item's data value (for example, wool color or wood type) | `Integer` |
| it.lore | Item Lore | `Array<String, String...>` |
| it.damage | Item Consumed Damage | `Integer` |
Expand Down
55 changes: 28 additions & 27 deletions docs/apis/GameAPI/Item.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,34 @@

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

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

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

Expand Down
10 changes: 7 additions & 3 deletions src/legacy/api/CommandAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Local<Value> convertResult(ParamStorageType const& result, CommandOrigin const&
} else if (result.hold(ParamKind::Kind::Vec3)) {
auto dim = origin.getDimension();
return FloatPos::newPos(
std::get<CommandPosition>(result.value())
std::get<CommandPositionFloat>(result.value())
.getPosition(CommandVersion::CurrentVersion(), origin, Vec3::ZERO()),
dim ? dim->getDimensionId().id : -1
);
Expand Down Expand Up @@ -222,6 +222,7 @@ Local<Value> McClass::runcmdEx(const Arguments& args) {
outputStr.pop_back();
}
resObj.set("success", false);
resObj.set("output", outputStr);
return resObj;
}
CATCH("Fail in RunCmdEx!")
Expand Down Expand Up @@ -361,8 +362,8 @@ void onExecute(CommandOrigin const& origin, CommandOutput& output, RuntimeComman
try {
Local<Object> args = Object::newObject();
auto cmd = CommandClass::newCommand(commandName);
auto ori = CommandOriginClass::newCommandOrigin(&origin);
auto outp = CommandOutputClass::newCommandOutput(&output);
auto * ori = new CommandOriginClass(origin.clone());
auto* outp = new CommandOutputClass(std::make_shared<CommandOutput>(output), ori->ptr);

auto& registeredCommands = getEngineOwnData()->plugin->registeredCommands;
if (registeredCommands.find(commandName) == registeredCommands.end()) {
Expand Down Expand Up @@ -395,6 +396,9 @@ void onExecute(CommandOrigin const& origin, CommandOutput& output, RuntimeComman
}
}
localShareData->commandCallbacks[commandName].func.get().call({}, cmd, ori, outp, args);
std::swap(output.mMessages, outp->output->mMessages);
output.mSuccessCount = outp->output->mSuccessCount;
outp->isAsync = true;
}
CATCH_WITHOUT_RETURN("Fail in executing command \"" + commandName + "\"!")
}
Expand Down
9 changes: 2 additions & 7 deletions src/legacy/api/CommandOriginAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,9 @@ ClassDefine<CommandOriginClass> CommandOriginClassBuilder =

//////////////////// APIs ////////////////////

CommandOriginClass::CommandOriginClass(CommandOrigin const* p)
CommandOriginClass::CommandOriginClass(std::shared_ptr<CommandOrigin> p)
: ScriptClass(ScriptClass::ConstructFromCpp<CommandOriginClass>{}),
ptr(p) {};

Local<Object> CommandOriginClass::newCommandOrigin(CommandOrigin const* p) {
auto newp = new CommandOriginClass(p);
return newp->getScriptObject();
}
ptr(std::move(p)) {};

Local<Value> CommandOriginClass::getOriginType() {
try {
Expand Down
27 changes: 14 additions & 13 deletions src/legacy/api/CommandOriginAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ extern ClassDefine<void> OriginTypeStaticBuilder;
extern ClassDefine<CommandOriginClass> CommandOriginClassBuilder;

class CommandOriginClass : public ScriptClass {
CommandOrigin const* ptr;
inline CommandOrigin const* get() { return ptr; }
public:
std::shared_ptr<CommandOrigin> ptr;
inline CommandOrigin* get() { return ptr.get(); }

public:
CommandOriginClass(CommandOrigin const* p);
static Local<Object> newCommandOrigin(CommandOrigin const* p);
Local<Value> getOriginType();
Local<Value> getOriginTypeName();
Local<Value> getOriginName();
Local<Value> getBlockPosition();
Local<Value> getPosition();
Local<Value> getEntity();
Local<Value> getPlayer();
Local<Value> getNbt(const Arguments& args);
Local<Value> toString();
CommandOriginClass(std::shared_ptr<CommandOrigin> p);
static std::shared_ptr<CommandOrigin> extract(Local<Value> v);
Local<Value> getOriginType();
Local<Value> getOriginTypeName();
Local<Value> getOriginName();
Local<Value> getBlockPosition();
Local<Value> getPosition();
Local<Value> getEntity();
Local<Value> getPlayer();
Local<Value> getNbt(const Arguments& args);
Local<Value> toString();
};
32 changes: 25 additions & 7 deletions src/legacy/api/CommandOutputAPI.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include "api/CommandOutputAPI.h"

#include "ll/api/service/Bedrock.h"
#include "mc/server/commands/CommandOutputMessageType.h"
#include "mc/server/commands/CommandPropertyBag.h"
#include "mc/server/commands/MinecraftCommands.h"
#include "mc/world/Minecraft.h"

//////////////////// Class Definition ////////////////////

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

//////////////////// APIs ////////////////////

CommandOutputClass::CommandOutputClass(CommandOutput* p)
CommandOutputClass::CommandOutputClass(std::shared_ptr<CommandOutput> out, std::shared_ptr<CommandOrigin> ori)
: ScriptClass(ScriptClass::ConstructFromCpp<CommandOutputClass>{}),
ptr(p) {};

Local<Object> CommandOutputClass::newCommandOutput(CommandOutput* p) {
auto newp = new CommandOutputClass(p);
return newp->getScriptObject();
}
output(std::move(out)),
origin(std::move(ori)),
isAsync(false) {};

Local<Value> CommandOutputClass::empty() {
try {
Expand Down Expand Up @@ -68,9 +69,11 @@ Local<Value> CommandOutputClass::success(const Arguments& args) {
param.push_back(CommandOutputParameter(paramArr.get(i).asString().toString().c_str()));
}
get()->success(msg, param);
send();
return Boolean::newBoolean(true);
}
get()->success(msg);
send();
return Boolean::newBoolean(true);
}
CATCH("Fail in success!");
Expand All @@ -90,12 +93,15 @@ Local<Value> CommandOutputClass::addMessage(const Arguments& args) {
if (args.size() >= 3) {
CHECK_ARG_TYPE(args[2], ValueKind::kNumber);
get()->addMessage(msg, param, (CommandOutputMessageType)args[2].asNumber().toInt32());
send();
return Boolean::newBoolean(true);
}
get()->addMessage(msg, param, (CommandOutputMessageType)0);
send();
return Boolean::newBoolean(true);
}
get()->addMessage(msg, {}, CommandOutputMessageType::Success);
send();
return Boolean::newBoolean(true);
}
CATCH("Fail in addMessage!");
Expand All @@ -114,14 +120,26 @@ Local<Value> CommandOutputClass::error(const Arguments& args) {
param.push_back(CommandOutputParameter(paramArr.get(i).asString().toString().c_str()));
}
get()->error(msg, param);
send();
return Boolean::newBoolean(true);
}
get()->error(msg);
send();
return Boolean::newBoolean(true);
}
CATCH("Fail in error!");
};

void CommandOutputClass::send() {
try {
if (!isAsync) return;
ll::service::getMinecraft()->mCommands->handleOutput(*origin, *output);
output->mSuccessCount = 0;
output->mMessages.clear();
}
CATCH_WITHOUT_RETURN("Fail in sendCommandOutput!");
}

Local<Value> CommandOutputClass::toString(const Arguments&) {
try {
return String::newString("<CommandOutput>");
Expand Down
12 changes: 8 additions & 4 deletions src/legacy/api/CommandOutputAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ class CommandOutputClass;
extern ClassDefine<CommandOutputClass> CommandOutputClassBuilder;

class CommandOutputClass : public ScriptClass {
CommandOutput* ptr;
inline CommandOutput* get() { return ptr; }
public:
std::shared_ptr<CommandOutput> output;
std::shared_ptr<CommandOrigin> origin;
bool isAsync;
inline CommandOutput* get() { return output.get(); }

public:
CommandOutputClass(CommandOutput* p);
static Local<Object> newCommandOutput(CommandOutput* p);
CommandOutputClass(std::shared_ptr<CommandOutput> output, std::shared_ptr<CommandOrigin> origin = {});

Local<Value> empty();

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

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

void send();

// Local<Value> setHasPlayerText()
//{
// try
Expand Down
48 changes: 18 additions & 30 deletions src/legacy/api/DataAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "mc/deps/crypto/hash/Hash.h"
#include "utils/JsonHelper.h"

#include <ctre/ctre.hpp>
#include <fstream>
#include <string>
#include <vector>
Expand Down Expand Up @@ -632,37 +633,24 @@ Local<Value> MoneyClass::trans(const Arguments& args) {
}

Local<Array> objectificationMoneyHistory(const string& res) {
std::vector<std::string_view> listV = ll::string_utils::splitByPattern(res, "\n");
std::vector<std::string> list = std::vector<std::string>(listV.begin(), listV.end());
// from -> to money time (note)

Local<Array> arr = Array::newArray();

string from, to, time1, time2, note, tmp;
long long money;
for (auto& str : list) {
if (str.back() == '\n') str.pop_back();

std::istringstream sin(str);
Local<Object> obj = Object::newObject();

note.clear();
sin >> from >> tmp >> to >> money >> time1 >> time2;
sin.get();
getline(sin, note);
if (note.front() == '(') note.erase(0, 1);
if (note.back() == '\n') note.pop_back();
if (note.back() == ')') note.pop_back();

time1 += " " + time2;

obj.set("from", String::newString(from));
obj.set("to", String::newString(to));
obj.set("money", Number::newNumber(money));
obj.set("time", String::newString(time1));
obj.set("note", String::newString(note));
arr.add(obj);
}
ll::string_utils::splitByPattern(
[&](std::string_view str) -> bool {
auto [whole, fromName, toName, money, time, note] =
ctre::match<R"(^(.*) -> (.*) (\d+) (\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}) \((.*)\)$)">(str);
if (time.empty()) return true;
Local<Object> obj = Object::newObject();
obj.set("from", String::newString(fromName));
obj.set("to", String::newString(toName));
obj.set("money", Number::newNumber(money.to_number<llong>()));
obj.set("time", String::newString(time));
obj.set("note", String::newString(note));
arr.add(obj);
return true;
},
res,
"\n"
);
return arr;
}

Expand Down
4 changes: 2 additions & 2 deletions src/legacy/api/EntityAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,12 +981,12 @@ Local<Value> EntityClass::hurt(const Arguments& args) {
type = args[1].asNumber().toInt32();
}
if (args.size() == 3) {
std::optional<Actor*> source = EntityClass::tryExtractActor(args[2]);
Actor* source = EntityClass::tryExtractActor(args[2]);
if (!source) {
return Boolean::newBoolean(false);
}
ActorDamageByActorSource damageBySource =
ActorDamageByActorSource(*source.value(), (SharedTypes::Legacy::ActorDamageCause)type);
ActorDamageByActorSource(*source, (SharedTypes::Legacy::ActorDamageCause)type);
return Boolean::newBoolean(entity->_hurt(damageBySource, damage, true, false));
}
ActorDamageSource damageSource;
Expand Down
Loading