added comments & improved organization

This commit is contained in:
endev15 2016-05-13 19:12:48 -07:00
parent 9870eaa3f7
commit acc432e506

View File

@ -1,3 +1,4 @@
-- trampoline nodebox
local trampolinebox = {
type = "fixed",
fixed = {
@ -10,6 +11,7 @@ local trampolinebox = {
}
}
-- cushion nodebox
local cushionbox = {
type = "fixed",
fixed = {
@ -17,16 +19,27 @@ local cushionbox = {
}
}
-- left click: update trampoline to increase power level
local trampoline_punch = function(pos, node)
local id = string.sub(node.name, #node.name)
local meta = minetest.get_meta(pos)
local id = string.sub(node.name, #node.name) -- get node "id"
local meta = minetest.get_meta(pos) -- get meta access
if id < "6" then
id = id + 1
minetest.add_node(pos, {name = string.sub(node.name, 1, #node.name - 1)..id})
meta:set_string("infotext", "Power Level: "..id)
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
meta:set_string("infotext", "Power Level: "..id) -- set infotext
end
end
-- right click: update trampoline to decrease power level
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
meta:set_string("infotext", "Power Level: "..id) -- set infotext
end
-- register trampolines of power level 2-6
for i = 2, 6 do
minetest.register_node("jumping:trampoline"..i, {
description = "Trampoline",
@ -34,13 +47,11 @@ for i = 2, 6 do
node_box = trampolinebox,
selection_box = trampolinebox,
paramtype = "light",
on_punch = trampoline_punch,
on_rightclick = function(pos, node)
local id = string.sub(node.name, #node.name)
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)
id = id - 1
minetest.add_node(pos, {name = string.sub(node.name, 1, #node.name - 1)..id})
meta:set_string("infotext", "Power Level: "..id)
meta:set_string("infotext", "Power Level: "..i)
end,
drop = "jumping:trampoline1",
tiles = {
@ -52,6 +63,7 @@ for i = 2, 6 do
})
end
-- register trampoline power level 1
minetest.register_node("jumping:trampoline1", {
description = "Trampoline",
drawtype = "nodebox",
@ -59,7 +71,7 @@ minetest.register_node("jumping:trampoline1", {
selection_box = trampolinebox,
paramtype = "light",
on_punch = trampoline_punch,
on_construct = function(pos)
on_construct = function(pos) -- set meta data on place
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Power Level: 1")
end,
@ -71,6 +83,7 @@ minetest.register_node("jumping:trampoline1", {
groups = {dig_immediate=2, bouncy=20+1*20, fall_damage_add_percent=-70},
})
-- register cushion
minetest.register_node("jumping:cushion", {
description = "Cushion",
drawtype = "nodebox",
@ -85,6 +98,7 @@ minetest.register_node("jumping:cushion", {
groups = {dig_immediate=2, disable_jump=1, fall_damage_add_percent=-100},
})
-- register recipe for trampoline (power lever 1)
minetest.register_craft({
output = "jumping:trampoline1",
recipe = {
@ -94,6 +108,7 @@ minetest.register_craft({
}
})
-- register recipe for cushion
minetest.register_craft({
output = "jumping:cushion",
recipe = {