@@ -63,11 +63,15 @@ int LuaItemStack::l_set_name(lua_State *L)
63
63
NO_MAP_LOCK_REQUIRED;
64
64
LuaItemStack *o = checkobject (L, 1 );
65
65
ItemStack &item = o->m_stack ;
66
- item.name = luaL_checkstring (L, 2 );
67
66
68
- if (item.name == " " || item.empty ())
67
+ bool status = true ;
68
+ item.name = luaL_checkstring (L, 2 );
69
+ if (item.name == " " || item.empty ()) {
69
70
item.clear ();
71
+ status = false ;
72
+ }
70
73
74
+ lua_pushboolean (L, status);
71
75
return 1 ;
72
76
}
73
77
@@ -87,11 +91,18 @@ int LuaItemStack::l_set_count(lua_State *L)
87
91
NO_MAP_LOCK_REQUIRED;
88
92
LuaItemStack *o = checkobject (L, 1 );
89
93
ItemStack &item = o->m_stack ;
90
- item.count = luaL_checkinteger (L, 2 );
91
94
92
- if (item.name == " " || item.empty ())
95
+ bool status;
96
+ lua_Integer count = luaL_checkinteger (L, 2 );
97
+ if (count <= 65535 ) {
98
+ item.count = count;
99
+ status = true ;
100
+ } else {
93
101
item.clear ();
102
+ status = false ;
103
+ }
94
104
105
+ lua_pushboolean (L, status);
95
106
return 1 ;
96
107
}
97
108
@@ -111,11 +122,18 @@ int LuaItemStack::l_set_wear(lua_State *L)
111
122
NO_MAP_LOCK_REQUIRED;
112
123
LuaItemStack *o = checkobject (L, 1 );
113
124
ItemStack &item = o->m_stack ;
114
- item.wear = luaL_checkinteger (L, 2 );
115
125
116
- if (item.wear > 65535 )
126
+ bool status;
127
+ lua_Integer wear = luaL_checkinteger (L, 2 );
128
+ if (wear <= 65535 ) {
129
+ item.wear = wear;
130
+ status = true ;
131
+ } else {
117
132
item.clear ();
133
+ status = false ;
134
+ }
118
135
136
+ lua_pushboolean (L, status);
119
137
return 1 ;
120
138
}
121
139
@@ -138,11 +156,9 @@ int LuaItemStack::l_set_metadata(lua_State *L)
138
156
139
157
size_t len = 0 ;
140
158
const char *ptr = luaL_checklstring (L, 2 , &len);
141
- if (ptr)
142
- item.metadata .assign (ptr, len);
143
- else
144
- item.metadata = " " ;
159
+ item.metadata .assign (ptr, len);
145
160
161
+ lua_pushboolean (L, true );
146
162
return 1 ;
147
163
}
148
164
@@ -533,7 +549,7 @@ int ModApiItemMod::l_get_content_id(lua_State *L)
533
549
534
550
INodeDefManager *ndef = getServer (L)->getNodeDefManager ();
535
551
content_t c = ndef->getId (name);
536
-
552
+
537
553
lua_pushinteger (L, c);
538
554
return 1 ; /* number of results */
539
555
}
@@ -546,7 +562,7 @@ int ModApiItemMod::l_get_name_from_content_id(lua_State *L)
546
562
547
563
INodeDefManager *ndef = getServer (L)->getNodeDefManager ();
548
564
const char *name = ndef->get (c).name .c_str ();
549
-
565
+
550
566
lua_pushstring (L, name);
551
567
return 1 ; /* number of results */
552
568
}
0 commit comments