1
0
Fork 0

Various fixes.

This commit is contained in:
iliekprogrammar 2021-03-21 14:06:54 +08:00
parent ebf9f8c918
commit ca635b69be
1 changed files with 23 additions and 16 deletions

View File

@ -2,6 +2,8 @@ local S = minetest.get_translator("mcl_ocean")
local mod_doc = minetest.get_modpath("doc") ~= nil local mod_doc = minetest.get_modpath("doc") ~= nil
-- NOTE: whenever it becomes possible to fully implement kelp without the -- NOTE: whenever it becomes possible to fully implement kelp without the
-- plantlike_rooted limitation, please adapt the code accordingly. -- plantlike_rooted limitation, please adapt the code accordingly.
-- 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.
-- List of supported surfaces for seagrass and kelp. -- List of supported surfaces for seagrass and kelp.
local surfaces = { local surfaces = {
@ -25,11 +27,13 @@ local function is_downward_flowing(pos, node, nodedef, is_above)
result = (math.floor(node.param2 / 8) % 2) == 1 result = (math.floor(node.param2 / 8) % 2) == 1
if not (result or is_above) then if not (result or is_above) then
-- If not, also check node above (this is needed due a weird quirk in the definition of -- If not, also check node above
-- "downwards flowing" liquids in Minetest) -- (this is needed due a weird quirk in the definition of "downwards flowing"
-- liquids in Minetest)
local node_above = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z}) local node_above = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
local nodedef_above = minetest.registered_nodes[node_above.name] local nodedef_above = minetest.registered_nodes[node_above.name]
result = is_submerged(node_above, nodedef_above) or is_downward_flowing(pos, node_above, nodedef_above, true) result = is_submerged(node_above, nodedef_above)
or is_downward_flowing(pos, node_above, nodedef_above, true)
end end
return result return result
end end
@ -114,7 +118,7 @@ local function kelp_on_place(itemstack, placer, pointed_thing)
end end
local new_kelp = false local new_kelp = false
local is_downward_flowing = false local downward_flowing = false
local pos_top, node_top, def_top local pos_top, node_top, def_top
-- When placed on kelp. -- When placed on kelp.
@ -136,6 +140,7 @@ local function kelp_on_place(itemstack, placer, pointed_thing)
node_under.name = "mcl_ocean:kelp_" ..surface[1] node_under.name = "mcl_ocean:kelp_" ..surface[1]
node_under.param2 = minetest.registered_items[nu_name].place_param2 or 16 node_under.param2 = minetest.registered_items[nu_name].place_param2 or 16
new_kelp = true new_kelp = true
break
end end
end end
@ -143,14 +148,15 @@ local function kelp_on_place(itemstack, placer, pointed_thing)
if not new_kelp or pos_under.y >= pos_above.y then if not new_kelp or pos_under.y >= pos_above.y then
return itemstack return itemstack
end end
pos_top = pos_above pos_top = pos_above
node_top = minetest.get_node(pos_above) node_top = minetest.get_node(pos_above)
def_top = minetest.registered_nodes[node_above.name] def_top = minetest.registered_nodes[node_top.name]
end end
-- New kelp must also be submerged in water. -- New kelp must also be submerged in water.
is_downward_flowing = is_downward_flowing(pos_top, node_top, def_top) downward_flowing = is_downward_flowing(pos_top, node_top, def_top)
if not (is_submerged(node_top, def_top) and is_downward_flowing) then if not (is_submerged(node_top, def_top) or downward_flowing) then
return itemstack return itemstack
end end
@ -159,7 +165,7 @@ local function kelp_on_place(itemstack, placer, pointed_thing)
if def_node.sounds then if def_node.sounds then
minetest.sound_play(def_node.sounds.place, { gain = 0.5, pos = pos_under }, true) minetest.sound_play(def_node.sounds.place, { gain = 0.5, pos = pos_under }, true)
end end
kelp_place(pos_under, node_under, pos_top, def_top, is_downward_flowing) kelp_place(pos_under, node_under, pos_top, def_top, downward_flowing)
if not minetest.is_creative_enabled(player_name) then if not minetest.is_creative_enabled(player_name) then
itemstack:take_item() itemstack:take_item()
end end
@ -175,26 +181,24 @@ local function kelp_drop(pos, height)
end end
end end
-- Dig kelp:
-- Each kelp from broken stem until the top drop a single item
-- Kelp's height decreases to the height below dig_pos
local function kelp_dig(dig_pos, pos, node, is_drop) local function kelp_dig(dig_pos, pos, node, is_drop)
local param2 = node.param2 local param2 = node.param2
local height = get_kelp_height(param2)
-- pos.y points to the surface, offset needed to point to the first kelp -- pos.y points to the surface, offset needed to point to the first kelp
local new_height = dig_pos.y - (pos.y+1) local new_height = dig_pos.y - (pos.y+1)
-- Digs the entire kelp: invoke after_dig_node to set_node -- Digs the entire kelp: invoke after_dig_node to set_node
if new_height == 0 then if new_height <= 0 then
if is_drop then if is_drop then
kelp_drop(dig_pos, height) kelp_drop(dig_pos, get_kelp_height(param2))
end end
minetest.set_node(pos, {name=minetest.registered_nodes[node.name].node_dig_prediction}) minetest.set_node(pos, {
name=minetest.registered_nodes[node.name].node_dig_prediction,
param=node.param, param2=0 })
-- Digs the kelp beginning at a height -- Digs the kelp beginning at a height
else else
if is_drop then if is_drop then
kelp_drop(dig_pos, height - new_height) kelp_drop(dig_pos, get_kelp_height(param2) - new_height)
end end
minetest.set_node(pos, {name=node.name, param=node.param, param2=16*new_height}) minetest.set_node(pos, {name=node.name, param=node.param, param2=16*new_height})
end end
@ -264,7 +268,10 @@ for s=1, #surfaces do
after_dig_node = function(pos) after_dig_node = function(pos)
minetest.set_node(pos, {name=surface[s][2]}) minetest.set_node(pos, {name=surface[s][2]})
end, end,
-- TODO: add ability to detect whether the kelp or the surface is dug.
-- Currently, digging the surface gives sand, which isn't ideal.
on_dig = function(pos, node, digger) on_dig = function(pos, node, digger)
minetest.chat_send_all("mo2")
local is_drop = true local is_drop = true
if digger and minetest.is_creative_enabled(digger:get_player_name()) then if digger and minetest.is_creative_enabled(digger:get_player_name()) then
is_drop = false is_drop = false