1
0
Fork 0

add simple liquid displacement

mineclone_compatibility
FaceDeer 2018-12-18 02:41:55 -07:00
parent c5907a1490
commit 5bc4e452b1
2 changed files with 36 additions and 1 deletions

View File

@ -42,7 +42,7 @@ local all_direction_permutations = {
} }
local get_node = minetest.get_node local get_node = minetest.get_node
local set_node = minetest.set_node local set_node = minetest.swap_node
-- Dynamic liquids -- Dynamic liquids
----------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------
@ -461,4 +461,34 @@ if mapgen_prefill then
vm:write_to_map() vm:write_to_map()
vm:update_liquids() vm:update_liquids()
end) end)
end
local displace_liquid = minetest.setting_getbool("dynamic_liquid_displace_liquid")
displace_liquid = displace_liquid or displace_liquid == nil -- default true
if displace_liquid then
-- Conserve liquids, when placing nodes in liquids try to find a place to displace the liquid to.
-- This isn't perfect, but is fast and covers most situations well enough.
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing)
local flowing = dynamic_liquid.registered_liquids[oldnode.name]
if flowing ~= nil then
-- first search a column directly above the liquid node to find a place to displace the liquid to
local air_column = minetest.find_nodes_in_area(pos, {x=pos.x, y=pos.y+64, z=pos.z}, {"air", flowing})
local lowest_air = air_column[1] -- order of returned nodes is lowest first
if lowest_air then
local liquid_column = minetest.find_nodes_in_area(pos, lowest_air, {oldnode.name}) -- check if there's an unbroken column of liquid
if table.getn(liquid_column) == lowest_air.y - pos.y - 1 then
minetest.swap_node(lowest_air, oldnode)
return false
end
end
-- failing that, look for an adjacent node
local nearest_air = minetest.find_node_near(pos, 1, {"air", flowing})
if nearest_air then
minetest.swap_node(nearest_air, oldnode)
return false
end
end
end)
end end

View File

@ -49,6 +49,11 @@ dynamic_liquid_new_lava_cooling (Revised lava cooling) bool true
#behave the same - this occurs only when it's first created. #behave the same - this occurs only when it's first created.
dynamic_liquid_falling_obsidian (Falling obsidian) bool false dynamic_liquid_falling_obsidian (Falling obsidian) bool false
#When true, placing a block where a registered liquid source currently is
#will make a simple attempt to displace the liquid source somewhere else
#rather than destroying it.
dynamic_liquid_displace_liquid (Displace liquid) bool true
[Flow Rates] [Flow Rates]
#Sets the probability of water flow per block per second. #Sets the probability of water flow per block per second.