Skip to content

Commit 9ea3739

Browse files
committed
fix: fix mc.newItem #348
1 parent ddade82 commit 9ea3739

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/legacy/api/CommandAPI.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,14 @@ Local<Value> convertResult(ParamStorageType const& result, CommandOrigin const&
9595
-1
9696
);
9797
} else if (result.hold(ParamKind::Kind::Item)) {
98-
if (auto itemPtr =
99-
ll::service::getLevel()->getItemRegistry().getItem(std::get<CommandItem>(result.value()).mId).lock()) {
100-
return ItemClass::newItem(std::make_unique<ItemStack>(*itemPtr));
101-
}
98+
auto item = std::make_unique<ItemStack>();
99+
item->reinit(
100+
ll::service::getLevel()->getItemRegistry().getNameFromLegacyID(std::get<CommandItem>(result.value()).mId),
101+
1,
102+
0
103+
);
104+
return ItemClass::newItem(std::move(item));
105+
102106
} else if (result.hold(ParamKind::Kind::Actor)) {
103107
auto arr = Array::newArray();
104108
for (auto i : std::get<CommandSelector<Actor>>(result.value()).results(origin)) {

src/legacy/api/ItemAPI.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,9 @@ Local<Value> McClass::newItem(const Arguments& args) {
469469
if (args.size() >= 2 && args[1].isNumber()) {
470470
std::string type = args[0].asString().toString();
471471
int cnt = args[1].asNumber().toInt32();
472-
473-
if (auto itemPtr = ll::service::getLevel()->getItemRegistry().getItem(HashedString(type)).lock()) {
474-
return ItemClass::newItem(std::make_unique<ItemStack>(*itemPtr));
475-
}
472+
auto item = std::make_unique<ItemStack>();
473+
item->reinit(type, cnt, 0);
474+
return ItemClass::newItem(std::move(item));
476475
} else {
477476
LOG_TOO_FEW_ARGS(__FUNCTION__);
478477
return Local<Value>();

0 commit comments

Comments
 (0)