1
0
Fork 0

add flowerpots API

This commit is contained in:
AFCMS 2021-03-11 22:13:43 +01:00
parent 134005180c
commit 7b5d67cdbe
8 changed files with 200 additions and 172 deletions

View File

@ -1,5 +0,0 @@
mcl_core
mcl_sounds
mcl_farming
mcl_flowers
doc?

View File

@ -1,4 +1,8 @@
local S = minetest.get_translator("mcl_flowerpots") local S = minetest.get_translator("mcl_flowerpots")
local has_doc = minetest.get_modpath("doc")
mcl_flowerpots = {}
mcl_flowerpots.registered_pots = {}
local flowers = { local flowers = {
{"dandelion", "mcl_flowers:dandelion", S("Dandelion Flower Pot")}, {"dandelion", "mcl_flowers:dandelion", S("Dandelion Flower Pot")},
@ -23,10 +27,6 @@ local flowers = {
{"fern", "mcl_flowers:fern", S("Fern Flower Pot"), {"mcl_flowers_fern_inv.png"}}, {"fern", "mcl_flowers:fern", S("Fern Flower Pot"), {"mcl_flowers_fern_inv.png"}},
} }
local cubes = {
{"cactus", "mcl_core:cactus", S("Cactus Flower Pot")},
}
minetest.register_node("mcl_flowerpots:flower_pot", { minetest.register_node("mcl_flowerpots:flower_pot", {
description = S("Flower Pot"), description = S("Flower Pot"),
_tt_help = S("Can hold a small flower or plant"), _tt_help = S("Can hold a small flower or plant"),
@ -62,24 +62,10 @@ minetest.register_node("mcl_flowerpots:flower_pot", {
return return
end end
local item = clicker:get_wielded_item():get_name() local item = clicker:get_wielded_item():get_name()
for _, row in ipairs(flowers) do if mcl_flowerpots.registered_pots[item] then
local flower = row[1] minetest.swap_node(pos, {name="mcl_flowerpots:flower_pot_"..mcl_flowerpots.registered_pots[item]})
local flower_node = row[2] if not minetest.is_creative_enabled(clicker:get_player_name()) then
if item == flower_node then itemstack:take_item()
minetest.swap_node(pos, {name="mcl_flowerpots:flower_pot_"..flower})
if not minetest.is_creative_enabled(clicker:get_player_name()) then
itemstack:take_item()
end
end
end
for _, row in ipairs(cubes) do
local flower = row[1]
local flower_node = row[2]
if item == flower_node then
minetest.swap_node(pos, {name="mcl_flowerpots:flower_pot_"..flower})
if not minetest.is_creative_enabled(clicker:get_player_name()) then
itemstack:take_item()
end
end end
end end
end, end,
@ -94,112 +80,106 @@ minetest.register_craft({
} }
}) })
for _, row in ipairs(flowers) do function mcl_flowerpots.register_potted_flower(name, def)
local flower = row[1] mcl_flowerpots.registered_pots[name] = def.name
local flower_node = row[2] minetest.register_node(":mcl_flowerpots:flower_pot_"..def.name, {
local desc = row[3] description = def.desc.." "..S("Flower Pot"),
local texture _doc_items_create_entry = false,
if row[4] then drawtype = "mesh",
texture = row[4] mesh = "flowerpot.obj",
else tiles = {
texture = minetest.registered_nodes[flower_node]["tiles"] "[combine:32x32:0,0=mcl_flowerpots_flowerpot.png:0,0="..def.image,
},
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true,
visual_scale = 0.5,
wield_scale = {x=1.0, y=1.0, z=1.0},
paramtype = "light",
sunlight_propagates = true,
selection_box = {
type = "fixed",
fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}
},
collision_box = {
type = "fixed",
fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}
},
is_ground_content = false,
groups = {dig_immediate=3, attached_node=1, dig_by_piston=1, not_in_creative_inventory=1, flower_pot=2},
sounds = mcl_sounds.node_sound_stone_defaults(),
on_rightclick = function(pos, item, clicker)
local player_name = clicker:get_player_name()
if minetest.is_protected(pos, player_name) then
minetest.record_protection_violation(pos, player_name)
return
end
minetest.add_item({x=pos.x, y=pos.y+0.5, z=pos.z}, name)
minetest.set_node(pos, {name="mcl_flowerpots:flower_pot"})
end,
drop = {
items = {
{ items = { "mcl_flowerpots:flower_pot", name } }
}
},
})
-- Add entry alias for the Help
if has_doc then
doc.add_entry_alias("nodes", "mcl_flowerpots:flower_pot", "nodes", "mcl_flowerpots:flower_pot_"..name)
end
end end
minetest.register_node("mcl_flowerpots:flower_pot_"..flower, {
description = desc, function mcl_flowerpots.register_potted_cube(name, def)
_doc_items_create_entry = false, mcl_flowerpots.registered_pots[name] = def.name
drawtype = "mesh", minetest.register_node(":mcl_flowerpots:flower_pot_"..def.name, {
mesh = "flowerpot.obj", description = def.desc.." "..S("Flower Pot"),
tiles = { _doc_items_create_entry = false,
"[combine:32x32:0,0=mcl_flowerpots_flowerpot.png:0,0="..texture[1], drawtype = "mesh",
}, mesh = "flowerpot_with_long_cube.obj",
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, tiles = {
visual_scale = 0.5, "[combine:32x32:0,0=mcl_flowerpots_flowerpot.png:0,0="..def.image,
wield_scale = {x=1.0, y=1.0, z=1.0}, },
paramtype = "light", use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true,
sunlight_propagates = true, visual_scale = 0.5,
selection_box = { wield_scale = {x=1.0, y=1.0, z=1.0},
type = "fixed", paramtype = "light",
fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2} sunlight_propagates = true,
}, selection_box = {
collision_box = { type = "fixed",
type = "fixed", fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}
fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2} },
}, collision_box = {
is_ground_content = false, type = "fixed",
groups = {dig_immediate=3, attached_node=1, dig_by_piston=1, not_in_creative_inventory=1, flower_pot=2}, fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}
sounds = mcl_sounds.node_sound_stone_defaults(), },
on_rightclick = function(pos, item, clicker) is_ground_content = false,
local name = clicker:get_player_name() groups = {dig_immediate=3, attached_node=1, dig_by_piston=1, not_in_creative_inventory=1, flower_pot=2},
if minetest.is_protected(pos, name) then sounds = mcl_sounds.node_sound_stone_defaults(),
minetest.record_protection_violation(pos, name) on_rightclick = function(pos, item, clicker)
return local name = ""
end if clicker:is_player() then
minetest.add_item({x=pos.x, y=pos.y+0.5, z=pos.z}, flower_node) player_name = clicker:get_player_name()
minetest.set_node(pos, {name="mcl_flowerpots:flower_pot"}) end
end, if minetest.is_protected(pos, player_name) then
drop = { minetest.record_protection_violation(pos, player_name)
items = { return
{ items = { "mcl_flowerpots:flower_pot", flower_node } } end
} minetest.add_item({x=pos.x, y=pos.y+0.5, z=pos.z}, name)
}, minetest.set_node(pos, {name="mcl_flowerpots:flower_pot"})
end,
drop = {
items = {
{ items = { "mcl_flowerpots:flower_pot", name } }
}
},
})
-- Add entry alias for the Help
if has_doc then
doc.add_entry_alias("nodes", "mcl_flowerpots:flower_pot", "nodes", "mcl_flowerpots:flower_pot_"..def.name)
end
end
--forced because hard dependency to mcl_core
mcl_flowerpots.register_potted_cube("mcl_core:cactus", {
name = "cactus",
desc = S("Cactus"),
image = "mcl_flowerpots_cactus.png",
}) })
-- Add entry alias for the Help
if minetest.get_modpath("doc") then
doc.add_entry_alias("nodes", "mcl_flowerpots:flower_pot", "nodes", "mcl_flowerpots:flower_pot_"..flower)
end
end
for _, row in ipairs(cubes) do
local flower = row[1]
local flower_node = row[2]
local desc = row[3]
minetest.register_node("mcl_flowerpots:flower_pot_"..flower, {
description = desc,
_doc_items_create_entry = false,
drawtype = "mesh",
mesh = "flowerpot_with_long_cube.obj",
tiles = {
"mcl_flowerpots_"..flower..".png",
},
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true,
visual_scale = 0.5,
wield_scale = {x=1.0, y=1.0, z=1.0},
paramtype = "light",
sunlight_propagates = true,
selection_box = {
type = "fixed",
fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}
},
collision_box = {
type = "fixed",
fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}
},
is_ground_content = false,
groups = {dig_immediate=3, attached_node=1, dig_by_piston=1, not_in_creative_inventory=1, flower_pot=2},
sounds = mcl_sounds.node_sound_stone_defaults(),
on_rightclick = function(pos, item, clicker)
local name = ""
if clicker:is_player() then
name = clicker:get_player_name()
end
if minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name)
return
end
minetest.add_item({x=pos.x, y=pos.y+0.5, z=pos.z}, flower_node)
minetest.set_node(pos, {name="mcl_flowerpots:flower_pot"})
end,
drop = {
items = {
{ items = { "mcl_flowerpots:flower_pot", flower_node } }
}
},
})
-- Add entry alias for the Help
if minetest.get_modpath("doc") then
doc.add_entry_alias("nodes", "mcl_flowerpots:flower_pot", "nodes", "mcl_flowerpots:flower_pot_"..flower)
end
end

