Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add Item.maxStackSize for LLSE #1189

Merged
merged 3 commits into from
Apr 10, 2023
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
33 changes: 20 additions & 13 deletions ScriptEngine/src/api/ItemAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ClassDefine<ItemClass> ItemClassBuilder =
.instanceProperty("lore", &ItemClass::getLore)
.instanceProperty("attackDamage", &ItemClass::getAttackDamage)
.instanceProperty("maxDamage", &ItemClass::getMaxDamage)
.instanceProperty("maxStackSize", &ItemClass::getMaxStackSize)
.instanceProperty("isArmorItem", &ItemClass::isArmorItem)
.instanceProperty("isBlock", &ItemClass::isBlock)
.instanceProperty("isDamageableItem", &ItemClass::isDamageableItem)
Expand Down Expand Up @@ -62,27 +63,26 @@ ClassDefine<ItemClass> ItemClassBuilder =
.instanceFunction("getTag", &ItemClass::getNbt)
.build();


//////////////////// Classes ////////////////////

ItemClass::ItemClass(ItemStack* p)
: ScriptClass(ScriptClass::ConstructFromCpp<ItemClass>{}), item(p) {
ItemClass::ItemClass(ItemStack* p) : ScriptClass(ScriptClass::ConstructFromCpp<ItemClass>{}), item(p) {
preloadData();
}

//生成函数
// 生成函数
Local<Object> ItemClass::newItem(ItemStack* p) {
auto newp = new ItemClass(p);
return newp->getScriptObject();
}

ItemStack* ItemClass::extract(Local<Value> v) {
if (EngineScope::currentEngine()->isInstanceOf<ItemClass>(v))
return EngineScope::currentEngine()->getNativeInstance<ItemClass>(v)->get();
else
return nullptr;
}

//成员函数
// 成员函数
void ItemClass::preloadData() {
name = item->getCustomName();
if (name.empty())
Expand All @@ -96,39 +96,39 @@ void ItemClass::preloadData() {

Local<Value> ItemClass::getName() {
try {
//已预加载
// 已预加载
return String::newString(name);
}
CATCH("Fail in GetItemName!");
}

Local<Value> ItemClass::getType() {
try {
//已预加载
// 已预加载
return String::newString(type);
}
CATCH("Fail in GetType!");
}

Local<Value> ItemClass::getId() {
try {
//已预加载
// 已预加载
return Number::newNumber(id);
}
CATCH("Fail in GetType!");
}

Local<Value> ItemClass::getCount() {
try {
//已预加载
// 已预加载
return Number::newNumber(count);
}
CATCH("Fail in GetCount!");
}

Local<Value> ItemClass::getAux() {
try {
//已预加载
// 已预加载
return Number::newNumber(aux);
}
CATCH("Fail in GetAux!");
Expand All @@ -155,6 +155,13 @@ Local<Value> ItemClass::getMaxDamage() {
CATCH("Fail in GetMaxDamage!");
}

Local<Value> ItemClass::getMaxStackSize() {
try {
return Number::newNumber(item->getMaxStackSize());
}
CATCH("Fail in GetMaxStackSize!");
}

Local<Value> ItemClass::getLore() {
try {
std::vector<std::string> loreArray = item->getCustomLore();
Expand All @@ -164,13 +171,12 @@ Local<Value> ItemClass::getLore() {
for (std::string lore : loreArray) {
loreValueList.add(String::newString(lore));
}

return loreValueList;
}
CATCH("Fail in GetLore!");
}


Local<Value> ItemClass::isArmorItem() {
try {
return Boolean::newBoolean(item->isArmorItem());
Expand Down Expand Up @@ -481,7 +487,8 @@ Local<Value> McClass::spawnItem(const Arguments& args) {
CHECK_ARG_TYPE(args[2], ValueKind::kNumber);
CHECK_ARG_TYPE(args[3], ValueKind::kNumber);
CHECK_ARG_TYPE(args[4], ValueKind::kNumber);
pos = {args[1].asNumber().toFloat(), args[2].asNumber().toFloat(), args[3].asNumber().toFloat(), args[4].toInt()};
pos = {args[1].asNumber().toFloat(), args[2].asNumber().toFloat(), args[3].asNumber().toFloat(),
args[4].toInt()};
} else {
LOG_WRONG_ARGS_COUNT();
return Local<Value>();
Expand Down
3 changes: 3 additions & 0 deletions ScriptEngine/src/api/ItemAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

//////////////////// Classes ////////////////////
class ItemStack;

class ItemClass : public ScriptClass {
private:
ItemStack* item;
Expand Down Expand Up @@ -33,6 +34,7 @@ class ItemClass : public ScriptClass {
Local<Value> getDamage();
Local<Value> getAttackDamage();
Local<Value> getMaxDamage();
Local<Value> getMaxStackSize();
Local<Value> getLore();

Local<Value> isArmorItem();
Expand Down Expand Up @@ -65,4 +67,5 @@ class ItemClass : public ScriptClass {

Local<Value> match(const Arguments& args);
};

extern ClassDefine<ItemClass> ItemClassBuilder;