@@ -155,6 +155,24 @@ function core.yaw_to_dir(yaw)
155155 return {x = - math.sin (yaw ), y = 0 , z = math.cos (yaw )}
156156end
157157
158+ function core .is_colored_paramtype (ptype )
159+ return (ptype == " color" ) or (ptype == " colorfacedir" ) or
160+ (ptype == " colorwallmounted" )
161+ end
162+
163+ function core .strip_param2_color (param2 , paramtype2 )
164+ if not core .is_colored_paramtype (paramtype2 ) then
165+ return nil
166+ end
167+ if paramtype2 == " colorfacedir" then
168+ param2 = math.floor (param2 / 32 ) * 32
169+ elseif paramtype2 == " colorwallmounted" then
170+ param2 = math.floor (param2 / 8 ) * 8
171+ end
172+ -- paramtype2 == "color" requires no modification.
173+ return param2
174+ end
175+
158176function core .get_node_drops (node , toolname )
159177 -- Compatibility, if node is string
160178 local nodename = node
@@ -166,24 +184,17 @@ function core.get_node_drops(node, toolname)
166184 end
167185 local def = core .registered_nodes [nodename ]
168186 local drop = def and def .drop
187+ local ptype = def and def .paramtype2
188+ -- get color, if there is color (otherwise nil)
189+ local palette_index = core .strip_param2_color (param2 , ptype )
169190 if drop == nil then
170191 -- default drop
171- local stack = ItemStack (nodename )
172- if def then
173- local type = def .paramtype2
174- if (type == " color" ) or (type == " colorfacedir" ) or
175- (type == " colorwallmounted" ) then
176- local meta = stack :get_meta ()
177- local color_part = param2
178- if (type == " colorfacedir" ) then
179- color_part = math.floor (color_part / 32 ) * 32 ;
180- elseif (type == " colorwallmounted" ) then
181- color_part = math.floor (color_part / 8 ) * 8 ;
182- end
183- meta :set_int (" palette_index" , color_part )
184- end
192+ if palette_index then
193+ local stack = ItemStack (nodename )
194+ stack :get_meta ():set_int (" palette_index" , palette_index )
195+ return {stack :to_string ()}
185196 end
186- return {stack : to_string () }
197+ return {nodename }
187198 elseif type (drop ) == " string" then
188199 -- itemstring drop
189200 return {drop }
@@ -218,6 +229,12 @@ function core.get_node_drops(node, toolname)
218229 if good_rarity and good_tool then
219230 got_count = got_count + 1
220231 for _ , add_item in ipairs (item .items ) do
232+ -- add color, if necessary
233+ if item .inherit_color and palette_index then
234+ local stack = ItemStack (add_item )
235+ stack :get_meta ():set_int (" palette_index" , palette_index )
236+ add_item = stack :to_string ()
237+ end
221238 got_items [# got_items + 1 ] = add_item
222239 end
223240 if drop .max_items ~= nil and got_count == drop .max_items then
0 commit comments