Restrict putting in furnace and jewelbench

This commit is contained in:
Wuzzy 2019-10-24 14:59:28 +02:00
parent 1e49bf270a
commit ce3b474228
3 changed files with 61 additions and 18 deletions

View File

@ -61,16 +61,28 @@ form_furnace = form_furnace .. "image[3.25,1.75;1,1;ui_arrow_bg.png^[transformR2
default.ui.register_page("default_furnace_inactive", form_furnace)
local protection_check_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local check_put = function(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) and
not minetest.check_player_privs(player, "protection_bypass") then
minetest.record_protection_violation(pos, player:get_player_name())
return 0
else
return count
end
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if listname == "fuel" then
if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
return stack:get_count()
else
return 0
end
elseif listname == "src" then
return stack:get_count()
elseif listname == "dst" then
return 0
end
end
local protection_check_put_take = function(pos, listname, index, stack, player)
local check_take = function(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) and
not minetest.check_player_privs(player, "protection_bypass") then
minetest.record_protection_violation(pos, player:get_player_name())
@ -80,6 +92,13 @@ local protection_check_put_take = function(pos, listname, index, stack, player)
end
end
local check_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stack = inv:get_stack(from_list, from_index)
return check_put(pos, to_list, to_index, stack, player)
end
minetest.register_node(
"default:furnace",
{
@ -100,9 +119,9 @@ minetest.register_node(
inv:set_size("src", 1)
inv:set_size("dst", 4)
end,
allow_metadata_inventory_move = protection_check_move,
allow_metadata_inventory_put = protection_check_put_take,
allow_metadata_inventory_take = protection_check_put_take,
allow_metadata_inventory_move = check_move,
allow_metadata_inventory_put = check_put,
allow_metadata_inventory_take = check_take,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
@ -139,9 +158,9 @@ minetest.register_node(
inv:set_size("src", 1)
inv:set_size("dst", 4)
end,
allow_metadata_inventory_move = protection_check_move,
allow_metadata_inventory_put = protection_check_put_take,
allow_metadata_inventory_take = protection_check_put_take,
allow_metadata_inventory_move = check_move,
allow_metadata_inventory_put = check_put,
allow_metadata_inventory_take = check_take,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()

View File

@ -189,16 +189,32 @@ minetest.register_craftitem(
-- Nodes
local protection_check_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local check_put = function(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) and
not minetest.check_player_privs(player, "protection_bypass") then
minetest.record_protection_violation(pos, player:get_player_name())
return 0
else
return count
end
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if listname == "main" then
local name = stack:get_name()
if minetest.registered_items[name] then
-- Disallow put for non-tools (unless it can be jeweled)
if (not jewels.can_jewel(name)) and minetest.registered_items[name].type ~= "tool" then
return 0
end
end
end
return stack:get_count()
end
local protection_check_put_take = function(pos, listname, index, stack, player)
local check_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stack = inv:get_stack(from_list, from_index)
return check_take(pos, to_list, to_index, stack, player)
end
local check_take = function(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) and
not minetest.check_player_privs(player, "protection_bypass") then
minetest.record_protection_violation(pos, player:get_player_name())
@ -233,9 +249,9 @@ minetest.register_node(
return inv:is_empty("main")
end,
allow_metadata_inventory_move = protection_check_move,
allow_metadata_inventory_put = protection_check_put_take,
allow_metadata_inventory_take = protection_check_put_take,
allow_metadata_inventory_move = check_move,
allow_metadata_inventory_put = check_put,
allow_metadata_inventory_take = check_take,
on_punch = function(pos, node, player, pointed_thing)
local itemstack = player:get_wielded_item()
local itemstack_changed = false
@ -248,9 +264,14 @@ minetest.register_node(
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local itemname = inv:get_stack("main", 1):get_name()
local iitem = inv:get_stack("main", 1)
if iitem:is_empty() then
return
end
local itemname = iitem:get_name()
if jewels.can_jewel(itemname) then
-- Success
inv:set_stack("main", 1, ItemStack(jewels.get_jeweled(itemname)))
if not minetest.settings:get_bool("creative_mode") then
@ -263,6 +284,9 @@ minetest.register_node(
achievements.trigger_achievement(player, "jeweler")
achievements.trigger_achievement(player, "master_jeweler")
else
-- Failure
minetest.sound_play({name="jewels_jewelling_fail"}, {gain=0.8, pos=pos, max_hear_distance=8})
end
end

Binary file not shown.