Make waterliles placable on the surface of standing water.

Lilies will be rotated randomly on place, in the same manner as they're
usually generated.

Hold 'sneak' (usually shift) while placing to force them to follow your
facedir instead.

Liles will replace buildable_to nodes when placed, including themselves.
This will cause a loss of lilies if you just keep placing them over and
over, but this is intentional.

node_ownership, glomie's protection mod, and zeg9's protection mod are
accounted for, as are infinite item stacks (e.g. plain creative mode).

Also, compact the waterlily register node calls into a loop.
This commit is contained in:
Vanessa Ezekowitz 2013-08-19 02:08:08 -04:00
parent c60212f3cc
commit a401f1369d
2 changed files with 156 additions and 97 deletions

View File

@ -5,31 +5,37 @@ local SPAWN_DELAY = 1000
local SPAWN_CHANCE = 200 local SPAWN_CHANCE = 200
local flowers_seed_diff = 329 local flowers_seed_diff = 329
-- Cotton plants are now provided by the default "farming" mod.
-- old cotton plants -> farming cotton stage 8
-- cotton wads -> string (can be crafted into wool blocks)
-- potted cotton plants -> potted white dandelions
minetest.register_alias("flowers:cotton_plant", "farming:cotton_8")
minetest.register_alias("flowers:flower_cotton", "farming:cotton_8")
minetest.register_alias("flowers:flower_cotton_pot", "flowers:potted_dandelion_white")
minetest.register_alias("flowers:potted_cotton_plant", "flowers:potted_dandelion_white")
minetest.register_alias("flowers:cotton", "farming:string")
minetest.register_alias("flowers:cotton_wad", "farming:string")
-- register the various rotations of waterlilies -- register the various rotations of waterlilies
minetest.register_node(":flowers:waterlily", { local lilies_list = {
{ nil, nil },
{ "225", "22.5" },
{ "45" , "45" },
{ "675", "67.5" },
}
for i in ipairs(lilies_list) do
local deg1 = ""
local deg2 = ""
local lily_groups = {snappy = 3,flammable=2,flower=1}
if lilies_list[i][1] ~= nil then
deg1 = "_"..lilies_list[i][1]
deg2 = "_"..lilies_list[i][2]
lily_groups = { snappy = 3,flammable=2,flower=1, not_in_creative_inventory=1 }
end
minetest.register_node(":flowers:waterlily"..deg1, {
description = "Waterlily", description = "Waterlily",
drawtype = "nodebox", drawtype = "nodebox",
tiles = { "flowers_waterlily.png" }, tiles = { "flowers_waterlily"..deg2..".png" },
inventory_image = "flowers_waterlily.png", inventory_image = "flowers_waterlily.png",
wield_image = "flowers_waterlily.png", wield_image = "flowers_waterlily.png",
sunlight_propagates = true, sunlight_propagates = true,
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
walkable = false, walkable = false,
groups = { snappy = 3,flammable=2,flower=1 }, groups = lily_groups,
sounds = default.node_sound_leaves_defaults(), sounds = default.node_sound_leaves_defaults(),
selection_box = { selection_box = {
type = "fixed", type = "fixed",
@ -40,73 +46,62 @@ minetest.register_node(":flowers:waterlily", {
fixed = { -0.5, -0.49, -0.5, 0.5, -0.49, 0.5 }, fixed = { -0.5, -0.49, -0.5, 0.5, -0.49, 0.5 },
}, },
buildable_to = true, buildable_to = true,
})
minetest.register_node(":flowers:waterlily_225", { liquids_pointable = true,
description = "Waterlily",
drawtype = "nodebox",
tiles = { "flowers_waterlily_22.5.png" },
sunlight_propagates = true,
paramtype = "light",
paramtype2 = "facedir",
walkable = false,
groups = { snappy = 3,flammable=2,flower=1, not_in_creative_inventory=1 },
sounds = default.node_sound_leaves_defaults(),
selection_box = {
type = "fixed",
fixed = { -0.4, -0.5, -0.4, 0.4, -0.45, 0.4 },
},
node_box = {
type = "fixed",
fixed = { -0.5, -0.49, -0.5, 0.5, -0.49, 0.5 },
},
drop = "flowers:waterlily", drop = "flowers:waterlily",
buildable_to = true, on_place = function(itemstack, placer, pointed_thing)
}) local keys=placer:get_player_control()
local pt = pointed_thing
minetest.register_node(":flowers:waterlily_45", { local place_pos = nil
description = "Waterlily", local top_pos = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z}
drawtype = "raillike", local under_node = minetest.get_node(pt.under)
tiles = { "flowers_waterlily_45.png" }, local above_node = minetest.get_node(pt.above)
sunlight_propagates = true, local top_node = minetest.get_node(top_pos)
paramtype = "light",
paramtype2 = "facedir",
walkable = false,
groups = { snappy = 3,flammable=2,flower=1, not_in_creative_inventory=1 },
sounds = default.node_sound_leaves_defaults(),
selection_box = {
type = "fixed",
fixed = { -0.4, -0.5, -0.4, 0.4, -0.45, 0.4 },
},
node_box = {
type = "fixed",
fixed = { -0.5, -0.49, -0.5, 0.5, -0.49, 0.5 },
},
drop = "flowers:waterlily",
buildable_to = true,
})
minetest.register_node(":flowers:waterlily_675", { if plantslib:get_nodedef_field(under_node.name, "buildable_to") then
description = "Waterlily", if under_node.name ~= "default:water_source" then
drawtype = "nodebox", place_pos = pt.under
tiles = { "flowers_waterlily_67.5.png" }, elseif top_node.name ~= "default:water_source"
sunlight_propagates = true, and plantslib:get_nodedef_field(top_node.name, "buildable_to") then
paramtype = "light", place_pos = top_pos
paramtype2 = "facedir", else
walkable = false, return
groups = { snappy = 3,flammable=2,flower=1, not_in_creative_inventory=1 }, end
sounds = default.node_sound_leaves_defaults(), elseif plantslib:get_nodedef_field(above_node.name, "buildable_to") then
selection_box = { place_pos = pt.above
type = "fixed", end
fixed = { -0.4, -0.5, -0.4, 0.4, -0.45, 0.4 },
}, if not plantslib:node_is_owned(place_pos, placer) then
node_box = {
type = "fixed", local nodename = "default:cobble" -- if this block appears, something went....wrong :-)
fixed = { -0.5, -0.49, -0.5, 0.5, -0.49, 0.5 },
}, if not keys["sneak"] then
drop = "flowers:waterlily", local node = minetest.env:get_node(pt.under)
buildable_to = true, local waterlily = math.random(1,4)
if waterlily == 1 then
nodename = "flowers:waterlily"
elseif waterlily == 2 then
nodename = "flowers:waterlily_225"
elseif waterlily == 3 then
nodename = "flowers:waterlily_45"
elseif waterlily == 4 then
nodename = "flowers:waterlily_675"
end
minetest.add_node(place_pos, {name = nodename, param2 = math.random(0,3) })
else
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
minetest.add_node(place_pos, {name = "flowers:waterlily", param2 = fdir})
end
if not plantslib.expect_infinite_stacks then
itemstack:take_item()
end
return itemstack
end
end,
}) })
end
minetest.register_node(":flowers:seaweed", { minetest.register_node(":flowers:seaweed", {
description = "Seaweed", description = "Seaweed",
@ -260,4 +255,16 @@ minetest.register_craft( {
}, },
}) })
-- Cotton plants are now provided by the default "farming" mod.
-- old cotton plants -> farming cotton stage 8
-- cotton wads -> string (can be crafted into wool blocks)
-- potted cotton plants -> potted white dandelions
minetest.register_alias("flowers:cotton_plant", "farming:cotton_8")
minetest.register_alias("flowers:flower_cotton", "farming:cotton_8")
minetest.register_alias("flowers:flower_cotton_pot", "flowers:potted_dandelion_white")
minetest.register_alias("flowers:potted_cotton_plant", "flowers:potted_dandelion_white")
minetest.register_alias("flowers:cotton", "farming:string")
minetest.register_alias("flowers:cotton_wad", "farming:string")
print("[Flowers] Loaded.") print("[Flowers] Loaded.")

