Add very basic cocoas (mostly node defs so far)

This commit is contained in:
Wuzzy 2017-02-18 16:06:18 +01:00
parent 2e8b78ee7f
commit 2b2a735d6d
10 changed files with 163 additions and 11 deletions

@ -0,0 +1,5 @@
This mod adds cocoas.
Cocoas grow at jungle trees in 3 stages and can be harvested for cocoa beans.
Cocoa beans can be used to plant new cocoas at jungle trees.
Partially based on the cocoas from Farming Redo by TenPlus1.

@ -0,0 +1,2 @@
mcl_sounds
mcl_core

@ -0,0 +1 @@
Cocoa pods which grow at jungle trees. Does not include cocoa beans.

@ -0,0 +1,129 @@
mcl_cocoa = {}
-- place cocoa
function mcl_cocoa.place_cocoa(itemstack, placer, pointed_thing, plantname)
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
-- am I right-clicking on something that has a custom on_place set?
-- thanks to Krock for helping with this issue :)
local def = minetest.registered_nodes[under.name]
if def and def.on_rightclick then
return def.on_rightclick(pt.under, under, placer, itemstack)
end
-- check if pointing at jungletree
if under.name ~= "mcl_core:jungletree"
or minetest.get_node(pt.above).name ~= "air" then
return
end
-- add the node and remove 1 item from the itemstack
minetest.set_node(pt.above, {name = plantname})
minetest.sound_play("default_place_node", {pos = pt.above, gain = 1.0})
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
-- check for refill
if itemstack:get_count() == 0 then
minetest.after(0.20,
farming.refill_plant,
placer,
"mcl_dye:brown",
placer:get_wield_index()
)
end
end
return itemstack
end
-- Note: cocoa beans are implemented as mcl_dye:brown
-- Cocoa definition
local crop_def = {
drawtype = "plantlike",
tiles = {"mcl_cocoa_cocoa_stage_0.png"},
paramtype = "light",
paramtype2 = "facedir",
walkable = true,
drop = "mcl_dye:brown",
selection_box = {
type = "fixed",
fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
},
groups = {
choppy=3, not_in_creative_inventory=1, dig_by_water = 1,
},
sounds = mcl_sounds.node_sound_wood_defaults()
}
-- stage 1
minetest.register_node("mcl_cocoa:cocoa_1", table.copy(crop_def))
-- stage2
crop_def.tiles = {"mcl_cocoa_cocoa_stage_1.png"}
minetest.register_node("mcl_cocoa:cocoa_2", table.copy(crop_def))
-- stage 3 (final)
crop_def.tiles = {"mcl_cocoa_cocoa_stage_2.png"}
crop_def.drop = "mcl_dye:brown 3",
minetest.register_node("mcl_cocoa:cocoa_3", table.copy(crop_def))
-- Add random cocoa pods to jungle trees
minetest.register_on_generated(function(minp, maxp)
if maxp.y < 0 then
return
end
local pos, dir
local cocoa = minetest.find_nodes_in_area(minp, maxp, "mcl_core:jungletree")
for n = 1, #cocoa do
pos = cocoa[n]
if minetest.find_node_near(pos, 1, {"mcl_core:jungleleaves"}) then
dir = math.random(1, 80)
if dir == 1 then
pos.x = pos.x + 1
elseif dir == 2 then
pos.x = pos.x - 1
elseif dir == 3 then
pos.z = pos.z + 1
elseif dir == 4 then
pos.z = pos.z -1
end
if dir < 5
and minetest.get_node(pos).name == "air"
and minetest.get_node_light(pos) > 12 then
minetest.swap_node(pos, {
name = "mcl_cocoa:cocoa_" .. tostring(math.random(1, 3))
})
end
end
end
end)

@ -0,0 +1 @@
name = mcl_cocoa

Binary file not shown.

After

Width:  |  Height:  |  Size: 677 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1018 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

@ -1,3 +1,4 @@
mcl_core
mcl_flowers
mcl_mobitems
mcl_cocoa

@ -85,16 +85,19 @@ dyelocal.dyes = {
-- Define items
for _, row in ipairs(dyelocal.dyes) do
local name = row[1]
local description = row[2]
local groups = row[3]
local item_name = "mcl_dye:"..name
local item_image = "dye_"..name..".png"
minetest.register_craftitem(item_name, {
inventory_image = item_image,
description = description,
groups = groups,
stack_max = 64,
})
-- White and brown dyes are defined explicitly below
if name ~= "white" and name ~= "brown" then
local description = row[2]
local groups = row[3]
local item_name = "mcl_dye:"..name
local item_image = "dye_"..name..".png"
minetest.register_craftitem(item_name, {
inventory_image = item_image,
description = description,
groups = groups,
stack_max = 64,
})
end
end
-- Bone Meal
@ -209,7 +212,7 @@ minetest.register_craftitem("mcl_dye:white", {
inventory_image = "dye_white.png",
description = "Bone Meal",
stack_max = 64,
groups = {dye=1, craftitem=1, basecolor_white=1, excolor_white=1, unicolor_white=1},
groups = dyelocal.dyes[1][3],
on_place = function(itemstack, user, pointed_thing)
if(mcl_dye.apply_bone_meal(pointed_thing) and not minetest.setting_getbool("creative_mode")) then
itemstack:take_item()
@ -218,6 +221,16 @@ minetest.register_craftitem("mcl_dye:white", {
end,
})
minetest.register_craftitem("mcl_dye:brown", {
inventory_image = "dye_brown.png",
description = "Cocoa Beans",
stack_max = 64,
groups = dyelocal.dyes[4][3],
on_place = function(itemstack, user, pointed_thing)
return mcl_cocoa.place_cocoa(itemstack, placer, pointed_thing, "mcl_cocoa:cocoa_1")
end,
})
-- Dye mixing
minetest.register_craft({
type = "shapeless",