forked from mtcontrib/homedecor_modpack
Add a tree swing
model and textures by jp To place, point at the underside of a node, e.g. a ceiling or the bottom side of tree leaves or something. It will automatically stretch downward trying to find the ground (well, anything that isn't buildable_to anyway), down to a maximum of 4 meters' worth of rope. To remove, dig the swing itself and it'll take the rope with it.
This commit is contained in:
parent
1196c17b31
commit
763d8fa200
|
@ -2748,4 +2748,29 @@ minetest.register_craft({
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "homedecor:swing",
|
||||||
|
recipe = {
|
||||||
|
{ "farming:string","","farming:string" },
|
||||||
|
{ "farming:string","","farming:string" },
|
||||||
|
{ "farming:string","stairs:slab_wood","farming:string" }
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "homedecor:swing",
|
||||||
|
recipe = {
|
||||||
|
{ "farming:string","","farming:string" },
|
||||||
|
{ "farming:string","","farming:string" },
|
||||||
|
{ "farming:string","moreblocks:slab_wood","farming:string" }
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "homedecor:swing",
|
||||||
|
recipe = {
|
||||||
|
{ "farming:string","","farming:string" },
|
||||||
|
{ "farming:string","","farming:string" },
|
||||||
|
{ "farming:string","moreblocks:panel_wood_1","farming:string" }
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
|
@ -146,6 +146,54 @@ function homedecor.stack_sideways(itemstack, placer, pointed_thing, node1, node2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Determine if the item being pointed at is the underside of a node (e.g a ceiling)
|
||||||
|
|
||||||
|
function homedecor.find_ceiling(itemstack, placer, pointed_thing)
|
||||||
|
-- most of this is copied from the rotate-and-place function in builtin
|
||||||
|
local unode = core.get_node_or_nil(pointed_thing.under)
|
||||||
|
if not unode then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local undef = core.registered_nodes[unode.name]
|
||||||
|
if undef and undef.on_rightclick then
|
||||||
|
undef.on_rightclick(pointed_thing.under, unode, placer,
|
||||||
|
itemstack, pointed_thing)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local pitch = placer:get_look_pitch()
|
||||||
|
local fdir = core.dir_to_facedir(placer:get_look_dir())
|
||||||
|
local wield_name = itemstack:get_name()
|
||||||
|
|
||||||
|
local above = pointed_thing.above
|
||||||
|
local under = pointed_thing.under
|
||||||
|
local iswall = (above.y == under.y)
|
||||||
|
local isceiling = not iswall and (above.y < under.y)
|
||||||
|
local anode = core.get_node_or_nil(above)
|
||||||
|
if not anode then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local pos = pointed_thing.above
|
||||||
|
local node = anode
|
||||||
|
|
||||||
|
if undef and undef.buildable_to then
|
||||||
|
pos = pointed_thing.under
|
||||||
|
node = unode
|
||||||
|
iswall = false
|
||||||
|
end
|
||||||
|
|
||||||
|
if core.is_protected(pos, placer:get_player_name()) then
|
||||||
|
core.record_protection_violation(pos,
|
||||||
|
placer:get_player_name())
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local ndef = core.registered_nodes[node.name]
|
||||||
|
if not ndef or not ndef.buildable_to then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
return isceiling, pos
|
||||||
|
end
|
||||||
|
|
||||||
-- load various other components
|
-- load various other components
|
||||||
|
|
||||||
dofile(homedecor.modpath.."/misc-nodes.lua") -- the catch-all for all misc nodes
|
dofile(homedecor.modpath.."/misc-nodes.lua") -- the catch-all for all misc nodes
|
||||||
|
|
|
@ -1788,6 +1788,7 @@ minetest.register_node("homedecor:swing", {
|
||||||
"homedecor_swing_bottom.png",
|
"homedecor_swing_bottom.png",
|
||||||
"homedecor_swing_sides.png"
|
"homedecor_swing_sides.png"
|
||||||
},
|
},
|
||||||
|
inventory_image = "homedecor_swing_inv.png",
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
|
@ -1797,17 +1798,60 @@ minetest.register_node("homedecor:swing", {
|
||||||
fixed = {
|
fixed = {
|
||||||
{-0.3125, 0.33, -0.125, 0.3125, 0.376, 0.1875}, -- NodeBox1
|
{-0.3125, 0.33, -0.125, 0.3125, 0.376, 0.1875}, -- NodeBox1
|
||||||
{-0.3125, 0.376, 0.025, -0.3, 0.5, 0.0375}, -- NodeBox2
|
{-0.3125, 0.376, 0.025, -0.3, 0.5, 0.0375}, -- NodeBox2
|
||||||
{0.3, 0.376, 0.025, 0.3125, 0.5, 0.0375}, -- NodeBox3
|
{ 0.3, 0.376, 0.025, 0.3125, 0.5, 0.0375}, -- NodeBox3
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
selection_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = { -0.3125, 0.33, -0.125, 0.3125, 0.5, 0.1875 }
|
||||||
|
},
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
return homedecor.stack_vertically(itemstack, placer, pointed_thing,
|
isceiling, pos = homedecor.find_ceiling(itemstack, placer, pointed_thing)
|
||||||
"homedecor:swing", "homedecor:swing_rope")
|
if isceiling then
|
||||||
|
local height = 0
|
||||||
|
|
||||||
|
for i = 0, 4 do -- search up to 5 spaces downward from the ceiling for the first non-buildable-to node...
|
||||||
|
height = i
|
||||||
|
local testpos = { x=pos.x, y=pos.y-i-1, z=pos.z }
|
||||||
|
local testnode = minetest.get_node(testpos)
|
||||||
|
local testreg = core.registered_nodes[testnode.name]
|
||||||
|
|
||||||
|
if not testreg.buildable_to then
|
||||||
|
if i < 1 then
|
||||||
|
minetest.chat_send_player(placer:get_player_name(), "No room under there to hang a swing.")
|
||||||
|
return
|
||||||
|
else
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for j = 0, height do -- then fill that space with ropes...
|
||||||
|
local testpos = { x=pos.x, y=pos.y-j, z=pos.z }
|
||||||
|
local testnode = minetest.get_node(testpos)
|
||||||
|
local testreg = core.registered_nodes[testnode.name]
|
||||||
|
minetest.set_node(testpos, { name = "homedecor:swing_rope", param2 = fdir })
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.set_node({ x=pos.x, y=pos.y-height, z=pos.z }, { name = "homedecor:swing", param2 = fdir })
|
||||||
|
|
||||||
|
if not homedecor.expect_infinite_stacks then
|
||||||
|
itemstack:take_item()
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
minetest.chat_send_player(placer:get_player_name(), "You have to point at the bottom side of an overhanging object to place a swing.")
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
local pos2 = { x = pos.x, y=pos.y + 1, z = pos.z }
|
for i = 0, 4 do
|
||||||
if minetest.get_node(pos2).name == "homedecor:swing_rope" then
|
local testpos = { x=pos.x, y=pos.y+i+1, z=pos.z }
|
||||||
minetest.remove_node(pos2)
|
if minetest.get_node(testpos).name == "homedecor:swing_rope" then
|
||||||
|
minetest.remove_node(testpos)
|
||||||
|
else
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -1819,12 +1863,16 @@ minetest.register_node("homedecor:swing_rope", {
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = { snappy=3, not_in_creative_inventory=1 },
|
groups = { not_in_creative_inventory=1 },
|
||||||
node_box = {
|
node_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {
|
fixed = {
|
||||||
{-0.3125, -0.5, 0.025, -0.3, 0.5, 0.0375}, -- NodeBox1
|
{-0.3125, -0.5, 0.025, -0.3, 0.5, 0.0375}, -- NodeBox1
|
||||||
{0.3, -0.5, 0.025, 0.3125, 0.5, 0.0375}, -- NodeBox2
|
{0.3, -0.5, 0.025, 0.3125, 0.5, 0.0375}, -- NodeBox2
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
selection_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = { 0, 0, 0, 0, 0, 0 }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
BIN
homedecor/textures/homedecor_swing_bottom.png
Normal file
BIN
homedecor/textures/homedecor_swing_bottom.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 272 B |
BIN
homedecor/textures/homedecor_swing_inv.png
Normal file
BIN
homedecor/textures/homedecor_swing_inv.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
BIN
homedecor/textures/homedecor_swing_sides.png
Normal file
BIN
homedecor/textures/homedecor_swing_sides.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 293 B |
BIN
homedecor/textures/homedecor_swing_top.png
Normal file
BIN
homedecor/textures/homedecor_swing_top.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 279 B |
BIN
homedecor/textures/homedecor_swingrope_sides.png
Normal file
BIN
homedecor/textures/homedecor_swingrope_sides.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 144 B |
Loading…
Reference in New Issue
Block a user