From fe6cf4de8fdbb95fc688667c00e557a6a2e8bfc2 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 14 Feb 2017 04:39:37 +0100 Subject: [PATCH] Require an intact bow for crafting a dispenser --- mods/redstone/mcl_dispensers/init.lua | 38 ++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/mods/redstone/mcl_dispensers/init.lua b/mods/redstone/mcl_dispensers/init.lua index dd48f7958f..bee73b7b5f 100644 --- a/mods/redstone/mcl_dispensers/init.lua +++ b/mods/redstone/mcl_dispensers/init.lua @@ -261,7 +261,6 @@ up_def.tiles = { minetest.register_node("mcl_dispensers:dispenser_up", up_def) - minetest.register_craft({ output = 'mcl_dispensers:dispenser', recipe = { @@ -270,3 +269,40 @@ minetest.register_craft({ {"mcl_core:cobble", "mesecons:redstone", "mcl_core:cobble",}, } }) + +-- Only allow crafting if the bow is intact +minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv) + if itemstack:get_name() == "mcl_dispensers:dispenser" then + local bow, id + for i=1, craft_inv:get_size("craft") do + local item = craft_inv:get_stack("craft", i) + if item:get_name() == "mcl_throwing:bow" then + bow = item + id = i + break + end + end + if bow:get_wear() ~= 0 then + return "" + end + end + return nil +end) + +minetest.register_craft_predict(function(itemstack, player, old_craft_grid, craft_inv) + if itemstack:get_name() == "mcl_dispensers:dispenser" then + local bow, id + for i=1, craft_inv:get_size("craft") do + local item = craft_inv:get_stack("craft", i) + if item:get_name() == "mcl_throwing:bow" then + bow = item + id = i + break + end + end + if bow:get_wear() ~= 0 then + return "" + end + end + return nil +end)