From b4971b298db6a2ad0c64733b125f848250ba7b70 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 25 Nov 2022 03:33:36 +0100 Subject: [PATCH] Move fish bucket code to separate file --- mods/ITEMS/mcl_buckets/fishbuckets.lua | 62 ++++++++++++++++++++++++++ mods/ITEMS/mcl_buckets/init.lua | 1 + mods/ITEMS/mcl_buckets/register.lua | 61 ------------------------- 3 files changed, 63 insertions(+), 61 deletions(-) create mode 100644 mods/ITEMS/mcl_buckets/fishbuckets.lua diff --git a/mods/ITEMS/mcl_buckets/fishbuckets.lua b/mods/ITEMS/mcl_buckets/fishbuckets.lua new file mode 100644 index 000000000..51bdc99b7 --- /dev/null +++ b/mods/ITEMS/mcl_buckets/fishbuckets.lua @@ -0,0 +1,62 @@ +local S = minetest.get_translator(minetest.get_current_modname()) + +-- Fish Buckets +local fish_names = { + ["cod"] = "Cod", + ["salmon"] = "Salmon", + ["tropical_fish"] = "Tropical Fish", + ["axolotl"] = "Axolotl", + --["pufferfish"] = "Pufferfish", --FIXME add pufferfish +} + +local fishbucket_prefix = "mcl_buckets:bucket_" + +local function on_place_fish(itemstack, placer, pointed_thing) + local pos = pointed_thing.above or pointed_thing.under + if not pos then return end + local n = minetest.get_node_or_nil(pos) + if n.name and minetest.registered_nodes[n.name].buildable_to or n.name == "mcl_portals:portal" then + local fish = itemstack:get_name():gsub(fishbucket_prefix,"") + if fish_names[fish] then + local o = minetest.add_entity(pos, "mobs_mc:" .. fish) + local props = itemstack:get_meta():get_string("properties") + if props ~= "" then + o:set_properties(minetest.deserialize(props)) + end + minetest.set_node(pos,{name = "mcl_core:water_source"}) + if not minetest.is_creative_enabled(placer:get_player_name()) then + itemstack:set_name("mcl_buckets:bucket_empty") + end + end + end + return itemstack +end + +for techname, fishname in pairs(fish_names) do + minetest.register_craftitem(fishbucket_prefix .. techname, { + description = S("Bucket of @1", S(fishname)), + _doc_items_longdesc = S("This bucket is filled with water and @1.", S(fishname)), + _doc_items_usagehelp = S("Place it to empty the bucket and place a @1. Obtain by right clicking on a @2 with a bucket of water.", S(fishname), S(fishname)), + _tt_help = S("Places a water source and a @1.", S(fishname)), + inventory_image = techname .. "_bucket.png", + stack_max = 1, + groups = {bucket = 1, fish_bucket = 1}, + liquids_pointable = false, + on_place = on_place_fish, + on_secondary_use = on_place_fish, + _on_dispense = function(stack, pos, droppos, dropnode, dropdir) + 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 + place_liquid(droppos, get_node_place(def.source_place, droppos)) + end + if take_bucket then + stack:set_name("mcl_buckets:bucket_empty") + end + return stack + end, + }) + + minetest.register_alias("mcl_fishing:bucket_" .. techname, "mcl_buckets:bucket_" .. techname) +end diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index 7e47e7e07..0fc1537d4 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -358,3 +358,4 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", { }) dofile(modpath.."/register.lua") +dofile(modpath.."/fishbuckets.lua") diff --git a/mods/ITEMS/mcl_buckets/register.lua b/mods/ITEMS/mcl_buckets/register.lua index f2baaf7a5..365966724 100644 --- a/mods/ITEMS/mcl_buckets/register.lua +++ b/mods/ITEMS/mcl_buckets/register.lua @@ -118,64 +118,3 @@ minetest.register_craft({ burntime = 1000, replacements = {{"mcl_buckets:bucket_lava", "mcl_buckets:bucket_empty"}}, }) - --- Fish Buckets -local fish_names = { - ["cod"] = "Cod", - ["salmon"] = "Salmon", - ["tropical_fish"] = "Tropical Fish", - ["axolotl"] = "Axolotl", - --["pufferfish"] = "Pufferfish", --FIXME add pufferfish -} - -local fishbucket_prefix = "mcl_buckets:bucket_" - -local function on_place_fish(itemstack, placer, pointed_thing) - local pos = pointed_thing.above or pointed_thing.under - if not pos then return end - local n = minetest.get_node_or_nil(pos) - if n.name and minetest.registered_nodes[n.name].buildable_to or n.name == "mcl_portals:portal" then - local fish = itemstack:get_name():gsub(fishbucket_prefix,"") - if fish_names[fish] then - local o = minetest.add_entity(pos, "mobs_mc:" .. fish) - local props = itemstack:get_meta():get_string("properties") - if props ~= "" then - o:set_properties(minetest.deserialize(props)) - end - minetest.set_node(pos,{name = "mcl_core:water_source"}) - if not minetest.is_creative_enabled(placer:get_player_name()) then - itemstack:set_name("mcl_buckets:bucket_empty") - end - end - end - return itemstack -end - -for techname, fishname in pairs(fish_names) do - minetest.register_craftitem(fishbucket_prefix .. techname, { - description = S("Bucket of @1", S(fishname)), - _doc_items_longdesc = S("This bucket is filled with water and @1.", S(fishname)), - _doc_items_usagehelp = S("Place it to empty the bucket and place a @1. Obtain by right clicking on a @2 with a bucket of water.", S(fishname), S(fishname)), - _tt_help = S("Places a water source and a @1.", S(fishname)), - inventory_image = techname .. "_bucket.png", - stack_max = 1, - groups = {bucket = 1, fish_bucket = 1}, - liquids_pointable = false, - on_place = on_place_fish, - on_secondary_use = on_place_fish, - _on_dispense = function(stack, pos, droppos, dropnode, dropdir) - 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 - place_liquid(droppos, get_node_place(def.source_place, droppos)) - end - if take_bucket then - stack:set_name("mcl_buckets:bucket_empty") - end - return stack - end, - }) - - minetest.register_alias("mcl_fishing:bucket_" .. techname, "mcl_buckets:bucket_" .. techname) -end