2021-05-29 14:12:33 +00:00
local S = minetest.get_translator ( minetest.get_current_modname ( ) )
2019-03-07 22:40:43 +00:00
2017-02-18 15:09:01 +00:00
mcl_cocoas = { }
2017-02-18 15:06:18 +00:00
2017-02-18 19:23:26 +00:00
-- Place cocoa
2021-03-15 08:02:45 +00:00
function mcl_cocoas . place ( itemstack , placer , pt , plantname )
2017-02-18 15:06:18 +00:00
-- check if pointing at a node
if not pt or pt.type ~= " node " then
return
end
local under = minetest.get_node ( pt.under )
-- return if any of the nodes are not registered
if not minetest.registered_nodes [ under.name ] then
return
end
2017-03-02 14:50:53 +00:00
-- Am I right-clicking on something that has a custom on_rightclick set?
if placer and not placer : get_player_control ( ) . sneak then
if minetest.registered_nodes [ under.name ] and minetest.registered_nodes [ under.name ] . on_rightclick then
2021-03-19 17:25:40 +00:00
return minetest.registered_nodes [ under.name ] . on_rightclick ( pt.under , under , placer , itemstack ) or itemstack
2017-03-02 14:50:53 +00:00
end
2017-02-18 15:06:18 +00:00
end
2017-02-18 17:28:33 +00:00
-- Check if pointing at jungle tree
2017-02-18 15:06:18 +00:00
if under.name ~= " mcl_core:jungletree "
or minetest.get_node ( pt.above ) . name ~= " air " then
return
end
2017-02-18 17:28:33 +00:00
-- Determine cocoa direction
local clickdir = vector.subtract ( pt.under , pt.above )
-- Did user click on the SIDE of a jungle tree?
if clickdir.y ~= 0 then
return
end
-- Add the node, set facedir and remove 1 item from the itemstack
minetest.set_node ( pt.above , { name = plantname , param2 = minetest.dir_to_facedir ( clickdir ) } )
2017-02-18 15:06:18 +00:00
2020-04-06 22:55:45 +00:00
minetest.sound_play ( " default_place_node " , { pos = pt.above , gain = 1.0 } , true )
2017-02-18 15:06:18 +00:00
2020-07-10 14:08:40 +00:00
if not minetest.is_creative_enabled ( placer : get_player_name ( ) ) then
2017-02-18 15:06:18 +00:00
itemstack : take_item ( )
end
return itemstack
end
2017-02-18 19:23:26 +00:00
-- Attempts to grow a cocoa at pos, returns true when grown, returns false if there's no cocoa
-- or it is already at full size
function mcl_cocoas . grow ( pos )
local node = minetest.get_node ( pos )
if node.name == " mcl_cocoas:cocoa_1 " then
minetest.set_node ( pos , { name = " mcl_cocoas:cocoa_2 " , param2 = node.param2 } )
elseif node.name == " mcl_cocoas:cocoa_2 " then
minetest.set_node ( pos , { name = " mcl_cocoas:cocoa_3 " , param2 = node.param2 } )
return true
end
return false
end
2017-02-18 15:06:18 +00:00
-- Cocoa definition
2017-02-18 19:23:26 +00:00
-- 1st stage
2017-02-18 15:06:18 +00:00
local crop_def = {
2019-03-21 19:13:35 +00:00
description = S ( " Premature Cocoa Pod " ) ,
2017-03-11 16:42:20 +00:00
_doc_items_create_entry = true ,
2019-03-21 19:13:35 +00:00
_doc_items_longdesc = S ( " Cocoa pods grow on the side of jungle trees in 3 stages. " ) ,
2022-11-16 13:38:44 +00:00
drawtype = " mesh " ,
mesh = " mcl_cocoas_cocoa_stage_0.obj " ,
tiles = { " mcl_cocoas_cocoa_stage_0.png " } ,
2021-02-18 13:00:17 +00:00
use_texture_alpha = minetest.features . use_texture_alpha_string_modes and " clip " or true ,
2017-02-18 15:06:18 +00:00
paramtype = " light " ,
2017-02-18 18:15:58 +00:00
sunlight_propagates = true ,
2017-02-18 15:06:18 +00:00
paramtype2 = " facedir " ,
walkable = true ,
2022-12-22 18:32:15 +00:00
drop = " mcl_cocoas:cocoa_beans " ,
2017-02-18 17:19:43 +00:00
collision_box = {
type = " fixed " ,
fixed = {
{ - 0.125 , - 0.0625 , 0.1875 , 0.125 , 0.25 , 0.4375 } , -- Pod
} ,
} ,
2017-02-18 15:06:18 +00:00
selection_box = {
type = " fixed " ,
2017-02-18 17:19:43 +00:00
fixed = {
{ - 0.125 , - 0.0625 , 0.1875 , 0.125 , 0.5 , 0.5 } , -- Pod
} ,
2017-02-18 15:06:18 +00:00
} ,
groups = {
2018-01-08 19:19:33 +00:00
handy = 1 , axey = 1 , cocoa = 1 , not_in_creative_inventory = 1 , dig_by_water = 1 , destroy_by_lava_flow = 1 , dig_by_piston = 1 , attached_node_facedir = 1 ,
2017-02-18 15:06:18 +00:00
} ,
2017-02-22 15:03:59 +00:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
2019-12-14 23:27:23 +00:00
on_rotate = false ,
2020-04-17 19:40:13 +00:00
_mcl_blast_resistance = 3 ,
2017-02-27 00:13:03 +00:00
_mcl_hardness = 0.2 ,
2017-02-18 15:06:18 +00:00
}
2017-02-18 19:23:26 +00:00
-- 2nd stage
2017-02-18 15:09:01 +00:00
minetest.register_node ( " mcl_cocoas:cocoa_1 " , table.copy ( crop_def ) )
2017-02-18 15:06:18 +00:00
2019-03-21 19:13:35 +00:00
crop_def.description = S ( " Medium Cocoa Pod " )
2017-03-11 16:42:20 +00:00
crop_def._doc_items_create_entry = false
2017-02-18 20:07:57 +00:00
crop_def.groups . cocoa = 2
2022-11-16 13:38:44 +00:00
crop_def.mesh = " mcl_cocoas_cocoa_stage_1.obj "
crop_def.tiles = { " mcl_cocoas_cocoa_stage_1.png " }
2017-02-18 17:19:43 +00:00
crop_def.collision_box = {
type = " fixed " ,
fixed = {
{ - 0.1875 , - 0.1875 , 0.0625 , 0.1875 , 0.25 , 0.4375 } , -- Pod
} ,
}
crop_def.selection_box = {
type = " fixed " ,
fixed = {
{ - 0.1875 , - 0.1875 , 0.0625 , 0.1875 , 0.5 , 0.5 } ,
} ,
}
2017-02-18 15:09:01 +00:00
minetest.register_node ( " mcl_cocoas:cocoa_2 " , table.copy ( crop_def ) )
2017-02-18 15:06:18 +00:00
2017-02-18 19:23:26 +00:00
-- Final stage
2019-03-21 19:13:35 +00:00
crop_def.description = S ( " Mature Cocoa Pod " )
crop_def._doc_items_longdesc = S ( " A mature cocoa pod grew on a jungle tree to its full size and it is ready to be harvested for cocoa beans. It won't grow any further. " )
2017-03-02 18:53:53 +00:00
crop_def._doc_items_create_entry = true
2017-02-18 20:07:57 +00:00
crop_def.groups . cocoa = 3
2022-11-16 13:38:44 +00:00
crop_def.mesh = " mcl_cocoas_cocoa_stage_2.obj "
crop_def.tiles = { " mcl_cocoas_cocoa_stage_2.png " }
2017-02-18 17:19:43 +00:00
crop_def.collision_box = {
type = " fixed " ,
fixed = {
{ - 0.25 , - 0.3125 , - 0.0625 , 0.25 , 0.25 , 0.4375 } , -- Pod
} ,
}
crop_def.selection_box = {
type = " fixed " ,
fixed = {
{ - 0.25 , - 0.3125 , - 0.0625 , 0.25 , 0.5 , 0.5 } ,
} ,
}
2022-12-22 18:32:15 +00:00
crop_def.drop = " mcl_cocoas:cocoa_beans 3 "
2017-02-18 15:09:01 +00:00
minetest.register_node ( " mcl_cocoas:cocoa_3 " , table.copy ( crop_def ) )
2017-02-18 15:06:18 +00:00
2022-12-22 18:32:15 +00:00
minetest.register_craftitem ( " mcl_cocoas:cocoa_beans " , {
description = S ( " Cocoa Beans " ) ,
_tt_help = S ( " Grows at the side of jungle trees " ) ,
_doc_items_longdesc = S ( " Cocoa beans can be used to plant cocoa, bake cookies or craft brown dye. " ) ,
_doc_items_usagehelp = S ( " Right click on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa. " ) ,
inventory_image = " mcl_cocoas_cocoa_beans.png " ,
groups = { craftitem = 1 , compostability = 65 } ,
on_place = function ( itemstack , placer , pointed_thing )
return cocoa_place ( itemstack , placer , pointed_thing , " mcl_cocoas:cocoa_1 " )
end ,
} )
2017-02-18 15:06:18 +00:00
2017-02-18 19:23:26 +00:00
minetest.register_abm ( {
2019-03-21 19:13:35 +00:00
label = " Cocoa pod growth " ,
2017-02-18 19:23:26 +00:00
nodenames = { " mcl_cocoas:cocoa_1 " , " mcl_cocoas:cocoa_2 " } ,
-- Same as potatoes
-- TODO: Tweak/balance the growth speed
interval = 50 ,
chance = 20 ,
action = function ( pos , node )
mcl_cocoas.grow ( pos )
end
} )
2017-03-20 17:12:05 +00:00
-- Add entry aliases for the Help
if minetest.get_modpath ( " doc " ) then
doc.add_entry_alias ( " nodes " , " mcl_cocoas:cocoa_1 " , " nodes " , " mcl_cocoas:cocoa_2 " )
end