forked from mtcontrib/plantlife_modpack
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:
parent
c60212f3cc
commit
a401f1369d
@ -5,108 +5,103 @@ 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 = {
|
||||||
description = "Waterlily",
|
{ nil, nil },
|
||||||
drawtype = "nodebox",
|
{ "225", "22.5" },
|
||||||
tiles = { "flowers_waterlily.png" },
|
{ "45" , "45" },
|
||||||
inventory_image = "flowers_waterlily.png",
|
{ "675", "67.5" },
|
||||||
wield_image = "flowers_waterlily.png",
|
}
|
||||||
sunlight_propagates = true,
|
|
||||||
paramtype = "light",
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
walkable = false,
|
|
||||||
groups = { snappy = 3,flammable=2,flower=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 },
|
|
||||||
},
|
|
||||||
buildable_to = true,
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node(":flowers:waterlily_225", {
|
for i in ipairs(lilies_list) do
|
||||||
description = "Waterlily",
|
local deg1 = ""
|
||||||
drawtype = "nodebox",
|
local deg2 = ""
|
||||||
tiles = { "flowers_waterlily_22.5.png" },
|
local lily_groups = {snappy = 3,flammable=2,flower=1}
|
||||||
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",
|
|
||||||
buildable_to = true,
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node(":flowers:waterlily_45", {
|
if lilies_list[i][1] ~= nil then
|
||||||
description = "Waterlily",
|
deg1 = "_"..lilies_list[i][1]
|
||||||
drawtype = "raillike",
|
deg2 = "_"..lilies_list[i][2]
|
||||||
tiles = { "flowers_waterlily_45.png" },
|
lily_groups = { snappy = 3,flammable=2,flower=1, not_in_creative_inventory=1 }
|
||||||
sunlight_propagates = true,
|
end
|
||||||
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", {
|
minetest.register_node(":flowers:waterlily"..deg1, {
|
||||||
description = "Waterlily",
|
description = "Waterlily",
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
tiles = { "flowers_waterlily_67.5.png" },
|
tiles = { "flowers_waterlily"..deg2..".png" },
|
||||||
sunlight_propagates = true,
|
inventory_image = "flowers_waterlily.png",
|
||||||
paramtype = "light",
|
wield_image = "flowers_waterlily.png",
|
||||||
paramtype2 = "facedir",
|
sunlight_propagates = true,
|
||||||
walkable = false,
|
paramtype = "light",
|
||||||
groups = { snappy = 3,flammable=2,flower=1, not_in_creative_inventory=1 },
|
paramtype2 = "facedir",
|
||||||
sounds = default.node_sound_leaves_defaults(),
|
walkable = false,
|
||||||
selection_box = {
|
groups = lily_groups,
|
||||||
type = "fixed",
|
sounds = default.node_sound_leaves_defaults(),
|
||||||
fixed = { -0.4, -0.5, -0.4, 0.4, -0.45, 0.4 },
|
selection_box = {
|
||||||
},
|
type = "fixed",
|
||||||
node_box = {
|
fixed = { -0.4, -0.5, -0.4, 0.4, -0.45, 0.4 },
|
||||||
type = "fixed",
|
},
|
||||||
fixed = { -0.5, -0.49, -0.5, 0.5, -0.49, 0.5 },
|
node_box = {
|
||||||
},
|
type = "fixed",
|
||||||
drop = "flowers:waterlily",
|
fixed = { -0.5, -0.49, -0.5, 0.5, -0.49, 0.5 },
|
||||||
buildable_to = true,
|
},
|
||||||
})
|
buildable_to = true,
|
||||||
|
|
||||||
|
liquids_pointable = true,
|
||||||
|
drop = "flowers:waterlily",
|
||||||
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
|
local keys=placer:get_player_control()
|
||||||
|
local pt = pointed_thing
|
||||||
|
|
||||||
|
local place_pos = nil
|
||||||
|
local top_pos = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z}
|
||||||
|
local under_node = minetest.get_node(pt.under)
|
||||||
|
local above_node = minetest.get_node(pt.above)
|
||||||
|
local top_node = minetest.get_node(top_pos)
|
||||||
|
|
||||||
|
if plantslib:get_nodedef_field(under_node.name, "buildable_to") then
|
||||||
|
if under_node.name ~= "default:water_source" then
|
||||||
|
place_pos = pt.under
|
||||||
|
elseif top_node.name ~= "default:water_source"
|
||||||
|
and plantslib:get_nodedef_field(top_node.name, "buildable_to") then
|
||||||
|
place_pos = top_pos
|
||||||
|
else
|
||||||
|
return
|
||||||
|
end
|
||||||
|
elseif plantslib:get_nodedef_field(above_node.name, "buildable_to") then
|
||||||
|
place_pos = pt.above
|
||||||
|
end
|
||||||
|
|
||||||
|
if not plantslib:node_is_owned(place_pos, placer) then
|
||||||
|
|
||||||
|
local nodename = "default:cobble" -- if this block appears, something went....wrong :-)
|
||||||
|
|
||||||
|
if not keys["sneak"] then
|
||||||
|
local node = minetest.env:get_node(pt.under)
|
||||||
|
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.")
|
||||||
|
@ -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")
|
||||||
|
Loading…
Reference in New Issue
Block a user