View File

@ -0,0 +1,3 @@
name=mcl_flowerpots
depends=mcl_core, mcl_sounds, mcl_farming
optional_depends=doc

View File

@ -1,5 +0,0 @@
mcl_core
mcl_util
mcl_sounds
screwdriver?
doc?

View File

@ -1,5 +1,6 @@
local S = minetest.get_translator("mcl_flowers") local S = minetest.get_translator("mcl_flowers")
local mod_screwdriver = minetest.get_modpath("screwdriver") ~= nil local mod_screwdriver = minetest.get_modpath("screwdriver") ~= nil
local has_mcl_flowerpots = minetest.get_modpath("mcl_flowerpots")
local modpath = minetest.get_modpath("mcl_flowers") local modpath = minetest.get_modpath("mcl_flowers")
mcl_flowers = {} mcl_flowers = {}
@ -53,48 +54,49 @@ local on_place_flower = mcl_util.generate_on_place_plant_function(function(pos,
return ok, colorize return ok, colorize
end) end)
function mcl_flowers.register_simple_flower(name, desc, image, simple_selection_box) function mcl_flowers.register_simple_flower(name, def)
local newname = "mcl_flowers:"..name local newname = "mcl_flowers:"..name
if not def._mcl_silk_touch_drop then def._mcl_silk_touch_drop = nil end
if not def.drop then def.drop = newname end
mcl_flowers.registered_simple_flowers[newname] = { mcl_flowers.registered_simple_flowers[newname] = {
desc=desc name=name,
image=image desc=def.desc,
simple_selection_box=simple_selection_box pot_desc=def.pot_desc,
image=def.image,
selection_box=def.selection_box,
} }
minetest.register_node(newname, { minetest.register_node(newname, {
description = desc, description = def.desc,
_doc_items_longdesc = smallflowerlongdesc, _doc_items_longdesc = smallflowerlongdesc,
_doc_items_usagehelp = plant_usage_help, _doc_items_usagehelp = plant_usage_help,
drawtype = "plantlike", drawtype = "plantlike",
waving = 1, waving = 1,
tiles = { image..".png" }, tiles = { def.image },
inventory_image = image..".png", inventory_image = def.image,
wield_image = image..".png", wield_image = def.image,
sunlight_propagates = true, sunlight_propagates = true,
paramtype = "light", paramtype = "light",
walkable = false, walkable = false,
stack_max = 64, stack_max = 64,
drop = def.drop,
groups = {dig_immediate=3,flammable=2,fire_encouragement=60,fire_flammability=100,plant=1,flower=1,place_flowerlike=1,non_mycelium_plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1,enderman_takable=1,deco_block=1}, groups = {dig_immediate=3,flammable=2,fire_encouragement=60,fire_flammability=100,plant=1,flower=1,place_flowerlike=1,non_mycelium_plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1,enderman_takable=1,deco_block=1},
sounds = mcl_sounds.node_sound_leaves_defaults(), sounds = mcl_sounds.node_sound_leaves_defaults(),
node_placement_prediction = "", node_placement_prediction = "",
on_place = on_place_flower, on_place = on_place_flower,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = simple_selection_box, fixed = def.selection_box,
}, },
_mcl_silk_touch_drop = def._mcl_silk_touch_drop,
}) })
if def.potted and has_mcl_flowerpots then
mcl_flowerpots.register_potted_flower(newname, {
name = name,
desc = def.desc,
image = def.image,
})
end
end end
local add_simple_flower = mcl_flowers.register_simple_flower
add_simple_flower("poppy", S("Poppy"), "mcl_flowers_poppy", { -5/16, -0.5, -5/16, 5/16, 5/16, 5/16 })
add_simple_flower("dandelion", S("Dandelion"), "flowers_dandelion_yellow", { -4/16, -0.5, -4/16, 4/16, 3/16, 4/16 })
add_simple_flower("oxeye_daisy", S("Oxeye Daisy"), "mcl_flowers_oxeye_daisy", { -4/16, -0.5, -4/16, 4/16, 4/16, 4/16 })
add_simple_flower("tulip_orange", S("Orange Tulip"), "flowers_tulip", { -3/16, -0.5, -3/16, 3/16, 5/16, 3/16 })
add_simple_flower("tulip_pink", S("Pink Tulip"), "mcl_flowers_tulip_pink", { -3/16, -0.5, -3/16, 3/16, 5/16, 3/16 })
add_simple_flower("tulip_red", S("Red Tulip"), "mcl_flowers_tulip_red", { -3/16, -0.5, -3/16, 3/16, 6/16, 3/16 })
add_simple_flower("tulip_white", S("White Tulip"), "mcl_flowers_tulip_white", { -3/16, -0.5, -3/16, 3/16, 4/16, 3/16 })
add_simple_flower("allium", S("Allium"), "mcl_flowers_allium", { -3/16, -0.5, -3/16, 3/16, 6/16, 3/16 })
add_simple_flower("azure_bluet", S("Azure Bluet"), "mcl_flowers_azure_bluet", { -5/16, -0.5, -5/16, 5/16, 3/16, 5/16 })
add_simple_flower("blue_orchid", S("Blue Orchid"), "mcl_flowers_blue_orchid", { -5/16, -0.5, -5/16, 5/16, 7/16, 5/16 })
local wheat_seed_drop = { local wheat_seed_drop = {
max_items = 1, max_items = 1,

View File

@ -0,0 +1,3 @@
name=mcl_flowers
depends=mcl_core, mcl_util, mcl_sounds
optional_depends=screwdriver, doc, mcl_flowerpots

View File

@ -1,12 +1,62 @@
local S = minetest.get_translator("mcl_flowers") local S = minetest.get_translator("mcl_flowers")
local add_simple_flower = mcl_flowers.register_simple_flower
add_simple_flower("poppy", S("Poppy"), "mcl_flowers_poppy", { -5/16, -0.5, -5/16, 5/16, 5/16, 5/16 }) mcl_flowers.register_simple_flower("poppy", {
add_simple_flower("dandelion", S("Dandelion"), "flowers_dandelion_yellow", { -4/16, -0.5, -4/16, 4/16, 3/16, 4/16 }) desc = S("Poppy"),
add_simple_flower("oxeye_daisy", S("Oxeye Daisy"), "mcl_flowers_oxeye_daisy", { -4/16, -0.5, -4/16, 4/16, 4/16, 4/16 }) image = "mcl_flowers_poppy.png",
add_simple_flower("tulip_orange", S("Orange Tulip"), "flowers_tulip", { -3/16, -0.5, -3/16, 3/16, 5/16, 3/16 }) selection_box = { -5/16, -0.5, -5/16, 5/16, 5/16, 5/16 },
add_simple_flower("tulip_pink", S("Pink Tulip"), "mcl_flowers_tulip_pink", { -3/16, -0.5, -3/16, 3/16, 5/16, 3/16 }) potted = true,
add_simple_flower("tulip_red", S("Red Tulip"), "mcl_flowers_tulip_red", { -3/16, -0.5, -3/16, 3/16, 6/16, 3/16 }) })
add_simple_flower("tulip_white", S("White Tulip"), "mcl_flowers_tulip_white", { -3/16, -0.5, -3/16, 3/16, 4/16, 3/16 }) mcl_flowers.register_simple_flower("dandelion", {
add_simple_flower("allium", S("Allium"), "mcl_flowers_allium", { -3/16, -0.5, -3/16, 3/16, 6/16, 3/16 }) desc = S("Dandelion"),
add_simple_flower("azure_bluet", S("Azure Bluet"), "mcl_flowers_azure_bluet", { -5/16, -0.5, -5/16, 5/16, 3/16, 5/16 }) image = "flowers_dandelion_yellow.png",
add_simple_flower("blue_orchid", S("Blue Orchid"), "mcl_flowers_blue_orchid", { -5/16, -0.5, -5/16, 5/16, 7/16, 5/16 }) selection_box = { -4/16, -0.5, -4/16, 4/16, 3/16, 4/16 },
potted = true,
})
mcl_flowers.register_simple_flower("oxeye_daisy", {
desc = S("Oxeye Daisy"),
image = "mcl_flowers_oxeye_daisy.png",
selection_box = { -4/16, -0.5, -4/16, 4/16, 4/16, 4/16 },
potted = true,
})
mcl_flowers.register_simple_flower("tulip_orange", {
desc = S("Orange Tulip"),
image = "flowers_tulip.png",
selection_box = { -3/16, -0.5, -3/16, 3/16, 5/16, 3/16 },
potted = true,
})
mcl_flowers.register_simple_flower("tulip_pink", {
desc = S("Pink Tulip"),
image = "mcl_flowers_tulip_pink.png",
selection_box = { -3/16, -0.5, -3/16, 3/16, 5/16, 3/16 },
potted = true,
})
mcl_flowers.register_simple_flower("tulip_red", {
desc = S("Red Tulip"),
image = "mcl_flowers_tulip_red.png",
selection_box = { -3/16, -0.5, -3/16, 3/16, 6/16, 3/16 },
potted = true,
})
mcl_flowers.register_simple_flower("tulip_white", {
desc = S("White Tulip"),
image = "mcl_flowers_tulip_white.png",
selection_box = { -3/16, -0.5, -3/16, 3/16, 4/16, 3/16 },
potted = true,
})
mcl_flowers.register_simple_flower("allium", {
desc = S("Allium"),
image = "mcl_flowers_allium.png",
selection_box = { -3/16, -0.5, -3/16, 3/16, 6/16, 3/16 },
potted = true,
})
mcl_flowers.register_simple_flower("azure_bluet", {
desc = S("Azure Bluet"),
image = "mcl_flowers_azure_bluet.png",
selection_box = { -5/16, -0.5, -5/16, 5/16, 3/16, 5/16 },
potted = true,
})
mcl_flowers.register_simple_flower("blue_orchid", {
desc = S("Blue Orchid"),
image = "mcl_flowers_blue_orchid.png",
selection_box = { -5/16, -0.5, -5/16, 5/16, 7/16, 5/16 },
potted = true,
})