2021-05-29 16:12:33 +02:00
local S = minetest.get_translator ( minetest.get_current_modname ( ) )
2021-03-11 22:13:43 +01:00
local has_doc = minetest.get_modpath ( " doc " )
mcl_flowerpots = { }
2022-10-08 11:20:35 +02:00
---@type table<string, string>
2021-03-11 22:13:43 +01:00
mcl_flowerpots.registered_pots = { }
2017-02-10 21:13:22 +01:00
2022-10-08 11:20:35 +02:00
---@type nodebox
local pot_box = {
type = " fixed " ,
fixed = {
{ - 0.1875 , - 0.5 , - 0.1875 , 0.1875 , - 0.125 , 0.1875 } ,
} ,
}
2017-11-18 04:44:23 +01:00
minetest.register_node ( " mcl_flowerpots:flower_pot " , {
2019-03-08 00:00:09 +01:00
description = S ( " Flower Pot " ) ,
2020-03-12 01:35:11 +01:00
_tt_help = S ( " Can hold a small flower or plant " ) ,
2019-03-09 17:01:36 +01:00
_doc_items_longdesc = S ( " Flower pots are decorative blocks in which flowers and other small plants can be placed. " ) ,
2019-03-15 06:12:03 +01:00
_doc_items_usagehelp = S ( " Just place a plant on the flower pot. Flower pots can hold small flowers (not higher than 1 block), saplings, ferns, dead bushes, mushrooms and cacti. Rightclick a potted plant to retrieve the plant. " ) ,
2017-11-18 04:44:23 +01:00
drawtype = " mesh " ,
mesh = " flowerpot.obj " ,
tiles = {
" mcl_flowerpots_flowerpot.png " ,
} ,
2022-10-08 11:20:35 +02:00
use_texture_alpha = " clip " ,
2017-11-18 04:44:23 +01:00
visual_scale = 0.5 ,
wield_image = " mcl_flowerpots_flowerpot_inventory.png " ,
paramtype = " light " ,
sunlight_propagates = true ,
2022-10-08 11:20:35 +02:00
selection_box = pot_box ,
collision_box = pot_box ,
2017-11-18 04:44:23 +01:00
is_ground_content = false ,
inventory_image = " mcl_flowerpots_flowerpot_inventory.png " ,
2022-10-08 11:20:35 +02:00
groups = { dig_immediate = 3 , deco_block = 1 , attached_node = 1 , dig_by_piston = 1 , flower_pot = 1 } ,
2017-11-18 04:44:23 +01:00
sounds = mcl_sounds.node_sound_stone_defaults ( ) ,
on_rightclick = function ( pos , node , clicker , itemstack )
2019-02-08 21:59:01 +01:00
local name = clicker : get_player_name ( )
if minetest.is_protected ( pos , name ) then
minetest.record_protection_violation ( pos , name )
return
end
2017-11-18 04:44:23 +01:00
local item = clicker : get_wielded_item ( ) : get_name ( )
2021-03-11 22:13:43 +01:00
if mcl_flowerpots.registered_pots [ item ] then
2022-10-08 11:20:35 +02:00
minetest.swap_node ( pos , { name = " mcl_flowerpots:flower_pot_ " .. mcl_flowerpots.registered_pots [ item ] } )
2021-03-11 22:13:43 +01:00
if not minetest.is_creative_enabled ( clicker : get_player_name ( ) ) then
itemstack : take_item ( )
2017-11-18 04:44:23 +01:00
end
end
end ,
} )
minetest.register_craft ( {
2021-05-29 16:12:33 +02:00
output = " mcl_flowerpots:flower_pot " ,
2017-11-18 04:44:23 +01:00
recipe = {
2022-10-08 11:20:35 +02:00
{ " mcl_core:brick " , " " , " mcl_core:brick " } ,
{ " " , " mcl_core:brick " , " " } ,
{ " " , " " , " " } ,
} ,
2017-11-18 04:44:23 +01:00
} )
2022-10-08 11:20:35 +02:00
---@param name string
---@param def {name: string, desc: string, image: string}
2021-03-11 22:13:43 +01:00
function mcl_flowerpots . register_potted_flower ( name , def )
mcl_flowerpots.registered_pots [ name ] = def.name
2022-10-08 11:20:35 +02:00
minetest.register_node ( " :mcl_flowerpots:flower_pot_ " .. def.name , {
description = def.desc .. " " .. S ( " Flower Pot " ) ,
2021-03-11 22:13:43 +01:00
_doc_items_create_entry = false ,
drawtype = " mesh " ,
mesh = " flowerpot.obj " ,
tiles = {
2023-02-24 14:53:35 +01:00
" [combine:32x32:0,0=mcl_flowerpots_flowerpot.png:0,0= " .. def.image .. " :0,0=mcl_flowerpots_flowerpot.png " ,
2021-03-11 22:13:43 +01:00
} ,
2022-10-08 11:20:35 +02:00
use_texture_alpha = " clip " ,
2021-03-11 22:13:43 +01:00
visual_scale = 0.5 ,
paramtype = " light " ,
2023-02-24 14:53:35 +01:00
paramtype2 = def.paramtype2 ,
palette = def.palette ,
2021-03-11 22:13:43 +01:00
sunlight_propagates = true ,
2022-10-08 11:20:35 +02:00
selection_box = pot_box ,
collision_box = pot_box ,
2021-03-11 22:13:43 +01:00
is_ground_content = false ,
2023-02-24 14:53:35 +01:00
groups = { dig_immediate = 3 , attached_node = 1 , dig_by_piston = 1 , not_in_creative_inventory = 1 , flower_pot = 2 , grass_palette = def.grass_palette_group } ,
2021-03-11 22:13:43 +01:00
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
2022-10-08 11:20:35 +02:00
minetest.add_item ( vector.offset ( pos , 0 , 0.5 , 0 ) , name )
minetest.set_node ( pos , { name = " mcl_flowerpots:flower_pot " } )
2021-03-11 22:13:43 +01:00
end ,
drop = {
items = {
2022-10-08 11:20:35 +02:00
{ items = { " mcl_flowerpots:flower_pot " , name } } ,
} ,
2021-03-11 22:13:43 +01:00
} ,
} )
-- Add entry alias for the Help
if has_doc then
2022-10-08 11:20:35 +02:00
doc.add_entry_alias ( " nodes " , " mcl_flowerpots:flower_pot " , " nodes " , " mcl_flowerpots:flower_pot_ " .. name )
2021-03-11 22:13:43 +01:00
end
2017-11-18 04:44:23 +01:00
end
2022-10-08 11:20:35 +02:00
---@param name string
---@param def {name: string, desc: string, image: string}
2021-03-11 22:13:43 +01:00
function mcl_flowerpots . register_potted_cube ( name , def )
mcl_flowerpots.registered_pots [ name ] = def.name
2022-10-08 11:20:35 +02:00
minetest.register_node ( " :mcl_flowerpots:flower_pot_ " .. def.name , {
description = def.desc .. " " .. S ( " Flower Pot " ) ,
2021-03-11 22:13:43 +01:00
_doc_items_create_entry = false ,
drawtype = " mesh " ,
mesh = " flowerpot_with_long_cube.obj " ,
tiles = {
2021-03-11 22:18:39 +01:00
def.image ,
2021-03-11 22:13:43 +01:00
} ,
2022-10-08 11:20:35 +02:00
use_texture_alpha = " clip " ,
2021-03-11 22:13:43 +01:00
visual_scale = 0.5 ,
paramtype = " light " ,
sunlight_propagates = true ,
2022-10-08 11:20:35 +02:00
selection_box = pot_box ,
collision_box = pot_box ,
2021-03-11 22:13:43 +01:00
is_ground_content = false ,
2022-10-08 11:20:35 +02:00
groups = { dig_immediate = 3 , attached_node = 1 , dig_by_piston = 1 , not_in_creative_inventory = 1 , flower_pot = 2 } ,
2021-03-11 22:13:43 +01:00
sounds = mcl_sounds.node_sound_stone_defaults ( ) ,
on_rightclick = function ( pos , item , clicker )
2021-03-11 22:42:42 +01:00
local player_name = " "
2021-03-11 22:13:43 +01:00
if clicker : is_player ( ) then
player_name = clicker : get_player_name ( )
end
if minetest.is_protected ( pos , player_name ) then
minetest.record_protection_violation ( pos , player_name )
return
end
2022-10-08 11:20:35 +02:00
minetest.add_item ( vector.offset ( pos , 0 , 0.5 , 0 ) , name )
minetest.set_node ( pos , { name = " mcl_flowerpots:flower_pot " } )
2021-03-11 22:13:43 +01:00
end ,
drop = {
items = {
2022-10-08 11:20:35 +02:00
{ items = { " mcl_flowerpots:flower_pot " , name } } ,
} ,
2021-03-11 22:13:43 +01:00
} ,
} )
-- Add entry alias for the Help
if has_doc then
2022-10-08 11:20:35 +02:00
doc.add_entry_alias ( " nodes " , " mcl_flowerpots:flower_pot " , " nodes " , " mcl_flowerpots:flower_pot_ " .. def.name )
2021-03-11 22:13:43 +01:00
end
end
2017-11-18 04:44:23 +01:00
2021-03-11 22:13:43 +01:00
--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 " ,
2017-11-18 04:44:23 +01:00
} )
2021-03-11 22:42:42 +01:00
mcl_flowerpots.register_potted_flower ( " mcl_mushrooms:mushroom_brown " , {
name = " mushroom_brown " ,
desc = S ( " Brown Mushroom " ) ,
image = " farming_mushroom_brown.png " ,
} )
mcl_flowerpots.register_potted_flower ( " mcl_mushrooms:mushroom_red " , {
name = " mushroom_red " ,
desc = S ( " Red Mushroom " ) ,
image = " farming_mushroom_red.png " ,
} )
mcl_flowerpots.register_potted_flower ( " mcl_core:sapling " , {
name = " sapling " ,
desc = S ( " Oak Sapling " ) ,
image = " default_sapling.png " ,
} )
mcl_flowerpots.register_potted_flower ( " mcl_core:acaciasapling " , {
name = " acaciasapling " ,
desc = S ( " Acacia Sapling " ) ,
image = " default_acacia_sapling.png " ,
} )
mcl_flowerpots.register_potted_flower ( " mcl_core:junglesapling " , {
name = " junglesapling " ,
desc = S ( " Jungle Sapling " ) ,
image = " default_junglesapling.png " ,
} )
mcl_flowerpots.register_potted_flower ( " mcl_core:darksapling " , {
name = " darksapling " ,
desc = S ( " Dark Oak Sapling " ) ,
image = " mcl_core_sapling_big_oak.png " ,
} )
mcl_flowerpots.register_potted_flower ( " mcl_core:sprucesapling " , {
name = " sprucesapling " ,
desc = S ( " Spruce Sapling " ) ,
image = " mcl_core_sapling_spruce.png " ,
} )
mcl_flowerpots.register_potted_flower ( " mcl_core:birchsapling " , {
name = " birchsapling " ,
desc = S ( " Birch Sapling " ) ,
image = " mcl_core_sapling_birch.png " ,
} )
mcl_flowerpots.register_potted_flower ( " mcl_core:deadbush " , {
name = " deadbush " ,
desc = S ( " Dead Bush " ) ,
image = " default_dry_shrub.png " ,
} )