2021-05-29 16:12:33 +02:00
local S = minetest.get_translator ( minetest.get_current_modname ( ) )
2019-03-07 23:40:43 +01:00
2017-02-18 16:09:01 +01:00
mcl_cocoas = { }
2017-02-18 16:06:18 +01:00
2022-05-02 00:58:31 +02:00
--- Place a cocoa pod.
-- Attempt to place a cocoa pod on a jungle tree. Checks if attachment
-- point is a jungle tree and sets the correct orientation of the stem.
--
function mcl_cocoas . place ( itemstack , placer , pt , plantname )
2017-02-18 16:06:18 +01:00
-- check if pointing at a node
if not pt or pt.type ~= " node " then
return
end
2022-05-02 00:58:31 +02:00
local node = minetest.get_node ( pt.under )
2017-02-18 16:06:18 +01:00
-- return if any of the nodes are not registered
2022-05-02 00:58:31 +02:00
local def = minetest.registered_nodes [ node.name ]
if not def then
2017-02-18 16:06:18 +01:00
return
end
2017-03-02 15:50:53 +01:00
-- Am I right-clicking on something that has a custom on_rightclick set?
if placer and not placer : get_player_control ( ) . sneak then
2022-05-02 00:58:31 +02:00
if def and def.on_rightclick then
return def.on_rightclick ( pt.under , node , placer , itemstack ) or itemstack
2017-03-02 15:50:53 +01:00
end
2017-02-18 16:06:18 +01:00
end
2017-02-18 18:28:33 +01:00
-- Check if pointing at jungle tree
2022-05-02 00:58:31 +02:00
if node.name ~= " mcl_core:jungletree "
2017-02-18 16:06:18 +01:00
or minetest.get_node ( pt.above ) . name ~= " air " then
return
end
2017-02-18 18:28:33 +01: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 ) } )
2020-04-07 00:55:45 +02:00
minetest.sound_play ( " default_place_node " , { pos = pt.above , gain = 1.0 } , true )
2020-07-10 16:08:40 +02:00
if not minetest.is_creative_enabled ( placer : get_player_name ( ) ) then
2017-02-18 16:06:18 +01:00
itemstack : take_item ( )
end
return itemstack
end
2022-05-02 00:58:31 +02:00
--- Grows cocoa pod one size larger.
-- 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.
--
2017-02-18 20:23:26 +01:00
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 } )
2022-05-02 00:58:31 +02:00
else
return false
2017-02-18 20:23:26 +01:00
end
2022-05-02 00:58:31 +02:00
return true
2017-02-18 20:23:26 +01:00
end
2022-05-02 00:58:31 +02:00
-- only caller was mcl_dye, now these can be local functions.
-- TODO: remove aliases, replace global functions with local functions.
local cocoa_place = mcl_cocoas.place
local cocoa_grow = mcl_cocoas.grow
-- Cocoa pod variant definitions.
--[[ TODO: Use a mesh for cocoas for perfect texture compability. ]]
local podinfo = {
{ desc = S ( " Premature Cocoa Pod " ) ,
longdesc = S ( " Cocoa pods grow on the side of jungle trees in 3 stages. " ) ,
tiles = {
" [combine:16x16:6,1=mcl_cocoas_cocoa_stage_0.png " ,
" [combine:16x16:6,11=mcl_cocoas_cocoa_stage_0.png " ,
" mcl_cocoas_cocoa_stage_0.png " ,
" mcl_cocoas_cocoa_stage_0.png^[transformFX " ,
" [combine:16x16:-5,0=mcl_cocoas_cocoa_stage_0.png " ,
" [combine:16x16:-5,0=mcl_cocoas_cocoa_stage_0.png " ,
2017-02-18 18:19:43 +01:00
} ,
2022-05-02 00:58:31 +02:00
n_box = { - 0.125 , - 0.0625 , 0.1875 , 0.125 , 0.25 , 0.4375 } ,
s_box = { - 0.125 , - 0.0625 , 0.1875 , 0.125 , 0.5 , 0.5 } ,
2017-02-18 18:19:43 +01:00
} ,
2022-05-02 00:58:31 +02:00
{ desc = S ( " Medium Cocoa Pod " ) ,
tiles = {
" [combine:16x16:5,1=mcl_cocoas_cocoa_stage_1.png " ,
" [combine:16x16:5,9=mcl_cocoas_cocoa_stage_1.png " ,
" mcl_cocoas_cocoa_stage_1.png " ,
" mcl_cocoas_cocoa_stage_1.png^[transformFX " ,
" [combine:16x16:-4,0=mcl_cocoas_cocoa_stage_1.png " ,
" [combine:16x16:-4,0=mcl_cocoas_cocoa_stage_1.png " ,
2017-02-18 18:19:43 +01:00
} ,
2022-05-02 00:58:31 +02:00
n_box = { - 0.1875 , - 0.1875 , 0.0625 , 0.1875 , 0.25 , 0.4375 } ,
s_box = { - 0.1875 , - 0.1875 , 0.0625 , 0.1875 , 0.5 , 0.5 } ,
2017-02-18 16:06:18 +01:00
} ,
2022-05-02 00:58:31 +02:00
{ desc = S ( " Mature Cocoa Pod " ) ,
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. " ) ,
tiles = {
-- The following 2 textures were derived from the original
-- because the size of the top/bottom is slightly different :-(
-- TODO: Find a way to *only* use the base texture
" mcl_cocoas_cocoa_top_stage_2.png " ,
" mcl_cocoas_cocoa_top_stage_2.png^[transformFY " ,
" mcl_cocoas_cocoa_stage_2.png " ,
" mcl_cocoas_cocoa_stage_2.png^[transformFX " ,
" [combine:16x16:-3,0=mcl_cocoas_cocoa_stage_2.png " ,
" [combine:16x16:-3,0=mcl_cocoas_cocoa_stage_2.png " ,
} ,
n_box = { - 0.25 , - 0.3125 , - 0.0625 , 0.25 , 0.25 , 0.4375 } ,
s_box = { - 0.25 , - 0.3125 , - 0.0625 , 0.25 , 0.5 , 0.5 } ,
2017-02-18 16:06:18 +01:00
} ,
}
2022-05-02 00:58:31 +02:00
for i = 1 , 3 do
local def = {
description = podinfo [ i ] . desc ,
_doc_items_create_entry = true ,
_doc_items_longdesc = podinfo [ i ] . longdesc ,
paramtype = " light " ,
paramtype2 = " facedir " ,
drawtype = " nodebox " ,
tiles = podinfo [ i ] . tiles ,
use_texture_alpha = " clip " ,
node_box = {
type = " fixed " ,
fixed = {
podinfo [ i ] . n_box , -- Pod
-- FIXME: This has a thickness of 0. Is this OK in Minetest?
{ 0 , 0.25 , 0.25 , 0 , 0.5 , 0.5 } , } , -- Stem
} ,
collision_box = {
type = " fixed " ,
fixed = podinfo [ i ] . n_box
} ,
selection_box = {
type = " fixed " ,
fixed = podinfo [ i ] . s_box
} ,
groups = {
handy = 1 , axey = 1 , attached_node_facedir = 1 ,
dig_by_water = 1 , destroy_by_lava_flow = 1 , dig_by_piston = 1 ,
cocoa = i , not_in_creative_inventory = 1 ,
} ,
sunlight_propagates = true ,
walkable = true ,
drop = " mcl_cocoas:cocoa_beans " ,
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
on_rotate = false ,
_mcl_blast_resistance = 3 ,
_mcl_hardness = 0.2 ,
_mcl_on_bonemealing = function ( pointed_thing , placer )
local pos = pointed_thing.under
return cocoa_grow ( pos )
end ,
}
if i == 2 then
def._doc_items_longdesc = nil
def._doc_items_create_entry = false
end
if i == 3 then
def.drop = " mcl_cocoas:cocoa_beans 3 "
end
2017-02-18 18:19:43 +01:00
2022-05-02 00:58:31 +02:00
minetest.register_node ( " mcl_cocoas:cocoa_ " .. i , table.copy ( def ) )
end
2017-02-18 16:06:18 +01:00
2022-12-22 19:32:15 +01:00
minetest.register_craftitem ( " mcl_cocoas:cocoa_beans " , {
2022-05-02 00:58:31 +02:00
inventory_image = " mcl_cocoa_beans.png " ,
2022-12-22 19:32:15 +01:00
_tt_help = S ( " Grows at the side of jungle trees " ) ,
2022-05-02 00:58:31 +02:00
_doc_items_longdesc = S ( " Cocoa beans can be used to plant cocoa, bake cookies or cract brown dye. " ) ,
_doc_items_usagehelp = S ( " Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa. " ) ,
description = S ( " Cocoa Beans " ) ,
stack_max = 64 ,
groups = {
dye = 1 , craftitem = 1 , compostability = 65 ,
basecolor_brown = 1 , excolor_orange = 1 , unicolor_dark_orange = 1 ,
} ,
2022-12-22 19:32:15 +01:00
on_place = function ( itemstack , placer , pointed_thing )
return cocoa_place ( itemstack , placer , pointed_thing , " mcl_cocoas:cocoa_1 " )
end ,
} )
2017-02-18 16:06:18 +01:00
2017-02-18 20:23:26 +01:00
minetest.register_abm ( {
2019-03-21 20:13:35 +01:00
label = " Cocoa pod growth " ,
2017-02-18 20:23:26 +01: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 18:12:05 +01: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