2021-06-21 01:58:18 +02:00
local S = minetest.get_translator ( minetest.get_current_modname ( ) )
2022-10-26 04:46:41 +02:00
local planton = { " mcl_core:dirt_with_grass " , " mcl_core:dirt " , " mcl_core:podzol " , " mcl_core:coarse_dirt " , " mcl_farming:soil " , " mcl_farming:soil_wet " , " mcl_moss:moss " }
2022-10-24 16:23:14 +02:00
2021-06-21 01:58:18 +02:00
for i = 0 , 3 do
local texture = " mcl_farming_sweet_berry_bush_ " .. i .. " .png "
local node_name = " mcl_farming:sweet_berry_bush_ " .. i
2022-10-24 16:32:40 +02:00
local groups = { sweet_berry = 1 , dig_immediate = 3 , not_in_creative_inventory = 1 , plant = 1 , attached_node = 1 , dig_by_water = 1 , destroy_by_lava_flow = 1 , dig_by_piston = 1 , flammable = 3 , fire_encouragement = 60 , fire_flammability = 20 , compostability = 30 }
if i > 0 then
groups.sweet_berry_thorny = 1
end
2022-12-24 18:38:55 +01:00
local drop_berries = ( i >= 2 )
local berries_to_drop = drop_berries and { i - 1 , i } or nil
2021-06-21 01:58:18 +02:00
minetest.register_node ( node_name , {
drawtype = " plantlike " ,
tiles = { texture } ,
description = S ( " Sweet Berry Bush (Stage @1) " , i ) ,
paramtype = " light " ,
sunlight_propagates = true ,
paramtype2 = " meshoptions " ,
place_param2 = 3 ,
2022-10-24 16:03:48 +02:00
liquid_viscosity = 15 ,
liquidtype = " source " ,
liquid_alternative_flowing = node_name ,
liquid_alternative_source = node_name ,
liquid_renewable = false ,
liquid_range = 0 ,
2021-06-21 01:58:18 +02:00
walkable = false ,
2022-12-24 18:38:55 +01:00
-- Dont even create a table if no berries are dropped.
drop = not drop_berries and " " or {
max_items = 1 ,
items = {
{ items = { " mcl_farming:sweet_berry " .. berries_to_drop [ 1 ] } , rarity = 2 } ,
{ items = { " mcl_farming:sweet_berry " .. berries_to_drop [ 2 ] } }
}
} ,
2021-06-21 01:58:18 +02:00
selection_box = {
type = " fixed " ,
2022-10-24 16:03:48 +02:00
fixed = { - 6 / 16 , - 0.5 , - 6 / 16 , 6 / 16 , ( - 0.30 + ( i * 0.25 ) ) , 6 / 16 } ,
2021-06-21 01:58:18 +02:00
} ,
inventory_image = texture ,
wield_image = texture ,
2022-10-24 16:32:40 +02:00
groups = groups ,
2021-06-21 01:58:18 +02:00
sounds = mcl_sounds.node_sound_leaves_defaults ( ) ,
_mcl_blast_resistance = 0 ,
2022-10-24 16:32:40 +02:00
_mcl_hardness = 0 ,
2022-11-16 02:58:15 +01:00
on_rightclick = function ( pos , node , clicker , itemstack , pointed_thing )
2022-11-28 11:43:09 +01:00
local pn = clicker : get_player_name ( )
if clicker : is_player ( ) and minetest.is_protected ( pos , pn ) then
minetest.record_protection_violation ( pos , pn )
return itemstack
end
2023-01-01 22:52:35 +01:00
if 3 ~= i and mcl_dye and
2023-01-01 22:02:38 +01:00
clicker : get_wielded_item ( ) : get_name ( ) == " mcl_bone_meal:bone_meal " then
2022-11-16 17:25:38 +01:00
mcl_dye.apply_bone_meal ( { under = pos } , clicker )
2022-12-24 19:38:32 +01:00
if not minetest.is_creative_enabled ( pn ) then
itemstack : take_item ( )
end
2022-11-16 17:25:38 +01:00
return
end
2022-12-24 18:38:55 +01:00
if drop_berries then
for j = 1 , berries_to_drop [ math.random ( 2 ) ] do
minetest.add_item ( pos , " mcl_farming:sweet_berry " )
2022-11-16 02:58:15 +01:00
end
2022-12-24 19:38:32 +01:00
minetest.swap_node ( pos , { name = " mcl_farming:sweet_berry_bush_1 " } )
2022-11-16 02:58:15 +01:00
end
2022-11-28 11:43:09 +01:00
return itemstack
2022-11-16 02:58:15 +01:00
end ,
2021-06-21 01:58:18 +02:00
} )
minetest.register_alias ( " mcl_sweet_berry:sweet_berry_bush_ " .. i , node_name )
end
minetest.register_craftitem ( " mcl_farming:sweet_berry " , {
description = S ( " Sweet Berry " ) ,
inventory_image = " mcl_farming_sweet_berry.png " ,
2022-10-24 16:35:47 +02:00
_mcl_saturation = 0.4 ,
2022-10-24 01:00:41 +02:00
groups = { food = 2 , eatable = 1 , compostability = 30 } ,
2021-06-21 01:58:18 +02:00
on_secondary_use = minetest.item_eat ( 1 ) ,
on_place = function ( itemstack , placer , pointed_thing )
2022-11-28 11:43:09 +01:00
local pn = placer : get_player_name ( )
2022-11-29 12:19:27 +01:00
if placer : is_player ( ) and minetest.is_protected ( pointed_thing.above , pn or " " ) then
2022-11-28 11:43:09 +01:00
minetest.record_protection_violation ( pointed_thing.above , pn )
return itemstack
end
2022-12-24 18:38:55 +01:00
if pointed_thing.type == " node " and
table.indexof ( planton , minetest.get_node ( pointed_thing.under ) . name ) ~= - 1 and
pointed_thing.above . y > pointed_thing.under . y and
minetest.get_node ( pointed_thing.above ) . name == " air " then
minetest.set_node ( pointed_thing.above , { name = " mcl_farming:sweet_berry_bush_0 " } )
2022-10-24 16:23:14 +02:00
if not minetest.is_creative_enabled ( placer : get_player_name ( ) ) then
itemstack : take_item ( )
end
return itemstack
2021-06-21 01:58:18 +02:00
end
2022-10-24 16:23:14 +02:00
return minetest.do_item_eat ( 1 , nil , itemstack , placer , pointed_thing )
2021-06-21 01:58:18 +02:00
end ,
} )
minetest.register_alias ( " mcl_sweet_berry:sweet_berry " , " mcl_farming:sweet_berry " )
2022-06-18 17:41:22 +02:00
-- TODO: Find proper interval and chance values for sweet berry bushes. Current interval and chance values are copied from mcl_farming:beetroot which has similar growth stages.
2022-10-24 01:13:44 +02:00
mcl_farming : add_plant ( " plant_sweet_berry_bush " , " mcl_farming:sweet_berry_bush_3 " , { " mcl_farming:sweet_berry_bush_0 " , " mcl_farming:sweet_berry_bush_1 " , " mcl_farming:sweet_berry_bush_2 " } , 68 , 3 )
2022-10-24 16:03:24 +02:00
local function berry_damage_check ( obj )
local p = obj : get_pos ( )
if not p then return end
2022-10-24 16:32:40 +02:00
if not minetest.find_node_near ( p , 0.4 , { " group:sweet_berry_thorny " } , true ) then return end
2022-10-24 16:03:24 +02:00
local v = obj : get_velocity ( )
2023-01-13 22:36:43 +01:00
if math.abs ( v.x ) < 0.1 and math.abs ( v.y ) < 0.1 and math.abs ( v.z ) < 0.1 then return end
2022-10-24 16:03:24 +02:00
mcl_util.deal_damage ( obj , 0.5 , { type = " sweet_berry " } )
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
berry_damage_check ( pl )
end
for _ , ent in pairs ( minetest.luaentities ) do
if ent.is_mob then
berry_damage_check ( ent.object )
end
end
end )