use mcl_util function
This commit is contained in:
parent
59f1c25296
commit
6577f54736
|
@ -11,20 +11,6 @@ mcl_flowers.registered_simple_flowers = {}
|
||||||
local smallflowerlongdesc = S("This is a small flower. Small flowers are mainly used for dye production and can also be potted.")
|
local smallflowerlongdesc = S("This is a small flower. Small flowers are mainly used for dye production and can also be potted.")
|
||||||
local plant_usage_help = S("It can only be placed on a block on which it would also survive.")
|
local plant_usage_help = S("It can only be placed on a block on which it would also survive.")
|
||||||
|
|
||||||
local get_palette_color_from_pos = function(pos)
|
|
||||||
local biome_data = minetest.get_biome_data(pos)
|
|
||||||
local index = 0
|
|
||||||
if biome_data then
|
|
||||||
local biome = biome_data.biome
|
|
||||||
local biome_name = minetest.get_biome_name(biome)
|
|
||||||
local reg_biome = minetest.registered_biomes[biome_name]
|
|
||||||
if reg_biome then
|
|
||||||
index = reg_biome._mcl_grass_palette_index
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return index
|
|
||||||
end
|
|
||||||
|
|
||||||
-- on_place function for flowers
|
-- on_place function for flowers
|
||||||
local on_place_flower = mcl_util.generate_on_place_plant_function(function(pos, node, itemstack)
|
local on_place_flower = mcl_util.generate_on_place_plant_function(function(pos, node, itemstack)
|
||||||
local below = {x=pos.x, y=pos.y-1, z=pos.z}
|
local below = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||||
|
@ -32,13 +18,7 @@ local on_place_flower = mcl_util.generate_on_place_plant_function(function(pos,
|
||||||
if not soil_node then return false end
|
if not soil_node then return false end
|
||||||
|
|
||||||
local has_palette = minetest.registered_nodes[itemstack:get_name()].palette ~= nil
|
local has_palette = minetest.registered_nodes[itemstack:get_name()].palette ~= nil
|
||||||
local colorize
|
local colorize = has_palette and mcl_util.get_palette_indexes_from_pos(pos).grass_palette_index or 0
|
||||||
if has_palette then
|
|
||||||
colorize = get_palette_color_from_pos(pos)
|
|
||||||
end
|
|
||||||
if not colorize then
|
|
||||||
colorize = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[ Placement requirements:
|
--[[ Placement requirements:
|
||||||
* Dirt or grass block
|
* Dirt or grass block
|
||||||
|
@ -47,10 +27,7 @@ local on_place_flower = mcl_util.generate_on_place_plant_function(function(pos,
|
||||||
]]
|
]]
|
||||||
local light_night = minetest.get_node_light(pos, 0.0)
|
local light_night = minetest.get_node_light(pos, 0.0)
|
||||||
local light_day = minetest.get_node_light(pos, 0.5)
|
local light_day = minetest.get_node_light(pos, 0.5)
|
||||||
local light_ok = false
|
local light_ok = (light_night and light_night >= 8) or (light_day and light_day >= minetest.LIGHT_MAX)
|
||||||
if (light_night and light_night >= 8) or (light_day and light_day >= minetest.LIGHT_MAX) then
|
|
||||||
light_ok = true
|
|
||||||
end
|
|
||||||
if itemstack:get_name() == "mcl_flowers:wither_rose" and ( minetest.get_item_group(soil_node.name, "grass_block") > 0 or soil_node.name == "mcl_core:dirt" or soil_node.name == "mcl_core:coarse_dirt" or soil_node.name == "mcl_mud:mud" or soil_node.name == "mcl_moss:moss" or soil_node.name == "mcl_nether:netherrack" or minetest.get_item_group(soil_node.name, "soul_block") > 0 ) then
|
if itemstack:get_name() == "mcl_flowers:wither_rose" and ( minetest.get_item_group(soil_node.name, "grass_block") > 0 or soil_node.name == "mcl_core:dirt" or soil_node.name == "mcl_core:coarse_dirt" or soil_node.name == "mcl_mud:mud" or soil_node.name == "mcl_moss:moss" or soil_node.name == "mcl_nether:netherrack" or minetest.get_item_group(soil_node.name, "soul_block") > 0 ) then
|
||||||
return true,colorize
|
return true,colorize
|
||||||
end
|
end
|
||||||
|
@ -359,10 +336,7 @@ local function add_large_plant(name, desc, longdesc, bottom_img, top_img, inv_im
|
||||||
-- * Only with light level >= 8
|
-- * Only with light level >= 8
|
||||||
-- * Only if two enough space
|
-- * Only if two enough space
|
||||||
if (floor.name == "mcl_core:dirt" or minetest.get_item_group(floor.name, "grass_block") == 1 or (not is_flower and (floor.name == "mcl_core:coarse_dirt" or floor.name == "mcl_core:podzol" or floor.name == "mcl_core:podzol_snow"))) and bottom_buildable and top_buildable and light_ok then
|
if (floor.name == "mcl_core:dirt" or minetest.get_item_group(floor.name, "grass_block") == 1 or (not is_flower and (floor.name == "mcl_core:coarse_dirt" or floor.name == "mcl_core:podzol" or floor.name == "mcl_core:podzol_snow"))) and bottom_buildable and top_buildable and light_ok then
|
||||||
local param2
|
local param2 = grass_color and mcl_util.get_palette_indexes_from_pos(bottom).grass_palette_index
|
||||||
if grass_color then
|
|
||||||
param2 = get_palette_color_from_pos(bottom)
|
|
||||||
end
|
|
||||||
-- Success! We can now place the flower
|
-- Success! We can now place the flower
|
||||||
minetest.sound_play(minetest.registered_nodes[itemstring].sounds.place, {pos = bottom, gain=1}, true)
|
minetest.sound_play(minetest.registered_nodes[itemstring].sounds.place, {pos = bottom, gain=1}, true)
|
||||||
minetest.set_node(bottom, {name=itemstring, param2=param2})
|
minetest.set_node(bottom, {name=itemstring, param2=param2})
|
||||||
|
|
Loading…
Reference in New Issue