240 lines
7.7 KiB
Lua
240 lines
7.7 KiB
Lua
-- get intllib optionally
|
|
local S
|
|
if (minetest.get_modpath("intllib")) then
|
|
dofile(minetest.get_modpath("intllib").."/intllib.lua")
|
|
S = intllib.Getter(minetest.get_current_modname())
|
|
else
|
|
S = function ( s ) return s end
|
|
end
|
|
math.randomseed(os.time())
|
|
|
|
--Register beanstalk nodes
|
|
minetest.register_node("magicbeans_w:leaves", {
|
|
description = S("Magic beanstalk leaves"),
|
|
tiles = {"magicbeans_w_leaves.png"},
|
|
inventory_image = "magicbeans_w_leaves.png",
|
|
drawtype = "plantlike",
|
|
is_ground_content = false,
|
|
walkable = false,
|
|
climbable = true,
|
|
paramtype = "light",
|
|
groups = {leaves = 1, snappy = 3, flammable = 2},
|
|
sounds = default.node_sound_leaves_defaults()
|
|
})
|
|
|
|
minetest.register_node("magicbeans_w:blank", {
|
|
description = S("Magic beanstalk climbable blank"),
|
|
x_doc_items_create_entry = false,
|
|
drawtype = "airlike",
|
|
inventory_image = "unknown_node.png",
|
|
wield_image = "unknown_node.png",
|
|
walkable = false,
|
|
climbable = true,
|
|
paramtype = "light",
|
|
buildable_to = true,
|
|
pointable = false,
|
|
diggable = false,
|
|
drop = "",
|
|
groups = {not_in_creative_inventory = 1},
|
|
})
|
|
|
|
minetest.register_node("magicbeans_w:stem", {
|
|
description = S("Magic beanstalk stem"),
|
|
is_ground_content = false,
|
|
tiles = {"magicbeans_w_stem_topbottom.png", "magicbeans_w_stem_topbottom.png", "magicbeans_w_stem.png"},
|
|
paramtype2 = "facedir",
|
|
groups = {oddly_breakable_by_hand = 1, choppy = 3, flammable = 2},
|
|
sounds = default.node_sound_wood_defaults(),
|
|
on_place = minetest.rotate_node,
|
|
})
|
|
|
|
minetest.register_node("magicbeans_w:cloud", {
|
|
description = S("Thin Cloud"),
|
|
drawtype = "liquid",
|
|
paramtype = "light",
|
|
tiles = {"default_cloud.png"},
|
|
walkable = false,
|
|
climbable = true,
|
|
sunlight_propagates = true,
|
|
post_effect_color = "#FFFFFFA0",
|
|
alpha = 192,
|
|
groups = {dig_immediate = 3},
|
|
sounds = { dig = { name = "", gain = 0 }, footstep = { name = "", gain = 0 },
|
|
dug = { name = "", gain = 0 }, player = { name = "", gain = 0 } },
|
|
drop = "",
|
|
})
|
|
|
|
if(minetest.get_modpath("awards") ~= nil) then
|
|
awards.register_achievement("magicbeans_w_beanstalk", {
|
|
title = S("Sam and the Beanstalk"),
|
|
description = S("Climb up a magic beanstalk and touch the clouds."),
|
|
icon = "magicbeans_w_stem.png",
|
|
trigger = {
|
|
type = "dig",
|
|
node = "magicbeans_w:cloud",
|
|
target = 1,
|
|
}
|
|
})
|
|
end
|
|
|
|
local magicbeans_w_list = {
|
|
{ S("Magic jumping bean"), S("Magic super jump"), "jumping", nil, 5, nil, {"jump"},
|
|
S("Eating this bean will make your jumps much, much higher for 30 seconds. In fact, you can jump so high that you may hurt yourself when you fall down again. Use with caution. It also cancels any previous jumping effects."),
|
|
doc.sub.items.temp.eat, },
|
|
{ S("Magic flying bean"), S("Magic flying"), "flying", 2, nil, 0.02, {"speed", "gravity"},
|
|
S("Eating a running bean will greatly increase your walking speed for 30 seconds. It also cancels out any previous walking speed effects."),
|
|
doc.sub.items.temp.eat, },
|
|
{ S("Magic running bean"), S("Magic super speed"), "running", 3, nil, nil, {"speed"},
|
|
S("Eating a flying bean will allow you to fly for 30 seconds, after which your flight will apruptly end. Use with caution. It also cancels out any gravity and walking speed effects you have."),
|
|
S("Hold it in your hand, then leftclick to eat the bean. To initiate the flight, just jump. You will very slowly rise high in the skies and eventually sink again. Plan your flights carefully as falling down in mid-flight can be very harmful."), },
|
|
{ S("Magic beanstalk bean"), nil, "beanstalk", nil, nil, nil, nil,
|
|
S("This magic bean will grow into a giant beanstalk when planted. The beanstalk can grop up to a height of about 100 blocks, easily reaching into the clouds."),
|
|
S("Rightclick with it on the floor to plant it, then wait for a short while for the giant beanstalk to appear."),
|
|
}
|
|
}
|
|
|
|
for i in ipairs(magicbeans_w_list) do
|
|
|
|
local beandesc = magicbeans_w_list[i][1]
|
|
local effdesc = magicbeans_w_list[i][2]
|
|
local bean = magicbeans_w_list[i][3]
|
|
local beanspeed = magicbeans_w_list[i][4]
|
|
local beanjump = magicbeans_w_list[i][5]
|
|
local beangrav = magicbeans_w_list[i][6]
|
|
local beangroups = magicbeans_w_list[i][7]
|
|
local longdesc = magicbeans_w_list[i][8]
|
|
local usagehelp = magicbeans_w_list[i][9]
|
|
|
|
--Register effect types
|
|
if(beangroups ~= nil) then
|
|
playereffects.register_effect_type("bean_"..bean, effdesc, "magicbeans_w_"..bean.."16.png", beangroups,
|
|
function(player)
|
|
player:set_physics_override({speed=beanspeed, jump=beanjump, gravity=beangrav})
|
|
end,
|
|
function(effect)
|
|
local player = minetest.get_player_by_name(effect.playername)
|
|
local speed, jump, grav
|
|
if beanspeed ~= nil then speed = 1 end
|
|
if beanjump ~= nil then jump = 1 end
|
|
if beangrav ~= nil then grav = 1 end
|
|
player:set_physics_override({speed=speed, jump=jump, gravity=grav})
|
|
end
|
|
)
|
|
end
|
|
--Register beans
|
|
minetest.register_craftitem("magicbeans_w:"..bean, {
|
|
description = beandesc,
|
|
x_doc_items_longdesc = longdesc,
|
|
x_doc_items_usagehelp = usagehelp,
|
|
inventory_image = "magicbeans_w_"..bean..".png",
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
if pointed_thing.above then
|
|
if bean ~= "beanstalk" then
|
|
minetest.add_item(pointed_thing.above, {name="magicbeans_w:"..bean})
|
|
else
|
|
-- Grow Beanstalk
|
|
local stalk = pointed_thing.above
|
|
stalk.x = stalk.x - 2
|
|
stalk.z = stalk.z - 2
|
|
local height = 127 - stalk.y
|
|
local c = {1, 1, 1, 1, 2, 1, 1, 1, 1}
|
|
local d = {1, 2, 3, 6}
|
|
local e = {9, 8, 7, 4}
|
|
local ex = 0
|
|
local zed = 1
|
|
local blank = 0
|
|
local why1, ex1, zed1, node
|
|
for why = 0,height do
|
|
blank = blank + 1
|
|
if blank > 4 then blank = 1 end
|
|
why1 = stalk.y + why
|
|
for i = 1,9 do
|
|
ex = ex + 1
|
|
if ex > 3 then
|
|
zed = zed + 1
|
|
ex = 1
|
|
end
|
|
if c[i] == 1 then
|
|
node = "magicbeans_w:leaves"
|
|
if i == d[blank] or i == e[blank] then node = "magicbeans_w:blank" end
|
|
else
|
|
node = "magicbeans_w:stem"
|
|
end
|
|
ex1 = stalk.x + ex
|
|
zed1 = stalk.z + zed
|
|
minetest.set_node({x=ex1, y=why1, z=zed1},{name=node})
|
|
end
|
|
zed = 0
|
|
end
|
|
-- Build cloud platform
|
|
for ex = -10,20 do
|
|
for zed = -10,20 do
|
|
ex1 = stalk.x + ex
|
|
zed1 = stalk.z + zed
|
|
minetest.set_node({x=ex1, y=why1, z=zed1},{name="magicbeans_w:cloud"})
|
|
end
|
|
end
|
|
end
|
|
itemstack:take_item()
|
|
end
|
|
return itemstack
|
|
end,
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
if bean == "beanstalk" then
|
|
-- Beanstalk bean can't be eaten
|
|
return
|
|
end
|
|
playereffects.apply_effect_type("bean_"..bean, 30, user)
|
|
itemstack:take_item()
|
|
return itemstack
|
|
end,
|
|
})
|
|
|
|
end
|
|
|
|
-- Bean Spawning
|
|
minetest.register_abm(
|
|
{nodenames = {"default:dirt_with_grass"},
|
|
interval = 600,
|
|
chance = 3000,
|
|
action = function(pos)
|
|
pos.y = pos.y + 1
|
|
math.randomseed(os.time())
|
|
local j = math.random(4)
|
|
local bean = magicbeans_w_list[j][3]
|
|
minetest.add_item(pos, {name="magicbeans_w:"..bean})
|
|
end,
|
|
})
|
|
|
|
-- Remove beanstalk blanks
|
|
minetest.register_abm(
|
|
{nodenames = {"magicbeans_w:blank"},
|
|
interval = 5,
|
|
chance = 1,
|
|
action = function(pos)
|
|
local neighbors = {
|
|
{ x=pos.x, y=pos.y, z=pos.z-1 },
|
|
{ x=pos.x, y=pos.y, z=pos.z+1 },
|
|
{ x=pos.x, y=pos.y-1, z=pos.z },
|
|
{ x=pos.x, y=pos.y+1, z=pos.z },
|
|
{ x=pos.x-1, y=pos.y, z=pos.z },
|
|
{ x=pos.x+1, y=pos.y, z=pos.z },
|
|
}
|
|
local attached = false
|
|
for i=1,#neighbors do
|
|
local node = minetest.get_node_or_nil(neighbors[i])
|
|
if(node ~= nil) then
|
|
if node.name == "magicbeans_w:leaves" or node.name == "magicbeans_w:stem" then
|
|
attached = true
|
|
break
|
|
end
|
|
end
|
|
end
|
|
if(attached == false) then
|
|
minetest.remove_node(pos)
|
|
end
|
|
end
|
|
})
|
|
|
|
|