summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAuke Kok <auke-jan.h.kok@intel.com>2015-04-10 11:08:27 -0700
committerAuke Kok <auke-jan.h.kok@intel.com>2015-04-10 11:08:27 -0700
commit25f37fbd0d92ca4960d97cf7fcaab155cfa5f789 (patch)
tree90ac4c2cff6a028766ace5b1a3f329a63d793981
parent9d54e7af933edd68088f123ca573c34f440d79e1 (diff)
Corn.
Corn plants are 2 blocks high, and yield corn cobs. These can be cooked to corn-on-the-cob, or processed to make corn seed (corn kernels, basically). Digging a mature plant yields the corn cob. A harvested corn plant "wilts", and needs to be dug away to make the land usable, or can be left as ornamental 2-block plant. Digging either top or bottom block works in all cases, although I need to verify that I've covered every block combo.
-rw-r--r--corn.lua271
-rw-r--r--init.lua1
-rw-r--r--models/crops_orthogonal_plant.obj33
-rw-r--r--textures/crops_corn.pngbin0 -> 349 bytes
-rw-r--r--textures/crops_corn_base_1.pngbin0 -> 343 bytes
-rw-r--r--textures/crops_corn_base_2.pngbin0 -> 515 bytes
-rw-r--r--textures/crops_corn_base_3.pngbin0 -> 548 bytes
-rw-r--r--textures/crops_corn_base_seed.pngbin0 -> 370 bytes
-rw-r--r--textures/crops_corn_cob.pngbin0 -> 557 bytes
-rw-r--r--textures/crops_corn_on_the_cob.pngbin0 -> 563 bytes
-rw-r--r--textures/crops_corn_top_1.pngbin0 -> 600 bytes
-rw-r--r--textures/crops_corn_top_2.pngbin0 -> 443 bytes
-rw-r--r--textures/crops_corn_top_3.pngbin0 -> 644 bytes
13 files changed, 305 insertions, 0 deletions
diff --git a/corn.lua b/corn.lua
new file mode 100644
index 0000000..b224e70
--- /dev/null
+++ b/corn.lua
@@ -0,0 +1,271 @@
+
+--[[
+
+Copyright (C) 2015 - Auke Kok <sofar@foo-projects.org>
+
+"crops" is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1
+of the license, or (at your option) any later version.
+
+--]]
+
+local interval = 30
+local chance = 10
+
+minetest.register_node("crops:corn", {
+ description = "corn",
+ inventory_image = "crops_corn.png",
+ wield_image = "crops_corn.png",
+ tiles = { "crops_corn_base_seed.png" },
+ drawtype = "mesh",
+ visual = "mesh",
+ mesh = "crops_orthogonal_plant.obj",
+ sunlight_propagates = true,
+ use_texture_alpha = true,
+ walkable = true,
+ paramtype = "light",
+ groups = { snappy=3,flammable=3,flora=1,attached_node=1 },
+ drop = {},
+
+ on_place = function(itemstack, placer, pointed_thing)
+ local under = minetest.get_node(pointed_thing.under)
+ if minetest.get_item_group(under.name, "soil") <= 1 then
+ return
+ end
+ minetest.set_node(pointed_thing.above, {name="crops:corn_base_seed"})
+ if not minetest.setting_getbool("creative_mode") then
+ itemstack:take_item()
+ end
+ return itemstack
+ end
+})
+
+minetest.register_craftitem("crops:corn_cob", {
+ description = "Corn Cob",
+ inventory_image = "crops_corn_cob.png",
+})
+
+minetest.register_craft({
+ type = "shapeless",
+ output = "crops:corn",
+ recipe = { "crops:corn_cob" }
+})
+
+minetest.register_craftitem("crops:corn_on_the_cob", {
+ description = "Corn on the Cob",
+ inventory_image = "crops_corn_on_the_cob.png",
+ on_use = minetest.item_eat(1)
+})
+
+minetest.register_craft({
+ type = "cooking",
+ output = "crops:corn_on_the_cob",
+ recipe = "crops:corn_cob"
+})
+
+minetest.register_node("crops:corn_base_seed", {
+ visual = "mesh",
+ description = "corn plant",
+ drawtype = "mesh",
+ mesh = "crops_orthogonal_plant.obj",
+ tiles = { "crops_corn_base_seed.png" },
+ use_texture_alpha = true,
+ walkable = false,
+ sunlight_propagates = true,
+ paramtype = "light",
+ groups = { snappy=3,flammable=3,flora=1,attached_node=1,not_in_creative_inventory=1 },
+ drop = {},
+ selection_box = {
+ type = "fixed",
+ fixed = {-0.5, -0.5, -0.5, 0.5, -0.3, 0.5}
+ },
+})
+
+minetest.register_abm({
+ nodenames = { "crops:corn_base_seed" },
+ interval = interval,
+ chance = chance,
+ action = function(pos, node, active_object_count, active_object_count_wider)
+ if minetest.get_node_light(pos, nil) < 13 then
+ return
+ end
+ minetest.set_node(pos, { name = "crops:corn_base_1" })
+ end
+})
+
+minetest.register_node("crops:corn_base_1", {
+ visual = "mesh",
+ description = "corn plant",
+ drawtype = "mesh",
+ mesh = "crops_orthogonal_plant.obj",
+ tiles = { "crops_corn_base_1.png" },
+ use_texture_alpha = true,
+ walkable = false,
+ sunlight_propagates = true,
+ paramtype = "light",
+ groups = { snappy=3,flammable=3,flora=1,attached_node=1,not_in_creative_inventory=1 },
+ drop = {},
+})
+
+minetest.register_abm({
+ nodenames = { "crops:corn_base_1" },
+ interval = interval,
+ chance = chance,
+ action = function(pos, node, active_object_count, active_object_count_wider)
+ if minetest.get_node_light(pos, nil) < 13 then
+ return
+ end
+ if not minetest.get_node({x = pos.x, y = pos.y + 1, z = pos.z}).name == "air" then
+ return
+ end
+ minetest.set_node(pos, { name = "crops:corn_base_2" })
+ minetest.set_node({x = pos.x, y = pos.y + 1, z = pos.z} , { name = "crops:corn_top_1" })
+ end
+})
+
+minetest.register_node("crops:corn_base_2", {
+ visual = "mesh",
+ description = "corn plant",
+ drawtype = "mesh",
+ mesh = "crops_orthogonal_plant.obj",
+ tiles = { "crops_corn_base_2.png" },
+ use_texture_alpha = true,
+ walkable = false,
+ sunlight_propagates = true,
+ paramtype = "light",
+ groups = { snappy=3,flammable=3,flora=1,attached_node=1,not_in_creative_inventory=1 },
+ drop = {},
+ on_dig = function(pos, node, digger)
+ local above = {x = pos.x, y = pos.y + 1, z = pos.z}
+ if not minetest.get_node(above) == "crops:corn_top_3" then
+ minetest.remove_node(pos)
+ end
+
+ local drops = {}
+ for i = 1,math.random(2,4) do
+ table.insert(drops, ('crops:corn_cob'))
+ end
+ minetest.set_node(pos, { name = "crops:corn_base_3" })
+ minetest.set_node(above, { name = "crops:corn_top_4" })
+ core.handle_node_drops(above, drops, digger)
+ end
+})
+
+minetest.register_node("crops:corn_base_3", {
+ visual = "mesh",
+ description = "corn plant",
+ drawtype = "mesh",
+ mesh = "crops_orthogonal_plant.obj",
+ tiles = { "crops_corn_base_3.png" },
+ use_texture_alpha = true,
+ walkable = false,
+ sunlight_propagates = true,
+ paramtype = "light",
+ groups = { snappy=3,flammable=3,flora=1,attached_node=1,not_in_creative_inventory=1 },
+ drop = {},
+ on_dig = function(pos, node, digger)
+ local above = {x = pos.x, y = pos.y + 1, z = pos.z}
+ if minetest.get_node(above).name == "crops:corn_top_4" then
+ minetest.remove_node(above)
+ end
+ minetest.remove_node(pos)
+ end
+})
+
+minetest.register_node("crops:corn_top_1", {
+ visual = "mesh",
+ description = "corn plant",
+ drawtype = "mesh",
+ mesh = "crops_orthogonal_plant.obj",
+ tiles = { "crops_corn_base_1.png" },
+ use_texture_alpha = true,
+ walkable = false,
+ sunlight_propagates = true,
+ paramtype = "light",
+ groups = { snappy=3,flammable=3,flora=1,not_in_creative_inventory=1 },
+ drop = {},
+})
+
+minetest.register_abm({
+ nodenames = { "crops:corn_top_1" },
+ interval = interval,
+ chance = chance,
+ action = function(pos, node, active_object_count, active_object_count_wider)
+ if minetest.get_node_light(pos, nil) < 13 then
+ return
+ end
+ minetest.set_node(pos, { name = "crops:corn_top_2" })
+ end
+})
+
+minetest.register_node("crops:corn_top_2", {
+ visual = "mesh",
+ description = "corn plant",
+ drawtype = "mesh",
+ mesh = "crops_orthogonal_plant.obj",
+ tiles = { "crops_corn_top_1.png" },
+ use_texture_alpha = true,
+ walkable = false,
+ sunlight_propagates = true,
+ paramtype = "light",
+ groups = { snappy=3,flammable=3,flora=1,not_in_creative_inventory=1 },
+ drop = {},
+})
+
+minetest.register_abm({
+ nodenames = { "crops:corn_top_2" },
+ interval = interval,
+ chance = chance,
+ action = function(pos, node, active_object_count, active_object_count_wider)
+ if minetest.get_node_light(pos, nil) < 13 then
+ return
+ end
+ minetest.set_node(pos, { name = "crops:corn_top_3" })
+ end
+})
+
+minetest.register_node("crops:corn_top_3", {
+ visual = "mesh",
+ description = "corn plant",
+ drawtype = "mesh",
+ mesh = "crops_orthogonal_plant.obj",
+ tiles = { "crops_corn_top_2.png" },
+ use_texture_alpha = true,
+ walkable = false,
+ sunlight_propagates = true,
+ paramtype = "light",
+ groups = { snappy=3,flammable=3,flora=1,not_in_creative_inventory=1 },
+ drop = {},
+ on_dig = function(pos, node, digger)
+ local drops = {}
+ for i = 1,math.random(2,4) do
+ table.insert(drops, ('crops:corn_cob'))
+ end
+ minetest.set_node(pos, { name = "crops:corn_top_4" })
+ minetest.set_node({x = pos.x, y = pos.y - 1, z = pos.z}, { name = "crops:corn_base_3" })
+ core.handle_node_drops(pos, drops, digger)
+ end
+})
+
+minetest.register_node("crops:corn_top_4", {
+ visual = "mesh",
+ description = "corn plant",
+ drawtype = "mesh",
+ mesh = "crops_orthogonal_plant.obj",
+ tiles = { "crops_corn_top_3.png" },
+ use_texture_alpha = true,
+ walkable = false,
+ sunlight_propagates = true,
+ paramtype = "light",
+ groups = { snappy=3,flammable=3,flora=1,not_in_creative_inventory=1 },
+ drop = {},
+ on_dig = function(pos, node, digger)
+ local below = {x = pos.x, y = pos.y - 1, z = pos.z}
+ if minetest.get_node(below).name == "crops:corn_base_3" then
+ minetest.remove_node(below)
+ end
+ minetest.remove_node(pos)
+ end
+})
+
diff --git a/init.lua b/init.lua
index 8f3ed2c..faf4ad3 100644
--- a/init.lua
+++ b/init.lua
@@ -11,5 +11,6 @@ of the license, or (at your option) any later version.
--]]
dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/melon.lua")
+dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/corn.lua")
minetest.log("action", "[crops] loaded.")
diff --git a/models/crops_orthogonal_plant.obj b/models/crops_orthogonal_plant.obj
new file mode 100644
index 0000000..64ab567
--- /dev/null
+++ b/models/crops_orthogonal_plant.obj
@@ -0,0 +1,33 @@
+# Blender v2.60 (sub 0) OBJ File: ''
+# www.blender.org
+mtllib crops_orthogonal_plant.mtl
+o Mesh_Mesh_Plant_Plant_.000
+v 0.500000 0.500000 0.300000
+v -0.500000 0.500000 0.300000
+v -0.500000 -0.500000 0.300000
+v 0.500000 -0.500000 0.300000
+v 0.500000 0.500000 -0.300000
+v -0.500000 0.500000 -0.300000
+v -0.500000 -0.500000 -0.300000
+v 0.500000 -0.500000 -0.300000
+v 0.300000 0.500000 0.500000
+v 0.300000 0.500000 -0.500000
+v 0.300000 -0.500000 -0.500000
+v 0.300000 -0.500000 0.500000
+v -0.300000 0.500000 0.500000
+v -0.300000 0.500000 -0.500000
+v -0.300000 -0.500000 -0.500000
+v -0.300000 -0.500000 0.500000
+vt 0.000000 1.000000
+vt 1.000000 1.000000
+vt 1.000000 0.000000
+vt 0.000000 0.000000
+g Mesh_Mesh_Plant_Plant_.000_Material.002_crops_corn_base_1.000
+usemtl Material.002_crops_corn_base_1.000
+s off
+f 13/1 14/2 15/3 16/4
+g Mesh_Mesh_Plant_Plant_.000_Material.002_crops_corn_base_1.png
+usemtl Material.002_crops_corn_base_1.png
+f 1/2 2/1 3/4 4/3
+f 5/1 6/2 7/3 8/4
+f 9/2 10/1 11/4 12/3
diff --git a/textures/crops_corn.png b/textures/crops_corn.png
new file mode 100644
index 0000000..ab4648f
--- /dev/null
+++ b/textures/crops_corn.png
Binary files differ
diff --git a/textures/crops_corn_base_1.png b/textures/crops_corn_base_1.png
new file mode 100644
index 0000000..0829f13
--- /dev/null
+++ b/textures/crops_corn_base_1.png
Binary files differ
diff --git a/textures/crops_corn_base_2.png b/textures/crops_corn_base_2.png
new file mode 100644
index 0000000..308706e
--- /dev/null
+++ b/textures/crops_corn_base_2.png
Binary files differ
diff --git a/textures/crops_corn_base_3.png b/textures/crops_corn_base_3.png
new file mode 100644
index 0000000..0339f05
--- /dev/null
+++ b/textures/crops_corn_base_3.png
Binary files differ
diff --git a/textures/crops_corn_base_seed.png b/textures/crops_corn_base_seed.png
new file mode 100644
index 0000000..129381f
--- /dev/null
+++ b/textures/crops_corn_base_seed.png
Binary files differ
diff --git a/textures/crops_corn_cob.png b/textures/crops_corn_cob.png
new file mode 100644
index 0000000..f64befc
--- /dev/null
+++ b/textures/crops_corn_cob.png
Binary files differ
diff --git a/textures/crops_corn_on_the_cob.png b/textures/crops_corn_on_the_cob.png
new file mode 100644
index 0000000..7d38cf8
--- /dev/null
+++ b/textures/crops_corn_on_the_cob.png
Binary files differ
diff --git a/textures/crops_corn_top_1.png b/textures/crops_corn_top_1.png
new file mode 100644
index 0000000..4c49c0a
--- /dev/null
+++ b/textures/crops_corn_top_1.png
Binary files differ
diff --git a/textures/crops_corn_top_2.png b/textures/crops_corn_top_2.png
new file mode 100644
index 0000000..634388a
--- /dev/null
+++ b/textures/crops_corn_top_2.png
Binary files differ
diff --git a/textures/crops_corn_top_3.png b/textures/crops_corn_top_3.png
new file mode 100644
index 0000000..8490f75
--- /dev/null
+++ b/textures/crops_corn_top_3.png
Binary files differ