2021-03-28 14:29:29 +02:00
|
|
|
-- TODO: whenever it becomes possible to fully implement kelp without the
|
2021-03-30 07:28:44 +02:00
|
|
|
-- plantlike_rooted limitation, please update accordingly.
|
2021-03-28 14:29:29 +02:00
|
|
|
--
|
2021-04-08 06:04:29 +02:00
|
|
|
-- TODO: whenever it becomes possible to make kelp grow infinitely without
|
|
|
|
-- resorting to making intermediate kelp stem node, please update accordingly.
|
|
|
|
--
|
2021-03-21 07:06:54 +01:00
|
|
|
-- TODO: In MC, you can't actually destroy kelp by bucket'ing water in the middle.
|
|
|
|
-- However, because of the plantlike_rooted hack, we'll just allow it for now.
|
2019-12-17 22:43:35 +01:00
|
|
|
|
2021-05-29 16:12:33 +02:00
|
|
|
local S = minetest.get_translator(minetest.get_current_modname())
|
|
|
|
local mod_doc = minetest.get_modpath("doc")
|
2021-03-28 08:11:08 +02:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- local-ify runtime functions
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- objects
|
2021-03-29 08:09:09 +02:00
|
|
|
local mt_registered_items = minetest.registered_items
|
|
|
|
local mt_registered_nodes = minetest.registered_nodes
|
2021-03-28 08:11:08 +02:00
|
|
|
|
|
|
|
-- functions
|
2021-03-30 07:28:44 +02:00
|
|
|
local mt_log = minetest.log
|
2021-03-29 08:09:09 +02:00
|
|
|
local mt_add_item = minetest.add_item
|
2021-03-28 08:11:08 +02:00
|
|
|
local mt_get_item_group = minetest.get_item_group
|
|
|
|
local mt_get_node = minetest.get_node
|
2021-03-29 08:09:09 +02:00
|
|
|
local mt_get_node_level = minetest.get_node_level
|
|
|
|
local mt_get_node_max_level = minetest.get_node_max_level
|
|
|
|
local mt_get_node_or_nil = minetest.get_node_or_nil
|
2021-03-30 07:28:44 +02:00
|
|
|
local mt_get_meta = minetest.get_meta
|
2021-03-31 11:31:28 +02:00
|
|
|
local mt_set_node = minetest.set_node
|
|
|
|
local mt_swap_node = minetest.swap_node
|
2021-03-30 07:28:44 +02:00
|
|
|
local mt_pos_to_string = minetest.pos_to_string
|
2021-03-29 08:09:09 +02:00
|
|
|
local mt_is_protected = minetest.is_protected
|
2021-03-30 07:28:44 +02:00
|
|
|
local mt_record_protection_violation = minetest.record_protection_violation
|
2021-03-29 08:09:09 +02:00
|
|
|
|
2021-03-28 08:11:08 +02:00
|
|
|
local mt_is_creative_enabled = minetest.is_creative_enabled
|
2021-03-29 08:09:09 +02:00
|
|
|
local mt_sound_play = minetest.sound_play
|
|
|
|
|
2021-04-15 23:41:34 +02:00
|
|
|
local math = math
|
2021-05-22 23:12:33 +02:00
|
|
|
--local string = string
|
2021-04-15 23:41:34 +02:00
|
|
|
local table = table
|
2021-03-28 08:11:08 +02:00
|
|
|
|
|
|
|
-- DEBUG: functions
|
2021-03-31 08:17:50 +02:00
|
|
|
-- local log = minetest.log
|
|
|
|
-- local chatlog = minetest.chat_send_all
|
2021-03-28 08:11:08 +02:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Kelp API
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2021-03-29 08:09:09 +02:00
|
|
|
local kelp = {}
|
|
|
|
mcl_ocean.kelp = kelp
|
|
|
|
|
2023-02-08 22:03:26 +01:00
|
|
|
-- Once reach the maximum, kelp no longer grows.
|
2021-03-30 07:28:44 +02:00
|
|
|
kelp.MIN_AGE = 0
|
2021-03-29 08:09:09 +02:00
|
|
|
kelp.MAX_AGE = 25
|
|
|
|
|
2023-02-08 22:03:26 +01:00
|
|
|
kelp.TICK = 0.2 -- Tick interval (in seconds) for updating kelp.
|
2021-03-30 07:28:44 +02:00
|
|
|
|
|
|
|
-- The average amount of growth for kelp in a day is 2.16 (https://youtu.be/5Bp4lAjAk3I)
|
|
|
|
-- Normally, a day lasts 20 minutes, meaning kelp.next_grow() is executed
|
|
|
|
-- 1200 / TICK times. Per tick probability = (216/100) / (1200/TICK)
|
|
|
|
-- NOTE: currently, we can't exactly use the same type of randomness MC does, because
|
|
|
|
-- it has multiple complicated sets of PRNGs.
|
|
|
|
-- NOTE: Small loss of precision, should be 10 to preserve it.
|
|
|
|
-- kelp.ROLL_GROWTH_PRECISION = 10
|
|
|
|
-- kelp.ROLL_GROWTH_NUMERATOR = 216 * kelp.TICK * kelp.ROLL_GROWTH_PRECISION
|
|
|
|
-- kelp.ROLL_GROWTH_DENOMINATOR = 100 * 1200 * kelp.ROLL_GROWTH_PRECISION
|
|
|
|
kelp.ROLL_GROWTH_PRECISION = 1
|
|
|
|
kelp.ROLL_GROWTH_NUMERATOR = 216 * kelp.TICK
|
2023-02-08 23:53:23 +01:00
|
|
|
kelp.ROLL_GROWTH_DENOMINATOR = 100 * 1200
|
2021-03-30 07:28:44 +02:00
|
|
|
|
|
|
|
-- Sounds used to dig and place kelp.
|
2021-03-29 08:09:09 +02:00
|
|
|
kelp.leaf_sounds = mcl_sounds.node_sound_leaves_defaults()
|
|
|
|
|
|
|
|
-- is age in the growable range?
|
|
|
|
function kelp.is_age_growable(age)
|
|
|
|
return age >= 0 and age < kelp.MAX_AGE
|
|
|
|
end
|
|
|
|
|
2019-12-17 22:43:35 +01:00
|
|
|
|
2021-03-20 10:47:04 +01:00
|
|
|
-- Is this water?
|
2021-03-28 08:11:08 +02:00
|
|
|
-- Returns the liquidtype, if indeed water.
|
2021-03-30 07:28:44 +02:00
|
|
|
function kelp.is_submerged(node)
|
2021-03-28 08:11:08 +02:00
|
|
|
if mt_get_item_group(node.name, "water") ~= 0 then
|
2021-03-30 07:28:44 +02:00
|
|
|
-- Expected only "source" and "flowing" from water liquids
|
|
|
|
return mt_registered_nodes[node.name].liquidtype
|
2021-03-20 10:47:04 +01:00
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
2021-03-28 08:11:08 +02:00
|
|
|
|
2021-03-20 10:47:04 +01:00
|
|
|
|
|
|
|
-- Is the water downward flowing?
|
2021-03-21 05:16:56 +01:00
|
|
|
-- (kelp can grow/be placed inside downward flowing water)
|
2021-03-30 07:28:44 +02:00
|
|
|
function kelp.is_downward_flowing(pos, node, pos_above, node_above, __is_above__)
|
|
|
|
-- Function params: (pos[, node]) or (node, pos_above) or (node, node_above)
|
|
|
|
local node = node or mt_get_node(pos)
|
|
|
|
|
2021-04-15 23:41:34 +02:00
|
|
|
local result = (math.floor(node.param2 / 8) % 2) == 1
|
2021-03-30 07:28:44 +02:00
|
|
|
if not (result or __is_above__) then
|
2021-03-28 08:11:08 +02:00
|
|
|
-- If not, also check node above.
|
2021-03-21 07:06:54 +01:00
|
|
|
-- (this is needed due a weird quirk in the definition of "downwards flowing"
|
|
|
|
-- liquids in Minetest)
|
2021-03-30 07:28:44 +02:00
|
|
|
local pos_above = pos_above or {x=pos.x,y=pos.y+1,z=pos.z}
|
|
|
|
local node_above = node_above or mt_get_node(pos_above)
|
|
|
|
result = kelp.is_submerged(node_above)
|
|
|
|
or kelp.is_downward_flowing(nil, node_above, nil, nil, true)
|
2021-03-20 10:47:04 +01:00
|
|
|
end
|
|
|
|
return result
|
|
|
|
end
|
2021-03-29 08:09:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
-- Will node fall at that position?
|
|
|
|
-- This only checks if a node would fall, meaning that node need not be at pos.
|
2021-03-30 07:28:44 +02:00
|
|
|
function kelp.is_falling(pos, node, is_falling, pos_bottom, node_bottom, def_bottom)
|
|
|
|
-- Optional params: is_falling, pos_bottom, node_bottom, def_bottom
|
|
|
|
|
2021-03-29 08:09:09 +02:00
|
|
|
-- NOTE: Modified from check_single_for_falling in builtin.
|
2021-03-30 07:28:44 +02:00
|
|
|
-- Please update accordingly.
|
2021-03-29 08:09:09 +02:00
|
|
|
local nodename = node.name
|
|
|
|
|
2021-03-30 07:28:44 +02:00
|
|
|
if is_falling == false or
|
|
|
|
is_falling == nil and mt_get_item_group(nodename, "falling_node") == 0 then
|
2021-03-29 08:09:09 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2021-03-30 07:28:44 +02:00
|
|
|
local pos_bottom = pos_bottom or {x = pos.x, y = pos.y - 1, z = pos.z}
|
2021-03-29 08:09:09 +02:00
|
|
|
-- get_node_or_nil: Only fall if node below is loaded
|
2021-03-30 07:28:44 +02:00
|
|
|
local node_bottom = node_bottom or mt_get_node_or_nil(pos_bottom)
|
2021-03-29 08:09:09 +02:00
|
|
|
local nodename_bottom = node_bottom.name
|
2021-03-30 07:28:44 +02:00
|
|
|
local def_bottom = def_bottom or node_bottom and mt_registered_nodes[nodename_bottom]
|
2021-03-29 08:09:09 +02:00
|
|
|
if not def_bottom then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
local same = nodename == nodename_bottom
|
|
|
|
-- Let leveled nodes fall if it can merge with the bottom node
|
|
|
|
if same and def_bottom.paramtype2 == "leveled" and
|
|
|
|
mt_get_node_level(pos_bottom) <
|
|
|
|
mt_get_node_max_level(pos_bottom) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Otherwise only if the bottom node is considered "fall through"
|
|
|
|
if not same and
|
|
|
|
(not def_bottom.walkable or def_bottom.buildable_to) and
|
|
|
|
(mt_get_item_group(nodename, "float") == 0 or
|
|
|
|
def_bottom.liquidtype == "none") then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
2021-03-28 08:11:08 +02:00
|
|
|
|
2021-03-20 10:47:04 +01:00
|
|
|
|
2021-03-30 07:28:44 +02:00
|
|
|
-- Roll whether to grow kelp or not.
|
|
|
|
function kelp.roll_growth(numerator, denominator)
|
|
|
|
-- Optional params: numerator, denominator
|
2023-02-08 23:53:23 +01:00
|
|
|
--return math.random(denominator or kelp.ROLL_GROWTH_DENOMINATOR) <= (numerator or kelp.ROLL_GROWTH_NUMERATOR)
|
|
|
|
return true -- probability done by ABM
|
2021-03-30 07:28:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- Roll initial age for kelp.
|
|
|
|
function kelp.roll_init_age(min, max)
|
|
|
|
-- Optional params
|
2021-04-15 23:41:34 +02:00
|
|
|
return math.random(min or kelp.MIN_AGE, (max or kelp.MAX_AGE)-1)
|
2021-03-30 07:28:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-03-21 05:16:56 +01:00
|
|
|
-- Converts param2 to kelp height.
|
2021-04-08 06:04:29 +02:00
|
|
|
-- For the special case where the max param2 is reached, interpret that as the
|
|
|
|
-- 16th kelp stem.
|
2021-03-29 08:09:09 +02:00
|
|
|
function kelp.get_height(param2)
|
2021-04-15 23:41:34 +02:00
|
|
|
return math.floor(param2 / 16) + math.floor(param2 % 16 / 8)
|
2021-03-20 10:47:04 +01:00
|
|
|
end
|
2021-03-28 08:11:08 +02:00
|
|
|
|
2021-03-20 10:47:04 +01:00
|
|
|
|
2021-03-29 08:09:09 +02:00
|
|
|
-- Obtain pos and node of the tip of kelp.
|
2021-04-08 06:04:29 +02:00
|
|
|
function kelp.get_tip(pos, height)
|
|
|
|
-- Optional params: height
|
|
|
|
local height = height or kelp.get_height(mt_get_node(pos).param2)
|
|
|
|
local pos_tip = {x=pos.x, y=pos.y+height+1, z=pos.z}
|
2021-03-30 07:28:44 +02:00
|
|
|
return pos_tip, mt_get_node(pos_tip), height
|
2019-12-18 15:06:35 +01:00
|
|
|
end
|
2021-03-28 08:11:08 +02:00
|
|
|
|
2019-12-18 15:06:35 +01:00
|
|
|
|
2021-03-21 05:16:56 +01:00
|
|
|
-- Obtain position of the first kelp unsubmerged.
|
2021-03-30 07:28:44 +02:00
|
|
|
function kelp.find_unsubmerged(pos, node, height)
|
|
|
|
-- Optional params: node, height
|
|
|
|
local node = node or mt_get_node(pos)
|
2021-04-08 07:34:04 +02:00
|
|
|
local height = height or ((node.param2 >= 0 and node.param2 < 16) and 1) or kelp.get_height(node.param2)
|
2021-03-29 08:09:09 +02:00
|
|
|
|
2021-03-30 07:28:44 +02:00
|
|
|
local walk_pos = {x=pos.x, z=pos.z}
|
|
|
|
local y = pos.y
|
2021-03-20 10:47:04 +01:00
|
|
|
for i=1,height do
|
2021-03-29 08:09:09 +02:00
|
|
|
walk_pos.y = y + i
|
|
|
|
local walk_node = mt_get_node(walk_pos)
|
2021-03-30 07:28:44 +02:00
|
|
|
if not kelp.is_submerged(walk_node) then
|
|
|
|
return walk_pos, walk_node, height, i
|
2019-12-18 15:06:35 +01:00
|
|
|
end
|
|
|
|
end
|
2021-03-30 07:28:44 +02:00
|
|
|
return nil, nil, height, height
|
2019-12-18 15:06:35 +01:00
|
|
|
end
|
|
|
|
|
2021-03-21 05:16:56 +01:00
|
|
|
|
2021-03-28 08:11:08 +02:00
|
|
|
-- Obtain next param2.
|
2021-03-29 08:09:09 +02:00
|
|
|
function kelp.next_param2(param2)
|
2021-04-08 06:04:29 +02:00
|
|
|
-- param2 max value is 255, so adding to 256 causes overflow.
|
2021-04-15 23:41:34 +02:00
|
|
|
return math.min(param2+16 - param2 % 16, 255);
|
2019-12-18 15:06:35 +01:00
|
|
|
end
|
2021-03-28 08:11:08 +02:00
|
|
|
|
2023-02-08 04:12:55 +01:00
|
|
|
local function store_age (pos, age)
|
|
|
|
if pos then
|
2023-02-08 23:53:23 +01:00
|
|
|
--minetest.log("age: ".. tostring(age) .. ", pos: ".. mt_pos_to_string(pos))
|
2023-02-08 04:12:55 +01:00
|
|
|
mt_get_meta(pos):set_int("mcl_ocean:kelp_age", age)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-31 00:39:57 +02:00
|
|
|
local function retrieve_age (pos)
|
2023-02-08 04:12:55 +01:00
|
|
|
local meta = mt_get_meta(pos)
|
2023-03-31 00:39:57 +02:00
|
|
|
local age_set = meta:contains("mcl_ocean:kelp_age")
|
|
|
|
if not age_set then
|
|
|
|
return nil
|
2023-02-08 23:53:23 +01:00
|
|
|
end
|
2023-03-31 00:39:57 +02:00
|
|
|
|
|
|
|
local age = meta:get_int("mcl_ocean:kelp_age")
|
|
|
|
--minetest.log("age: " .. tostring(age))
|
|
|
|
return age
|
2023-02-08 04:12:55 +01:00
|
|
|
end
|
2019-12-18 15:06:35 +01:00
|
|
|
|
2021-03-30 07:28:44 +02:00
|
|
|
-- Initialise a kelp's age.
|
2023-03-31 00:39:57 +02:00
|
|
|
function kelp.init_age(pos)
|
2021-03-30 07:28:44 +02:00
|
|
|
-- Watched params: pos
|
2023-02-08 23:53:23 +01:00
|
|
|
-- Optional params: age, from_lbm
|
2021-03-30 07:28:44 +02:00
|
|
|
|
2023-03-31 00:39:57 +02:00
|
|
|
local age = retrieve_age(pos)
|
2023-02-08 04:12:55 +01:00
|
|
|
|
2023-03-31 00:39:57 +02:00
|
|
|
if not age then
|
|
|
|
age = kelp.roll_init_age()
|
2023-02-08 23:53:23 +01:00
|
|
|
--minetest.log("no kelp age set so init with: " .. tostring(new_age))
|
2023-03-31 00:39:57 +02:00
|
|
|
store_age(pos, age)
|
2021-03-30 07:28:44 +02:00
|
|
|
else
|
2023-03-31 00:39:57 +02:00
|
|
|
--minetest.log("stored_age: " .. tostring(age))
|
2021-03-30 07:28:44 +02:00
|
|
|
end
|
|
|
|
|
2023-03-31 00:39:57 +02:00
|
|
|
return age
|
2021-03-30 07:28:44 +02:00
|
|
|
end
|
|
|
|
|
2021-04-08 07:34:04 +02:00
|
|
|
-- Apply next kelp height. The surface is swapped. so on_construct is skipped.
|
2021-03-31 13:27:57 +02:00
|
|
|
function kelp.next_height(pos, node, pos_tip, node_tip, submerged, downward_flowing)
|
2021-03-30 07:28:44 +02:00
|
|
|
-- Modified params: node
|
2021-03-31 11:31:28 +02:00
|
|
|
-- Optional params: node, set_node, pos_tip, node_tip, submerged, downward_flowing
|
2021-03-30 07:28:44 +02:00
|
|
|
local node = node or mt_get_node(pos)
|
|
|
|
local pos_tip = pos_tip
|
|
|
|
local node_tip = node_tip or (pos_tip and mt_get_node(pos_tip))
|
|
|
|
if not pos_tip then
|
|
|
|
pos_tip,node_tip = kelp.get_tip(pos)
|
2021-03-29 08:09:09 +02:00
|
|
|
end
|
2021-03-30 07:28:44 +02:00
|
|
|
local downward_flowing = downward_flowing or
|
|
|
|
(submerged or kelp.is_submerged(node_tip)
|
|
|
|
and kelp.is_downward_flowing(pos_tip, node_tip))
|
2021-03-29 08:09:09 +02:00
|
|
|
|
2021-03-28 08:11:08 +02:00
|
|
|
-- Liquid source: Grow normally.
|
2021-03-29 08:09:09 +02:00
|
|
|
node.param2 = kelp.next_param2(node.param2)
|
2021-03-31 13:27:57 +02:00
|
|
|
mt_swap_node(pos, node)
|
2021-03-21 05:16:56 +01:00
|
|
|
|
2021-03-29 08:09:09 +02:00
|
|
|
-- Flowing liquid: Grow 1 step, but also turn the tip node into a liquid source.
|
|
|
|
if downward_flowing then
|
2021-03-30 07:28:44 +02:00
|
|
|
local alt_liq = mt_registered_nodes[node_tip.name].liquid_alternative_source
|
2023-11-03 22:46:00 +01:00
|
|
|
local alt_liq_accessible = mt_get_item_group(node_tip.name,"waterlogged") -- returns 0 if it isn't waterlogged.
|
|
|
|
if alt_liq and not alt_liq_accessible then
|
2021-03-29 08:09:09 +02:00
|
|
|
mt_set_node(pos_tip, {name=alt_liq})
|
2021-03-28 08:11:08 +02:00
|
|
|
end
|
|
|
|
end
|
2021-03-29 08:09:09 +02:00
|
|
|
|
2021-03-30 07:28:44 +02:00
|
|
|
return node, pos_tip, node_tip, submerged, downward_flowing
|
|
|
|
end
|
2021-03-29 08:09:09 +02:00
|
|
|
|
|
|
|
|
2021-03-30 07:28:44 +02:00
|
|
|
-- Grow next kelp.
|
2023-02-08 23:53:23 +01:00
|
|
|
function kelp.next_grow(age, pos, node, pos_tip, node_tip, submerged, downward_flowing)
|
2021-03-30 07:28:44 +02:00
|
|
|
-- Watched params: pos
|
|
|
|
-- Modified params: node
|
2023-02-08 23:53:23 +01:00
|
|
|
-- Optional params: node, pos_tip, node_tip, submerged, downward_flowing
|
2021-03-30 07:28:44 +02:00
|
|
|
local node = node or mt_get_node(pos)
|
|
|
|
local pos_tip = pos_tip
|
|
|
|
local node_tip = node_tip or (pos_tip and mt_get_node(pos_tip))
|
|
|
|
if not pos_tip then
|
|
|
|
pos_tip,node_tip = kelp.get_tip(pos)
|
|
|
|
end
|
2021-03-29 08:09:09 +02:00
|
|
|
|
2021-03-30 07:28:44 +02:00
|
|
|
-- New kelp must also be submerged in water.
|
|
|
|
local downward_flowing = downward_flowing or kelp.is_downward_flowing(pos_tip, node_tip)
|
|
|
|
if not (submerged or kelp.is_submerged(node_tip)) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2021-03-31 13:27:57 +02:00
|
|
|
kelp.next_height(pos, node, pos_tip, node_tip, submerged, downward_flowing)
|
2023-02-08 04:12:55 +01:00
|
|
|
store_age(pos, age)
|
2023-02-08 23:53:23 +01:00
|
|
|
return true, node, pos_tip, node_tip, submerged, downward_flowing
|
2021-03-29 08:09:09 +02:00
|
|
|
end
|
2021-03-28 08:11:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
-- Drops the items for detached kelps.
|
2021-04-08 07:34:04 +02:00
|
|
|
function kelp.detach_drop(pos, height)
|
|
|
|
-- Optional params: height
|
|
|
|
local height = height or kelp.get_height(mt_get_node(pos).param2)
|
2021-03-30 07:28:44 +02:00
|
|
|
local y = pos.y
|
|
|
|
local walk_pos = {x=pos.x, z=pos.z}
|
2021-03-28 08:11:08 +02:00
|
|
|
for i=1,height do
|
2021-03-30 07:28:44 +02:00
|
|
|
walk_pos.y = y+i
|
|
|
|
mt_add_item(walk_pos, "mcl_ocean:kelp")
|
2021-03-28 08:11:08 +02:00
|
|
|
end
|
2021-03-29 08:09:09 +02:00
|
|
|
return true
|
2021-03-28 08:11:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- Detach the kelp at dig_pos, and drop their items.
|
2021-03-28 14:29:29 +02:00
|
|
|
-- Synonymous to digging the kelp.
|
|
|
|
-- NOTE: this is intended for whenever kelp truly becomes segmented plants
|
|
|
|
-- instead of rooted to the floor. Don't try to remove dig_pos.
|
2021-04-08 07:34:04 +02:00
|
|
|
function kelp.detach_dig(dig_pos, pos, drop, node, height)
|
|
|
|
-- Optional params: drop, node, height
|
2021-03-29 08:09:09 +02:00
|
|
|
|
2021-04-08 07:34:04 +02:00
|
|
|
local node = node or mt_get_node(pos)
|
|
|
|
local height = height or kelp.get_height(node.param2)
|
2021-03-28 08:11:08 +02:00
|
|
|
-- pos.y points to the surface, offset needed to point to the first kelp.
|
|
|
|
local new_height = dig_pos.y - (pos.y+1)
|
|
|
|
|
2021-03-31 11:31:28 +02:00
|
|
|
-- Digs the entire kelp.
|
2021-03-28 08:11:08 +02:00
|
|
|
if new_height <= 0 then
|
2021-03-30 07:28:44 +02:00
|
|
|
if drop then
|
2021-04-08 07:34:04 +02:00
|
|
|
kelp.detach_drop(dig_pos, height)
|
2021-03-21 05:16:56 +01:00
|
|
|
end
|
2021-03-28 08:11:08 +02:00
|
|
|
mt_set_node(pos, {
|
2021-03-29 08:09:09 +02:00
|
|
|
name=mt_registered_nodes[node.name].node_dig_prediction,
|
2021-03-30 07:28:44 +02:00
|
|
|
param=node.param,
|
|
|
|
param2=0 })
|
2021-03-28 08:11:08 +02:00
|
|
|
|
2021-03-31 11:31:28 +02:00
|
|
|
-- Digs the kelp beginning at a height.
|
2021-03-28 08:11:08 +02:00
|
|
|
else
|
2021-03-30 07:28:44 +02:00
|
|
|
if drop then
|
2021-04-08 07:34:04 +02:00
|
|
|
kelp.detach_drop(dig_pos, height - new_height)
|
2021-03-28 08:11:08 +02:00
|
|
|
end
|
2021-03-31 11:31:28 +02:00
|
|
|
mt_swap_node(pos, {name=node.name, param=node.param, param2=16*new_height})
|
2021-03-21 05:16:56 +01:00
|
|
|
end
|
|
|
|
end
|
2021-03-29 08:09:09 +02:00
|
|
|
|
2021-03-28 08:11:08 +02:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Kelp callback functions
|
|
|
|
--------------------------------------------------------------------------------
|
2021-03-21 05:16:56 +01:00
|
|
|
|
2021-03-29 08:09:09 +02:00
|
|
|
function kelp.surface_on_dig(pos, node, digger)
|
2021-04-08 07:34:04 +02:00
|
|
|
kelp.detach_dig(pos, pos, true, node)
|
2021-03-28 14:29:29 +02:00
|
|
|
end
|
|
|
|
|
2021-03-29 08:09:09 +02:00
|
|
|
function kelp.surface_after_dig_node(pos, node)
|
2021-05-22 23:12:33 +02:00
|
|
|
return mt_set_node(pos, {name=minetest.registered_nodes[node.name].node_dig_prediction})
|
2021-03-28 14:29:29 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2023-02-08 22:03:26 +01:00
|
|
|
local function detach_unsubmerged(pos)
|
2021-03-28 14:29:29 +02:00
|
|
|
local node = mt_get_node(pos)
|
2021-03-30 07:28:44 +02:00
|
|
|
|
2021-04-08 07:34:04 +02:00
|
|
|
local dig_pos,_, height = kelp.find_unsubmerged(pos, node)
|
2021-03-28 14:29:29 +02:00
|
|
|
if dig_pos then
|
2021-03-31 07:55:07 +02:00
|
|
|
mt_sound_play(mt_registered_nodes[node.name].sounds.dug, { gain = 0.5, pos = dig_pos }, true)
|
2021-04-08 07:34:04 +02:00
|
|
|
kelp.detach_dig(dig_pos, pos, true, node, height)
|
2023-02-08 04:12:55 +01:00
|
|
|
local new_age = kelp.roll_init_age()
|
|
|
|
store_age(pos, new_age)
|
2021-03-28 14:29:29 +02:00
|
|
|
end
|
2023-02-08 22:03:26 +01:00
|
|
|
end
|
2021-03-29 08:09:09 +02:00
|
|
|
|
2023-02-08 22:03:26 +01:00
|
|
|
local function grow_kelp (pos)
|
|
|
|
local node = mt_get_node(pos)
|
2023-03-31 00:39:57 +02:00
|
|
|
local age = retrieve_age(pos)
|
2023-02-08 04:12:55 +01:00
|
|
|
|
2023-03-31 00:39:57 +02:00
|
|
|
if not age then
|
|
|
|
--minetest.log("init a new age as not set: " .. mt_pos_to_string(pos))
|
|
|
|
age = kelp.init_age(pos)
|
|
|
|
end
|
2023-02-08 23:53:23 +01:00
|
|
|
|
2023-03-31 00:39:57 +02:00
|
|
|
if kelp.is_age_growable(age) then
|
|
|
|
--minetest.log("age growable: ".. tostring(age) .. ", pos: ".. mt_pos_to_string(pos))
|
|
|
|
kelp.next_grow(age+1, pos, node)
|
|
|
|
else
|
|
|
|
--minetest.log("age not: ".. tostring(age) .. ", pos: ".. mt_pos_to_string(pos))
|
2021-03-29 08:09:09 +02:00
|
|
|
end
|
2023-02-08 22:03:26 +01:00
|
|
|
end
|
|
|
|
|
2021-03-30 07:28:44 +02:00
|
|
|
function kelp.surface_on_construct(pos)
|
2023-02-08 23:53:23 +01:00
|
|
|
--minetest.log("on construct kelp called")
|
2023-03-31 00:39:57 +02:00
|
|
|
kelp.init_age(pos)
|
2021-03-30 07:28:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-03-29 08:09:09 +02:00
|
|
|
function kelp.surface_on_destruct(pos)
|
|
|
|
local node = mt_get_node(pos)
|
|
|
|
|
|
|
|
-- on_falling callback. Activated by pistons for falling nodes too.
|
2023-02-08 22:03:26 +01:00
|
|
|
-- I'm not sure this works. I think piston digs water and the unsubmerged nature drops kelp.
|
2021-03-29 08:09:09 +02:00
|
|
|
if kelp.is_falling(pos, node) then
|
2021-04-08 07:34:04 +02:00
|
|
|
kelp.detach_drop(pos, kelp.get_height(node.param2))
|
2021-03-29 08:09:09 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-03-30 07:28:44 +02:00
|
|
|
|
2021-03-29 08:09:09 +02:00
|
|
|
function kelp.surface_on_mvps_move(pos, node, oldpos, nodemeta)
|
|
|
|
-- Pistons moving falling nodes will have already activated on_falling callback.
|
2023-02-08 23:53:23 +01:00
|
|
|
--minetest.log("kelp.surface_on_mvps_move: " .. mt_pos_to_string(pos))
|
2021-04-08 07:34:04 +02:00
|
|
|
kelp.detach_dig(pos, pos, mt_get_item_group(node.name, "falling_node") ~= 1, node)
|
2021-03-29 08:09:09 +02:00
|
|
|
end
|
|
|
|
|
2021-03-28 14:29:29 +02:00
|
|
|
|
2021-03-29 08:09:09 +02:00
|
|
|
function kelp.kelp_on_place(itemstack, placer, pointed_thing)
|
2019-12-17 22:43:35 +01:00
|
|
|
if pointed_thing.type ~= "node" or not placer then
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
|
|
|
local player_name = placer:get_player_name()
|
|
|
|
local pos_under = pointed_thing.under
|
|
|
|
local pos_above = pointed_thing.above
|
2021-03-28 08:11:08 +02:00
|
|
|
local node_under = mt_get_node(pos_under)
|
2021-03-20 10:47:04 +01:00
|
|
|
local nu_name = node_under.name
|
2021-03-29 08:09:09 +02:00
|
|
|
local def_under = mt_registered_nodes[nu_name]
|
2019-12-17 22:43:35 +01:00
|
|
|
|
2021-03-29 08:09:09 +02:00
|
|
|
-- Allow rightclick to override place.
|
2019-12-17 22:43:35 +01:00
|
|
|
if def_under and def_under.on_rightclick and not placer:get_player_control().sneak then
|
|
|
|
return def_under.on_rightclick(pos_under, node_under,
|
|
|
|
placer, itemstack, pointed_thing) or itemstack
|
|
|
|
end
|
|
|
|
|
2021-03-29 08:09:09 +02:00
|
|
|
-- Protection
|
2021-03-28 08:11:08 +02:00
|
|
|
if mt_is_protected(pos_under, player_name) or
|
|
|
|
mt_is_protected(pos_above, player_name) then
|
2021-03-30 07:28:44 +02:00
|
|
|
mt_log("action", player_name
|
2019-12-17 22:43:35 +01:00
|
|
|
.. " tried to place " .. itemstack:get_name()
|
|
|
|
.. " at protected position "
|
2021-03-30 07:28:44 +02:00
|
|
|
.. mt_pos_to_string(pos_under))
|
|
|
|
mt_record_protection_violation(pos_under, player_name)
|
2019-12-17 22:43:35 +01:00
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
2021-03-29 08:09:09 +02:00
|
|
|
|
2021-04-08 13:25:19 +02:00
|
|
|
local pos_tip, node_tip, def_tip, new_surface, height
|
2021-03-29 08:09:09 +02:00
|
|
|
-- Kelp must also be placed on the top/tip side of the surface/kelp
|
|
|
|
if pos_under.y >= pos_above.y then
|
|
|
|
return itemstack
|
|
|
|
end
|
2021-03-20 10:47:04 +01:00
|
|
|
|
|
|
|
-- When placed on kelp.
|
2021-03-28 08:11:08 +02:00
|
|
|
if mt_get_item_group(nu_name, "kelp") == 1 then
|
2021-04-08 13:25:19 +02:00
|
|
|
height = kelp.get_height(node_under.param2)
|
|
|
|
pos_tip,node_tip = kelp.get_tip(pos_under, height)
|
2021-03-29 08:09:09 +02:00
|
|
|
def_tip = mt_registered_nodes[node_tip.name]
|
|
|
|
|
2021-03-20 10:47:04 +01:00
|
|
|
-- When placed on surface.
|
2019-12-18 13:37:20 +01:00
|
|
|
else
|
2021-04-08 07:34:04 +02:00
|
|
|
new_surface = false
|
2021-03-29 08:09:09 +02:00
|
|
|
for _,surface in pairs(kelp.surfaces) do
|
2021-03-28 08:11:08 +02:00
|
|
|
if nu_name == surface.nodename then
|
|
|
|
node_under.name = "mcl_ocean:kelp_" ..surface.name
|
2021-03-29 08:09:09 +02:00
|
|
|
node_under.param2 = 0
|
2021-04-08 07:34:04 +02:00
|
|
|
new_surface = true
|
2021-03-21 07:06:54 +01:00
|
|
|
break
|
2021-03-20 10:47:04 +01:00
|
|
|
end
|
|
|
|
end
|
2021-03-29 08:09:09 +02:00
|
|
|
-- Surface must support kelp
|
2021-04-08 07:34:04 +02:00
|
|
|
if not new_surface then
|
2019-12-18 13:37:20 +01:00
|
|
|
return itemstack
|
|
|
|
end
|
2021-03-21 07:06:54 +01:00
|
|
|
|
2021-03-29 08:09:09 +02:00
|
|
|
pos_tip = pos_above
|
|
|
|
node_tip = mt_get_node(pos_above)
|
|
|
|
def_tip = mt_registered_nodes[node_tip.name]
|
2021-04-08 13:25:19 +02:00
|
|
|
height = 0
|
2021-03-21 05:16:56 +01:00
|
|
|
end
|
2021-03-20 10:47:04 +01:00
|
|
|
|
2021-04-08 07:34:04 +02:00
|
|
|
-- Next kelp must also be submerged in water.
|
2021-03-30 07:28:44 +02:00
|
|
|
local downward_flowing = kelp.is_downward_flowing(pos_tip, node_tip)
|
|
|
|
local submerged = kelp.is_submerged(node_tip)
|
|
|
|
if not submerged then
|
2021-03-21 05:16:56 +01:00
|
|
|
return itemstack
|
2019-12-18 13:37:20 +01:00
|
|
|
end
|
2021-03-20 10:47:04 +01:00
|
|
|
|
2021-03-31 13:27:57 +02:00
|
|
|
-- Play sound, place surface/kelp and take away an item
|
2021-03-29 08:09:09 +02:00
|
|
|
local def_node = mt_registered_items[nu_name]
|
2019-12-17 22:43:35 +01:00
|
|
|
if def_node.sounds then
|
2021-03-28 08:11:08 +02:00
|
|
|
mt_sound_play(def_node.sounds.place, { gain = 0.5, pos = pos_under }, true)
|
2019-12-17 22:43:35 +01:00
|
|
|
end
|
2021-04-08 13:25:19 +02:00
|
|
|
-- TODO: get rid of rooted plantlike hack
|
|
|
|
if height < 16 then
|
|
|
|
kelp.next_height(pos_under, node_under, pos_tip, node_tip, def_tip, submerged, downward_flowing)
|
|
|
|
else
|
|
|
|
mt_add_item(pos_tip, "mcl_ocean:kelp")
|
|
|
|
end
|
2021-03-28 08:11:08 +02:00
|
|
|
if not mt_is_creative_enabled(player_name) then
|
2019-12-17 22:43:35 +01:00
|
|
|
itemstack:take_item()
|
|
|
|
end
|
|
|
|
|
2023-03-31 00:39:57 +02:00
|
|
|
kelp.init_age(pos_under)
|
2021-03-31 13:27:57 +02:00
|
|
|
|
2019-12-17 22:43:35 +01:00
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
2023-02-08 23:53:23 +01:00
|
|
|
function kelp.lbm_register(pos)
|
2023-03-31 00:39:57 +02:00
|
|
|
kelp.init_age(pos)
|
2021-03-30 07:28:44 +02:00
|
|
|
end
|
|
|
|
|
2021-03-28 08:11:08 +02:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Kelp registration API
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- List of supported surfaces for seagrass and kelp.
|
2021-03-29 08:09:09 +02:00
|
|
|
kelp.surfaces = {
|
2021-03-28 08:11:08 +02:00
|
|
|
{ name="dirt", nodename="mcl_core:dirt", },
|
|
|
|
{ name="sand", nodename="mcl_core:sand", },
|
|
|
|
{ name="redsand", nodename="mcl_core:redsand", },
|
|
|
|
{ name="gravel", nodename="mcl_core:gravel", },
|
|
|
|
}
|
2021-03-29 08:09:09 +02:00
|
|
|
kelp.registered_surfaces = {}
|
2021-03-28 08:11:08 +02:00
|
|
|
|
2021-03-28 14:29:29 +02:00
|
|
|
-- Commented properties are the ones obtained using register_kelp_surface.
|
|
|
|
-- If you define your own properties, it overrides the default ones.
|
2021-03-29 08:09:09 +02:00
|
|
|
kelp.surface_deftemplate = {
|
2021-03-28 08:11:08 +02:00
|
|
|
drawtype = "plantlike_rooted",
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "leveled",
|
|
|
|
place_param2 = 16,
|
|
|
|
--tiles = def.tiles,
|
|
|
|
special_tiles = {
|
|
|
|
{
|
|
|
|
image = "mcl_ocean_kelp_plant.png",
|
|
|
|
animation = {type="vertical_frames", aspect_w=16, aspect_h=16, length=2.0},
|
|
|
|
tileable_vertical = true,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
--inventory_image = "("..def.tiles[1]..")^mcl_ocean_kelp_item.png",
|
|
|
|
wield_image = "mcl_ocean_kelp_item.png",
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{ -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
|
|
|
|
{ -0.5, 0.5, -0.5, 0.5, 1.5, 0.5 },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
-- groups.falling_node = is_falling,
|
2024-07-31 16:02:21 +02:00
|
|
|
groups = { dig_immediate = 3, deco_block = 1, plant = 1, kelp = 1, not_in_creative_inventory = 1 },
|
2021-03-28 08:11:08 +02:00
|
|
|
--sounds = sounds,
|
|
|
|
--node_dig_prediction = nodename,
|
2021-03-30 07:28:44 +02:00
|
|
|
on_construct = kelp.surface_on_construct,
|
2021-03-29 08:09:09 +02:00
|
|
|
on_destruct = kelp.surface_on_destruct,
|
|
|
|
on_dig = kelp.surface_on_dig,
|
2021-03-30 07:28:44 +02:00
|
|
|
after_dig_node = kelp.surface_after_dig_node,
|
2021-03-29 08:09:09 +02:00
|
|
|
mesecon = { on_mvps_move = kelp.surface_on_mvps_move, },
|
2021-03-28 08:11:08 +02:00
|
|
|
drop = "", -- drops are handled in on_dig
|
|
|
|
--_mcl_falling_node_alternative = is_falling and nodename or nil,
|
|
|
|
_mcl_hardness = 0,
|
|
|
|
_mcl_blast_resistance = 0,
|
2024-07-31 16:02:21 +02:00
|
|
|
--_vl_pickblock = nodename,
|
2021-03-28 08:11:08 +02:00
|
|
|
}
|
|
|
|
|
2021-03-28 14:29:29 +02:00
|
|
|
-- Commented properties are the ones obtained using register_kelp_surface.
|
2021-03-29 08:09:09 +02:00
|
|
|
kelp.surface_docs = {
|
2021-03-28 08:11:08 +02:00
|
|
|
-- entry_id_orig = nodename,
|
|
|
|
_doc_items_entry_name = S("Kelp"),
|
|
|
|
_doc_items_longdesc = S("Kelp grows inside water on top of dirt, sand or gravel."),
|
|
|
|
--_doc_items_create_entry = doc_create,
|
|
|
|
_doc_items_image = "mcl_ocean_kelp_item.png",
|
|
|
|
}
|
|
|
|
|
2021-03-29 08:09:09 +02:00
|
|
|
-- Creates new surfaces.
|
|
|
|
-- NOTE: surface_deftemplate will be modified in-place.
|
|
|
|
function kelp.register_kelp_surface(surface, surface_deftemplate, surface_docs)
|
2021-03-28 08:11:08 +02:00
|
|
|
local name = surface.name
|
|
|
|
local nodename = surface.nodename
|
2021-03-29 08:09:09 +02:00
|
|
|
local def = mt_registered_nodes[nodename]
|
2021-03-28 08:11:08 +02:00
|
|
|
local def_tiles = def.tiles
|
|
|
|
|
|
|
|
local surfacename = "mcl_ocean:kelp_"..name
|
2021-03-29 08:09:09 +02:00
|
|
|
local surface_deftemplate = surface_deftemplate or kelp.surface_deftemplate -- Optional param
|
2021-03-28 08:11:08 +02:00
|
|
|
|
|
|
|
local doc_create = surface.doc_create or false
|
2021-03-29 08:09:09 +02:00
|
|
|
local surface_docs = surface_docs or kelp.surface_docs -- Optional param
|
2021-03-28 08:11:08 +02:00
|
|
|
|
|
|
|
if doc_create then
|
|
|
|
surface_deftemplate._doc_items_entry_name = surface_docs._doc_items_entry_name
|
|
|
|
surface_deftemplate._doc_items_longdesc = surface_docs._doc_items_longdesc
|
|
|
|
surface_deftemplate._doc_items_create_entry = true
|
|
|
|
surface_deftemplate._doc_items_image = surface_docs._doc_items_image
|
2021-03-29 08:09:09 +02:00
|
|
|
-- Sets the first surface as the docs' entry ID
|
2021-03-28 08:11:08 +02:00
|
|
|
if not surface_docs.entry_id_orig then
|
|
|
|
surface_docs.entry_id_orig = nodename
|
2021-03-20 10:47:04 +01:00
|
|
|
end
|
2021-03-28 08:11:08 +02:00
|
|
|
elseif mod_doc then
|
|
|
|
doc.add_entry_alias("nodes", surface_docs.entry_id_orig, "nodes", surfacename)
|
2021-03-20 10:47:04 +01:00
|
|
|
end
|
2021-03-28 08:11:08 +02:00
|
|
|
|
2021-04-15 23:41:34 +02:00
|
|
|
local sounds = table.copy(def.sounds)
|
2021-03-29 08:09:09 +02:00
|
|
|
sounds.dig = kelp.leaf_sounds.dig
|
|
|
|
sounds.dug = kelp.leaf_sounds.dug
|
|
|
|
sounds.place = kelp.leaf_sounds.place
|
2021-03-28 08:11:08 +02:00
|
|
|
|
|
|
|
surface_deftemplate.tiles = surface_deftemplate.tiles or def_tiles
|
|
|
|
surface_deftemplate.inventory_image = surface_deftemplate.inventory_image or "("..def_tiles[1]..")^mcl_ocean_kelp_item.png"
|
|
|
|
surface_deftemplate.sounds = surface_deftemplate.sound or sounds
|
|
|
|
local falling_node = mt_get_item_group(nodename, "falling_node")
|
|
|
|
surface_deftemplate.node_dig_prediction = surface_deftemplate.node_dig_prediction or nodename
|
2021-03-28 14:29:29 +02:00
|
|
|
surface_deftemplate.groups.falling_node = surface_deftemplate.groups.falling_node or falling_node
|
2021-03-28 08:11:08 +02:00
|
|
|
surface_deftemplate._mcl_falling_node_alternative = surface_deftemplate._mcl_falling_node_alternative or (falling_node and nodename or nil)
|
2024-07-31 16:02:21 +02:00
|
|
|
surface_deftemplate._vl_pickblock = surface_deftemplate._vl_pickblock or nodename
|
2021-03-28 08:11:08 +02:00
|
|
|
|
|
|
|
minetest.register_node(surfacename, surface_deftemplate)
|
2020-12-03 14:19:37 +01:00
|
|
|
end
|
|
|
|
|
2021-03-28 08:11:08 +02:00
|
|
|
-- Kelp surfaces nodes ---------------------------------------------------------
|
|
|
|
|
|
|
|
-- Dirt must be registered first, for the docs
|
2021-04-15 23:41:34 +02:00
|
|
|
kelp.register_kelp_surface(kelp.surfaces[1], table.copy(kelp.surface_deftemplate), kelp.surface_docs)
|
2021-03-29 08:09:09 +02:00
|
|
|
for i=2, #kelp.surfaces do
|
2021-04-15 23:41:34 +02:00
|
|
|
kelp.register_kelp_surface(kelp.surfaces[i], table.copy(kelp.surface_deftemplate), kelp.surface_docs)
|
2021-03-28 08:11:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Kelp item -------------------------------------------------------------------
|
|
|
|
|
2019-12-17 22:43:35 +01:00
|
|
|
minetest.register_craftitem("mcl_ocean:kelp", {
|
|
|
|
description = S("Kelp"),
|
2020-03-08 03:18:47 +01:00
|
|
|
_tt_help = S("Grows in water on dirt, sand, gravel"),
|
2019-12-18 12:43:17 +01:00
|
|
|
_doc_items_create_entry = false,
|
2019-12-17 22:43:35 +01:00
|
|
|
inventory_image = "mcl_ocean_kelp_item.png",
|
|
|
|
wield_image = "mcl_ocean_kelp_item.png",
|
2021-03-29 08:09:09 +02:00
|
|
|
on_place = kelp.kelp_on_place,
|
2022-11-18 00:16:58 +01:00
|
|
|
groups = {deco_block = 1, compostability = 30, smoker_cookable = 1},
|
2019-12-17 22:43:35 +01:00
|
|
|
})
|
|
|
|
|
2019-12-18 12:43:17 +01:00
|
|
|
if mod_doc then
|
2021-03-29 08:09:09 +02:00
|
|
|
doc.add_entry_alias("nodes", kelp.surface_docs.entry_id_orig, "craftitems", "mcl_ocean:kelp")
|
2019-12-18 12:43:17 +01:00
|
|
|
end
|
2019-12-17 22:43:35 +01:00
|
|
|
|
2021-03-28 08:11:08 +02:00
|
|
|
-- Dried kelp ------------------------------------------------------------------
|
2019-12-17 22:43:35 +01:00
|
|
|
|
|
|
|
-- TODO: This is supposed to be eaten very fast
|
|
|
|
minetest.register_craftitem("mcl_ocean:dried_kelp", {
|
|
|
|
description = S("Dried Kelp"),
|
2019-12-18 12:43:17 +01:00
|
|
|
_doc_items_longdesc = S("Dried kelp is a food item."),
|
2019-12-17 22:43:35 +01:00
|
|
|
inventory_image = "mcl_ocean_dried_kelp.png",
|
|
|
|
wield_image = "mcl_ocean_dried_kelp.png",
|
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 12:54:51 +02:00
|
|
|
groups = {food = 2, eatable = 1, compostability = 30},
|
2019-12-17 22:43:35 +01:00
|
|
|
on_place = minetest.item_eat(1),
|
|
|
|
on_secondary_use = minetest.item_eat(1),
|
|
|
|
_mcl_saturation = 0.6,
|
|
|
|
})
|
|
|
|
|
2021-03-28 08:11:08 +02:00
|
|
|
|
2021-05-29 16:12:33 +02:00
|
|
|
local mod_screwdriver = minetest.get_modpath("screwdriver")
|
2019-12-17 22:43:35 +01:00
|
|
|
local on_rotate
|
|
|
|
if mod_screwdriver then
|
|
|
|
on_rotate = screwdriver.rotate_3way
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("mcl_ocean:dried_kelp_block", {
|
|
|
|
description = S("Dried Kelp Block"),
|
2019-12-18 12:43:17 +01:00
|
|
|
_doc_items_longdesc = S("A decorative block that serves as a great furnace fuel."),
|
2019-12-17 22:43:35 +01:00
|
|
|
tiles = { "mcl_ocean_dried_kelp_top.png", "mcl_ocean_dried_kelp_bottom.png", "mcl_ocean_dried_kelp_side.png" },
|
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 12:54:51 +02:00
|
|
|
groups = {
|
|
|
|
handy = 1, hoey = 1, building_block = 1, compostability = 50,
|
|
|
|
flammable = 2, fire_encouragement = 30, fire_flammability = 60
|
|
|
|
},
|
2019-12-17 22:43:35 +01:00
|
|
|
sounds = mcl_sounds.node_sound_leaves_defaults(),
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
on_place = mcl_util.rotate_axis,
|
|
|
|
on_rotate = on_rotate,
|
|
|
|
_mcl_hardness = 0.5,
|
2022-06-12 11:30:39 +02:00
|
|
|
_mcl_blast_resistance = 2.5,
|
2019-12-17 22:43:35 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
type = "cooking",
|
|
|
|
recipe = "mcl_ocean:kelp",
|
|
|
|
output = "mcl_ocean:dried_kelp",
|
|
|
|
cooktime = 10,
|
|
|
|
})
|
|
|
|
minetest.register_craft({
|
|
|
|
recipe = {
|
|
|
|
{ "mcl_ocean:dried_kelp","mcl_ocean:dried_kelp","mcl_ocean:dried_kelp" },
|
|
|
|
{ "mcl_ocean:dried_kelp","mcl_ocean:dried_kelp","mcl_ocean:dried_kelp" },
|
|
|
|
{ "mcl_ocean:dried_kelp","mcl_ocean:dried_kelp","mcl_ocean:dried_kelp" },
|
|
|
|
},
|
|
|
|
output = "mcl_ocean:dried_kelp_block",
|
|
|
|
})
|
2020-07-17 00:17:18 +02:00
|
|
|
minetest.register_craft({
|
|
|
|
recipe = {
|
|
|
|
{ "mcl_ocean:dried_kelp_block" },
|
|
|
|
},
|
|
|
|
output = "mcl_ocean:dried_kelp 9",
|
|
|
|
})
|
2019-12-17 22:43:35 +01:00
|
|
|
minetest.register_craft({
|
|
|
|
type = "fuel",
|
|
|
|
recipe = "mcl_ocean:dried_kelp_block",
|
|
|
|
burntime = 200,
|
|
|
|
})
|
2019-12-18 15:06:35 +01:00
|
|
|
|
2023-03-30 21:10:10 +02:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Kelp ABM + LBM's
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_lbm({
|
|
|
|
label = "Kelp initialise",
|
|
|
|
name = "mcl_ocean:kelp_init_83",
|
|
|
|
nodenames = { "group:kelp" },
|
|
|
|
run_at_every_load = false, -- so old kelps are also initialised
|
|
|
|
action = kelp.lbm_register,
|
|
|
|
})
|
|
|
|
|
2023-02-08 04:12:55 +01:00
|
|
|
minetest.register_abm({
|
|
|
|
label = "Kelp drops",
|
|
|
|
nodenames = { "group:kelp" },
|
|
|
|
interval = 1.0,
|
|
|
|
chance = 1,
|
|
|
|
catch_up = false,
|
2023-02-08 22:03:26 +01:00
|
|
|
action = detach_unsubmerged, --surface_unsubmerged_abm,
|
2023-02-08 04:12:55 +01:00
|
|
|
})
|
2023-02-08 22:03:26 +01:00
|
|
|
|
2023-02-08 04:12:55 +01:00
|
|
|
|
|
|
|
-- 50% growth over a minute https://minecraft.fandom.com/wiki/Tutorials/Kelp_farming
|
|
|
|
-- 14% chance every random tick
|
|
|
|
-- On average, blocks are updated every 68.27 seconds (1365.33 game ticks)
|
|
|
|
-- 1 in 7 every 68
|
|
|
|
-- 1 in 28 every 17
|
|
|
|
-- 1 in 21 every 22
|
|
|
|
-- https://minecraft.fandom.com/wiki/Tick#Random_tick
|
|
|
|
minetest.register_abm({
|
|
|
|
label = "Kelp growth",
|
|
|
|
nodenames = { "group:kelp" },
|
2023-03-31 00:39:57 +02:00
|
|
|
interval = 17,
|
2023-02-08 17:17:44 +01:00
|
|
|
chance = 28,
|
2023-02-08 04:12:55 +01:00
|
|
|
catch_up = false,
|
2023-02-08 22:03:26 +01:00
|
|
|
action = grow_kelp,
|
2023-02-08 04:12:55 +01:00
|
|
|
})
|