2017-02-18 17:09:01 +02:00
mcl_cocoas = { }
2017-02-18 17:06:18 +02:00
2017-02-18 21:23:26 +02:00
-- Place cocoa
function mcl_cocoas . place ( itemstack , placer , pointed_thing , plantname )
2017-02-18 17:06:18 +02:00
local pt = pointed_thing
-- 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 16:50:53 +02: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
return minetest.registered_nodes [ under.name ] . on_rightclick ( pointed_thing.under , under , placer , itemstack ) or itemstack
end
2017-02-18 17:06:18 +02:00
end
2017-02-18 19:28:33 +02:00
-- Check if pointing at jungle tree
2017-02-18 17:06:18 +02:00
if under.name ~= " mcl_core:jungletree "
or minetest.get_node ( pt.above ) . name ~= " air " then
return
end
2017-02-18 19:28:33 +02: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 17:06:18 +02:00
minetest.sound_play ( " default_place_node " , { pos = pt.above , gain = 1.0 } )
if not minetest.setting_getbool ( " creative_mode " ) then
itemstack : take_item ( )
end
return itemstack
end
2017-02-18 21:23:26 +02: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 17:06:18 +02:00
-- Note: cocoa beans are implemented as mcl_dye:brown
-- Cocoa definition
2017-02-18 21:23:26 +02:00
-- 1st stage
2017-02-18 22:07:57 +02:00
--[[ TODO (code quality): Turn the cocoa nodes into attached nodes and make use of wallmounted. This is much better
than the current ugly hacky check after digging a jungle tree ( in mcl_core ) .
Problem : If we want to use wallmounted , we MUST use a mesh , since wallmounted does not support
nodeboxes with multiple boxes . : - (
Using meshes will also clean up the texture mess .
] ]
2017-02-18 17:06:18 +02:00
local crop_def = {
2017-03-11 18:42:20 +02:00
description = " Premature Cocoa " ,
_doc_items_create_entry = true ,
2017-03-13 19:56:50 +02:00
_doc_items_longdesc = " Cocoas are plants which grow on the side of jungle trees in 3 stages. " ,
2017-02-18 19:19:43 +02:00
drawtype = " nodebox " ,
tiles = {
" [combine:32x32:12,2=mcl_cocoas_cocoa_stage_0.png " , " [combine:32x32:12,22=mcl_cocoas_cocoa_stage_0.png " ,
" mcl_cocoas_cocoa_stage_0.png " , " mcl_cocoas_cocoa_stage_0.png^[transformFX " ,
" [combine:32x32:-10,0=mcl_cocoas_cocoa_stage_0.png " , " [combine:32x32:-10,0=mcl_cocoas_cocoa_stage_0.png " ,
} ,
2017-02-18 17:06:18 +02:00
paramtype = " light " ,
2017-02-18 20:15:58 +02:00
sunlight_propagates = true ,
2017-02-18 17:06:18 +02:00
paramtype2 = " facedir " ,
walkable = true ,
drop = " mcl_dye:brown " ,
2017-02-18 19:19:43 +02:00
node_box = {
type = " fixed " ,
fixed = {
{ - 0.125 , - 0.0625 , 0.1875 , 0.125 , 0.25 , 0.4375 } , -- 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 = {
{ - 0.125 , - 0.0625 , 0.1875 , 0.125 , 0.25 , 0.4375 } , -- Pod
} ,
} ,
2017-02-18 17:06:18 +02:00
selection_box = {
type = " fixed " ,
2017-02-18 19:19:43 +02:00
fixed = {
{ - 0.125 , - 0.0625 , 0.1875 , 0.125 , 0.5 , 0.5 } , -- Pod
} ,
2017-02-18 17:06:18 +02:00
} ,
groups = {
2017-02-27 19:32:35 +02:00
handy = 1 , axey = 1 , cocoa = 1 , not_in_creative_inventory = 1 , dig_by_water = 1 ,
2017-02-18 17:06:18 +02:00
} ,
2017-02-22 17:03:59 +02:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
_mcl_blast_resistance = 15 ,
2017-02-27 02:13:03 +02:00
_mcl_hardness = 0.2 ,
2017-02-18 17:06:18 +02:00
}
2017-02-18 21:23:26 +02:00
-- 2nd stage
2017-02-18 17:09:01 +02:00
minetest.register_node ( " mcl_cocoas:cocoa_1 " , table.copy ( crop_def ) )
2017-02-18 17:06:18 +02:00
2017-02-18 21:23:26 +02:00
crop_def.description = " Medium Cocoa "
2017-03-11 18:42:20 +02:00
crop_def._doc_items_create_entry = false
2017-02-18 22:07:57 +02:00
crop_def.groups . cocoa = 2
2017-02-18 19:19:43 +02:00
crop_def.tiles = {
" [combine:32x32:10,2=mcl_cocoas_cocoa_stage_1.png " , " [combine:32x32:10,18=mcl_cocoas_cocoa_stage_1.png " ,
" mcl_cocoas_cocoa_stage_1.png " , " mcl_cocoas_cocoa_stage_1.png^[transformFX " ,
" [combine:32x32:-8,0=mcl_cocoas_cocoa_stage_1.png " , " [combine:32x32:-8,0=mcl_cocoas_cocoa_stage_1.png " ,
}
crop_def.node_box = {
type = " fixed " ,
fixed = {
{ - 0.1875 , - 0.1875 , 0.0625 , 0.1875 , 0.25 , 0.4375 } , -- Pod
{ 0 , 0.25 , 0.25 , 0 , 0.5 , 0.5 } , -- Stem
} ,
}
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 17:09:01 +02:00
minetest.register_node ( " mcl_cocoas:cocoa_2 " , table.copy ( crop_def ) )
2017-02-18 17:06:18 +02:00
2017-02-18 21:23:26 +02:00
-- Final stage
crop_def.description = " Mature Cocoa "
2017-03-13 19:56:50 +02:00
crop_def._doc_items_longdesc = " A mature cocoa is a plant which 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 20:53:53 +02:00
crop_def._doc_items_create_entry = true
2017-02-18 22:07:57 +02:00
crop_def.groups . cocoa = 3
2017-02-18 19:19:43 +02:00
crop_def.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:32x32:-6,0=mcl_cocoas_cocoa_stage_2.png " , " [combine:32x32:-6,0=mcl_cocoas_cocoa_stage_2.png " ,
}
crop_def.node_box = {
type = " fixed " ,
fixed = {
{ - 0.25 , - 0.3125 , - 0.0625 , 0.25 , 0.25 , 0.4375 } , -- Pod
{ 0 , 0.25 , 0.25 , 0 , 0.5 , 0.5 } , -- Stem
} ,
}
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 } ,
} ,
}
2017-02-18 22:14:27 +02:00
crop_def.drop = " mcl_dye:brown 3 "
2017-02-18 17:09:01 +02:00
minetest.register_node ( " mcl_cocoas:cocoa_3 " , table.copy ( crop_def ) )
2017-02-18 17:06:18 +02:00
-- Add random cocoa pods to jungle trees
2017-02-18 20:15:58 +02:00
-- TODO: Do this more efficiently, with LuaVoxelManip
2017-02-18 17:06:18 +02:00
minetest.register_on_generated ( function ( minp , maxp )
if maxp.y < 0 then
return
end
2017-02-18 20:15:58 +02:00
local pos , treepos , dir
2017-02-18 17:06:18 +02:00
local cocoa = minetest.find_nodes_in_area ( minp , maxp , " mcl_core:jungletree " )
for n = 1 , # cocoa do
pos = cocoa [ n ]
2017-02-18 20:15:58 +02:00
treepos = table.copy ( pos )
2017-02-18 17:06:18 +02:00
if minetest.find_node_near ( pos , 1 , { " mcl_core:jungleleaves " } ) then
2017-02-18 20:15:58 +02:00
dir = math.random ( 1 , 40 )
2017-02-18 17:06:18 +02:00
if dir == 1 then
2017-02-18 20:15:58 +02:00
pos.z = pos.z + 1
2017-02-18 17:06:18 +02:00
elseif dir == 2 then
2017-02-18 20:15:58 +02:00
pos.z = pos.z - 1
2017-02-18 17:06:18 +02:00
elseif dir == 3 then
2017-02-18 20:15:58 +02:00
pos.x = pos.x + 1
2017-02-18 17:06:18 +02:00
elseif dir == 4 then
2017-02-18 20:15:58 +02:00
pos.x = pos.x - 1
2017-02-18 17:06:18 +02:00
end
2017-02-18 20:15:58 +02:00
local nn = minetest.get_node ( pos ) . name
2017-02-18 17:06:18 +02:00
if dir < 5
2017-02-18 20:15:58 +02:00
and nn == " air "
2017-02-18 17:06:18 +02:00
and minetest.get_node_light ( pos ) > 12 then
minetest.swap_node ( pos , {
2017-02-18 20:15:58 +02:00
name = " mcl_cocoas:cocoa_ " .. tostring ( math.random ( 1 , 3 ) ) ,
param2 = minetest.dir_to_facedir ( vector.subtract ( treepos , pos ) )
2017-02-18 17:06:18 +02:00
} )
end
end
end
end )
2017-02-18 21:23:26 +02:00
minetest.register_abm ( {
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
} )