Browse Source

Add large cactus seedling

Alter 'large cactus' schematic to place another force-placed cactus node,
to replace the cactus seedling on growth.
Make schematic 5x7x5 to solve rotation, placement and protection check
issues.
Add a y-slice probability for height variation.

Growth time is tuned to not make this a faster way to obtain cactus nodes
compared to normal cactus farming.
Seedling texture by Extex101.

Use sapling/seedling description in protection intersection message in
'sapling_on_place' function.
Paramat 5 years ago
parent
commit
6688ddf6d4

+ 3 - 0
mods/default/README.txt

@@ -244,6 +244,9 @@ Topywo (CC BY-SA 3.0)
   default_coral_green.png
   default_coral_pink.png
 
+Extex101 (CC BY-SA 3.0)
+  default_large_cactus_seedling.png
+
 
 Sounds
 ------

+ 15 - 0
mods/default/crafting.lua

@@ -779,6 +779,15 @@ minetest.register_craft({
 	}
 })
 
+minetest.register_craft({
+	output = "default:large_cactus_seedling",
+	recipe = {
+		{"", "default:cactus", ""},
+		{"default:cactus", "default:cactus", "default:cactus"},
+		{"", "default:cactus", ""},
+	}
+})
+
 
 --
 -- Crafting (tool repair)
@@ -1095,6 +1104,12 @@ minetest.register_craft({
 	burntime = 15,
 })
 
+minetest.register_craft({
+	type = "fuel",
+	recipe = "default:large_cactus_seedling",
+	burntime = 5,
+})
+
 minetest.register_craft({
 	type = "fuel",
 	recipe = "default:papyrus",

+ 1 - 0
mods/default/license.txt

@@ -50,6 +50,7 @@ Copyright (C) 2010-2018:
   TumeniNodes
   Mossmanikin
   random-geek
+  Extex101
 
 You are free to:
 Share — copy and redistribute the material in any medium or format.

+ 1 - 1
mods/default/mapgen.lua

@@ -1893,7 +1893,7 @@ function default.register_decorations()
 		y_max = 31000,
 		y_min = 4,
 		schematic = minetest.get_modpath("default") .. "/schematics/large_cactus.mts",
-		flags = "place_center_x",
+		flags = "place_center_x, place_center_z",
 		rotation = "random",
 	})
 

+ 73 - 0
mods/default/nodes.lua

@@ -132,6 +132,8 @@ Plantlife
 ---------
 
 default:cactus
+default:large_cactus_seedling
+
 default:papyrus
 default:dry_shrub
 default:junglegrass
@@ -1276,6 +1278,77 @@ minetest.register_node("default:cactus", {
 	on_place = minetest.rotate_node,
 })
 
+minetest.register_node("default:large_cactus_seedling", {
+	description = "Large Cactus Seedling",
+	drawtype = "plantlike",
+	tiles = {"default_large_cactus_seedling.png"},
+	inventory_image = "default_large_cactus_seedling.png",
+	wield_image = "default_large_cactus_seedling.png",
+	paramtype = "light",
+	sunlight_propagates = true,
+	walkable = false,
+	selection_box = {
+		type = "fixed",
+		fixed = {
+			-5 / 16, -0.5, -5 / 16,
+			5 / 16, 0.5, 5 / 16
+		}
+	},
+	groups = {choppy = 3, dig_immediate = 3, attached_node = 1},
+	sounds = default.node_sound_wood_defaults(),
+
+	on_place = function(itemstack, placer, pointed_thing)
+		itemstack = default.sapling_on_place(itemstack, placer, pointed_thing,
+			"default:large_cactus_seedling",
+			{x = -2, y = -1, z = -2},
+			{x = 2, y = 5, z = 2},
+			4)
+
+		return itemstack
+	end,
+
+	on_construct = function(pos)
+		-- Normal cactus farming adds 1 cactus node by ABM,
+		-- interval 12s, chance 83.
+		-- Consider starting with 5 cactus nodes. We make sure that growing a
+		-- large cactus is not a faster way to produce new cactus nodes.
+		-- Confirmed by experiment, when farming 5 cacti, on average 1 new
+		-- cactus node is added on average every
+		-- 83 / 5 = 16.6 intervals = 16.6 * 12 = 199.2s.
+		-- Large cactus contains on average 14 cactus nodes.
+		-- 14 * 199.2 = 2788.8s.
+		-- Set random range to average to 2789s.
+		minetest.get_node_timer(pos):start(math.random(1859, 3719))
+	end,
+
+	on_timer = function(pos)
+		local node_under = minetest.get_node_or_nil(
+			{x = pos.x, y = pos.y - 1, z = pos.z})
+		if not node_under then
+			-- Node under not yet loaded, try later
+			minetest.get_node_timer(pos):start(300)
+			return
+		end
+
+		if minetest.get_item_group(node_under.name, "sand") == 0 then
+			-- Seedling dies
+			minetest.remove_node(pos)
+			return
+		end
+
+		local light_level = minetest.get_node_light(pos)
+		if not light_level or light_level < 13 then
+			-- Too dark for growth, try later in case it's night
+			minetest.get_node_timer(pos):start(300)
+			return
+		end
+
+		minetest.log("action", "A large cactus seedling grows into a large" ..
+			"cactus at ".. minetest.pos_to_string(pos))
+		default.grow_large_cactus(pos)
+	end,
+})
+
 minetest.register_node("default:papyrus", {
 	description = "Papyrus",
 	drawtype = "plantlike",

BIN
mods/default/schematics/large_cactus.mts


BIN
mods/default/textures/default_large_cactus_seedling.png


+ 13 - 1
mods/default/trees.lua

@@ -510,6 +510,16 @@ function default.grow_pine_bush(pos)
 end
 
 
+-- Large cactus
+
+function default.grow_large_cactus(pos)
+	local path = minetest.get_modpath("default") ..
+		"/schematics/large_cactus.mts"
+	minetest.place_schematic({x = pos.x - 2, y = pos.y - 1, z = pos.z - 2},
+		path, "random", nil, false)
+end
+
+
 --
 -- Sapling 'on place' function to check protection of node and resulting tree volume
 --
@@ -550,7 +560,9 @@ function default.sapling_on_place(itemstack, placer, pointed_thing,
 			interval) then
 		minetest.record_protection_violation(pos, player_name)
 		-- Print extra information to explain
-		minetest.chat_send_player(player_name, "Tree will intersect protection")
+		minetest.chat_send_player(player_name,
+			itemstack:get_definition().description .. " will intersect protection " ..
+			"on growth")
 		return itemstack
 	end
 

+ 37 - 2
schematic_tables.txt

@@ -2050,15 +2050,50 @@ local R = {name = "default:cactus", prob = 255, param2 = 20, force_place = true}
 local E = {name = "default:cactus", prob = 127, param2 = 20}
 
 mts_save("large_cactus", {
-	size = {x = 5, y = 7, z = 1},
+	size = {x = 5, y = 7, z = 5},
 	data = {
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+
+		_, _, R, _, _,
 		_, _, R, _, _,
-		_, _, C, _, _,
 		_, _, C, _, _,
 		C, C, C, C, C,
 		C, _, C, _, C,
 		E, _, C, _, E,
 		_, _, C, _, _,
+
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+		_, _, _, _, _,
+	},
+	yslice_prob = {
+		{ypos = 2, prob = 127},
 	},
 })