diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index 5d372ef1fb..e253a342a8 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -19,9 +19,15 @@ local string = string local raycast = minetest.raycast local get_node = minetest.get_node +local set_node = minetest.set_node local add_node = minetest.add_node local add_item = minetest.add_item +local registered_nodes = minetest.registered_nodes +local get_item_group = minetest.get_item_group +local is_creative_enabled = minetest.is_creative_enabled +local is_protected = minetest.is_protected +local record_protection_violation = minetest.record_protection_violation if mod_mcl_core then minetest.register_craft({ @@ -40,28 +46,28 @@ mcl_buckets = { -- Sound helper functions for placing and taking liquids local function sound_place(itemname, pos) - local def = minetest.registered_nodes[itemname] + local def = registered_nodes[itemname] if def and def.sounds and def.sounds.place then minetest.sound_play(def.sounds.place, {gain=1.0, pos = pos, pitch = 1 + math.random(-10, 10)*0.005}, true) end end local function sound_take(itemname, pos) - local def = minetest.registered_nodes[itemname] + local def = registered_nodes[itemname] if def and def.sounds and def.sounds.dug then minetest.sound_play(def.sounds.dug, {gain=1.0, pos = pos, pitch = 1 + math.random(-10, 10)*0.005}, true) end end local function place_liquid(pos, itemstring) - local fullness = minetest.registered_nodes[itemstring].liquid_range + local fullness = registered_nodes[itemstring].liquid_range sound_place(itemstring, pos) - minetest.add_node(pos, {name=itemstring, param2=fullness}) + add_node(pos, {name=itemstring, param2=fullness}) end local function give_bucket(new_bucket, itemstack, user) local inv = user:get_inventory() - if minetest.is_creative_enabled(user:get_player_name()) then + if is_creative_enabled(user:get_player_name()) then --TODO: is a full bucket added if inv doesn't contain one? return itemstack else @@ -128,7 +134,7 @@ end local function get_bucket_drop(itemstack, user, take_bucket) -- Handle bucket item and inventory stuff - if take_bucket and not minetest.is_creative_enabled(user:get_player_name()) then + if take_bucket and not is_creative_enabled(user:get_player_name()) then -- Add empty bucket and put it into inventory, if possible. -- Drop empty bucket otherwise. local new_bucket = ItemStack("mcl_buckets:bucket_empty") @@ -162,19 +168,16 @@ local function on_place_bucket(itemstack, user, pointed_thing, def) local undernode = get_node(pointed_thing.under) local abovenode = get_node(pointed_thing.above) - local buildable1 = minetest.registered_nodes[undernode.name] and minetest.registered_nodes[undernode.name].buildable_to - local buildable2 = minetest.registered_nodes[abovenode.name] and minetest.registered_nodes[abovenode.name].buildable_to - if not buildable1 and not buildable2 then return itemstack end --if both nodes aren't buildable_to, skip - if buildable1 then + if registered_nodes[undernode.name].buildable_to or get_item_group(undernode.name, "cauldron") == 1 then local result, take_bucket = get_extra_check(def.extra_check, pointed_thing.under, user) if result then local node_place = get_node_place(def.source_place, pointed_thing.under) local pns = user:get_player_name() -- Check protection - if minetest.is_protected(pointed_thing.under, pns) then - minetest.record_protection_violation(pointed_thing.under, pns) + if is_protected(pointed_thing.under, pns) then + record_protection_violation(pointed_thing.under, pns) return itemstack end @@ -187,15 +190,15 @@ local function on_place_bucket(itemstack, user, pointed_thing, def) end end return get_bucket_drop(itemstack, user, take_bucket) - elseif buildable2 then + elseif registered_nodes[abovenode.name].buildable_to or get_item_group(abovenode.name, "cauldron") == 1 then local result, take_bucket = get_extra_check(def.extra_check, pointed_thing.above, user) if result then local node_place = get_node_place(def.source_place, pointed_thing.above) local pns = user:get_player_name() -- Check protection - if minetest.is_protected(pointed_thing.above, pns) then - minetest.record_protection_violation(pointed_thing.above, pns) + if is_protected(pointed_thing.above, pns) then + record_protection_violation(pointed_thing.above, pns) return itemstack end @@ -226,14 +229,14 @@ local function on_place_bucket_empty(itemstack, user, pointed_thing) return new_stack end - local node = minetest.get_node(pointed_thing.under) + local node = get_node(pointed_thing.under) local nn = node.name local new_bucket local liquid_node = bucket_raycast(user) if liquid_node then - if minetest.is_protected(liquid_node.above, user:get_player_name()) then - minetest.record_protection_violation(liquid_node.above, user:get_player_name()) + if is_protected(liquid_node.above, user:get_player_name()) then + record_protection_violation(liquid_node.above, user:get_player_name()) end local liquid_name = get_node(liquid_node.above).name if liquid_name then @@ -242,7 +245,7 @@ local function on_place_bucket_empty(itemstack, user, pointed_thing) --minetest.chat_send_all("test") -- Fill bucket, but not in Creative Mode -- FIXME: remove this line - --if not minetest.is_creative_enabled(user:get_player_name()) then + --if not is_creative_enabled(user:get_player_name()) then if not false then new_bucket = ItemStack({name = liquid_def.bucketname}) if liquid_def.on_take then @@ -267,15 +270,15 @@ local function on_place_bucket_empty(itemstack, user, pointed_thing) -- FIXME: replace this ugly code by cauldrons API if nn == "mcl_cauldrons:cauldron_3" then -- Take water out of full cauldron - minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron"}) - if not minetest.is_creative_enabled(user:get_player_name()) then + set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron"}) + if not is_creative_enabled(user:get_player_name()) then new_bucket = ItemStack("mcl_buckets:bucket_water") end sound_take("mcl_core:water_source", pointed_thing.under) elseif nn == "mcl_cauldrons:cauldron_3r" then -- Take river water out of full cauldron - minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron"}) - if not minetest.is_creative_enabled(user:get_player_name()) then + set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron"}) + if not is_creative_enabled(user:get_player_name()) then new_bucket = ItemStack("mcl_buckets:bucket_river_water") end sound_take("mclx_core:river_water_source", pointed_thing.under) @@ -344,7 +347,7 @@ function mcl_buckets.register_liquid(def) stack_max = 1, groups = def.groups, _on_dispense = function(stack, pos, droppos, dropnode, dropdir) - local buildable = minetest.registered_nodes[dropnode.name].buildable_to or dropnode.name == "mcl_portals:portal" + local buildable = registered_nodes[dropnode.name].buildable_to or dropnode.name == "mcl_portals:portal" if not buildable then return stack end local result, take_bucket = get_extra_check(def.extra_check, droppos, nil) if result then -- Fail placement of liquid if result is false @@ -379,13 +382,13 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", { collect_liquid = true end if collect_liquid then - minetest.set_node(droppos, {name="air"}) + set_node(droppos, {name="air"}) -- Fill bucket with liquid stack = new_bucket else -- No liquid found: Drop empty bucket - minetest.add_item(droppos, stack) + add_item(droppos, stack) stack:take_item() end return stack