-- File: codersea/fixwater.lua -- Purpose: CoderSea water fixup module -- Credits: See "codersea.md" -- Licenses: See "LICENSE" -- =================================================================== -- notes -- =================================================================== -- If "plantlike" nodes are drawn under water, by default, they appear -- inside transparent boxes. "sea" used code referred to as "noair- -- blocks" to fix this. "codersea" uses similar but simpler code, in -- this file, for the same purpose. -- "codersea's" code produces better results and, additionally, sup- -- ports Ethereal seaplants. -- "codersea's" approach requires a special PNG file named: codersea_ -- water.png -- The PNG file in question is simply a 16x16 blank PNG file with a -- transparent background. -- =================================================================== -- initial setup -- =================================================================== local codersea_drowning = minetest.setting_getbool ("codersea_drowning") -- =================================================================== -- handle external plants -- =================================================================== local external_plants = { "ethereal:coral2" , "ethereal:coral3" , "ethereal:coral4" , "ethereal:coral5" , "ethereal:seaweed" , } local function setplant (name) local table1 = minetest.registered_nodes [name] if table1 == nil then return end local table2 = {} for i,v in pairs (table1) do table2 [i] = v end if table2.groups == nil then table2.groups = { xyzzy=1 } end table2.groups.seaplants = 1 table2.groups.wrapwater = 1 minetest.register_node (":" .. name, table2) end for _,node_name in ipairs (external_plants) do setplant (node_name) end -- =================================================================== -- disable flowing-water animation -- =================================================================== -- This is "debug" code. local debug_flowing_water = false if debug_flowing_water then local wname = "default:water_flowing" local wtable1 = minetest.registered_nodes [wname] local wtable2 = {} for i,v in pairs (wtable1) do wtable2 [i] = v end wtable2.special_tiles = nil minetest.register_node (":" .. wname, wtable2) end -- =================================================================== -- nodes -- =================================================================== local inventory_water = "default_water.png" minetest.register_node ("codersea:water_flowing", { description = "Flowing Water" , inventory_image = inventory_water , drawtype = "flowingliquid" , tiles = { "codersea_water.png" } , alpha = 1 , paramtype = "light" , paramtype2 = "flowingliquid" , walkable = false , pointable = false , diggable = false , buildable_to = true , drop = "" , drowning = codersea_drowning , liquidtype = "flowing" , liquid_alternative_flowing = "codersea:water_flowing" , liquid_alternative_source = "codersea:water_source" , liquid_viscosity = 1, freezemelt = "default:snow" , -- This should probably match the setting for "default:water" post_effect_color = { a = 103, r = 30, g = 60, b = 90 } , groups = { water=3, liquid=3, puts_out_fire=1, not_in_creative_inventory=1, freezes=1, melt_around=1 } , }) -- ------------------------------------------------------------------- minetest.register_node ("codersea:water_source" , { alpha = 1 , buildable_to = true , description = "Codersea Water Source" , diggable = false , drawtype = "liquid" , drop = "" , drowning = codersea_drowning , freezemelt = "default:ice" , inventory_image = inventory_water , liquid_viscosity = 1 , liquidtype = "source" , paramtype = "light" , pointable = false , tiles = { "codersea_water.png" } , walkable = false , liquid_alternative_flowing = "codersea:water_flowing" , liquid_alternative_source = "codersea:water_source" , -- This should probably match the setting for "default:water" post_effect_color = { a = 103, r = 30, g = 60, b = 90 } , groups = { water=3, liquid=3, puts_out_fire=1, freezes=1, not_in_creative_inventory=1 } , }) -- =================================================================== -- ABMs -- =================================================================== -- This section defines the ABMs used by this module. -- ------------------------------------------------------------------- -- Wrap seaplants in layers of coderwater to fix visual glitches. minetest.register_abm ({ catch_up = false , chance = 1 , interval = 4 , neighbors = { "group:wrapwater" } , nodenames = { "default:water_source", "default:water_flowing" } , action = function (pos, node) local newnode = "codersea:water_source" if node.name == "default:water_flowing" then newnode = "codersea:water_flowing" end local uppos = { x = pos.x, y = pos.y+1, z = pos.z } local upname = minetest.get_node (uppos).name if upname ~= "air" then minetest.add_node (pos, { name = newnode }) end end , }) -- ------------------------------------------------------------------- -- Periodically revert unneeded "codersea" water nodes. -- This ABM affects wide areas, so the interval used should be rela- -- tively large. minetest.register_abm ({ catch_up = false , chance = 1 , interval = 30 , nodenames = { "codersea:water_source", "codersea:water_flowing" } , action = function (pos, node) local pos0 = { x=pos.x-1, y=pos.y-1, z=pos.z-1 } local pos1 = { x=pos.x+1, y=pos.y+1, z=pos.z+1 } if #minetest.find_nodes_in_area (pos0, pos1, "group:wrapwater") < 1 then local newnode = "default:water_source" if node.name == "codersea:water_flowing" then newnode = "default:water_flowing" end minetest.add_node (pos, { name = newnode }) end end , }) -- ------------------------------------------------------------------- -- "Debug" code. local debug_thermoclines = false if debug_thermoclines then minetest.register_abm ({ catch_up = false , chance = 1 , interval = 2 , neighbors = { "codersea:water_source" , "codersea:water_flowing" } , nodenames = { "default:water_flowing" } , action = function (pos, node) minetest.add_node (pos, { name = "default:water_source" }) end , }) end