91 lines
3.2 KiB
Lua
91 lines
3.2 KiB
Lua
local S = core.get_translator(core.get_current_modname())
|
|
|
|
local max_stack = tonumber(core.settings:get("default_stack_max")) or 99
|
|
|
|
-- LuaFormatter off
|
|
local machine_formspec = "" ..
|
|
"size[8,9]" ..
|
|
"label[0,0;" .. core.formspec_escape(S("Chiseling Machine")) .. "]" ..
|
|
"image[2,2;1,1;chisel.png]" ..
|
|
"list[current_name;src;2,1;1,1;]" ..
|
|
"list[current_name;dst;5,1;2,2;]" ..
|
|
"list[current_player;main;0,5;8,4;]" ..
|
|
"listring[current_name;dst]" ..
|
|
"listring[current_player;main]" ..
|
|
"listring[current_name;src]" ..
|
|
"listring[current_player;main]"
|
|
-- LuaFormatter on
|
|
|
|
core.register_node(
|
|
"stripped_tree:chiseling_machine", {
|
|
description = S("Chiseling Machine"),
|
|
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},
|
|
|
|
after_place_node = function(pos, placer)
|
|
local meta = core.get_meta(pos)
|
|
meta:set_string("formspec", machine_formspec)
|
|
end,
|
|
|
|
on_construct = function(pos)
|
|
local inv = core.get_meta(pos):get_inventory()
|
|
inv:set_size("src", 1)
|
|
inv:set_size("dst", 2)
|
|
core.get_node_timer(pos):start(1.0)
|
|
end,
|
|
|
|
can_dig = function(pos)
|
|
local meta = core.get_meta(pos)
|
|
local inv = meta:get_inventory()
|
|
|
|
return inv:is_empty("dst") and inv:is_empty("src")
|
|
end,
|
|
|
|
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
|
local inv = core.get_meta(pos):get_inventory()
|
|
local src_stack = inv:get_stack("src", 1)
|
|
local dst_stack = inv:get_stack("dst", 1)
|
|
if listname == "src" and not src_stack:is_empty() then
|
|
local src_name = src_stack:get_name()
|
|
local src_count = src_stack:get_count()
|
|
local mod_name, node_name = unpack(src_name:split(":"))
|
|
local stripped_name = mod_name .. ":stripped_" .. node_name
|
|
local has_stripped = core.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,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
if fields.quit then return end
|
|
print(fields.x)
|
|
end,
|
|
|
|
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
|
return count
|
|
end,
|
|
}
|
|
)
|
|
|
|
core.register_craft(
|
|
{
|
|
output = "stripped_tree:chiseling_machine",
|
|
recipe = {
|
|
{"group:wood", "default:diamond", "group:wood"},
|
|
{"group:wood", "stripped_tree:chisel", "group:wood"},
|
|
{"group:wood", "group:wood", "group:wood"},
|
|
},
|
|
}
|
|
)
|