Improve sticks

Now you can use sticks on items too. When you are creating a furnace, unnecessary coals adds in the furnace. If coals is less than 9, it will not hide.
This commit is contained in:
Kotolegokot 2012-10-13 22:06:22 +06:00
parent c882f0e6d9
commit cd0f7783e1

View File

@ -2,14 +2,19 @@ minetest.register_tool("sticks:sticks", {
description = "Sticks",
inventory_image = "default_sticks.png",
on_use = function(item, user, pointed_thing)
if pointed_thing.type ~= "node" then
local pos
if pointed_thing.type == "node" then
pos = pointed_thing.above
elseif pointed_thing.type == "object" then
pos = pointed_thing.ref:getpos()
else
return
end
if minetest.env:get_node(pointed_thing.above).name == "air" then
local objects = minetest.env:get_objects_inside_radius(pointed_thing.above, 0.5)
local pos = pointed_thing.above
if minetest.env:get_node(pos).name == "air" then
local objects = minetest.env:get_objects_inside_radius(pos, 0.5)
local bonfireb = 0
local furnaceb = 0
local coals = {}
for _, v in ipairs(objects) do
if not v:is_player() and v:get_luaentity() and v:get_luaentity().name == "__builtin:item" then
local istack = ItemStack(v:get_luaentity().itemstring)
@ -21,13 +26,24 @@ minetest.register_tool("sticks:sticks", {
v:remove()
elseif istack:get_name() == "default:coal_lump" then
furnaceb = furnaceb + istack:get_count()
table.insert(coals,v)
end
end
end
if furnaceb >= 9 then
if furnace.check_furnace_blocks(pos) then
for _, v in ipairs(coals) do
v:remove()
end
end
end
if furnaceb >= 9 and furnace.check_furnace_blocks(pos) then
minetest.env:set_node(pos, {name = "furnace:self"})
elseif bonfireb >= 10 then
if furnaceb > 9 then
local meta = minetest.env:get_meta(pos)
local inv = meta:get_inventory()
inv:add_item("fuel", "default:coal_lump "..furnaceb-9)
end
end
end
if bonfireb >= 10 and minetest.env:get_node(pos).name == "air" then
minetest.env:set_node(pos, {name = "bonfire:self"})
end
end