mirror of
https://github.com/minefaco/stripped_tree.git
synced 2024-10-05 17:23:09 +02:00
Update chiseling_machine.lua
Mejor manejo de inventario
This commit is contained in:
parent
b3af420d2d
commit
c80623fa60
@ -1,9 +1,10 @@
|
|||||||
local max_stack = tonumber(minetest.settings:get("default_stack_max")) or 99
|
local max_stack = tonumber(minetest.settings:get("default_stack_max")) or 99
|
||||||
--*************************************************************************
|
|
||||||
minetest.register_node("stripped_tree:chiseling_machine", {
|
minetest.register_node("stripped_tree:chiseling_machine", {
|
||||||
description = "Chiseladora para troncos",
|
description = "Chiseladora para troncos",
|
||||||
tiles = {"chiseling_machine.png", "chiseling_machine.png", "chiseling_machine_side.png", "chiseling_machine_side.png","chiseling_machine_side.png", "chiseling_machine_side.png"},
|
tiles = {"chiseling_machine.png", "chiseling_machine.png", "chiseling_machine_side.png", "chiseling_machine_side.png","chiseling_machine_side.png", "chiseling_machine_side.png"},
|
||||||
groups = {cracky = 1},
|
groups = {cracky = 1},
|
||||||
|
|
||||||
after_place_node = function(pos, placer)
|
after_place_node = function(pos, placer)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("formspec",
|
meta:set_string("formspec",
|
||||||
@ -19,10 +20,9 @@ minetest.register_node("stripped_tree:chiseling_machine", {
|
|||||||
"listring[current_player;main]"
|
"listring[current_player;main]"
|
||||||
)
|
)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("formspec", formspec)
|
|
||||||
meta:set_string("infotext", machine_name)
|
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
inv:set_size("src", 1)
|
inv:set_size("src", 1)
|
||||||
inv:set_size("dst", 2)
|
inv:set_size("dst", 2)
|
||||||
@ -30,45 +30,39 @@ minetest.register_node("stripped_tree:chiseling_machine", {
|
|||||||
meta:set_int("cook_time", 0)
|
meta:set_int("cook_time", 0)
|
||||||
minetest.get_node_timer(pos):start(1.0)
|
minetest.get_node_timer(pos):start(1.0)
|
||||||
end,
|
end,
|
||||||
on_metadata_inventory_move = function(pos)
|
|
||||||
minetest.get_node_timer(pos):start(1.0)
|
|
||||||
end,
|
|
||||||
on_metadata_inventory_put = function(pos)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
local stack = inv:get_stack("src", 1)
|
|
||||||
local nodename = stack:get_name()
|
|
||||||
if nodename ~= "" then
|
|
||||||
|
|
||||||
local count = stack:get_count()
|
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
local mod_name, node_name = unpack(nodename:split(":"))
|
local inv = minetest.get_meta(pos):get_inventory()
|
||||||
local has_stripped = minetest.registered_nodes[mod_name..":".."stripped_"..node_name]
|
local src_stack = inv:get_stack("src", 1)
|
||||||
local dstcount = inv:get_stack("dst",1):get_count()
|
local dst_stack = inv:get_stack("dst", 1)
|
||||||
if has_stripped and dstcount < max_stack then
|
if listname == "src" and not src_stack:is_empty() then
|
||||||
local stripped =mod_name..":".."stripped_"..node_name
|
local src_name = src_stack:get_name()
|
||||||
inv:add_item("dst", stripped.." "..count)
|
local src_count = src_stack:get_count()
|
||||||
inv:add_item("dst", "default:tree_bark "..count.."")
|
local mod_name, node_name = unpack(src_name:split(":"))
|
||||||
inv:remove_item("src", stack)
|
local stripped_name = mod_name .. ":stripped_" .. node_name
|
||||||
|
local has_stripped = minetest.registered_nodes[stripped_name]
|
||||||
|
local dst_count = dst_stack:get_count()
|
||||||
|
if has_stripped and dst_count < max_stack then
|
||||||
|
inv:add_item("dst", stripped_name .. " " .. src_count)
|
||||||
|
inv:add_item("dst", "default:tree_bark " .. src_count)
|
||||||
|
inv:remove_item("src", src_stack)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_receive_fields = function(pos, formname, fields, player)
|
on_receive_fields = function(pos, formname, fields, sender)
|
||||||
if fields.quit then
|
if fields.quit then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
-- Aquí puedes manejar los campos del formulario según sea necesario
|
||||||
print(fields.x)
|
print(fields.x)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
if pos then
|
|
||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
return 0
|
|
||||||
end
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "stripped_tree:chiseling_machine",
|
output = "stripped_tree:chiseling_machine",
|
||||||
recipe = {
|
recipe = {
|
||||||
|
Loading…
Reference in New Issue
Block a user