View File

@ -437,6 +437,58 @@ function plantslib:grow_tree(pos, node_or_function_or_model)
plantslib:dbg("Generated one tree in ".. (os.clock()-t)*1000 .."ms") plantslib:dbg("Generated one tree in ".. (os.clock()-t)*1000 .."ms")
end end
-- check if a node is owned before allowing manual placement of a node
-- (used by flowers_plus)
function plantslib:node_is_owned(pos, placer)
local ownername = false
if type(IsPlayerNodeOwner) == "function" then -- node_ownership mod
if HasOwner(pos, placer) then -- returns true if the node is owned
if not IsPlayerNodeOwner(pos, placer:get_player_name()) then
if type(getLastOwner) == "function" then -- ...is an old version
ownername = getLastOwner(pos)
elseif type(GetNodeOwnerName) == "function" then -- ...is a recent version
ownername = GetNodeOwnerName(pos)
else
ownername = S("someone")
end
end
end
elseif type(isprotect)=="function" then -- glomie's protection mod
if not isprotect(5, pos, placer) then
ownername = S("someone")
end
elseif type(protector)=="table" and type(protector.can_dig)=="function" then -- Zeg9's protection mod
if not protector.can_dig(5, pos, placer) then
ownername = S("someone")
end
end
if ownername ~= false then
minetest.chat_send_player( placer:get_player_name(), S("Sorry, %s owns that spot."):format(ownername) )
return true
else
return false
end
end
-- Check for infinite stacks
if minetest.get_modpath("unified_inventory") or not minetest.setting_getbool("creative_mode") then
plantslib.expect_infinite_stacks = false
else
plantslib.expect_infinite_stacks = true
end
-- read a field from a node's definition
function plantslib:get_nodedef_field(nodename, fieldname)
if not minetest.registered_nodes[nodename] then
return nil
end
return minetest.registered_nodes[nodename][fieldname]
end
print("[Plantlife Library] Loaded") print("[Plantlife Library] Loaded")