From 2c9d1da73abdd2b999ed52c02bf505e7b080251a Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 29 Jul 2017 00:47:47 +0200 Subject: [PATCH] Allow to wash off top layer off banners --- mods/ITEMS/mcl_banners/depends.txt | 1 + mods/ITEMS/mcl_banners/init.lua | 33 ++++++++++++++++++++++++- mods/ITEMS/mcl_banners/patterncraft.lua | 4 +-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_banners/depends.txt b/mods/ITEMS/mcl_banners/depends.txt index 4fe44438..a8070d13 100644 --- a/mods/ITEMS/mcl_banners/depends.txt +++ b/mods/ITEMS/mcl_banners/depends.txt @@ -1,3 +1,4 @@ mcl_sounds? mcl_core? mcl_wool? +mcl_cauldrons? diff --git a/mods/ITEMS/mcl_banners/init.lua b/mods/ITEMS/mcl_banners/init.lua index 17f1d0a2..304b2f43 100644 --- a/mods/ITEMS/mcl_banners/init.lua +++ b/mods/ITEMS/mcl_banners/init.lua @@ -136,14 +136,45 @@ for colorid, colortab in pairs(mcl_banners.colors) do local above = pointed_thing.above local under = pointed_thing.under - -- Use pointed node's on_rightclick function first, if present local node_under = minetest.get_node(under) if placer and not placer:get_player_control().sneak then + -- Use pointed node's on_rightclick function first, if present if minetest.registered_nodes[node_under.name] and minetest.registered_nodes[node_under.name].on_rightclick then return minetest.registered_nodes[node_under.name].on_rightclick(under, node_under, placer, itemstack) or itemstack end + + if minetest.get_modpath("mcl_cauldrons") then + -- Use banner on cauldron to remove the top-most layer. This reduces the water level by 1. + local new_node + if node_under.name == "mcl_cauldrons:cauldron_3" then + new_node = "mcl_cauldrons:cauldron_2" + elseif node_under.name == "mcl_cauldrons:cauldron_2" then + new_node = "mcl_cauldrons:cauldron_1" + elseif node_under.name == "mcl_cauldrons:cauldron_1" then + new_node = "mcl_cauldrons:cauldron" + end + if new_node then + local imeta = itemstack:get_meta() + local layers_raw = imeta:get_string("layers") + local layers = minetest.deserialize(layers_raw) + if type(layers) == "table" and #layers > 0 then + minetest.log("error", dump(layers)) + table.remove(layers) + imeta:set_string("layers", minetest.serialize(layers)) + local newdesc = mcl_banners.make_advanced_banner_description(itemstack:get_definition().description, layers) + imeta:set_string("description", newdesc) + end + + -- Washing off reduces the water level by 1. + -- (It is possible to waste water if the banner had 0 layers.) + minetest.set_node(pointed_thing.under, {name=new_node}) + + return itemstack + end + end end + -- Place the node! local _, success = minetest.item_place_node(ItemStack("mcl_banners:standing_banner"), placer, pointed_thing) if not success then diff --git a/mods/ITEMS/mcl_banners/patterncraft.lua b/mods/ITEMS/mcl_banners/patterncraft.lua index 229124f3..2a27a846 100644 --- a/mods/ITEMS/mcl_banners/patterncraft.lua +++ b/mods/ITEMS/mcl_banners/patterncraft.lua @@ -248,7 +248,7 @@ for colorid, colortab in pairs(mcl_banners.colors) do end -- Create a banner description containing all the layer names -local make_advanced_banner_description = function(description, layers) +mcl_banners.make_advanced_banner_description = function(description, layers) if layers == nil or #layers == 0 then -- No layers, revert to default return "" @@ -393,7 +393,7 @@ local banner_pattern_craft = function(itemstack, player, old_craft_grid, craft_i imeta:set_string("layers", minetest.serialize(layers)) local odesc = itemstack:get_definition().description - local description = make_advanced_banner_description(odesc, layers) + local description = mcl_banners.make_advanced_banner_description(odesc, layers) imeta:set_string("description", description) return itemstack end