jumping/init.lua

119 lines
3.5 KiB
Lua
Raw Normal View History

2016-05-14 04:12:48 +02:00
-- trampoline nodebox
2012-09-05 10:35:50 +02:00
local trampolinebox = {
type = "fixed",
fixed = {
{-0.5, -0.2, -0.5, 0.5, 0, 0.5},
{-0.5, -0.5, -0.5, -0.4, -0.2, -0.4},
{ 0.4, -0.5, -0.5, 0.5, -0.2, -0.4},
{ 0.4, -0.5, 0.4, 0.5, -0.2, 0.5},
{-0.5, -0.5, 0.4, -0.4, -0.2, 0.5},
}
}
2016-05-14 04:12:48 +02:00
-- cushion nodebox
2012-09-05 10:35:50 +02:00
local cushionbox = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, -0.3, 0.5},
}
}
2016-05-14 05:17:05 +02:00
-- left click: update trampoline to increase bouncy level
local trampoline_punch = function(pos, node)
2016-05-14 04:12:48 +02:00
local id = string.sub(node.name, #node.name) -- get node "id"
local meta = minetest.get_meta(pos) -- get meta access
if id < "6" then
2016-05-14 04:12:48 +02:00
id = id + 1 -- set id one value higher
minetest.add_node(pos, {name = string.sub(node.name, 1, #node.name - 1)..id}) -- update trampoline node
2016-05-14 05:17:05 +02:00
meta:set_string("infotext", "Bouncy Level: "..id) -- set infotext
end
end
2016-05-14 05:17:05 +02:00
-- right click: update trampoline to decrease bouncy level
2016-05-14 04:12:48 +02:00
local power_decrease = function(pos, node)
local id = string.sub(node.name, #node.name) -- get node "id"
local meta = minetest.get_meta(pos) -- get meta access
id = id - 1 -- set id one value lower
minetest.add_node(pos, {name = string.sub(node.name, 1, #node.name - 1)..id}) -- update trampoline node
2016-05-14 05:17:05 +02:00
meta:set_string("infotext", "Bouncy Level: "..id) -- set infotext
2016-05-14 04:12:48 +02:00
end
2016-05-14 05:17:05 +02:00
-- register trampolines of bouncy level 2-6
for i = 2, 6 do
minetest.register_node("jumping:trampoline"..i, {
description = "Trampoline",
drawtype = "nodebox",
node_box = trampolinebox,
selection_box = trampolinebox,
paramtype = "light",
2016-05-14 04:12:48 +02:00
on_punch = trampoline_punch, -- on punch (left click) increase poser lever
on_rightclick = power_decrease,
on_construct = function(pos) -- set meta data on place
local meta = minetest.get_meta(pos)
2016-05-14 05:17:05 +02:00
meta:set_string("infotext", "Bouncy Level: "..i)
end,
drop = "jumping:trampoline1",
tiles = {
"jumping_trampoline_top.png",
"jumping_trampoline_bottom.png",
"jumping_trampoline_sides.png^jumping_trampoline_sides_overlay"..i..".png"
},
groups = {dig_immediate=2, bouncy=20+i*20, fall_damage_add_percent=-70, not_in_creative_inventory=1},
})
end
2012-09-05 10:35:50 +02:00
2016-05-14 05:17:05 +02:00
-- register trampoline bouncy level 1
minetest.register_node("jumping:trampoline1", {
description = "Trampoline",
drawtype = "nodebox",
node_box = trampolinebox,
selection_box = trampolinebox,
paramtype = "light",
on_punch = trampoline_punch,
2016-05-14 04:12:48 +02:00
on_construct = function(pos) -- set meta data on place
local meta = minetest.get_meta(pos)
2016-05-14 05:17:05 +02:00
meta:set_string("infotext", "Bouncy Level: 1")
end,
tiles = {
"jumping_trampoline_top.png",
"jumping_trampoline_bottom.png",
"jumping_trampoline_sides.png^jumping_trampoline_sides_overlay1.png"
},
groups = {dig_immediate=2, bouncy=20+1*20, fall_damage_add_percent=-70},
})
2016-05-14 04:12:48 +02:00
-- register cushion
2012-09-05 10:35:50 +02:00
minetest.register_node("jumping:cushion", {
description = "Cushion",
drawtype = "nodebox",
node_box = cushionbox,
selection_box = cushionbox,
paramtype = "light",
2012-09-05 14:12:25 +02:00
tiles = {
"jumping_cushion_tb.png",
"jumping_cushion_tb.png",
"jumping_cushion_sides.png"
},
2012-09-05 10:35:50 +02:00
groups = {dig_immediate=2, disable_jump=1, fall_damage_add_percent=-100},
})
2012-09-24 16:15:14 +02:00
2016-05-14 04:12:48 +02:00
-- register recipe for trampoline (power lever 1)
2012-09-24 16:15:14 +02:00
minetest.register_craft({
output = "jumping:trampoline1",
recipe = {
2016-05-14 04:33:24 +02:00
{"jumping:cushion", "jumping:cushion", "jumping:cushion"},
{"default:steel_ingot", "", "default:steel_ingot"}
2012-09-24 16:15:14 +02:00
}
})
2016-05-14 04:12:48 +02:00
-- register recipe for cushion
2012-09-24 16:15:14 +02:00
minetest.register_craft({
output = "jumping:cushion",
recipe = {
2016-05-14 04:33:24 +02:00
{"farming:cotton", "group:wool", "farming:cotton"},
{"farming:cotton", "group:wool", "farming:cotton"},
{"farming:cotton", "farming:cotton", "farming:cotton"}
2012-09-24 16:15:14 +02:00
}
})