2017-07-07 17:37:05 +03:00
-- Cactus and Sugar Cane
2021-05-29 17:12:33 +03:00
local S = minetest.get_translator ( minetest.get_current_modname ( ) )
2019-03-08 01:40:43 +03:00
2017-07-07 17:37:05 +03:00
minetest.register_node ( " mcl_core:cactus " , {
2019-03-08 01:40:43 +03:00
description = S ( " Cactus " ) ,
2021-03-30 01:01:29 +03:00
_tt_help = S ( " Grows on sand " ) .. " \n " .. minetest.colorize ( mcl_colors.YELLOW , S ( " Contact damage: @1 per half second " , 1 ) ) ,
2019-03-08 01:40:43 +03:00
_doc_items_longdesc = S ( " This is a piece of cactus commonly found in dry areas, especially deserts. Over time, cacti will grow up to 3 blocks high on sand or red sand. A cactus hurts living beings touching it with a damage of 1 HP every half second. When a cactus block is broken, all cactus blocks connected above it will break as well. " ) ,
_doc_items_usagehelp = S ( " A cactus can only be placed on top of another cactus or any sand. " ) ,
2017-07-07 17:37:05 +03:00
drawtype = " nodebox " ,
2021-02-18 16:00:17 +03:00
use_texture_alpha = minetest.features . use_texture_alpha_string_modes and " clip " or true ,
2019-02-04 14:21:58 +03:00
tiles = { " mcl_core_cactus_top.png " , " mcl_core_cactus_bottom.png " , " mcl_core_cactus_side.png " } ,
2017-07-07 17:37:05 +03:00
is_ground_content = true ,
stack_max = 64 ,
Add `compostability` to node definition group.
* mcl_cake/init.lua (cake);
* mcl_core/craftitems.lua (apple);
* mcl_core/nodes_base.lua (dirt with grass);
* mcl_core/nodes_cactuscane.lua (cactus, sugarcane);
* mcl_core/nodes_climb.lua (vines);
* mcl_core/nodes_trees.lua (leaves, saplings);
* mcl_dye/init.lua (cocoa beans);
* mcl_farming/beetroot.lua (beetroot, & seeds);
* mcl_farming/carrots.lua (carrot);
* mcl_farming/melon.lua (melon, & slice, & seeds);
* mcl_farming/potatoes.lua (potato, baked potato);
* mcl_farming/pumpkin.lua (pumpkin, carved &, & seeds, & pie);
* mcl_farming/wheat.lua (wheat, cookie, bread, hay block);
* mcl_flowers/init.lua (flowers, ferns, grass, & tall variants);
* mcl_mushrooms/small.lua (red and brown mushrooms);
* mcl_mushrooms/huge.lua (red and brown huge mushrooms);
* mcl_nether/init.lua (nether wart block);
* mcl_nether/nether_wart.lua (nether wart);
* mcl_ocean/kelp.lua (kelp, dried &, & block);
* mcl_ocean/sea_pickle.lua (sea pickle);
* mcl_ocean/seagrass.lua (seagrass).
2022-03-29 13:54:51 +03:00
groups = {
handy = 1 , attached_node = 1 , deco_block = 1 , dig_by_piston = 1 ,
plant = 1 , enderman_takable = 1 , compostability = 50
} ,
2017-07-07 17:37:05 +03:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
paramtype = " light " ,
sunlight_propagates = true ,
node_placement_prediction = " " ,
node_box = {
type = " fixed " ,
fixed = {
{ - 7 / 16 , - 8 / 16 , - 7 / 16 , 7 / 16 , 8 / 16 , 7 / 16 } , -- Main body
{ - 8 / 16 , - 8 / 16 , - 7 / 16 , 8 / 16 , 8 / 16 , - 7 / 16 } , -- Spikes
{ - 8 / 16 , - 8 / 16 , 7 / 16 , 8 / 16 , 8 / 16 , 7 / 16 } , -- Spikes
{ - 7 / 16 , - 8 / 16 , - 8 / 16 , - 7 / 16 , 8 / 16 , 8 / 16 } , -- Spikes
{ 7 / 16 , - 8 / 16 , 8 / 16 , 7 / 16 , 8 / 16 , - 8 / 16 } , -- Spikes
} ,
} ,
collision_box = {
type = " fixed " ,
fixed = { - 7 / 16 , - 8 / 16 , - 7 / 16 , 7 / 16 , 7 / 16 , 7 / 16 } , -- Main body. slightly lower than node box
} ,
selection_box = {
type = " fixed " ,
fixed = {
{ - 7 / 16 , - 8 / 16 , - 7 / 16 , 7 / 16 , 8 / 16 , 7 / 16 } ,
} ,
} ,
-- Only allow to place cactus on sand or cactus
on_place = mcl_util.generate_on_place_plant_function ( function ( pos , node )
local node_below = minetest.get_node_or_nil ( { x = pos.x , y = pos.y - 1 , z = pos.z } )
if not node_below then return false end
return ( node_below.name == " mcl_core:cactus " or minetest.get_item_group ( node_below.name , " sand " ) == 1 )
end ) ,
2020-04-15 14:27:29 +03:00
_mcl_blast_resistance = 0.4 ,
2017-07-07 17:37:05 +03:00
_mcl_hardness = 0.4 ,
} )
minetest.register_node ( " mcl_core:reeds " , {
2019-03-08 01:40:43 +03:00
description = S ( " Sugar Canes " ) ,
2020-02-19 06:54:17 +03:00
_tt_help = S ( " Grows on sand or dirt next to water " ) ,
2019-03-08 01:40:43 +03:00
_doc_items_longdesc = S ( " Sugar canes are a plant which has some uses in crafting. Sugar canes will slowly grow up to 3 blocks when they are next to water and are placed on a grass block, dirt, sand, red sand, podzol or coarse dirt. When a sugar cane is broken, all sugar canes connected above will break as well. " ) ,
_doc_items_usagehelp = S ( " Sugar canes can only be placed top of other sugar canes and on top of blocks on which they would grow. " ) ,
2017-07-07 17:37:05 +03:00
drawtype = " plantlike " ,
2021-08-04 13:41:25 +03:00
paramtype2 = " color " ,
2022-03-03 05:13:24 +03:00
tiles = { " mcl_core_papyrus.png " } ,
2021-08-04 13:41:25 +03:00
palette = " mcl_core_palette_grass.png " ,
palette_index = 0 ,
2017-07-07 17:37:05 +03:00
inventory_image = " mcl_core_reeds.png " ,
wield_image = " mcl_core_reeds.png " ,
paramtype = " light " ,
walkable = false ,
is_ground_content = true ,
node_box = {
type = " fixed " ,
fixed = {
{ - 7 / 16 , - 8 / 16 , - 7 / 16 , 7 / 16 , 8 / 16 , 7 / 16 } , -- Main Body
{ - 8 / 16 , - 8 / 16 , - 7 / 16 , 8 / 16 , 8 / 16 , - 7 / 16 } , -- Spikes
{ - 8 / 16 , - 8 / 16 , 7 / 16 , 8 / 16 , 8 / 16 , 7 / 16 } , -- Spikes
{ - 7 / 16 , - 8 / 16 , - 8 / 16 , - 7 / 16 , 8 / 16 , 8 / 16 } , -- Spikes
{ 7 / 16 , - 8 / 16 , 8 / 16 , 7 / 16 , 8 / 16 , - 8 / 16 } , -- Spikes
} ,
} ,
selection_box = {
type = " fixed " ,
fixed = {
{ - 6 / 16 , - 8 / 16 , - 6 / 16 , 6 / 16 , 8 / 16 , 6 / 16 } ,
} ,
} ,
stack_max = 64 ,
Add `compostability` to node definition group.
* mcl_cake/init.lua (cake);
* mcl_core/craftitems.lua (apple);
* mcl_core/nodes_base.lua (dirt with grass);
* mcl_core/nodes_cactuscane.lua (cactus, sugarcane);
* mcl_core/nodes_climb.lua (vines);
* mcl_core/nodes_trees.lua (leaves, saplings);
* mcl_dye/init.lua (cocoa beans);
* mcl_farming/beetroot.lua (beetroot, & seeds);
* mcl_farming/carrots.lua (carrot);
* mcl_farming/melon.lua (melon, & slice, & seeds);
* mcl_farming/potatoes.lua (potato, baked potato);
* mcl_farming/pumpkin.lua (pumpkin, carved &, & seeds, & pie);
* mcl_farming/wheat.lua (wheat, cookie, bread, hay block);
* mcl_flowers/init.lua (flowers, ferns, grass, & tall variants);
* mcl_mushrooms/small.lua (red and brown mushrooms);
* mcl_mushrooms/huge.lua (red and brown huge mushrooms);
* mcl_nether/init.lua (nether wart block);
* mcl_nether/nether_wart.lua (nether wart);
* mcl_ocean/kelp.lua (kelp, dried &, & block);
* mcl_ocean/sea_pickle.lua (sea pickle);
* mcl_ocean/seagrass.lua (seagrass).
2022-03-29 13:54:51 +03:00
groups = {
dig_immediate = 3 , craftitem = 1 , deco_block = 1 , dig_by_piston = 1 ,
2023-02-24 16:52:04 +03:00
plant = 1 , non_mycelium_plant = 1 , compostability = 50 , grass_palette = 1
Add `compostability` to node definition group.
* mcl_cake/init.lua (cake);
* mcl_core/craftitems.lua (apple);
* mcl_core/nodes_base.lua (dirt with grass);
* mcl_core/nodes_cactuscane.lua (cactus, sugarcane);
* mcl_core/nodes_climb.lua (vines);
* mcl_core/nodes_trees.lua (leaves, saplings);
* mcl_dye/init.lua (cocoa beans);
* mcl_farming/beetroot.lua (beetroot, & seeds);
* mcl_farming/carrots.lua (carrot);
* mcl_farming/melon.lua (melon, & slice, & seeds);
* mcl_farming/potatoes.lua (potato, baked potato);
* mcl_farming/pumpkin.lua (pumpkin, carved &, & seeds, & pie);
* mcl_farming/wheat.lua (wheat, cookie, bread, hay block);
* mcl_flowers/init.lua (flowers, ferns, grass, & tall variants);
* mcl_mushrooms/small.lua (red and brown mushrooms);
* mcl_mushrooms/huge.lua (red and brown huge mushrooms);
* mcl_nether/init.lua (nether wart block);
* mcl_nether/nether_wart.lua (nether wart);
* mcl_ocean/kelp.lua (kelp, dried &, & block);
* mcl_ocean/sea_pickle.lua (sea pickle);
* mcl_ocean/seagrass.lua (seagrass).
2022-03-29 13:54:51 +03:00
} ,
2017-07-07 17:37:05 +03:00
sounds = mcl_sounds.node_sound_leaves_defaults ( ) ,
node_placement_prediction = " " ,
2021-08-04 13:41:25 +03:00
drop = " mcl_core:reeds " , -- to prevent color inheritation
2017-07-07 17:37:05 +03:00
on_place = mcl_util.generate_on_place_plant_function ( function ( place_pos , place_node )
local soil_pos = { x = place_pos.x , y = place_pos.y - 1 , z = place_pos.z }
local soil_node = minetest.get_node_or_nil ( soil_pos )
if not soil_node then return false end
local snn = soil_node.name -- soil node name
-- Placement rules:
2017-08-22 16:20:00 +03:00
-- * On top of group:soil_sugarcane AND next to water or frosted ice. OR
-- * On top of sugar canes
2020-11-12 23:12:25 +03:00
-- * Not inside liquid
2017-08-22 16:20:00 +03:00
if snn == " mcl_core:reeds " then
return true
elseif minetest.get_item_group ( snn , " soil_sugarcane " ) == 0 then
2017-07-07 17:37:05 +03:00
return false
end
2020-11-12 23:12:25 +03:00
local place_node = minetest.get_node ( place_pos )
local pdef = minetest.registered_nodes [ place_node.name ]
if pdef and pdef.liquidtype ~= " none " then
return false
end
2017-07-07 17:37:05 +03:00
2020-11-11 23:00:37 +03:00
-- Legal water position rules are the same as for decoration spawn_by rules.
-- This differs from MC, which does not allow diagonal neighbors
-- and neighbors 1 layer above.
local np1 = { x = soil_pos.x - 1 , y = soil_pos.y , z = soil_pos.z - 1 }
local np2 = { x = soil_pos.x + 1 , y = soil_pos.y + 1 , z = soil_pos.z + 1 }
if # minetest.find_nodes_in_area ( np1 , np2 , { " group:water " , " group:frosted_ice " } ) > 0 then
-- Water found! Sugar canes are happy! :-)
return true
2017-07-07 17:37:05 +03:00
end
-- No water found! Sugar canes are not amuzed and refuses to be placed. :-(
return false
end ) ,
2021-08-04 13:41:25 +03:00
on_construct = function ( pos )
local node = minetest.get_node ( pos )
if node.param2 == 0 then
2023-02-16 21:09:39 +03:00
node.param2 = mcl_util.get_palette_indexes_from_pos ( pos ) . grass_palette_index
2021-08-04 13:41:25 +03:00
if node.param2 ~= 0 then
minetest.set_node ( pos , node )
end
end
end ,
2017-07-07 17:37:05 +03:00
_mcl_blast_resistance = 0 ,
_mcl_hardness = 0 ,
2017-08-22 16:20:00 +03:00
} )
2024-01-16 17:55:40 +03:00
2024-01-16 21:53:40 +03:00
-- Moved cactus mob damage logic to /ENTITIES/mcl_mobs/physics.lua
--[[
local function cactus_damage_check ( obj , is_mob )
2024-01-16 17:55:40 +03:00
-- where am I?
local pos = obj : get_pos ( )
if pos then
-- Am I near a cactus?
2024-01-16 21:53:40 +03:00
local near = minetest.find_node_near ( pos , 1 , " mcl_core:cactus " , true )
2024-01-16 17:55:40 +03:00
if not near and near ~= nil then
2024-01-16 21:53:40 +03:00
near = find_node_near ( { x = pos.x , y = pos.y - 1 , z = pos.z } , 1 , " mcl_core:cactus " , true )
2024-01-16 17:55:40 +03:00
end
if near then
-- Am I touching the cactus? If so, it hurts
local dist = vector.distance ( pos , near )
local dist_feet = vector.distance ( { x = pos.x , y = pos.y - 1 , z = pos.z } , near )
2024-01-16 21:53:40 +03:00
if dist < 1.1 or dist_feet < 1.1 or ( is_mob and ( dist < 1.25 or dist_feet < 1.9 ) ) then
2024-01-16 17:55:40 +03:00
if obj : get_hp ( ) > 0 then
mcl_util.deal_damage ( obj , 1 , { type = " cactus " } )
end
end
end
end
end
local etime = 0
minetest.register_globalstep ( function ( dtime )
etime = dtime + etime
if etime < 0.5 then return end
etime = 0
--for _,pl in pairs(minetest.get_connected_players()) do
--cactus_damage_check(pl) -- Another player cactus damage check code is in mcl_playerplus
--end
for _ , ent in pairs ( minetest.luaentities ) do
if ent.is_mob then
2024-01-16 21:53:40 +03:00
cactus_damage_check ( ent.object , true )
2024-01-16 17:55:40 +03:00
end
end
2024-01-16 21:53:40 +03:00
end )
] ]