Refactor ladders
parent
e1014ae701
commit
f503975cd0
|
@ -183,6 +183,97 @@ function default.register_fence(name, def)
|
|||
minetest.register_node(name, def)
|
||||
end
|
||||
|
||||
default.register_ladder = function(id, def)
|
||||
local odef = {
|
||||
description = def.description,
|
||||
_doc_items_longdesc = "A piece of ladder which allows you to climb vertically.",
|
||||
drawtype = "signlike",
|
||||
is_ground_content = false,
|
||||
tiles = { def.texture },
|
||||
inventory_image = def.texture,
|
||||
wield_image = def.texture,
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "wallmounted",
|
||||
walkable = false,
|
||||
climbable = true,
|
||||
node_box = {
|
||||
type = "wallmounted",
|
||||
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 },
|
||||
},
|
||||
groups = groups,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
node_placement_prediction = "",
|
||||
-- Restrict placement of ladders
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then
|
||||
-- no interaction possible with entities
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local under = pointed_thing.under
|
||||
local node = minetest.get_node(under)
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
if not def then
|
||||
return itemstack
|
||||
end
|
||||
local groups = def.groups
|
||||
|
||||
-- Don't allow to place the ladder at particular nodes
|
||||
if groups and (groups.ladder or groups.slab or groups.attached_node) then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- Check special rightclick action of pointed node
|
||||
if def and def.on_rightclick then
|
||||
if not placer:get_player_control().sneak then
|
||||
return def.on_rightclick(under, node, placer, itemstack,
|
||||
pointed_thing) or itemstack, false
|
||||
end
|
||||
end
|
||||
local above = pointed_thing.above
|
||||
local adef = minetest.registered_nodes[minetest.get_node(above).name]
|
||||
if not adef.buildable_to then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- Ladders may not be placed on ceiling or floor
|
||||
if under.y ~= above.y then
|
||||
return itemstack
|
||||
end
|
||||
local idef = itemstack:get_definition()
|
||||
local success = minetest.item_place_node(itemstack, placer, pointed_thing)
|
||||
|
||||
if success then
|
||||
if idef.sounds and idef.sounds.place then
|
||||
minetest.sound_play(idef.sounds.place, {pos=above, gain=1})
|
||||
end
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
|
||||
on_rotate = function() return false end,
|
||||
}
|
||||
|
||||
for k, v in pairs(def) do
|
||||
odef[k] = v
|
||||
end
|
||||
|
||||
local groups = def.groups
|
||||
if not groups then
|
||||
groups = {}
|
||||
end
|
||||
groups.ladder = 1
|
||||
groups.attached_node = 1
|
||||
|
||||
|
||||
minetest.register_node(id, odef)
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Legacy
|
||||
|
|
|
@ -1093,52 +1093,20 @@ minetest.register_node("default:rail", {
|
|||
sounds = default.node_sound_metal_defaults(),
|
||||
})
|
||||
|
||||
|
||||
minetest.register_node("default:ladder", {
|
||||
default.register_ladder("default:ladder", {
|
||||
description = "Wooden Ladder",
|
||||
drawtype = "signlike",
|
||||
tiles = {"default_ladder.png"},
|
||||
inventory_image = "default_ladder.png",
|
||||
wield_image = "default_ladder.png",
|
||||
paramtype = "light",
|
||||
paramtype2 = "wallmounted",
|
||||
walkable = false,
|
||||
climbable = true,
|
||||
is_ground_content = false,
|
||||
selection_box = {
|
||||
type = "wallmounted",
|
||||
--wall_top = = <default>
|
||||
--wall_bottom = = <default>
|
||||
--wall_side = = <default>
|
||||
},
|
||||
texture = "default_ladder.png",
|
||||
groups = {choppy=2,oddly_breakable_by_hand=3,flammable=2},
|
||||
legacy_wallmounted = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_node("default:ladder_bronze", {
|
||||
default.register_ladder("default:ladder_bronze", {
|
||||
description = "Bronze Ladder",
|
||||
drawtype = "signlike",
|
||||
tiles = {"default_ladder_bronze.png"},
|
||||
inventory_image = "default_ladder_bronze.png",
|
||||
wield_image = "default_ladder_bronze.png",
|
||||
paramtype = "light",
|
||||
paramtype2 = "wallmounted",
|
||||
walkable = false,
|
||||
climbable = true,
|
||||
is_ground_content = false,
|
||||
selection_box = {
|
||||
type = "wallmounted",
|
||||
--wall_top = = <default>
|
||||
--wall_bottom = = <default>
|
||||
--wall_side = = <default>
|
||||
},
|
||||
groups = {choppy=2,oddly_breakable_by_hand=3},
|
||||
legacy_wallmounted = true,
|
||||
texture = "default_ladder_bronze.png",
|
||||
groups = {cracky=3},
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
})
|
||||
|
||||
|
||||
minetest.register_node("default:wood", {
|
||||
description = "Common Wood Planks",
|
||||
tiles = {"default_wood.png"},
|
||||
|
|
Loading…
Reference in New Issue