Skip to content

Commit

Permalink
feat: add Item.maxStackSize for LLSE (#1189)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgc2333 authored Apr 10, 2023
1 parent e4892ca commit 80981b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
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;

0 comments on commit 80981b6

Please sign in to comment.