From e9f38c6b90ea33234a75a1a95dc03b94c760f602 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 22 May 2021 10:47:28 +0200 Subject: [PATCH 01/28] WIP raycast base buckets --- mods/ITEMS/mcl_buckets/init.lua | 320 +++++++++++++++++++++----------- 1 file changed, 211 insertions(+), 109 deletions(-) diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index 7e67eee8e..3103aeb4f 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -44,129 +44,166 @@ local place_liquid = function(pos, itemstring) sound_place(itemstring, pos) minetest.add_node(pos, {name=itemstring, param2=fullness}) end +local function give_bucket(new_bucket, itemstack, user) + if itemstack:get_count() == 1 then + return new_bucket + else + local inv = user:get_inventory() + if inv:room_for_item("main", new_bucket) then + inv:add_item("main", new_bucket) + else + minetest.add_item(user:get_pos(), new_bucket) + end + if not minetest.is_creative_enabled(user:get_player_name()) then + itemstack:take_item() + end + return itemstack + end +end + +local function bucket_raycast(user) + local pos = user:get_pos() + pos.y = pos.y + user:get_properties().eye_height + local look_dir = user:get_look_dir() + look_dir = vector.multiply(look_dir, 6) + local pos2 = vector.add(pos, look_dir) + + local ray = raycast(pos, pos2, false, true) + if ray then + for pointed_thing in ray do + if pointed_thing and get_node_group(get_node(pointed_thing.above).name, "_mcl_bucket_pointable") == 1 then + --minetest.chat_send_all("found!") + return {under=pointed_thing.under,above=pointed_thing.above} + end + end + end + return nil +end function mcl_buckets.register_liquid(def) - for i=1, #def.source_take do - mcl_buckets.liquids[def.source_take[i]] = { + for _,source in ipairs(def.source_take) do + mcl_buckets.liquids[source] = { source_place = def.source_place, - source_take = def.source_take[i], + source_take = source, on_take = def.on_take, itemname = def.itemname, } if type(def.source_place) == "string" then - mcl_buckets.liquids[def.source_place] = mcl_buckets.liquids[def.source_take[i]] + mcl_buckets.liquids[def.source_place] = mcl_buckets.liquids[source] end end - if def.itemname ~= nil then - minetest.register_craftitem(def.itemname, { - description = def.name, - _doc_items_longdesc = def.longdesc, - _doc_items_usagehelp = def.usagehelp, - _tt_help = def.tt_help, - inventory_image = def.inventory_image, - stack_max = 1, - groups = def.groups, - on_place = function(itemstack, user, pointed_thing) - -- Must be pointing to node - if pointed_thing.type ~= "node" then - return - end + if def.itemname == nil or def.itemname == "" then + error(string.format("[mcl_bucket] Invalid itemname then registering [%s]!", def.name)) + end - local node = minetest.get_node(pointed_thing.under) - local place_pos = pointed_thing.under - local nn = node.name - -- Call on_rightclick if the pointed node defines it - if user and not user:get_player_control().sneak then - if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].on_rightclick then - return minetest.registered_nodes[nn].on_rightclick(place_pos, node, user, itemstack) or itemstack - end - end + minetest.register_craftitem(def.itemname, { + description = def.name, + _doc_items_longdesc = def.longdesc, + _doc_items_usagehelp = def.usagehelp, + _tt_help = def.tt_help, + inventory_image = def.inventory_image, + stack_max = 1, + groups = def.groups, + on_place = function(itemstack, user, pointed_thing) + -- Must be pointing to node + if pointed_thing.type ~= "node" then + return + end - local node_place - if type(def.source_place) == "function" then - node_place = def.source_place(place_pos) - else - node_place = def.source_place + local node = minetest.get_node(pointed_thing.under) + local place_pos = pointed_thing.under + local nn = node.name + -- Call on_rightclick if the pointed node defines it + if user and not user:get_player_control().sneak then + if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].on_rightclick then + return minetest.registered_nodes[nn].on_rightclick(place_pos, node, user, itemstack) or itemstack end - -- Check if pointing to a buildable node - local item = itemstack:get_name() + end - if def.extra_check and def.extra_check(place_pos, user) == false then - -- Fail placement of liquid - elseif minetest.registered_nodes[nn] and minetest.registered_nodes[nn].buildable_to then - -- buildable; replace the node - local pns = user:get_player_name() - if minetest.is_protected(place_pos, pns) then - minetest.record_protection_violation(place_pos, pns) + local node_place + if type(def.source_place) == "function" then + node_place = def.source_place(place_pos) + else + node_place = def.source_place + end + -- Check if pointing to a buildable node + local item = itemstack:get_name() + + if def.extra_check and def.extra_check(place_pos, user) == false then + -- Fail placement of liquid + elseif minetest.registered_nodes[nn] and minetest.registered_nodes[nn].buildable_to then + -- buildable; replace the node + local pns = user:get_player_name() + if minetest.is_protected(place_pos, pns) then + minetest.record_protection_violation(place_pos, pns) + return itemstack + end + place_liquid(place_pos, node_place) + if mod_doc and doc.entry_exists("nodes", node_place) then + doc.mark_entry_as_revealed(user:get_player_name(), "nodes", node_place) + end + else + -- not buildable to; place the liquid above + -- check if the node above can be replaced + local abovenode = minetest.get_node(pointed_thing.above) + if minetest.registered_nodes[abovenode.name] and minetest.registered_nodes[abovenode.name].buildable_to then + local pn = user:get_player_name() + if minetest.is_protected(pointed_thing.above, pn) then + minetest.record_protection_violation(pointed_thing.above, pn) return itemstack end - place_liquid(place_pos, node_place) + place_liquid(pointed_thing.above, node_place) if mod_doc and doc.entry_exists("nodes", node_place) then doc.mark_entry_as_revealed(user:get_player_name(), "nodes", node_place) end else - -- not buildable to; place the liquid above - -- check if the node above can be replaced - local abovenode = minetest.get_node(pointed_thing.above) - if minetest.registered_nodes[abovenode.name] and minetest.registered_nodes[abovenode.name].buildable_to then - local pn = user:get_player_name() - if minetest.is_protected(pointed_thing.above, pn) then - minetest.record_protection_violation(pointed_thing.above, pn) - return itemstack - end - place_liquid(pointed_thing.above, node_place) - if mod_doc and doc.entry_exists("nodes", node_place) then - doc.mark_entry_as_revealed(user:get_player_name(), "nodes", node_place) - end - else - -- do not remove the bucket with the liquid - return - end - end - - -- Handle bucket item and inventory stuff - if not minetest.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") - if itemstack:get_count() == 1 then - return new_bucket - else - local inv = user:get_inventory() - if inv:room_for_item("main", new_bucket) then - inv:add_item("main", new_bucket) - else - minetest.add_item(user:get_pos(), new_bucket) - end - itemstack:take_item() - return itemstack - end - else + -- do not remove the bucket with the liquid return end - end, - _on_dispense = function(stack, pos, droppos, dropnode, dropdir) - local iname = stack:get_name() - local buildable = minetest.registered_nodes[dropnode.name].buildable_to or dropnode.name == "mcl_portals:portal" + end - if def.extra_check and def.extra_check(droppos, nil) == false then - -- Fail placement of liquid - elseif buildable then - -- buildable; replace the node - local node_place - if type(def.source_place) == "function" then - node_place = def.source_place(droppos) + -- Handle bucket item and inventory stuff + if not minetest.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") + if itemstack:get_count() == 1 then + return new_bucket + else + local inv = user:get_inventory() + if inv:room_for_item("main", new_bucket) then + inv:add_item("main", new_bucket) else - node_place = def.source_place + minetest.add_item(user:get_pos(), new_bucket) end - place_liquid(droppos, node_place) - stack:set_name("mcl_buckets:bucket_empty") + itemstack:take_item() + return itemstack end - return stack - end, - }) - end + else + return + end + end, + _on_dispense = function(stack, pos, droppos, dropnode, dropdir) + local iname = stack:get_name() + local buildable = minetest.registered_nodes[dropnode.name].buildable_to or dropnode.name == "mcl_portals:portal" + + if def.extra_check and def.extra_check(droppos, nil) == false then + -- Fail placement of liquid + elseif buildable then + -- buildable; replace the node + local node_place + if type(def.source_place) == "function" then + node_place = def.source_place(droppos) + else + node_place = def.source_place + end + place_liquid(droppos, node_place) + stack:set_name("mcl_buckets:bucket_empty") + end + return stack + end, + }) end minetest.register_craftitem("mcl_buckets:bucket_empty", { @@ -174,26 +211,25 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", { _doc_items_longdesc = S("A bucket can be used to collect and release liquids."), _doc_items_usagehelp = S("Punch a liquid source to collect it. You can then use the filled bucket to place the liquid somewhere else."), _tt_help = S("Collects liquids"), - - liquids_pointable = true, + --liquids_pointable = true, inventory_image = "bucket.png", stack_max = 16, on_place = function(itemstack, user, pointed_thing) - -- Must be pointing to node + --[[-- Must be pointing to node if pointed_thing.type ~= "node" then return itemstack end -- Call on_rightclick if the pointed node defines it - local node = minetest.get_node(pointed_thing.under) - local nn = node.name - if user and not user:get_player_control().sneak then - if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].on_rightclick then - return minetest.registered_nodes[nn].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack - end - end + + + local pointed_liquid = bucket_raycast(user) -- Can't steal liquids + if minetest.is_protected(pointed_liquid.above, user:get_player_name()) then + minetest.record_protection_violation(pointed_liquid.under, user:get_player_name()) + return itemstack + end if minetest.is_protected(pointed_thing.above, user:get_player_name()) then minetest.record_protection_violation(pointed_thing.under, user:get_player_name()) return itemstack @@ -208,8 +244,8 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", { if not minetest.is_creative_enabled(user:get_player_name()) then new_bucket = ItemStack({name = liquiddef.itemname}) if liquiddef.on_take then - liquiddef.on_take(user) - end + liquiddef.on_take(user) + end end minetest.add_node(pointed_thing.under, {name="air"}) @@ -252,7 +288,73 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", { end return itemstack end + end]] + if pointed_thing.type ~= "node" then + return itemstack end + local node = minetest.get_node(pointed_thing.under) + local nn = node.name + if user and not user:get_player_control().sneak then + if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].on_rightclick then + return minetest.registered_nodes[nn].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack + end + end + + 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()) + end + local liquid_name = get_node(liquid_node.above).name + if liquid_name then + local liquid_def = mcl_buckets.liquids[liquid_name] + if liquid_def then + local new_bucket + --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 false then + new_bucket = ItemStack({name = liquid_def.itemname}) + if liquid_def.on_take then + liquid_def.on_take(user) + end + end + add_node(liquid_node.above, {name="air"}) + sound_take(nn, liquid_node.above) + + if mod_doc and doc.entry_exists("nodes", liquid_name) then + doc.mark_entry_as_revealed(user:get_player_name(), "nodes", liquid_name) + end + if new_bucket then + return give_bucket(new_bucket, itemstack, user) + end + else + minetest.log("error", string.format("[mcl_buckets] Node [%s] has invalid group [_mcl_bucket_pointable]!", liquid_name)) + end + end + return itemstack + else + -- 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 + 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 + new_bucket = ItemStack("mcl_buckets:bucket_river_water") + end + sound_take("mclx_core:river_water_source", pointed_thing.under) + end + if new_bucket then + return give_bucket(new_bucket, itemstack, user) + end + end end, _on_dispense = function(stack, pos, droppos, dropnode, dropdir) -- Fill empty bucket with liquid or drop bucket if no liquid From 5d65c8a3aa58da596befac454eae5ed205e2e510 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 22 May 2021 18:57:51 +0200 Subject: [PATCH 02/28] Working empty bucket --- mods/ITEMS/mcl_buckets/init.lua | 6 ++++++ mods/ITEMS/mcl_core/nodes_liquid.lua | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index 3103aeb4f..327d553c8 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -11,6 +11,11 @@ local mod_doc = minetest.get_modpath("doc") local mod_mcl_core = minetest.get_modpath("mcl_core") local mod_mclx_core = minetest.get_modpath("mclx_core") +local raycast = minetest.raycast +local get_node = minetest.get_node +local add_node = minetest.add_node +local get_node_group = minetest.get_node_group + if mod_mcl_core then minetest.register_craft({ output = 'mcl_buckets:bucket_empty 1', @@ -355,6 +360,7 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", { return give_bucket(new_bucket, itemstack, user) end end + return itemstack end, _on_dispense = function(stack, pos, droppos, dropnode, dropdir) -- Fill empty bucket with liquid or drop bucket if no liquid diff --git a/mods/ITEMS/mcl_core/nodes_liquid.lua b/mods/ITEMS/mcl_core/nodes_liquid.lua index c49b685eb..47c22c7c6 100644 --- a/mods/ITEMS/mcl_core/nodes_liquid.lua +++ b/mods/ITEMS/mcl_core/nodes_liquid.lua @@ -100,7 +100,7 @@ S("• When water is directly below lava, the water turns into stone."), liquid_range = 7, post_effect_color = {a=209, r=0x03, g=0x3C, b=0x5C}, stack_max = 64, - groups = { water=3, liquid=3, puts_out_fire=1, freezes=1, not_in_creative_inventory=1, dig_by_piston=1}, + groups = { water=3, liquid=3, puts_out_fire=1, freezes=1, not_in_creative_inventory=1, dig_by_piston=1, _mcl_bucket_pointable=1}, _mcl_blast_resistance = 100, -- Hardness intentionally set to infinite instead of 100 (Minecraft value) to avoid problems in creative mode _mcl_hardness = -1, @@ -203,7 +203,7 @@ S("• When lava is directly above water, the water turns into stone."), _mcl_node_death_message = lava_death_messages, post_effect_color = {a=245, r=208, g=73, b=10}, stack_max = 64, - groups = { lava=3, lava_source=1, liquid=2, destroys_items=1, not_in_creative_inventory=1, dig_by_piston=1, set_on_fire=15, fire_damage=1}, + groups = { lava=3, lava_source=1, liquid=2, destroys_items=1, not_in_creative_inventory=1, dig_by_piston=1, set_on_fire=15, fire_damage=1, _mcl_bucket_pointable=1}, _mcl_blast_resistance = 100, -- Hardness intentionally set to infinite instead of 100 (Minecraft value) to avoid problems in creative mode _mcl_hardness = -1, From 17202115fa2e99fb825dcaf53c73bbaf9a47cb82 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 22 May 2021 18:58:58 +0200 Subject: [PATCH 03/28] cache general functions --- mods/ITEMS/mcl_buckets/init.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index 327d553c8..7f5ab2b16 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -11,6 +11,10 @@ local mod_doc = minetest.get_modpath("doc") local mod_mcl_core = minetest.get_modpath("mcl_core") local mod_mclx_core = minetest.get_modpath("mclx_core") +local vector = vector +local math = math +local string = string + local raycast = minetest.raycast local get_node = minetest.get_node local add_node = minetest.add_node From 40f4287ff200ec20bb2d25650a0b37606bd74b38 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 12 Jun 2021 12:21:01 +0200 Subject: [PATCH 04/28] new buckets fixes --- mods/ITEMS/mcl_buckets/init.lua | 50 ++++++++++++++++------------ mods/ITEMS/mcl_buckets/register.lua | 2 +- mods/ITEMS/mcl_core/nodes_liquid.lua | 4 +-- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index 23d7244e5..f2f61ccfc 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -18,7 +18,8 @@ local string = string local raycast = minetest.raycast local get_node = minetest.get_node local add_node = minetest.add_node -local get_node_group = minetest.get_node_group +local add_item = minetest.add_item + if mod_mcl_core then minetest.register_craft({ @@ -26,7 +27,7 @@ if mod_mcl_core then recipe = { {"mcl_core:iron_ingot", "", "mcl_core:iron_ingot"}, {"", "mcl_core:iron_ingot", ""}, - } + }, }) end @@ -34,42 +35,47 @@ mcl_buckets = {} mcl_buckets.liquids = {} -- Sound helper functions for placing and taking liquids -local sound_place = function(itemname, pos) +local function sound_place(itemname, pos) local def = minetest.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 sound_take = function(itemname, pos) +local function sound_take(itemname, pos) local def = minetest.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 place_liquid = function(pos, itemstring) +local function place_liquid(pos, itemstring) local fullness = minetest.registered_nodes[itemstring].liquid_range sound_place(itemstring, pos) minetest.add_node(pos, {name=itemstring, param2=fullness}) end local function give_bucket(new_bucket, itemstack, user) - if itemstack:get_count() == 1 then - return new_bucket - else - local inv = user:get_inventory() - if inv:room_for_item("main", new_bucket) then - inv:add_item("main", new_bucket) - else - minetest.add_item(user:get_pos(), new_bucket) - end - if not minetest.is_creative_enabled(user:get_player_name()) then - itemstack:take_item() - end + local inv = user:get_inventory() + if minetest.is_creative_enabled(user:get_player_name()) then + --TODO: is a full bucket added if inv doesn't contain one? return itemstack + else + if itemstack:get_count() == 1 then + return new_bucket + else + if inv:room_for_item("main", new_bucket) then + inv:add_item("main", new_bucket) + else + add_item(user:get_pos(), new_bucket) + end + itemstack:take_item() + return itemstack + end end end +local pointable_sources = {} + local function bucket_raycast(user) local pos = user:get_pos() pos.y = pos.y + user:get_properties().eye_height @@ -77,10 +83,10 @@ local function bucket_raycast(user) look_dir = vector.multiply(look_dir, 6) local pos2 = vector.add(pos, look_dir) - local ray = raycast(pos, pos2, false, true) + local ray = raycast(pos, pos2, false, true) if ray then for pointed_thing in ray do - if pointed_thing and get_node_group(get_node(pointed_thing.above).name, "_mcl_bucket_pointable") == 1 then + if pointed_thing and pointable_sources[get_node(pointed_thing.above).name] then --minetest.chat_send_all("found!") return {under=pointed_thing.under,above=pointed_thing.above} end @@ -97,6 +103,7 @@ function mcl_buckets.register_liquid(def) on_take = def.on_take, itemname = def.itemname, } + pointable_sources[source] = true if type(def.source_place) == "string" then mcl_buckets.liquids[def.source_place] = mcl_buckets.liquids[source] end @@ -137,7 +144,7 @@ function mcl_buckets.register_liquid(def) node_place = def.source_place end -- Check if pointing to a buildable node - local item = itemstack:get_name() + --local item = itemstack:get_name() if def.extra_check and def.extra_check(place_pos, user) == false then -- Fail placement of liquid @@ -308,7 +315,7 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", { return minetest.registered_nodes[nn].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack end end - + 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 @@ -318,7 +325,6 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", { if liquid_name then local liquid_def = mcl_buckets.liquids[liquid_name] if liquid_def then - local new_bucket --minetest.chat_send_all("test") -- Fill bucket, but not in Creative Mode -- FIXME: remove this line diff --git a/mods/ITEMS/mcl_buckets/register.lua b/mods/ITEMS/mcl_buckets/register.lua index 863aa074c..12790598c 100644 --- a/mods/ITEMS/mcl_buckets/register.lua +++ b/mods/ITEMS/mcl_buckets/register.lua @@ -3,7 +3,7 @@ local mod_mcl_core = minetest.get_modpath("mcl_core") local mod_mclx_core = minetest.get_modpath("mclx_core") local has_awards = minetest.get_modpath("awards") -local sound_place = function(itemname, pos) +local function sound_place(itemname, pos) local def = minetest.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) diff --git a/mods/ITEMS/mcl_core/nodes_liquid.lua b/mods/ITEMS/mcl_core/nodes_liquid.lua index d4234b8ac..0e0f71a11 100644 --- a/mods/ITEMS/mcl_core/nodes_liquid.lua +++ b/mods/ITEMS/mcl_core/nodes_liquid.lua @@ -95,7 +95,7 @@ S("• When water is directly below lava, the water turns into stone."), liquid_range = 7, post_effect_color = {a=209, r=0x03, g=0x3C, b=0x5C}, stack_max = 64, - groups = { water=3, liquid=3, puts_out_fire=1, freezes=1, not_in_creative_inventory=1, dig_by_piston=1, _mcl_bucket_pointable=1}, + groups = { water=3, liquid=3, puts_out_fire=1, freezes=1, not_in_creative_inventory=1, dig_by_piston=1}, _mcl_blast_resistance = 100, -- Hardness intentionally set to infinite instead of 100 (Minecraft value) to avoid problems in creative mode _mcl_hardness = -1, @@ -196,7 +196,7 @@ S("• When lava is directly above water, the water turns into stone."), damage_per_second = 4*2, post_effect_color = {a=245, r=208, g=73, b=10}, stack_max = 64, - groups = { lava=3, lava_source=1, liquid=2, destroys_items=1, not_in_creative_inventory=1, dig_by_piston=1, set_on_fire=15, fire_damage=1, _mcl_bucket_pointable=1}, + groups = { lava=3, lava_source=1, liquid=2, destroys_items=1, not_in_creative_inventory=1, dig_by_piston=1, set_on_fire=15, fire_damage=1}, _mcl_blast_resistance = 100, -- Hardness intentionally set to infinite instead of 100 (Minecraft value) to avoid problems in creative mode _mcl_hardness = -1, From 30e2e0d70afbbadf9fc7181bfde097ccf6fdd014 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Mon, 14 Jun 2021 14:36:17 +0200 Subject: [PATCH 05/28] test values --- mods/ITEMS/mcl_buckets/init.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index f2f61ccfc..70a219ffb 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -77,10 +77,11 @@ end local pointable_sources = {} local function bucket_raycast(user) - local pos = user:get_pos() + --local pos = user:get_pos() + local pos = mcl_util.get_object_center(user) pos.y = pos.y + user:get_properties().eye_height local look_dir = user:get_look_dir() - look_dir = vector.multiply(look_dir, 6) + look_dir = vector.multiply(look_dir, 4) local pos2 = vector.add(pos, look_dir) local ray = raycast(pos, pos2, false, true) From d26b1b1402056b5add6bf25d5e791bfc6c8b1ab1 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 14 Jul 2021 09:10:01 +0200 Subject: [PATCH 06/28] use mcl_util.call_on_rightclick insteed of current implementation --- mods/ITEMS/mcl_buckets/init.lua | 27 ++++++++++++++++----------- mods/ITEMS/mcl_buckets/mod.conf | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index 70a219ffb..fdd08bdf9 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -3,6 +3,7 @@ local modname = minetest.get_current_modname() local S = minetest.get_translator(modname) local modpath = minetest.get_modpath(modname) +-- Compatibility with old bucket mod minetest.register_alias("bucket:bucket_empty", "mcl_buckets:bucket_empty") minetest.register_alias("bucket:bucket_water", "mcl_buckets:bucket_water") minetest.register_alias("bucket:bucket_lava", "mcl_buckets:bucket_lava") @@ -11,6 +12,7 @@ local mod_doc = minetest.get_modpath("doc") local mod_mcl_core = minetest.get_modpath("mcl_core") --local mod_mclx_core = minetest.get_modpath("mclx_core") +-- Localize some functions for faster access local vector = vector local math = math local string = string @@ -127,16 +129,15 @@ function mcl_buckets.register_liquid(def) if pointed_thing.type ~= "node" then return end + -- Call on_rightclick if the pointed node defines it + local new_stack = mcl_util.call_on_rightclick(itemstack, user, pointed_thing) + if new_stack then + return new_stack + end local node = minetest.get_node(pointed_thing.under) local place_pos = pointed_thing.under local nn = node.name - -- Call on_rightclick if the pointed node defines it - if user and not user:get_player_control().sneak then - if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].on_rightclick then - return minetest.registered_nodes[nn].on_rightclick(place_pos, node, user, itemstack) or itemstack - end - end local node_place if type(def.source_place) == "function" then @@ -306,16 +307,20 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", { return itemstack end end]] + -- Must be pointing to node if pointed_thing.type ~= "node" then return itemstack end + + -- Call on_rightclick if the pointed node defines it + local new_stack = mcl_util.call_on_rightclick(itemstack, user, pointed_thing) + if new_stack then + return new_stack + end + local node = minetest.get_node(pointed_thing.under) local nn = node.name - if user and not user:get_player_control().sneak then - if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].on_rightclick then - return minetest.registered_nodes[nn].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack - end - end + local new_bucket local liquid_node = bucket_raycast(user) if liquid_node then diff --git a/mods/ITEMS/mcl_buckets/mod.conf b/mods/ITEMS/mcl_buckets/mod.conf index 5a78e70ad..0d7b764b8 100644 --- a/mods/ITEMS/mcl_buckets/mod.conf +++ b/mods/ITEMS/mcl_buckets/mod.conf @@ -1,6 +1,6 @@ name = mcl_buckets author = Kahrl description = -depends = mcl_worlds +depends = mcl_worlds, mcl_util optional_depends = mcl_core, mclx_core, doc From b0127fc1c3cb66ba0e024b9ea4cf82080ea80ced Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 14 Jul 2021 09:18:15 +0200 Subject: [PATCH 07/28] fix bucket dispense function --- mods/ITEMS/mcl_buckets/init.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index fdd08bdf9..95ec97443 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -205,11 +205,16 @@ function mcl_buckets.register_liquid(def) _on_dispense = function(stack, pos, droppos, dropnode, dropdir) local iname = stack:get_name() local buildable = minetest.registered_nodes[dropnode.name].buildable_to or dropnode.name == "mcl_portals:portal" + if not buildable then return stack end - if def.extra_check and def.extra_check(droppos, nil) == false then - -- Fail placement of liquid - elseif buildable then - -- buildable; replace the node + local result + if def.extra_check then + result = def.extra_check(droppos, nil) + if result == nil then result = true end + else + result = true + end + if result then -- Fail placement of liquid if result is false local node_place if type(def.source_place) == "function" then node_place = def.source_place(droppos) From ca277b6769c8edb1c498c268dd349bd2cd6c72ee Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 14 Jul 2021 11:29:15 +0200 Subject: [PATCH 08/28] mcl_bucket code refactoring + fix extra_check noot working --- mods/ITEMS/mcl_buckets/API.md | 30 +++++- mods/ITEMS/mcl_buckets/init.lua | 144 ++++++++++++++++++++++------ mods/ITEMS/mcl_buckets/register.lua | 26 +---- 3 files changed, 149 insertions(+), 51 deletions(-) diff --git a/mods/ITEMS/mcl_buckets/API.md b/mods/ITEMS/mcl_buckets/API.md index 53f7d3698..4595d8e72 100644 --- a/mods/ITEMS/mcl_buckets/API.md +++ b/mods/ITEMS/mcl_buckets/API.md @@ -15,7 +15,33 @@ Accept folowing params: * longdesc: long explanatory description (for help) * usagehelp: short usage explanation (for help) * tt_help: very short tooltip help -* extra_check(pos, placer): (optional) function(pos) which can returns false to avoid placing the liquid. Placer is object/player who is placing the liquid, can be nil. +* extra_check(pos, placer): (optional) function(pos) * groups: optional list of item groups -This function can be called from any mod (which depends on this one) \ No newline at end of file + +**Usage exemple:** +```lua +mcl_buckets.register_liquid({ + itemname = "dummy:bucket_dummy", + source_place = "dummy:dummy_source", + source_take = {"dummy:dummy_source"}, + inventory_image = "bucket_dummy.png", + name = S("Dummy liquid Bucket"), + longdesc = S("This bucket is filled with a dummy liquid."), + usagehelp = S("Place it to empty the bucket and create a dummy liquid source."), + tt_help = S("Places a dummy liquid source"), + extra_check = function(pos, placer) + --pos = pos where the liquid should be placed + --placer people who tried to place the bucket (can be nil) + + --no liquid node will be placed + --the bucket will not be emptied + --return false, false + + --liquid node will be placed + --the bucket will be emptied + return true, true + end, + groups = { dummy_group = 123 }, +}) +``` \ No newline at end of file diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index 95ec97443..9ae712ced 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -56,6 +56,7 @@ local function place_liquid(pos, itemstring) sound_place(itemstring, pos) minetest.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 @@ -81,6 +82,7 @@ local pointable_sources = {} local function bucket_raycast(user) --local pos = user:get_pos() local pos = mcl_util.get_object_center(user) + --local pos = vector.add(user:get_pos(), user:get_bone_position("Head_Control")) pos.y = pos.y + user:get_properties().eye_height local look_dir = user:get_look_dir() look_dir = vector.multiply(look_dir, 4) @@ -98,6 +100,53 @@ local function bucket_raycast(user) return nil end +local function get_node_place(source_place, place_pos) + local node_place + if type(source_place) == "function" then + node_place = source_place(place_pos) + else + node_place = source_place + end + return node_place +end + +local function get_extra_check(check, pos, user) + local result + local take_bucket + if check then + result, take_bucket = check(pos, user) + if result == nil then result = true end + if take_bucket == nil then take_bucket = true end + else + result = true + take_bucket = true + end + return result, take_bucket +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 + -- Add empty bucket and put it into inventory, if possible. + -- Drop empty bucket otherwise. + local new_bucket = ItemStack("mcl_buckets:bucket_empty") + if itemstack:get_count() == 1 then + return new_bucket + else + local inv = user:get_inventory() + if inv:room_for_item("main", new_bucket) then + inv:add_item("main", new_bucket) + else + add_item(user:get_pos(), new_bucket) + end + itemstack:take_item() + return itemstack + end + else + return itemstack + end +end + function mcl_buckets.register_liquid(def) for _,source in ipairs(def.source_take) do mcl_buckets.liquids[source] = { @@ -135,23 +184,75 @@ function mcl_buckets.register_liquid(def) return new_stack end - local node = minetest.get_node(pointed_thing.under) - local place_pos = pointed_thing.under - local nn = node.name + local undernode = get_node(pointed_thing.under) + local abovenode = get_node(pointed_thing.above) + local nn = undernode.name + 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 + 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() - local node_place - if type(def.source_place) == "function" then - node_place = def.source_place(place_pos) + -- Check protection + if minetest.is_protected(pointed_thing.under, pns) then + minetest.record_protection_violation(pointed_thing.under, pns) + return itemstack + end + + -- Place liquid + place_liquid(pointed_thing.under, node_place) + + -- Update doc mod + if mod_doc and doc.entry_exists("nodes", node_place) then + doc.mark_entry_as_revealed(user:get_player_name(), "nodes", node_place) + end + end + return get_bucket_drop(itemstack, user, take_bucket) + elseif buildable2 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) + return itemstack + end + + -- Place liquid + place_liquid(pointed_thing.above, node_place) + + -- Update doc mod + if mod_doc and doc.entry_exists("nodes", node_place) then + doc.mark_entry_as_revealed(user:get_player_name(), "nodes", node_place) + end + end + return get_bucket_drop(itemstack, user, take_bucket) else - node_place = def.source_place + return itemstack end + -- Check if pointing to a buildable node --local item = itemstack:get_name() - if def.extra_check and def.extra_check(place_pos, user) == false then - -- Fail placement of liquid - elseif minetest.registered_nodes[nn] and minetest.registered_nodes[nn].buildable_to then - -- buildable; replace the node + --[[ + if buildable_to_1 then + if can_place(pos) then + Place + end + else if buildable_to_2 then + if can_place2() then + Place + end + end + ]] + --[[ + if result then -- Fail placement of liquid if result is false local pns = user:get_player_name() if minetest.is_protected(place_pos, pns) then minetest.record_protection_violation(place_pos, pns) @@ -200,28 +301,17 @@ function mcl_buckets.register_liquid(def) end else return - end + end]] end, _on_dispense = function(stack, pos, droppos, dropnode, dropdir) local iname = stack:get_name() local buildable = minetest.registered_nodes[dropnode.name].buildable_to or dropnode.name == "mcl_portals:portal" if not buildable then return stack end - - local result - if def.extra_check then - result = def.extra_check(droppos, nil) - if result == nil then result = true end - else - result = true - end + local result, take_bucket = get_extra_check(def.extra_check, droppos, nil) if result then -- Fail placement of liquid if result is false - local node_place - if type(def.source_place) == "function" then - node_place = def.source_place(droppos) - else - node_place = def.source_place - end - place_liquid(droppos, node_place) + 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 diff --git a/mods/ITEMS/mcl_buckets/register.lua b/mods/ITEMS/mcl_buckets/register.lua index 12790598c..97349533e 100644 --- a/mods/ITEMS/mcl_buckets/register.lua +++ b/mods/ITEMS/mcl_buckets/register.lua @@ -53,15 +53,6 @@ if mod_mcl_core then usagehelp = S("Place it to empty the bucket and create a water source."), tt_help = S("Places a water source"), extra_check = function(pos, placer) - -- Check protection - local placer_name = "" - if placer then - placer_name = placer:get_player_name() - end - if placer and minetest.is_protected(pos, placer_name) then - minetest.record_protection_violation(pos, placer_name) - return false - end local nn = minetest.get_node(pos).name -- Pour water into cauldron if minetest.get_item_group(nn, "cauldron") ~= 0 then @@ -70,13 +61,13 @@ if mod_mcl_core then minetest.set_node(pos, {name="mcl_cauldrons:cauldron_3"}) end sound_place("mcl_core:water_source", pos) - return false + return false, true -- Evaporate water if used in Nether (except on cauldron) else local dim = mcl_worlds.pos_to_dimension(pos) if dim == "nether" then minetest.sound_play("fire_extinguish_flame", {pos = pos, gain = 0.25, max_hear_distance = 16}, true) - return false + return false, true end end end, @@ -96,15 +87,6 @@ if mod_mclx_core then usagehelp = S("Place it to empty the bucket and create a river water source."), tt_help = S("Places a river water source"), extra_check = function(pos, placer) - -- Check protection - local placer_name = "" - if placer then - placer_name = placer:get_player_name() - end - if placer and minetest.is_protected(pos, placer_name) then - minetest.record_protection_violation(pos, placer_name) - return false - end local nn = minetest.get_node(pos).name -- Pour into cauldron if minetest.get_item_group(nn, "cauldron") ~= 0 then @@ -113,13 +95,13 @@ if mod_mclx_core then minetest.set_node(pos, {name="mcl_cauldrons:cauldron_3r"}) end sound_place("mcl_core:water_source", pos) - return false + return false, true else -- Evaporate water if used in Nether (except on cauldron) local dim = mcl_worlds.pos_to_dimension(pos) if dim == "nether" then minetest.sound_play("fire_extinguish_flame", {pos = pos, gain = 0.25, max_hear_distance = 16}, true) - return false + return false, true end end end, From cd08df175c767fe502065d5327d37ec633c7af2e Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 14 Jul 2021 11:41:09 +0200 Subject: [PATCH 09/28] add better documentation --- mods/ITEMS/mcl_buckets/API.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_buckets/API.md b/mods/ITEMS/mcl_buckets/API.md index 4595d8e72..abbdb0a07 100644 --- a/mods/ITEMS/mcl_buckets/API.md +++ b/mods/ITEMS/mcl_buckets/API.md @@ -23,7 +23,14 @@ Accept folowing params: ```lua mcl_buckets.register_liquid({ itemname = "dummy:bucket_dummy", - source_place = "dummy:dummy_source", + --source_place = "dummy:dummy_source", + source_place = function(pos) + if condition then + return "dummy:dummy_source" + else + return "dummy:dummy_source_nether" + end + end, source_take = {"dummy:dummy_source"}, inventory_image = "bucket_dummy.png", name = S("Dummy liquid Bucket"), From 88e59d3592b7f56044273296bce96e299cf2de17 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 14 Jul 2021 11:52:27 +0200 Subject: [PATCH 10/28] more mt like API (improved readability) --- mods/ITEMS/mcl_buckets/API.md | 14 +-- mods/ITEMS/mcl_buckets/init.lua | 150 +--------------------------- mods/ITEMS/mcl_buckets/register.lua | 9 +- 3 files changed, 14 insertions(+), 159 deletions(-) diff --git a/mods/ITEMS/mcl_buckets/API.md b/mods/ITEMS/mcl_buckets/API.md index abbdb0a07..93af64acf 100644 --- a/mods/ITEMS/mcl_buckets/API.md +++ b/mods/ITEMS/mcl_buckets/API.md @@ -1,15 +1,18 @@ # mcl_buckets Add an API to register buckets to mcl -## mcl_buckets.register_liquid(def) +## mcl_buckets.register_liquid(itemname, def) + +Register a new bucket of liquid. + +`itemname` is the itemstring of the new bucket item + +`def` is a table containing the folowing fields: -Register a new liquid -Accept folowing params: * source_place: a string or function. * string: name of the node to place * function(pos): will returns name of the node to place with pos being the placement position * source_take: table of liquid source node names to take -* itemname: itemstring of the new bucket item (or nil if liquid is not takeable) * inventory_image: texture of the new bucket item (ignored if itemname == nil) * name: user-visible bucket description * longdesc: long explanatory description (for help) @@ -21,8 +24,7 @@ Accept folowing params: **Usage exemple:** ```lua -mcl_buckets.register_liquid({ - itemname = "dummy:bucket_dummy", +mcl_buckets.register_liquid("dummy:bucket_dummy", { --source_place = "dummy:dummy_source", source_place = function(pos) if condition then diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index 9ae712ced..11fede816 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -147,13 +147,13 @@ local function get_bucket_drop(itemstack, user, take_bucket) end end -function mcl_buckets.register_liquid(def) +function mcl_buckets.register_liquid(itemname, def) for _,source in ipairs(def.source_take) do mcl_buckets.liquids[source] = { source_place = def.source_place, source_take = source, on_take = def.on_take, - itemname = def.itemname, + itemname = itemname, } pointable_sources[source] = true if type(def.source_place) == "string" then @@ -161,11 +161,7 @@ function mcl_buckets.register_liquid(def) end end - if def.itemname == nil or def.itemname == "" then - error(string.format("[mcl_bucket] Invalid itemname then registering [%s]!", def.name)) - end - - minetest.register_craftitem(def.itemname, { + minetest.register_craftitem(itemname, { description = def.name, _doc_items_longdesc = def.longdesc, _doc_items_usagehelp = def.usagehelp, @@ -236,72 +232,6 @@ function mcl_buckets.register_liquid(def) else return itemstack end - - -- Check if pointing to a buildable node - --local item = itemstack:get_name() - - --[[ - if buildable_to_1 then - if can_place(pos) then - Place - end - else if buildable_to_2 then - if can_place2() then - Place - end - end - ]] - --[[ - if result then -- Fail placement of liquid if result is false - local pns = user:get_player_name() - if minetest.is_protected(place_pos, pns) then - minetest.record_protection_violation(place_pos, pns) - return itemstack - end - place_liquid(place_pos, node_place) - if mod_doc and doc.entry_exists("nodes", node_place) then - doc.mark_entry_as_revealed(user:get_player_name(), "nodes", node_place) - end - else - -- not buildable to; place the liquid above - -- check if the node above can be replaced - local abovenode = minetest.get_node(pointed_thing.above) - if minetest.registered_nodes[abovenode.name] and minetest.registered_nodes[abovenode.name].buildable_to then - local pn = user:get_player_name() - if minetest.is_protected(pointed_thing.above, pn) then - minetest.record_protection_violation(pointed_thing.above, pn) - return itemstack - end - place_liquid(pointed_thing.above, node_place) - if mod_doc and doc.entry_exists("nodes", node_place) then - doc.mark_entry_as_revealed(user:get_player_name(), "nodes", node_place) - end - else - -- do not remove the bucket with the liquid - return - end - end - - -- Handle bucket item and inventory stuff - if not minetest.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") - if itemstack:get_count() == 1 then - return new_bucket - else - local inv = user:get_inventory() - if inv:room_for_item("main", new_bucket) then - inv:add_item("main", new_bucket) - else - minetest.add_item(user:get_pos(), new_bucket) - end - itemstack:take_item() - return itemstack - end - else - return - end]] end, _on_dispense = function(stack, pos, droppos, dropnode, dropdir) local iname = stack:get_name() @@ -328,80 +258,6 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", { inventory_image = "bucket.png", stack_max = 16, on_place = function(itemstack, user, pointed_thing) - --[[-- Must be pointing to node - if pointed_thing.type ~= "node" then - return itemstack - end - - -- Call on_rightclick if the pointed node defines it - - - local pointed_liquid = bucket_raycast(user) - - -- Can't steal liquids - if minetest.is_protected(pointed_liquid.above, user:get_player_name()) then - minetest.record_protection_violation(pointed_liquid.under, user:get_player_name()) - return itemstack - end - if minetest.is_protected(pointed_thing.above, user:get_player_name()) then - minetest.record_protection_violation(pointed_thing.under, user:get_player_name()) - return itemstack - end - - -- Check if pointing to a liquid source - local liquiddef = mcl_buckets.liquids[nn] - local new_bucket - if liquiddef and liquiddef.itemname and (nn == liquiddef.source_take) then - - -- Fill bucket, but not in Creative Mode - if not minetest.is_creative_enabled(user:get_player_name()) then - new_bucket = ItemStack({name = liquiddef.itemname}) - if liquiddef.on_take then - liquiddef.on_take(user) - end - end - - minetest.add_node(pointed_thing.under, {name="air"}) - sound_take(nn, pointed_thing.under) - - if mod_doc and doc.entry_exists("nodes", nn) then - doc.mark_entry_as_revealed(user:get_player_name(), "nodes", nn) - end - - elseif 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 - 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 - new_bucket = ItemStack("mcl_buckets:bucket_river_water") - end - sound_take("mclx_core:river_water_source", pointed_thing.under) - end - - -- Add liquid bucket and put it into inventory, if possible. - -- Drop new bucket otherwise. - if new_bucket then - if itemstack:get_count() == 1 then - return new_bucket - else - local inv = user:get_inventory() - if inv:room_for_item("main", new_bucket) then - inv:add_item("main", new_bucket) - else - minetest.add_item(user:get_pos(), new_bucket) - end - if not minetest.is_creative_enabled(user:get_player_name()) then - itemstack:take_item() - end - return itemstack - end - end]] -- Must be pointing to node if pointed_thing.type ~= "node" then return itemstack diff --git a/mods/ITEMS/mcl_buckets/register.lua b/mods/ITEMS/mcl_buckets/register.lua index 97349533e..46abce1d0 100644 --- a/mods/ITEMS/mcl_buckets/register.lua +++ b/mods/ITEMS/mcl_buckets/register.lua @@ -19,7 +19,7 @@ end]] if mod_mcl_core then -- Lava bucket - mcl_buckets.register_liquid({ + mcl_buckets.register_liquid("mcl_buckets:bucket_lava", { source_place = function(pos) local dim = mcl_worlds.pos_to_dimension(pos) if dim == "nether" then @@ -34,7 +34,6 @@ if mod_mcl_core then awards.unlock(user:get_player_name(), "mcl:hotStuff") end end, - itemname = "mcl_buckets:bucket_lava", inventory_image = "bucket_lava.png", name = S("Lava Bucket"), longdesc = S("A bucket can be used to collect and release liquids. This one is filled with hot lava, safely contained inside. Use with caution."), @@ -43,10 +42,9 @@ if mod_mcl_core then }) -- Water bucket - mcl_buckets.register_liquid({ + mcl_buckets.register_liquid("mcl_buckets:bucket_water", { source_place = "mcl_core:water_source", source_take = {"mcl_core:water_source"}, - itemname = "mcl_buckets:bucket_water", inventory_image = "bucket_water.png", name = S("Water Bucket"), longdesc = S("A bucket can be used to collect and release liquids. This one is filled with water."), @@ -77,10 +75,9 @@ end if mod_mclx_core then -- River water bucket - mcl_buckets.register_liquid({ + mcl_buckets.register_liquid("mcl_buckets:bucket_river_water", { source_place = "mclx_core:river_water_source", source_take = {"mclx_core:river_water_source"}, - itemname = "mcl_buckets:bucket_river_water", inventory_image = "bucket_river_water.png", name = S("River Water Bucket"), longdesc = S("A bucket can be used to collect and release liquids. This one is filled with river water."), From cf5703d528426bbbb810c327ecfe59b0c9867cf0 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 14 Jul 2021 11:53:37 +0200 Subject: [PATCH 11/28] fix luacheck warnings --- mods/ITEMS/mcl_buckets/init.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index 11fede816..a496fb2ff 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -182,11 +182,10 @@ function mcl_buckets.register_liquid(itemname, def) local undernode = get_node(pointed_thing.under) local abovenode = get_node(pointed_thing.above) - local nn = undernode.name 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 local result, take_bucket = get_extra_check(def.extra_check, pointed_thing.under, user) if result then @@ -234,7 +233,6 @@ function mcl_buckets.register_liquid(itemname, def) end end, _on_dispense = function(stack, pos, droppos, dropnode, dropdir) - local iname = stack:get_name() local buildable = minetest.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) From 6d7aafe0d462bccdb8a7a32f78a27898fb1705d7 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 14 Jul 2021 15:13:40 +0200 Subject: [PATCH 12/28] Revert "more mt like API (improved readability)" This reverts commit 88e59d3592b7f56044273296bce96e299cf2de17. --- mods/ITEMS/mcl_buckets/API.md | 14 ++- mods/ITEMS/mcl_buckets/init.lua | 150 +++++++++++++++++++++++++++- mods/ITEMS/mcl_buckets/register.lua | 9 +- 3 files changed, 159 insertions(+), 14 deletions(-) diff --git a/mods/ITEMS/mcl_buckets/API.md b/mods/ITEMS/mcl_buckets/API.md index 93af64acf..abbdb0a07 100644 --- a/mods/ITEMS/mcl_buckets/API.md +++ b/mods/ITEMS/mcl_buckets/API.md @@ -1,18 +1,15 @@ # mcl_buckets Add an API to register buckets to mcl -## mcl_buckets.register_liquid(itemname, def) - -Register a new bucket of liquid. - -`itemname` is the itemstring of the new bucket item - -`def` is a table containing the folowing fields: +## mcl_buckets.register_liquid(def) +Register a new liquid +Accept folowing params: * source_place: a string or function. * string: name of the node to place * function(pos): will returns name of the node to place with pos being the placement position * source_take: table of liquid source node names to take +* itemname: itemstring of the new bucket item (or nil if liquid is not takeable) * inventory_image: texture of the new bucket item (ignored if itemname == nil) * name: user-visible bucket description * longdesc: long explanatory description (for help) @@ -24,7 +21,8 @@ Register a new bucket of liquid. **Usage exemple:** ```lua -mcl_buckets.register_liquid("dummy:bucket_dummy", { +mcl_buckets.register_liquid({ + itemname = "dummy:bucket_dummy", --source_place = "dummy:dummy_source", source_place = function(pos) if condition then diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index a496fb2ff..b75c10696 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -147,13 +147,13 @@ local function get_bucket_drop(itemstack, user, take_bucket) end end -function mcl_buckets.register_liquid(itemname, def) +function mcl_buckets.register_liquid(def) for _,source in ipairs(def.source_take) do mcl_buckets.liquids[source] = { source_place = def.source_place, source_take = source, on_take = def.on_take, - itemname = itemname, + itemname = def.itemname, } pointable_sources[source] = true if type(def.source_place) == "string" then @@ -161,7 +161,11 @@ function mcl_buckets.register_liquid(itemname, def) end end - minetest.register_craftitem(itemname, { + if def.itemname == nil or def.itemname == "" then + error(string.format("[mcl_bucket] Invalid itemname then registering [%s]!", def.name)) + end + + minetest.register_craftitem(def.itemname, { description = def.name, _doc_items_longdesc = def.longdesc, _doc_items_usagehelp = def.usagehelp, @@ -231,6 +235,72 @@ function mcl_buckets.register_liquid(itemname, def) else return itemstack end + + -- Check if pointing to a buildable node + --local item = itemstack:get_name() + + --[[ + if buildable_to_1 then + if can_place(pos) then + Place + end + else if buildable_to_2 then + if can_place2() then + Place + end + end + ]] + --[[ + if result then -- Fail placement of liquid if result is false + local pns = user:get_player_name() + if minetest.is_protected(place_pos, pns) then + minetest.record_protection_violation(place_pos, pns) + return itemstack + end + place_liquid(place_pos, node_place) + if mod_doc and doc.entry_exists("nodes", node_place) then + doc.mark_entry_as_revealed(user:get_player_name(), "nodes", node_place) + end + else + -- not buildable to; place the liquid above + -- check if the node above can be replaced + local abovenode = minetest.get_node(pointed_thing.above) + if minetest.registered_nodes[abovenode.name] and minetest.registered_nodes[abovenode.name].buildable_to then + local pn = user:get_player_name() + if minetest.is_protected(pointed_thing.above, pn) then + minetest.record_protection_violation(pointed_thing.above, pn) + return itemstack + end + place_liquid(pointed_thing.above, node_place) + if mod_doc and doc.entry_exists("nodes", node_place) then + doc.mark_entry_as_revealed(user:get_player_name(), "nodes", node_place) + end + else + -- do not remove the bucket with the liquid + return + end + end + + -- Handle bucket item and inventory stuff + if not minetest.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") + if itemstack:get_count() == 1 then + return new_bucket + else + local inv = user:get_inventory() + if inv:room_for_item("main", new_bucket) then + inv:add_item("main", new_bucket) + else + minetest.add_item(user:get_pos(), new_bucket) + end + itemstack:take_item() + return itemstack + end + else + return + end]] end, _on_dispense = function(stack, pos, droppos, dropnode, dropdir) local buildable = minetest.registered_nodes[dropnode.name].buildable_to or dropnode.name == "mcl_portals:portal" @@ -256,6 +326,80 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", { inventory_image = "bucket.png", stack_max = 16, on_place = function(itemstack, user, pointed_thing) + --[[-- Must be pointing to node + if pointed_thing.type ~= "node" then + return itemstack + end + + -- Call on_rightclick if the pointed node defines it + + + local pointed_liquid = bucket_raycast(user) + + -- Can't steal liquids + if minetest.is_protected(pointed_liquid.above, user:get_player_name()) then + minetest.record_protection_violation(pointed_liquid.under, user:get_player_name()) + return itemstack + end + if minetest.is_protected(pointed_thing.above, user:get_player_name()) then + minetest.record_protection_violation(pointed_thing.under, user:get_player_name()) + return itemstack + end + + -- Check if pointing to a liquid source + local liquiddef = mcl_buckets.liquids[nn] + local new_bucket + if liquiddef and liquiddef.itemname and (nn == liquiddef.source_take) then + + -- Fill bucket, but not in Creative Mode + if not minetest.is_creative_enabled(user:get_player_name()) then + new_bucket = ItemStack({name = liquiddef.itemname}) + if liquiddef.on_take then + liquiddef.on_take(user) + end + end + + minetest.add_node(pointed_thing.under, {name="air"}) + sound_take(nn, pointed_thing.under) + + if mod_doc and doc.entry_exists("nodes", nn) then + doc.mark_entry_as_revealed(user:get_player_name(), "nodes", nn) + end + + elseif 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 + 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 + new_bucket = ItemStack("mcl_buckets:bucket_river_water") + end + sound_take("mclx_core:river_water_source", pointed_thing.under) + end + + -- Add liquid bucket and put it into inventory, if possible. + -- Drop new bucket otherwise. + if new_bucket then + if itemstack:get_count() == 1 then + return new_bucket + else + local inv = user:get_inventory() + if inv:room_for_item("main", new_bucket) then + inv:add_item("main", new_bucket) + else + minetest.add_item(user:get_pos(), new_bucket) + end + if not minetest.is_creative_enabled(user:get_player_name()) then + itemstack:take_item() + end + return itemstack + end + end]] -- Must be pointing to node if pointed_thing.type ~= "node" then return itemstack diff --git a/mods/ITEMS/mcl_buckets/register.lua b/mods/ITEMS/mcl_buckets/register.lua index 46abce1d0..97349533e 100644 --- a/mods/ITEMS/mcl_buckets/register.lua +++ b/mods/ITEMS/mcl_buckets/register.lua @@ -19,7 +19,7 @@ end]] if mod_mcl_core then -- Lava bucket - mcl_buckets.register_liquid("mcl_buckets:bucket_lava", { + mcl_buckets.register_liquid({ source_place = function(pos) local dim = mcl_worlds.pos_to_dimension(pos) if dim == "nether" then @@ -34,6 +34,7 @@ if mod_mcl_core then awards.unlock(user:get_player_name(), "mcl:hotStuff") end end, + itemname = "mcl_buckets:bucket_lava", inventory_image = "bucket_lava.png", name = S("Lava Bucket"), longdesc = S("A bucket can be used to collect and release liquids. This one is filled with hot lava, safely contained inside. Use with caution."), @@ -42,9 +43,10 @@ if mod_mcl_core then }) -- Water bucket - mcl_buckets.register_liquid("mcl_buckets:bucket_water", { + mcl_buckets.register_liquid({ source_place = "mcl_core:water_source", source_take = {"mcl_core:water_source"}, + itemname = "mcl_buckets:bucket_water", inventory_image = "bucket_water.png", name = S("Water Bucket"), longdesc = S("A bucket can be used to collect and release liquids. This one is filled with water."), @@ -75,9 +77,10 @@ end if mod_mclx_core then -- River water bucket - mcl_buckets.register_liquid("mcl_buckets:bucket_river_water", { + mcl_buckets.register_liquid({ source_place = "mclx_core:river_water_source", source_take = {"mclx_core:river_water_source"}, + itemname = "mcl_buckets:bucket_river_water", inventory_image = "bucket_river_water.png", name = S("River Water Bucket"), longdesc = S("A bucket can be used to collect and release liquids. This one is filled with river water."), From ec6086d8e631fc19bd9dfca43eb5109f3125d0e4 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 14 Jul 2021 15:14:23 +0200 Subject: [PATCH 13/28] cleanup --- mods/ITEMS/mcl_buckets/init.lua | 140 -------------------------------- 1 file changed, 140 deletions(-) diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index b75c10696..312669c5e 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -235,72 +235,6 @@ function mcl_buckets.register_liquid(def) else return itemstack end - - -- Check if pointing to a buildable node - --local item = itemstack:get_name() - - --[[ - if buildable_to_1 then - if can_place(pos) then - Place - end - else if buildable_to_2 then - if can_place2() then - Place - end - end - ]] - --[[ - if result then -- Fail placement of liquid if result is false - local pns = user:get_player_name() - if minetest.is_protected(place_pos, pns) then - minetest.record_protection_violation(place_pos, pns) - return itemstack - end - place_liquid(place_pos, node_place) - if mod_doc and doc.entry_exists("nodes", node_place) then - doc.mark_entry_as_revealed(user:get_player_name(), "nodes", node_place) - end - else - -- not buildable to; place the liquid above - -- check if the node above can be replaced - local abovenode = minetest.get_node(pointed_thing.above) - if minetest.registered_nodes[abovenode.name] and minetest.registered_nodes[abovenode.name].buildable_to then - local pn = user:get_player_name() - if minetest.is_protected(pointed_thing.above, pn) then - minetest.record_protection_violation(pointed_thing.above, pn) - return itemstack - end - place_liquid(pointed_thing.above, node_place) - if mod_doc and doc.entry_exists("nodes", node_place) then - doc.mark_entry_as_revealed(user:get_player_name(), "nodes", node_place) - end - else - -- do not remove the bucket with the liquid - return - end - end - - -- Handle bucket item and inventory stuff - if not minetest.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") - if itemstack:get_count() == 1 then - return new_bucket - else - local inv = user:get_inventory() - if inv:room_for_item("main", new_bucket) then - inv:add_item("main", new_bucket) - else - minetest.add_item(user:get_pos(), new_bucket) - end - itemstack:take_item() - return itemstack - end - else - return - end]] end, _on_dispense = function(stack, pos, droppos, dropnode, dropdir) local buildable = minetest.registered_nodes[dropnode.name].buildable_to or dropnode.name == "mcl_portals:portal" @@ -326,80 +260,6 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", { inventory_image = "bucket.png", stack_max = 16, on_place = function(itemstack, user, pointed_thing) - --[[-- Must be pointing to node - if pointed_thing.type ~= "node" then - return itemstack - end - - -- Call on_rightclick if the pointed node defines it - - - local pointed_liquid = bucket_raycast(user) - - -- Can't steal liquids - if minetest.is_protected(pointed_liquid.above, user:get_player_name()) then - minetest.record_protection_violation(pointed_liquid.under, user:get_player_name()) - return itemstack - end - if minetest.is_protected(pointed_thing.above, user:get_player_name()) then - minetest.record_protection_violation(pointed_thing.under, user:get_player_name()) - return itemstack - end - - -- Check if pointing to a liquid source - local liquiddef = mcl_buckets.liquids[nn] - local new_bucket - if liquiddef and liquiddef.itemname and (nn == liquiddef.source_take) then - - -- Fill bucket, but not in Creative Mode - if not minetest.is_creative_enabled(user:get_player_name()) then - new_bucket = ItemStack({name = liquiddef.itemname}) - if liquiddef.on_take then - liquiddef.on_take(user) - end - end - - minetest.add_node(pointed_thing.under, {name="air"}) - sound_take(nn, pointed_thing.under) - - if mod_doc and doc.entry_exists("nodes", nn) then - doc.mark_entry_as_revealed(user:get_player_name(), "nodes", nn) - end - - elseif 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 - 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 - new_bucket = ItemStack("mcl_buckets:bucket_river_water") - end - sound_take("mclx_core:river_water_source", pointed_thing.under) - end - - -- Add liquid bucket and put it into inventory, if possible. - -- Drop new bucket otherwise. - if new_bucket then - if itemstack:get_count() == 1 then - return new_bucket - else - local inv = user:get_inventory() - if inv:room_for_item("main", new_bucket) then - inv:add_item("main", new_bucket) - else - minetest.add_item(user:get_pos(), new_bucket) - end - if not minetest.is_creative_enabled(user:get_player_name()) then - itemstack:take_item() - end - return itemstack - end - end]] -- Must be pointing to node if pointed_thing.type ~= "node" then return itemstack From 8fff20eec9f1045c9d16d2a4cdb79c989d627966 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 14 Jul 2021 15:18:12 +0200 Subject: [PATCH 14/28] fix misleading API --- mods/ITEMS/mcl_buckets/init.lua | 12 ++++++------ mods/ITEMS/mcl_buckets/register.lua | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index 312669c5e..17d333485 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -153,7 +153,7 @@ function mcl_buckets.register_liquid(def) source_place = def.source_place, source_take = source, on_take = def.on_take, - itemname = def.itemname, + bucketname = def.bucketname, } pointable_sources[source] = true if type(def.source_place) == "string" then @@ -161,11 +161,11 @@ function mcl_buckets.register_liquid(def) end end - if def.itemname == nil or def.itemname == "" then + if def.bucketname == nil or def.bucketname == "" then error(string.format("[mcl_bucket] Invalid itemname then registering [%s]!", def.name)) end - minetest.register_craftitem(def.itemname, { + minetest.register_craftitem(def.bucketname, { description = def.name, _doc_items_longdesc = def.longdesc, _doc_items_usagehelp = def.usagehelp, @@ -289,7 +289,7 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", { -- FIXME: remove this line --if not minetest.is_creative_enabled(user:get_player_name()) then if not false then - new_bucket = ItemStack({name = liquid_def.itemname}) + new_bucket = ItemStack({name = liquid_def.bucketname}) if liquid_def.on_take then liquid_def.on_take(user) end @@ -337,9 +337,9 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", { local liquiddef = mcl_buckets.liquids[dropnode.name] local new_bucket - if liquiddef and liquiddef.itemname and (dropnode.name == liquiddef.source_take) then + if liquiddef and liquiddef.bucketname and (dropnode.name == liquiddef.source_take) then -- Fill bucket - new_bucket = ItemStack({name = liquiddef.itemname}) + new_bucket = ItemStack({name = liquiddef.bucketname}) sound_take(dropnode.name, droppos) collect_liquid = true end diff --git a/mods/ITEMS/mcl_buckets/register.lua b/mods/ITEMS/mcl_buckets/register.lua index 97349533e..1a7c8fe14 100644 --- a/mods/ITEMS/mcl_buckets/register.lua +++ b/mods/ITEMS/mcl_buckets/register.lua @@ -34,7 +34,7 @@ if mod_mcl_core then awards.unlock(user:get_player_name(), "mcl:hotStuff") end end, - itemname = "mcl_buckets:bucket_lava", + bucketname = "mcl_buckets:bucket_lava", inventory_image = "bucket_lava.png", name = S("Lava Bucket"), longdesc = S("A bucket can be used to collect and release liquids. This one is filled with hot lava, safely contained inside. Use with caution."), @@ -46,7 +46,7 @@ if mod_mcl_core then mcl_buckets.register_liquid({ source_place = "mcl_core:water_source", source_take = {"mcl_core:water_source"}, - itemname = "mcl_buckets:bucket_water", + bucketname = "mcl_buckets:bucket_water", inventory_image = "bucket_water.png", name = S("Water Bucket"), longdesc = S("A bucket can be used to collect and release liquids. This one is filled with water."), @@ -80,7 +80,7 @@ if mod_mclx_core then mcl_buckets.register_liquid({ source_place = "mclx_core:river_water_source", source_take = {"mclx_core:river_water_source"}, - itemname = "mcl_buckets:bucket_river_water", + bucketname = "mcl_buckets:bucket_river_water", inventory_image = "bucket_river_water.png", name = S("River Water Bucket"), longdesc = S("A bucket can be used to collect and release liquids. This one is filled with river water."), From 873a1e73dc58bf38ca4738feb86f4f4ab8c5d2ba Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 14 Jul 2021 15:22:27 +0200 Subject: [PATCH 15/28] fix documentation --- mods/ITEMS/mcl_buckets/API.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_buckets/API.md b/mods/ITEMS/mcl_buckets/API.md index abbdb0a07..94ec48de5 100644 --- a/mods/ITEMS/mcl_buckets/API.md +++ b/mods/ITEMS/mcl_buckets/API.md @@ -9,7 +9,7 @@ Accept folowing params: * string: name of the node to place * function(pos): will returns name of the node to place with pos being the placement position * source_take: table of liquid source node names to take -* itemname: itemstring of the new bucket item (or nil if liquid is not takeable) +* bucketname: itemstring of the new bucket item * inventory_image: texture of the new bucket item (ignored if itemname == nil) * name: user-visible bucket description * longdesc: long explanatory description (for help) @@ -22,7 +22,7 @@ Accept folowing params: **Usage exemple:** ```lua mcl_buckets.register_liquid({ - itemname = "dummy:bucket_dummy", + bucketname = "dummy:bucket_dummy", --source_place = "dummy:dummy_source", source_place = function(pos) if condition then From dc17cc91a3ea225936869d1f01b1bed498efd0e8 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 15 Jul 2021 00:01:56 +0200 Subject: [PATCH 16/28] make raycast start from player head --- mods/ITEMS/mcl_buckets/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index 17d333485..f1d131ea2 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -81,7 +81,7 @@ local pointable_sources = {} local function bucket_raycast(user) --local pos = user:get_pos() - local pos = mcl_util.get_object_center(user) + local pos = user:get_pos() --local pos = vector.add(user:get_pos(), user:get_bone_position("Head_Control")) pos.y = pos.y + user:get_properties().eye_height local look_dir = user:get_look_dir() From 49bde37a5e80a91f7ad0f03ef371aa32cf7972b8 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 15 Jul 2021 01:03:50 +0200 Subject: [PATCH 17/28] rewrite README to markdown --- mods/ITEMS/mcl_buckets/{README.txt => README.md} | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) rename mods/ITEMS/mcl_buckets/{README.txt => README.md} (67%) diff --git a/mods/ITEMS/mcl_buckets/README.txt b/mods/ITEMS/mcl_buckets/README.md similarity index 67% rename from mods/ITEMS/mcl_buckets/README.txt rename to mods/ITEMS/mcl_buckets/README.md index 06862d589..b783cc133 100644 --- a/mods/ITEMS/mcl_buckets/README.txt +++ b/mods/ITEMS/mcl_buckets/README.md @@ -1,9 +1,12 @@ -Bucket mod. -Originally taken from Minetest Game, adapted for MineClone 2. +# MineClone2 Bucket (`mcl_bucket`) +Originally taken from Minetest Game, adapted for MineClone2. + +This mod add buckets to the game, including an API to register your own (see `API.md`). + +## License -License of source code: ------------------------ Copyright (C) 2011-2012 Kahrl + Copyright (C) 2011-2012 celeron55, Perttu Ahola This program is free software; you can redistribute it and/or modify From 181bc24e5ee7db23cf6430514704ad4d821fab7b Mon Sep 17 00:00:00 2001 From: kay27 Date: Sat, 17 Jul 2021 03:38:48 +0400 Subject: [PATCH 18/28] Check Nether portal exit before teleporting --- mods/ITEMS/mcl_portals/portal_nether.lua | 37 ++++++++++++++---------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/mods/ITEMS/mcl_portals/portal_nether.lua b/mods/ITEMS/mcl_portals/portal_nether.lua index 3f15a134d..1b673a7c2 100644 --- a/mods/ITEMS/mcl_portals/portal_nether.lua +++ b/mods/ITEMS/mcl_portals/portal_nether.lua @@ -137,19 +137,8 @@ local function find_exit(p, dx, dy, dz) if not p or not p.y or not p.z or not p.x then return end local dx, dy, dz = dx or DISTANCE_MAX, dy or DISTANCE_MAX, dz or DISTANCE_MAX if dx < 1 or dy < 1 or dz < 1 then return false end - - --y values aren't used - local x = floor(p.x) - --local y = floor(p.y) - local z = floor(p.z) - - local x1 = x-dx+1 - --local y1 = y-dy+1 - local z1 = z-dz+1 - - local x2 = x+dx-1 - --local y2 = y+dy-1 - local z2 = z+dz-1 + local x, y, z = floor(p.x), floor(p.y), floor(p.z) + local x1, y1, z1, x2, y2, z2 = x-dx+1, y-dy+1, z-dz+1, x+dx-1, y+dy-1, z+dz-1 local k1x, k2x = floor(x1/256), floor(x2/256) local k1z, k2z = floor(z1/256), floor(z2/256) @@ -170,11 +159,27 @@ local function find_exit(p, dx, dy, dz) end end end - if t and abs(t.x-p.x) <= dx and abs(t.y-p.y) <= dy and abs(t.z-p.z) <= dz then + if t and abs(t.x-x) <= dx and abs(t.y-y) <= dy and abs(t.z-z) <= dz then return t end end +-- This functon searches Nether portal nodes whitin distance specified and checks the node +local function find_exit_with_check(p, dx, dy, dz) + while true do + local pos = find_exit(p, dx, dy, dz) + if not pos then + -- not found: + return + end + if (get_node(pos).name == PORTAL) then + return pos + end + -- I don't know the reason why it can happen, but if we're here, let's log it, remove this record and try again: + log("warning", "[mcl_portals] Found faulty exit from Nether portal at " .. pos_to_string(pos) .. " - removed") + remove_exit(pos) + end +end -- Ping-Pong the coordinate for Fast Travelling, https://git.minetest.land/Wuzzy/MineClone2/issues/795#issuecomment-11058 local function ping_pong(x, m, l1, l2) @@ -458,7 +463,7 @@ local function ecb_scan_area_2(blockpos, action, calls_remaining, param) for _, p in pairs(portals) do add_exit(p) end - local exit = find_exit(pos) + local exit = find_exit_with_check(pos) if exit then finalize_teleport(obj, exit) end @@ -676,7 +681,7 @@ local function teleport_no_delay(obj, pos) name = obj:get_player_name() end - local exit = find_exit(target) + local exit = find_exit_with_check(target) if exit then finalize_teleport(obj, exit) else From b364faa7c7d76370953f798e207837f4e6b7cfab Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 17 Jul 2021 16:22:46 +0200 Subject: [PATCH 19/28] make bucket use 5 lenght raycast --- mods/ITEMS/mcl_buckets/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index f1d131ea2..931214b95 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -85,7 +85,7 @@ local function bucket_raycast(user) --local pos = vector.add(user:get_pos(), user:get_bone_position("Head_Control")) pos.y = pos.y + user:get_properties().eye_height local look_dir = user:get_look_dir() - look_dir = vector.multiply(look_dir, 4) + look_dir = vector.multiply(look_dir, 5) local pos2 = vector.add(pos, look_dir) local ray = raycast(pos, pos2, false, true) From 999b82c94a167cdb62d2894fe45718bd48a91ce9 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Tue, 20 Jul 2021 15:21:07 +0200 Subject: [PATCH 20/28] small documentation graphical improvement --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1b5098a4f..4c9bf3e38 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -52,17 +52,17 @@ Each mod must provide `mod.conf`. Each mod which add API functions should store functions inside a global table named like the mod. Public functions should not use self references but rather just access the table directly. Functions should be defined in this way: -``` +```lua function mcl_xyz.stuff(param) end ``` Insteed of this way: -``` +```lua mcl_xyz.stuff = function(param) end ``` Indentation must be unified, more likely with tabs. Time sensitive mods should make a local copy of most used API functions to improve performances. -``` +```lua local vector = vector local get_node = minetest.get_node ``` From 31d3ea8a871fef4acbab8493d85768ea7884ac76 Mon Sep 17 00:00:00 2001 From: NO11 Date: Tue, 20 Jul 2021 20:09:43 +0000 Subject: [PATCH 21/28] Fix #1801 (add better texture for golden boots) --- .../textures/mcl_armor_inv_boots_gold.png | Bin 167 -> 409 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/mods/ITEMS/mcl_armor/textures/mcl_armor_inv_boots_gold.png b/mods/ITEMS/mcl_armor/textures/mcl_armor_inv_boots_gold.png index dc452d41372344c624d15270867e81ea7551b52a..ef1f9fa87ca43be01bc084da406069ce278d3c1f 100644 GIT binary patch delta 382 zcmV-^0fGLf0ht4kB!32COGiWi{{a60|De66lK=n!32;bRa{vG?BLDy{BLR4&KXw2B z00(qQO+^Rg2NVS)N@!D*zX#WvQEA z04#(nBfex{Rjq`aWmi8Z5*|?Csfm&M27np1J9o)$LRS>Zl1E_v~4!`V2#&%;Q32n c`Ir8}H*o=PdJ9oayZ`_I07*qoM6N<$g80X(CIA2c delta 139 zcmV;60CfME1E&FyB!6y6L_t(|0b>|^;Q#;s_%N*uz|=^*L1E2{L6~|5?CR0_55iDB zhB#gWt}HkG|LS1U|0NYl7zO~vz;Ylp*bIQ#0#bm>0I(cT4PFC4nsFKc#25y^G?Rl- t4M^~)Ar`|7ppFYb4017LDUoUb0H9FFs6zF<5C8xG07*qoLI9vb# From a0d52010bf6dcfe3b7fa1175dc5c76923b515eed Mon Sep 17 00:00:00 2001 From: NO11 Date: Wed, 21 Jul 2021 22:16:37 +0000 Subject: [PATCH 22/28] Fix that aliases attemp to register mineclone:book_enchanted again and again --- mods/HELP/mcl_item_id/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/HELP/mcl_item_id/init.lua b/mods/HELP/mcl_item_id/init.lua index e7772d141..01eb40362 100644 --- a/mods/HELP/mcl_item_id/init.lua +++ b/mods/HELP/mcl_item_id/init.lua @@ -28,7 +28,7 @@ tt.register_snippet(function(itemstring) end end end - minetest.register_alias(new_id, itemstring) + minetest.register_alias_force(new_id, itemstring) if minetest.settings:get_bool("mcl_item_id_debug", true) then return new_id, "#555555" end From fef23d0b6f224ed178d109ec5d74137168119421 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 22 Jul 2021 00:39:05 +0200 Subject: [PATCH 23/28] fix missing depend to `mcl_credits` of `mcl_portals` --- mods/ITEMS/mcl_portals/mod.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_portals/mod.conf b/mods/ITEMS/mcl_portals/mod.conf index d99344a76..610b590c6 100644 --- a/mods/ITEMS/mcl_portals/mod.conf +++ b/mods/ITEMS/mcl_portals/mod.conf @@ -1,4 +1,4 @@ name = mcl_portals description = Adds buildable portals to the Nether and End dimensions. -depends = mcl_nether, mcl_end, mcl_particles, mcl_spawn +depends = mcl_nether, mcl_end, mcl_particles, mcl_spawn, mcl_credits optional_depends = awards, doc From 667ef5cad51684f79debd5a133dc78f3ea29974c Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 22 Jul 2021 00:46:43 +0200 Subject: [PATCH 24/28] cache doc modpath --- mods/ITEMS/mcl_portals/portal_end.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_portals/portal_end.lua b/mods/ITEMS/mcl_portals/portal_end.lua index d591537e1..9f0db352a 100644 --- a/mods/ITEMS/mcl_portals/portal_end.lua +++ b/mods/ITEMS/mcl_portals/portal_end.lua @@ -4,6 +4,8 @@ local table = table local vector = vector local math = math +local has_doc = minetest.get_modpath("doc") + -- Parameters --local SPAWN_MIN = mcl_vars.mg_end_min+70 --local SPAWN_MAX = mcl_vars.mg_end_min+98 @@ -339,7 +341,7 @@ minetest.register_node("mcl_portals:end_portal_frame_eye", { _mcl_hardness = -1, }) -if minetest.get_modpath("doc") then +if has_doc then doc.add_entry_alias("nodes", "mcl_portals:end_portal_frame", "nodes", "mcl_portals:end_portal_frame_eye") end @@ -366,7 +368,7 @@ minetest.override_item("mcl_end:ender_eye", { end minetest.set_node(pointed_thing.under, { name = "mcl_portals:end_portal_frame_eye", param2 = node.param2 }) - if minetest.get_modpath("doc") then + if has_doc then doc.mark_entry_as_revealed(user:get_player_name(), "nodes", "mcl_portals:end_portal_frame") end minetest.sound_play( @@ -381,7 +383,7 @@ minetest.override_item("mcl_end:ender_eye", { -- Epic 'portal open' sound effect that can be heard everywhere minetest.sound_play("mcl_portals_open_end_portal", {gain=0.8}, true) end_portal_area(ppos) - if minetest.get_modpath("doc") then + if has_doc then doc.mark_entry_as_revealed(user:get_player_name(), "nodes", "mcl_portals:portal_end") end end From a44d9643ae8b826f1e5efb67259d6d77320dfade Mon Sep 17 00:00:00 2001 From: NO11 Date: Thu, 22 Jul 2021 19:23:48 +0000 Subject: [PATCH 25/28] Fix several problems in `mcl_item_id` --- mods/HELP/mcl_item_id/init.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mods/HELP/mcl_item_id/init.lua b/mods/HELP/mcl_item_id/init.lua index 01eb40362..3b3128f26 100644 --- a/mods/HELP/mcl_item_id/init.lua +++ b/mods/HELP/mcl_item_id/init.lua @@ -28,8 +28,12 @@ tt.register_snippet(function(itemstring) end end end - minetest.register_alias_force(new_id, itemstring) - if minetest.settings:get_bool("mcl_item_id_debug", true) then + if new_id ~= game .. ":book_enchanted" then + minetest.register_alias_force(new_id, itemstring) + end + if minetest.settings:get_bool("mcl_item_id_debug", false) then return new_id, "#555555" end end) + +minetest.register_alias_force(game .. ":book_enchanted", "mcl_enchanting:book_enchanted") From 016ca1bdbaf8d83679d841dffbe30cfcb8789a89 Mon Sep 17 00:00:00 2001 From: NO11 Date: Thu, 22 Jul 2021 20:11:46 +0000 Subject: [PATCH 26/28] Enable axe override in mcl_copper --- mods/ITEMS/mcl_copper/functions.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_copper/functions.lua b/mods/ITEMS/mcl_copper/functions.lua index 6e36cde1a..c553d5927 100644 --- a/mods/ITEMS/mcl_copper/functions.lua +++ b/mods/ITEMS/mcl_copper/functions.lua @@ -169,8 +169,8 @@ for _, s in pairs(stair_oxidation) do register_oxidation_abm("Copper oxidation", "mcl_stairs:"..s[1].."_copper_"..s[2], "mcl_stairs:"..s[1].."_copper_"..s[3]) end local axes = {"wood", "stone", "iron", "gold", "diamond"} ---[[ + for _, axe in pairs(axes) do register_axe_override(axe) end -]] + From 74449cb75e87c74be5740bd9b130cdb8b223f210 Mon Sep 17 00:00:00 2001 From: NO11 Date: Fri, 23 Jul 2021 16:35:30 +0000 Subject: [PATCH 27/28] Fix #17 (remove FOV after releasing righclick) --- mods/ITEMS/mcl_spyglass/init.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/mods/ITEMS/mcl_spyglass/init.lua b/mods/ITEMS/mcl_spyglass/init.lua index a1f20f7e0..1a1f4529d 100644 --- a/mods/ITEMS/mcl_spyglass/init.lua +++ b/mods/ITEMS/mcl_spyglass/init.lua @@ -43,6 +43,7 @@ local function remove_scope(player) player:hud_remove(spyglass_scope[player]) spyglass_scope[player] = nil player:hud_set_flags({wielditem = true}) + player:set_fov(86.1) end end From 28ee3e66e403670594961e0165cb3fe7879cb163 Mon Sep 17 00:00:00 2001 From: kay27 Date: Sat, 24 Jul 2021 02:24:00 +0400 Subject: [PATCH 28/28] Update version number to 0.71.6 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e81334123..ce924ec58 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # MineClone 5 -Version: 0.71.5 +Version: 0.71.6 MineClone 5 is a fork of MineClone 2 with different workflow: * No Minecraft version limitation, target version is Latest Java Edition