mirror of
https://github.com/minetest-mods/digtron.git
synced 2025-01-03 09:37:27 +01:00
Allow duplicating into protected crates (#80)
This commit is contained in:
parent
ed62ae3275
commit
8cd481daea
@ -83,8 +83,10 @@ minetest.register_node("digtron:duplicator", {
|
||||
end,
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
local player_name = sender:get_player_name()
|
||||
if fields.help then
|
||||
minetest.after(0.5, doc.show_entry, sender:get_player_name(), "nodes", "digtron:duplicator", true)
|
||||
minetest.after(0.5, doc.show_entry, player_name, "nodes", "digtron:duplicator", true)
|
||||
return
|
||||
end
|
||||
|
||||
if fields.duplicate then
|
||||
@ -93,8 +95,19 @@ minetest.register_node("digtron:duplicator", {
|
||||
local inv = meta:get_inventory()
|
||||
local target_pos = vector.add(pos, minetest.facedir_to_dir(node.param2))
|
||||
local target_node = minetest.get_node(target_pos)
|
||||
local target_name
|
||||
|
||||
if target_node.name ~= "digtron:empty_crate" then
|
||||
if target_node.name == "digtron:empty_crate" then
|
||||
target_name = "digtron:loaded_crate"
|
||||
elseif target_node.name == "digtron:empty_locked_crate" then
|
||||
if minetest.get_meta(target_pos):get_string("owner") ~= player_name then
|
||||
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
||||
meta:set_string("infotext", S("The empty locked crate needs to be owned by you."))
|
||||
return
|
||||
end
|
||||
target_name = "digtron:loaded_locked_crate"
|
||||
end
|
||||
if not target_name then
|
||||
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
||||
meta:set_string("infotext", S("Needs an empty crate in output position to store duplicate"))
|
||||
return
|
||||
@ -114,7 +127,7 @@ minetest.register_node("digtron:duplicator", {
|
||||
return
|
||||
end
|
||||
|
||||
layout.all[1] = {node={name="digtron:empty_crate"}, meta={fields = {}, inventory = {}}, pos={x=pos.x, y=pos.y, z=pos.z}} -- replace the duplicator's image with the empty crate image
|
||||
layout.all[1] = {node={name=target_node.name}, meta={fields = {}, inventory = {}}, pos={x=pos.x, y=pos.y, z=pos.z}} -- replace the duplicator's image with the empty crate image
|
||||
|
||||
-- count required nodes, skipping node 1 since it's the crate and we already know it's present in-world
|
||||
local required_count = {}
|
||||
@ -175,13 +188,18 @@ minetest.register_node("digtron:duplicator", {
|
||||
-- replace empty crate with loaded crate and write image to its metadata
|
||||
local layout_string = layout:serialize()
|
||||
|
||||
minetest.set_node(target_pos, {name="digtron:loaded_crate", param1=node.param1, param2=node.param2})
|
||||
minetest.set_node(target_pos, {name=target_name, param1=node.param1, param2=node.param2})
|
||||
local target_meta = minetest.get_meta(target_pos)
|
||||
target_meta:set_string("crated_layout", layout_string)
|
||||
|
||||
local titlestring = S("Crated @1-block Digtron", tostring(#layout.all-1))
|
||||
target_meta:set_string("title", titlestring)
|
||||
if target_name == "digtron:loaded_locked_crate" then
|
||||
target_meta:set_string("owner", player_name)
|
||||
target_meta:set_string("infotext", titlestring .. "\n" .. S("Owned by @1", player_name))
|
||||
else
|
||||
target_meta:set_string("infotext", titlestring)
|
||||
end
|
||||
minetest.sound_play("machine1", {gain=1.0, pos=pos})
|
||||
end
|
||||
end,
|
||||
|
Loading…
Reference in New Issue
Block a user