From a960bf2e8e3da2dd4086a511f85aec97694d23c7 Mon Sep 17 00:00:00 2001 From: Dehydrate6684 Date: Sat, 16 Sep 2023 13:16:49 +0800 Subject: [PATCH 1/8] Update trapdoor climbable behavior --- mods/ITEMS/mcl_core/nodes_climb.lua | 48 ++++++++++++++++++++++++- mods/ITEMS/mcl_doors/api_trapdoors.lua | 50 +++++++++++++++++++++++--- 2 files changed, 93 insertions(+), 5 deletions(-) diff --git a/mods/ITEMS/mcl_core/nodes_climb.lua b/mods/ITEMS/mcl_core/nodes_climb.lua index 33a34f899..1e94a37dc 100644 --- a/mods/ITEMS/mcl_core/nodes_climb.lua +++ b/mods/ITEMS/mcl_core/nodes_climb.lua @@ -33,7 +33,14 @@ minetest.register_node("mcl_core:ladder", { wall_side = { -0.5, -0.5, -0.5, -7/16, 0.5, 0.5 }, }, stack_max = 64, - groups = {handy=1,axey=1, attached_node=1, deco_block=1, dig_by_piston=1}, + groups = { + handy = 1, + axey = 1, + attached_node = 1, + deco_block = 1, + dig_by_piston = 1, + ladder = 1 + }, sounds = mcl_sounds.node_sound_wood_defaults(), node_placement_prediction = "", -- Restrict placement of ladders @@ -80,7 +87,46 @@ minetest.register_node("mcl_core:ladder", { end return itemstack end, + after_destruct = function(pos, oldnode) + local pos_above = vector.add(pos, {x = 0, y = 1, z = 0 }) + local node_above = minetest.get_node_or_nil(pos_above) + if node_above then + local is_trapdoor = minetest.get_item_group(node_above.name, "trapdoor") + + -- If node above is an opened trapdoor + if is_trapdoor == 2 then + local above_def = minetest.registered_nodes[node_above.name] + if above_def._other then + minetest.swap_node(pos_above, { + name = above_def._other, + param1 = node_above.param1, + param2 = node_above.param2, + }) + end + end + end + end, + after_place_node = function(pos, oldnode) + local pos_above = vector.add(pos, {x = 0, y = 1, z = 0 }) + local node_above = minetest.get_node_or_nil(pos_above) + + if node_above then + local is_trapdoor = minetest.get_item_group(node_above.name, "trapdoor") + + -- If node above is an opened trapdoor + if is_trapdoor == 2 then + local above_def = minetest.registered_nodes[node_above.name] + if above_def._other then + minetest.swap_node(pos_above, { + name = above_def._other, + param1 = node_above.param1, + param2 = node_above.param2, + }) + end + end + end + end, _mcl_blast_resistance = 0.4, _mcl_hardness = 0.4, on_rotate = rotate_climbable, diff --git a/mods/ITEMS/mcl_doors/api_trapdoors.lua b/mods/ITEMS/mcl_doors/api_trapdoors.lua index 5b7a0e5d0..c42ffd7c3 100644 --- a/mods/ITEMS/mcl_doors/api_trapdoors.lua +++ b/mods/ITEMS/mcl_doors/api_trapdoors.lua @@ -72,7 +72,21 @@ function mcl_doors:register_trapdoor(name, def) -- Open else minetest.sound_play(def.sound_open, {pos = pos, gain = 0.3, max_hear_distance = 16}, true) - tmp_node = {name=name.."_open", param1=me.param1, param2=me.param2} + + local bottom_node = minetest.get_node_or_nil(vector.subtract(pos, { x = 0, y = 1, z = 0 })) + local name_end = "_open" + + -- Checking if there is something underneath the trapdoor + if bottom_node then + local bottom_def = minetest.registered_nodes[bottom_node.name] + local trapdoor = minetest.get_item_group(bottom_node.name, "trapdoor") + + -- Changing trapdoor into a ladder if bottom node is climbable and not a trapdoor + if trapdoor ~= 2 and bottom_def.climbable then + name_end = "_ladder" + end + end + tmp_node = {name=name..name_end, param1=me.param1, param2=me.param2} end minetest.set_node(pos, tmp_node) end @@ -193,6 +207,7 @@ function mcl_doors:register_trapdoor(name, def) groups_open.trapdoor = 2 groups_open.not_in_creative_inventory = 1 + -- Non-climbable opened minetest.register_node(name.."_open", { drawtype = "nodebox", tiles = tiles_open, @@ -200,9 +215,35 @@ function mcl_doors:register_trapdoor(name, def) is_ground_content = false, paramtype = "light", paramtype2 = "facedir", - -- TODO: Implement Minecraft behaviour: Climbable if directly above - -- ladder w/ matching orientation. - -- Current behavour: Always climbable + sunlight_propagates = true, + pointable = true, + groups = groups_open, + _mcl_hardness = def._mcl_hardness, + _mcl_blast_resistance = def._mcl_blast_resistance, + sounds = def.sounds, + drop = name, + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, 5/16, 0.5, 0.5, 0.5} + }, + on_rightclick = on_rightclick, + mesecons = {effector = { + action_off = (function(pos, node) + punch(pos) + end), + }}, + on_rotate = on_rotate, + _other = name .. "_ladder" + }) + + -- Climbable opened + minetest.register_node(name.."_ladder", { + drawtype = "nodebox", + tiles = tiles_open, + use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, + is_ground_content = false, + paramtype = "light", + paramtype2 = "facedir", climbable = true, sunlight_propagates = true, pointable = true, @@ -222,6 +263,7 @@ function mcl_doors:register_trapdoor(name, def) end), }}, on_rotate = on_rotate, + _other = name .. "_open" }) if minetest.get_modpath("doc") then From e6653b78eed3af654039234fe8d974be63360e2d Mon Sep 17 00:00:00 2001 From: Dehydrate6684 Date: Sun, 17 Sep 2023 17:03:04 +0800 Subject: [PATCH 2/8] Added directional checks --- mods/ITEMS/mcl_core/nodes_climb.lua | 96 ++++++++++++++++---------- mods/ITEMS/mcl_doors/api_trapdoors.lua | 41 ++++++++--- 2 files changed, 89 insertions(+), 48 deletions(-) diff --git a/mods/ITEMS/mcl_core/nodes_climb.lua b/mods/ITEMS/mcl_core/nodes_climb.lua index 1e94a37dc..ca45a39f5 100644 --- a/mods/ITEMS/mcl_core/nodes_climb.lua +++ b/mods/ITEMS/mcl_core/nodes_climb.lua @@ -11,6 +11,59 @@ local function rotate_climbable(pos, node, user, mode) return false end +---Checks the direction (param2) of a ladder and a trapdoor and determine if they are +---facing the same direction. +--- +---@param ladder integer The param2 value of the ladder. +---@param trapdoor integer The param2 value of the trapdoor. +---@return boolean If the ladder and trapdoor are in the same direction. +local function check_direction(ladder, trapdoor) + local convert_table = {}; + convert_table[2] = { 1, 23 } + convert_table[3] = { 3, 21 } + convert_table[4] = { 0, 20 } + convert_table[5] = { 2, 22 } + + local conversion = convert_table[ladder]; + if conversion == nil then + return false + elseif conversion[1] == trapdoor or conversion[2] == trapdoor then + return true + end + + return false +end + +---Updates the trapdoor above (if any). +--- +---@param pos mt.Vector The position of the ladder. +---@param ladder integer The param2 value of the ladder. +---@param event "place" | "destruct" The place or destruct event. +local function update_trapdoor(pos, ladder, event) + local top_pos = vector.add(pos, { x = 0, y = 1, z = 0 }) + local top_node = minetest.get_node_or_nil(top_pos) + if top_node then + local new_name = top_node.name + if event == "place" then + new_name = string.gsub(new_name, "open$", "ladder") + elseif event == "destruct" then + new_name = string.gsub(new_name, "ladder$", "open") + end + + local is_trapdoor = minetest.get_item_group(top_node.name, "trapdoor") + + -- If node above is an opened trapdoor + if is_trapdoor == 2 and check_direction(ladder, top_node.param2) then + minetest.swap_node(top_pos, { + name = new_name, + param1 = top_node.param1, + param2 = top_node.param2, + }) + end + end +end + +-- TODO: Move ladders into their own API. minetest.register_node("mcl_core:ladder", { description = S("Ladder"), _doc_items_longdesc = S("A piece of ladder which allows you to climb vertically. Ladders can only be placed on the side of solid blocks and not on glass, leaves, ice, slabs, glowstone, nor sea lanterns."), @@ -87,45 +140,12 @@ minetest.register_node("mcl_core:ladder", { end return itemstack end, - after_destruct = function(pos, oldnode) - local pos_above = vector.add(pos, {x = 0, y = 1, z = 0 }) - local node_above = minetest.get_node_or_nil(pos_above) - - if node_above then - local is_trapdoor = minetest.get_item_group(node_above.name, "trapdoor") - - -- If node above is an opened trapdoor - if is_trapdoor == 2 then - local above_def = minetest.registered_nodes[node_above.name] - if above_def._other then - minetest.swap_node(pos_above, { - name = above_def._other, - param1 = node_above.param1, - param2 = node_above.param2, - }) - end - end - end + after_destruct = function(pos, old) + update_trapdoor(pos, old.param2, "destruct") end, - after_place_node = function(pos, oldnode) - local pos_above = vector.add(pos, {x = 0, y = 1, z = 0 }) - local node_above = minetest.get_node_or_nil(pos_above) - - if node_above then - local is_trapdoor = minetest.get_item_group(node_above.name, "trapdoor") - - -- If node above is an opened trapdoor - if is_trapdoor == 2 then - local above_def = minetest.registered_nodes[node_above.name] - if above_def._other then - minetest.swap_node(pos_above, { - name = above_def._other, - param1 = node_above.param1, - param2 = node_above.param2, - }) - end - end - end + after_place_node = function(pos) + local me = minetest.get_node(pos) + update_trapdoor(pos, me.param2, "place") end, _mcl_blast_resistance = 0.4, _mcl_hardness = 0.4, diff --git a/mods/ITEMS/mcl_doors/api_trapdoors.lua b/mods/ITEMS/mcl_doors/api_trapdoors.lua index c42ffd7c3..455534878 100644 --- a/mods/ITEMS/mcl_doors/api_trapdoors.lua +++ b/mods/ITEMS/mcl_doors/api_trapdoors.lua @@ -48,6 +48,29 @@ if minetest.get_modpath("screwdriver") then end end +---Checks the direction (param2) of a ladder and a trapdoor and determine if they are +---facing the same direction. +--- +---@param ladder integer The param2 value of the ladder. +---@param trapdoor integer The param2 value of the trapdoor. +---@return boolean If the ladder and trapdoor are in the same direction. +function check_direction(ladder, trapdoor) + local convert_table = {}; + convert_table[2] = { 1, 23 } + convert_table[3] = { 3, 21 } + convert_table[4] = { 0, 20 } + convert_table[5] = { 2, 22 } + + local conversion = convert_table[ladder]; + if conversion == nil then + return false + elseif conversion[1] == trapdoor or conversion[2] == trapdoor then + return true + end + + return false +end + function mcl_doors:register_trapdoor(name, def) local groups = table.copy(def.groups) if groups == nil then @@ -67,26 +90,24 @@ function mcl_doors:register_trapdoor(name, def) local tmp_node -- Close if minetest.get_item_group(me.name, "trapdoor") == 2 then - minetest.sound_play(def.sound_close, {pos = pos, gain = 0.3, max_hear_distance = 16}, true) - tmp_node = {name=name, param1=me.param1, param2=me.param2} - -- Open + minetest.sound_play(def.sound_close, { pos = pos, gain = 0.3, max_hear_distance = 16 }, true) + tmp_node = { name = name, param1 = me.param1, param2 = me.param2 } + -- Open else - minetest.sound_play(def.sound_open, {pos = pos, gain = 0.3, max_hear_distance = 16}, true) + minetest.sound_play(def.sound_open, { pos = pos, gain = 0.3, max_hear_distance = 16 }, true) local bottom_node = minetest.get_node_or_nil(vector.subtract(pos, { x = 0, y = 1, z = 0 })) local name_end = "_open" -- Checking if there is something underneath the trapdoor if bottom_node then - local bottom_def = minetest.registered_nodes[bottom_node.name] - local trapdoor = minetest.get_item_group(bottom_node.name, "trapdoor") - - -- Changing trapdoor into a ladder if bottom node is climbable and not a trapdoor - if trapdoor ~= 2 and bottom_def.climbable then + local is_ladder = minetest.get_item_group(bottom_node.name, "ladder") + local same_direction = check_direction(bottom_node.param2, me.param2) + if is_ladder > 0 and same_direction then name_end = "_ladder" end end - tmp_node = {name=name..name_end, param1=me.param1, param2=me.param2} + tmp_node = { name = name .. name_end, param1 = me.param1, param2 = me.param2 } end minetest.set_node(pos, tmp_node) end From cc217d008985e4a65a91305c68ace348c558f6ca Mon Sep 17 00:00:00 2001 From: Dehydrate6684 Date: Sun, 17 Sep 2023 17:13:50 +0800 Subject: [PATCH 3/8] Removed unnessary node definitions --- mods/ITEMS/mcl_doors/api_trapdoors.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/mods/ITEMS/mcl_doors/api_trapdoors.lua b/mods/ITEMS/mcl_doors/api_trapdoors.lua index 455534878..1ea45abbf 100644 --- a/mods/ITEMS/mcl_doors/api_trapdoors.lua +++ b/mods/ITEMS/mcl_doors/api_trapdoors.lua @@ -254,7 +254,6 @@ function mcl_doors:register_trapdoor(name, def) end), }}, on_rotate = on_rotate, - _other = name .. "_ladder" }) -- Climbable opened @@ -284,7 +283,6 @@ function mcl_doors:register_trapdoor(name, def) end), }}, on_rotate = on_rotate, - _other = name .. "_open" }) if minetest.get_modpath("doc") then From 0c48a46f7cf9a24745e56873f6081db52afec9e6 Mon Sep 17 00:00:00 2001 From: Dehydrate6684 Date: Mon, 9 Oct 2023 13:55:08 +0800 Subject: [PATCH 4/8] Updated code based on reviews --- mods/ITEMS/mcl_core/nodes_climb.lua | 72 +++++++++++-------- mods/ITEMS/mcl_doors/api_trapdoors.lua | 98 +++++++++++--------------- 2 files changed, 83 insertions(+), 87 deletions(-) diff --git a/mods/ITEMS/mcl_core/nodes_climb.lua b/mods/ITEMS/mcl_core/nodes_climb.lua index ca45a39f5..7bad7b318 100644 --- a/mods/ITEMS/mcl_core/nodes_climb.lua +++ b/mods/ITEMS/mcl_core/nodes_climb.lua @@ -17,15 +17,17 @@ end ---@param ladder integer The param2 value of the ladder. ---@param trapdoor integer The param2 value of the trapdoor. ---@return boolean If the ladder and trapdoor are in the same direction. -local function check_direction(ladder, trapdoor) - local convert_table = {}; - convert_table[2] = { 1, 23 } - convert_table[3] = { 3, 21 } - convert_table[4] = { 0, 20 } - convert_table[5] = { 2, 22 } +function mcl_core.check_direction(ladder, trapdoor) + local convert_table = { + nil, + { 1, 23 }, + { 3, 21 }, + { 0, 20 }, + { 2, 22 }, + } local conversion = convert_table[ladder]; - if conversion == nil then + if not conversion then return false elseif conversion[1] == trapdoor or conversion[2] == trapdoor then return true @@ -42,7 +44,10 @@ end local function update_trapdoor(pos, ladder, event) local top_pos = vector.add(pos, { x = 0, y = 1, z = 0 }) local top_node = minetest.get_node_or_nil(top_pos) - if top_node then + + + if top_node and minetest.get_item_group(top_node.name, "trapdoor") == 2 + and mcl_core.check_direction(ladder, top_node.param2) then local new_name = top_node.name if event == "place" then new_name = string.gsub(new_name, "open$", "ladder") @@ -50,26 +55,23 @@ local function update_trapdoor(pos, ladder, event) new_name = string.gsub(new_name, "ladder$", "open") end - local is_trapdoor = minetest.get_item_group(top_node.name, "trapdoor") - -- If node above is an opened trapdoor - if is_trapdoor == 2 and check_direction(ladder, top_node.param2) then - minetest.swap_node(top_pos, { - name = new_name, - param1 = top_node.param1, - param2 = top_node.param2, - }) - end + minetest.swap_node(top_pos, { + name = new_name, + param1 = top_node.param1, + param2 = top_node.param2, + }) end end -- TODO: Move ladders into their own API. minetest.register_node("mcl_core:ladder", { description = S("Ladder"), - _doc_items_longdesc = S("A piece of ladder which allows you to climb vertically. Ladders can only be placed on the side of solid blocks and not on glass, leaves, ice, slabs, glowstone, nor sea lanterns."), + _doc_items_longdesc = S( + "A piece of ladder which allows you to climb vertically. Ladders can only be placed on the side of solid blocks and not on glass, leaves, ice, slabs, glowstone, nor sea lanterns."), drawtype = "signlike", is_ground_content = false, - tiles = {"default_ladder.png"}, + tiles = { "default_ladder.png" }, inventory_image = "default_ladder.png", wield_image = "default_ladder.png", paramtype = "light", @@ -79,11 +81,11 @@ minetest.register_node("mcl_core:ladder", { climbable = true, node_box = { type = "wallmounted", - wall_side = { -0.5, -0.5, -0.5, -7/16, 0.5, 0.5 }, + wall_side = { -0.5, -0.5, -0.5, -7 / 16, 0.5, 0.5 }, }, selection_box = { type = "wallmounted", - wall_side = { -0.5, -0.5, -0.5, -7/16, 0.5, 0.5 }, + wall_side = { -0.5, -0.5, -0.5, -7 / 16, 0.5, 0.5 }, }, stack_max = 64, groups = { @@ -113,7 +115,7 @@ minetest.register_node("mcl_core:ladder", { -- Don't allow to place the ladder at particular nodes if (groups and (groups.glass or groups.leaves or groups.slab)) or - node.name == "mcl_core:ladder" or node.name == "mcl_core:ice" or node.name == "mcl_nether:glowstone" or node.name == "mcl_ocean:sea_lantern" then + node.name == "mcl_core:ladder" or node.name == "mcl_core:ice" or node.name == "mcl_nether:glowstone" or node.name == "mcl_ocean:sea_lantern" then return itemstack end @@ -135,7 +137,7 @@ minetest.register_node("mcl_core:ladder", { if success then if idef.sounds and idef.sounds.place then - minetest.sound_play(idef.sounds.place, {pos=above, gain=1}, true) + minetest.sound_play(idef.sounds.place, { pos = above, gain = 1 }, true) end end return itemstack @@ -155,9 +157,10 @@ minetest.register_node("mcl_core:ladder", { minetest.register_node("mcl_core:vine", { description = S("Vines"), - _doc_items_longdesc = S("Vines are climbable blocks which can be placed on the sides of solid full-cube blocks. Vines slowly grow and spread."), + _doc_items_longdesc = S( + "Vines are climbable blocks which can be placed on the sides of solid full-cube blocks. Vines slowly grow and spread."), drawtype = "signlike", - tiles = {"mcl_core_vine.png"}, + tiles = { "mcl_core_vine.png" }, color = "#48B518", inventory_image = "mcl_core_vine.png", wield_image = "mcl_core_vine.png", @@ -173,9 +176,18 @@ minetest.register_node("mcl_core:vine", { }, stack_max = 64, groups = { - handy = 1, axey = 1, shearsy = 1, swordy = 1, deco_block = 1, - dig_by_piston = 1, destroy_by_lava_flow = 1, compostability = 50, - flammable = 2, fire_encouragement = 15, fire_flammability = 100, foliage_palette_wallmounted = 1 + handy = 1, + axey = 1, + shearsy = 1, + swordy = 1, + deco_block = 1, + dig_by_piston = 1, + destroy_by_lava_flow = 1, + compostability = 50, + flammable = 2, + fire_encouragement = 15, + fire_flammability = 100, + foliage_palette_wallmounted = 1 }, sounds = mcl_sounds.node_sound_leaves_defaults(), drop = "", @@ -217,7 +229,7 @@ minetest.register_node("mcl_core:vine", { if success then if idef.sounds and idef.sounds.place then - minetest.sound_play(idef.sounds.place, {pos=above, gain=1}, true) + minetest.sound_play(idef.sounds.place, { pos = above, gain = 1 }, true) end end return itemstack @@ -240,7 +252,7 @@ minetest.register_node("mcl_core:vine", { -- If dug, also dig a “dependant” vine below it. -- A vine is dependant if it hangs from this node and has no supporting block. on_dig = function(pos, node, digger) - local below = vector.offset(pos,0,-1,0) + local below = vector.offset(pos, 0, -1, 0) local belownode = minetest.get_node(below) minetest.node_dig(pos, node, digger) if belownode.name == node.name and (not mcl_core.check_vines_supported(below, belownode)) then diff --git a/mods/ITEMS/mcl_doors/api_trapdoors.lua b/mods/ITEMS/mcl_doors/api_trapdoors.lua index 1ea45abbf..61530ab98 100644 --- a/mods/ITEMS/mcl_doors/api_trapdoors.lua +++ b/mods/ITEMS/mcl_doors/api_trapdoors.lua @@ -48,29 +48,6 @@ if minetest.get_modpath("screwdriver") then end end ----Checks the direction (param2) of a ladder and a trapdoor and determine if they are ----facing the same direction. ---- ----@param ladder integer The param2 value of the ladder. ----@param trapdoor integer The param2 value of the trapdoor. ----@return boolean If the ladder and trapdoor are in the same direction. -function check_direction(ladder, trapdoor) - local convert_table = {}; - convert_table[2] = { 1, 23 } - convert_table[3] = { 3, 21 } - convert_table[4] = { 0, 20 } - convert_table[5] = { 2, 22 } - - local conversion = convert_table[ladder]; - if conversion == nil then - return false - elseif conversion[1] == trapdoor or conversion[2] == trapdoor then - return true - end - - return false -end - function mcl_doors:register_trapdoor(name, def) local groups = table.copy(def.groups) if groups == nil then @@ -102,7 +79,7 @@ function mcl_doors:register_trapdoor(name, def) -- Checking if there is something underneath the trapdoor if bottom_node then local is_ladder = minetest.get_item_group(bottom_node.name, "ladder") - local same_direction = check_direction(bottom_node.param2, me.param2) + local same_direction = mcl_core.check_direction(bottom_node.param2, me.param2) if is_ladder > 0 and same_direction then name_end = "_ladder" end @@ -124,20 +101,22 @@ function mcl_doors:register_trapdoor(name, def) longdesc = def._doc_items_longdesc if not longdesc then if def.only_redstone_can_open then - longdesc = S("Trapdoors are horizontal barriers which can be opened or closed and climbed like a ladder when open. They occupy the upper or lower part of a block, depending on how they have been placed. This trapdoor can only be opened or closed by redstone power.") + longdesc = S( + "Trapdoors are horizontal barriers which can be opened or closed and climbed like a ladder when open. They occupy the upper or lower part of a block, depending on how they have been placed. This trapdoor can only be opened or closed by redstone power.") else - longdesc = S("Trapdoors are horizontal barriers which can be opened or closed and climbed like a ladder when open. They occupy the upper or lower part of a block, depending on how they have been placed. This trapdoor can be opened or closed by hand or redstone power.") + longdesc = S( + "Trapdoors are horizontal barriers which can be opened or closed and climbed like a ladder when open. They occupy the upper or lower part of a block, depending on how they have been placed. This trapdoor can be opened or closed by hand or redstone power.") end end usagehelp = def._doc_items_usagehelp if not usagehelp and not def.only_redstone_can_open then usagehelp = S("To open or close this trapdoor, rightclick it or send a redstone signal to it.") end - if def.only_redstone_can_open then - tt_help = S("Openable by redstone power") - else - tt_help = S("Openable by players and redstone power") - end + if def.only_redstone_can_open then + tt_help = S("Openable by redstone power") + else + tt_help = S("Openable by players and redstone power") + end -- Closed trapdoor @@ -163,7 +142,7 @@ function mcl_doors:register_trapdoor(name, def) _doc_items_usagehelp = usagehelp, drawtype = "nodebox", tiles = tiles_closed, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, + use_texture_alpha = "clip", inventory_image = def.inventory_image, wield_image = def.wield_image, is_ground_content = false, @@ -178,13 +157,15 @@ function mcl_doors:register_trapdoor(name, def) node_box = { type = "fixed", fixed = { - {-8/16, -8/16, -8/16, 8/16, -5/16, 8/16},}, + { -8 / 16, -8 / 16, -8 / 16, 8 / 16, -5 / 16, 8 / 16 }, }, + }, + mesecons = { + effector = { + action_on = (function(pos, node) + punch(pos) + end), + } }, - mesecons = {effector = { - action_on = (function(pos, node) - punch(pos) - end), - }}, on_place = function(itemstack, placer, pointed_thing) local p0 = pointed_thing.under local p1 = pointed_thing.above @@ -199,7 +180,7 @@ function mcl_doors:register_trapdoor(name, def) --local origname = itemstack:get_name() if p0.y - 1 == p1.y or (fpos > 0 and fpos < 0.5) - or (fpos < -0.5 and fpos > -0.999999999) then + or (fpos < -0.5 and fpos > -0.999999999) then param2 = param2 + 20 if param2 == 21 then param2 = 23 @@ -229,10 +210,10 @@ function mcl_doors:register_trapdoor(name, def) groups_open.trapdoor = 2 groups_open.not_in_creative_inventory = 1 -- Non-climbable opened - minetest.register_node(name.."_open", { + minetest.register_node(name .. "_open", { drawtype = "nodebox", tiles = tiles_open, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, + use_texture_alpha = "clip", is_ground_content = false, paramtype = "light", paramtype2 = "facedir", @@ -245,22 +226,24 @@ function mcl_doors:register_trapdoor(name, def) drop = name, node_box = { type = "fixed", - fixed = {-0.5, -0.5, 5/16, 0.5, 0.5, 0.5} + fixed = { -0.5, -0.5, 5 / 16, 0.5, 0.5, 0.5 } }, on_rightclick = on_rightclick, - mesecons = {effector = { - action_off = (function(pos, node) - punch(pos) - end), - }}, + mesecons = { + effector = { + action_off = (function(pos, node) + punch(pos) + end), + } + }, on_rotate = on_rotate, }) -- Climbable opened - minetest.register_node(name.."_ladder", { + minetest.register_node(name .. "_ladder", { drawtype = "nodebox", tiles = tiles_open, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, + use_texture_alpha = "clip", is_ground_content = false, paramtype = "light", paramtype2 = "facedir", @@ -274,19 +257,20 @@ function mcl_doors:register_trapdoor(name, def) drop = name, node_box = { type = "fixed", - fixed = {-0.5, -0.5, 5/16, 0.5, 0.5, 0.5} + fixed = { -0.5, -0.5, 5 / 16, 0.5, 0.5, 0.5 } }, on_rightclick = on_rightclick, - mesecons = {effector = { - action_off = (function(pos, node) - punch(pos) - end), - }}, + mesecons = { + effector = { + action_off = (function(pos, node) + punch(pos) + end), + } + }, on_rotate = on_rotate, }) if minetest.get_modpath("doc") then - doc.add_entry_alias("nodes", name, "nodes", name.."_open") + doc.add_entry_alias("nodes", name, "nodes", name .. "_open") end - end From 23468cc2ddeb85dcdf496debae3380441b9ba6db Mon Sep 17 00:00:00 2001 From: Dehydrate6684 Date: Tue, 10 Oct 2023 09:39:16 +0800 Subject: [PATCH 5/8] Used vector.offset instead of add/subtract --- mods/ITEMS/mcl_core/nodes_climb.lua | 2 +- mods/ITEMS/mcl_doors/api_trapdoors.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_core/nodes_climb.lua b/mods/ITEMS/mcl_core/nodes_climb.lua index 7bad7b318..81022bbb3 100644 --- a/mods/ITEMS/mcl_core/nodes_climb.lua +++ b/mods/ITEMS/mcl_core/nodes_climb.lua @@ -42,7 +42,7 @@ end ---@param ladder integer The param2 value of the ladder. ---@param event "place" | "destruct" The place or destruct event. local function update_trapdoor(pos, ladder, event) - local top_pos = vector.add(pos, { x = 0, y = 1, z = 0 }) + local top_pos = vector.offset(pos, 0, 1, 0) local top_node = minetest.get_node_or_nil(top_pos) diff --git a/mods/ITEMS/mcl_doors/api_trapdoors.lua b/mods/ITEMS/mcl_doors/api_trapdoors.lua index 61530ab98..17765f27e 100644 --- a/mods/ITEMS/mcl_doors/api_trapdoors.lua +++ b/mods/ITEMS/mcl_doors/api_trapdoors.lua @@ -73,7 +73,7 @@ function mcl_doors:register_trapdoor(name, def) else minetest.sound_play(def.sound_open, { pos = pos, gain = 0.3, max_hear_distance = 16 }, true) - local bottom_node = minetest.get_node_or_nil(vector.subtract(pos, { x = 0, y = 1, z = 0 })) + local bottom_node = minetest.get_node_or_nil(vector.offset(pos, 0, -1, 0)) local name_end = "_open" -- Checking if there is something underneath the trapdoor From b320d008cad45df0578c0047699c3a55e08f12a4 Mon Sep 17 00:00:00 2001 From: Dehydrate6684 Date: Wed, 18 Oct 2023 08:04:54 +0800 Subject: [PATCH 6/8] Unhardcoded nil --- mods/ITEMS/mcl_core/nodes_climb.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_core/nodes_climb.lua b/mods/ITEMS/mcl_core/nodes_climb.lua index 81022bbb3..c1514926f 100644 --- a/mods/ITEMS/mcl_core/nodes_climb.lua +++ b/mods/ITEMS/mcl_core/nodes_climb.lua @@ -19,14 +19,13 @@ end ---@return boolean If the ladder and trapdoor are in the same direction. function mcl_core.check_direction(ladder, trapdoor) local convert_table = { - nil, { 1, 23 }, { 3, 21 }, { 0, 20 }, { 2, 22 }, } - local conversion = convert_table[ladder]; + local conversion = convert_table[ladder - 1]; if not conversion then return false elseif conversion[1] == trapdoor or conversion[2] == trapdoor then From 9b2b8ee56e5ea643b3dca671034af980a365da5d Mon Sep 17 00:00:00 2001 From: Dehydrate6684 Date: Sun, 5 Nov 2023 14:06:53 +0800 Subject: [PATCH 7/8] Removed direction checks --- mods/ITEMS/mcl_core/nodes_climb.lua | 36 +++----------------------- mods/ITEMS/mcl_doors/api_trapdoors.lua | 3 +-- 2 files changed, 5 insertions(+), 34 deletions(-) diff --git a/mods/ITEMS/mcl_core/nodes_climb.lua b/mods/ITEMS/mcl_core/nodes_climb.lua index c1514926f..609dd3cb9 100644 --- a/mods/ITEMS/mcl_core/nodes_climb.lua +++ b/mods/ITEMS/mcl_core/nodes_climb.lua @@ -11,42 +11,15 @@ local function rotate_climbable(pos, node, user, mode) return false end ----Checks the direction (param2) of a ladder and a trapdoor and determine if they are ----facing the same direction. ---- ----@param ladder integer The param2 value of the ladder. ----@param trapdoor integer The param2 value of the trapdoor. ----@return boolean If the ladder and trapdoor are in the same direction. -function mcl_core.check_direction(ladder, trapdoor) - local convert_table = { - { 1, 23 }, - { 3, 21 }, - { 0, 20 }, - { 2, 22 }, - } - - local conversion = convert_table[ladder - 1]; - if not conversion then - return false - elseif conversion[1] == trapdoor or conversion[2] == trapdoor then - return true - end - - return false -end - ---Updates the trapdoor above (if any). --- ---@param pos mt.Vector The position of the ladder. ----@param ladder integer The param2 value of the ladder. ---@param event "place" | "destruct" The place or destruct event. -local function update_trapdoor(pos, ladder, event) +local function update_trapdoor(pos, event) local top_pos = vector.offset(pos, 0, 1, 0) local top_node = minetest.get_node_or_nil(top_pos) - - if top_node and minetest.get_item_group(top_node.name, "trapdoor") == 2 - and mcl_core.check_direction(ladder, top_node.param2) then + if top_node and minetest.get_item_group(top_node.name, "trapdoor") == 2 then local new_name = top_node.name if event == "place" then new_name = string.gsub(new_name, "open$", "ladder") @@ -142,11 +115,10 @@ minetest.register_node("mcl_core:ladder", { return itemstack end, after_destruct = function(pos, old) - update_trapdoor(pos, old.param2, "destruct") + update_trapdoor(pos, "destruct") end, after_place_node = function(pos) - local me = minetest.get_node(pos) - update_trapdoor(pos, me.param2, "place") + update_trapdoor(pos, "place") end, _mcl_blast_resistance = 0.4, _mcl_hardness = 0.4, diff --git a/mods/ITEMS/mcl_doors/api_trapdoors.lua b/mods/ITEMS/mcl_doors/api_trapdoors.lua index 17765f27e..8bbefdda3 100644 --- a/mods/ITEMS/mcl_doors/api_trapdoors.lua +++ b/mods/ITEMS/mcl_doors/api_trapdoors.lua @@ -79,8 +79,7 @@ function mcl_doors:register_trapdoor(name, def) -- Checking if there is something underneath the trapdoor if bottom_node then local is_ladder = minetest.get_item_group(bottom_node.name, "ladder") - local same_direction = mcl_core.check_direction(bottom_node.param2, me.param2) - if is_ladder > 0 and same_direction then + if is_ladder > 0 then name_end = "_ladder" end end From e5a260b56304e5cd959c54879c87728a86df8ef7 Mon Sep 17 00:00:00 2001 From: Dehydrate6684 Date: Sun, 5 Nov 2023 14:10:58 +0800 Subject: [PATCH 8/8] Added vines and skulk vines to ladder group --- mods/ITEMS/mcl_core/nodes_climb.lua | 15 +++++++++++---- mods/ITEMS/mcl_sculk/init.lua | 18 ++++++++++++++++-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/mods/ITEMS/mcl_core/nodes_climb.lua b/mods/ITEMS/mcl_core/nodes_climb.lua index 609dd3cb9..0de0e9abd 100644 --- a/mods/ITEMS/mcl_core/nodes_climb.lua +++ b/mods/ITEMS/mcl_core/nodes_climb.lua @@ -15,7 +15,7 @@ end --- ---@param pos mt.Vector The position of the ladder. ---@param event "place" | "destruct" The place or destruct event. -local function update_trapdoor(pos, event) +function mcl_core.update_trapdoor(pos, event) local top_pos = vector.offset(pos, 0, 1, 0) local top_node = minetest.get_node_or_nil(top_pos) @@ -115,10 +115,10 @@ minetest.register_node("mcl_core:ladder", { return itemstack end, after_destruct = function(pos, old) - update_trapdoor(pos, "destruct") + mcl_core.update_trapdoor(pos, "destruct") end, after_place_node = function(pos) - update_trapdoor(pos, "place") + mcl_core.update_trapdoor(pos, "place") end, _mcl_blast_resistance = 0.4, _mcl_hardness = 0.4, @@ -158,7 +158,8 @@ minetest.register_node("mcl_core:vine", { flammable = 2, fire_encouragement = 15, fire_flammability = 100, - foliage_palette_wallmounted = 1 + foliage_palette_wallmounted = 1, + ladder = 1 }, sounds = mcl_sounds.node_sound_leaves_defaults(), drop = "", @@ -230,6 +231,12 @@ minetest.register_node("mcl_core:vine", { minetest.registered_nodes[node.name].on_dig(below, node, digger) end end, + after_destruct = function(pos, old) + mcl_core.update_trapdoor(pos, "destruct") + end, + after_place_node = function(pos) + mcl_core.update_trapdoor(pos, "place") + end, _mcl_blast_resistance = 0.2, diff --git a/mods/ITEMS/mcl_sculk/init.lua b/mods/ITEMS/mcl_sculk/init.lua index b2ef04152..4af60178e 100644 --- a/mods/ITEMS/mcl_sculk/init.lua +++ b/mods/ITEMS/mcl_sculk/init.lua @@ -215,9 +215,23 @@ minetest.register_node("mcl_sculk:vein", { type = "wallmounted", }, groups = { - handy = 1, axey = 1, shearsy = 1, swordy = 1, deco_block = 1, - dig_by_piston = 1, destroy_by_lava_flow = 1, sculk = 1, dig_by_water = 1, + handy = 1, + axey = 1, + shearsy = 1, + swordy = 1, + deco_block = 1, + dig_by_piston = 1, + destroy_by_lava_flow = 1, + sculk = 1, + dig_by_water = 1, + ladder = 1 }, + after_destruct = function(pos, old) + mcl_core.update_trapdoor(pos, "destruct") + end, + after_place_node = function(pos) + mcl_core.update_trapdoor(pos, "place") + end, sounds = sounds, drop = "", _mcl_shears_drop = true,