-- =================================================================== -- Welcome to the Minetest Water API. -- We'd like to avoid adding APIs that create a huge number of nodes, -- as RealTest did, or ones that slows things down, as the Clouds API -- did. -- This said, the Water API creates complex data structures but is -- quite useful. It greatly simplifies the process of adding new types -- of water to the "_game". -- One call sets up all of the following: -- -- * Water Source and Flowing nodes -- * Water Gel and Slope nodes -- * Buckets for the bucket-able nodes -- -- plus these configurable parameters and/or modes: -- -- * Optional lighting (a) -- * Optional damage (a) -- * Optional drowning (a) -- * Viscosity (a) -- * Flow range (b) -- * Renewable (b) -- * Allow water source in creative inventory or not -- * Conversion of water source by buckets into gel form -- -- (a) Can be different for normal water and gel forms -- (b) Doesn't apply to gels -- The water API automatically builds full-bucket images that match -- each water type. The images look correct both in inventory and when -- a bucket is wielded. -- Three ".png" image files are required for each water type: -- -- default_red_punch.png -- default_red_punch_source_animated.png -- default_red_punch_flowing_animated.png -- -- These files use the same icon, source animated, and flowing anima- -- ted formats that were used for standard Minetest water nodes in the -- past. -- Most settings are illustrated in the sample definitions block be- -- low. There is one related "world.conf" setting: -- -- bucket_gels_water = true -- -- If the preceding setting is used, putting a water source node into -- a bucket will convert it to the corresponding type of gel. -- =================================================================== -- local defs = { -- -- Regular water: 160 -- -- Thicker water: 200 -- alpha = 200 , -- -- -- Omit these to suppress lighting -- -- Or set them to integer lighting values -- -- Settings of -1 trigger maximum brightness -- -- "light" sets both "light_..." at once -- -- -- light_gel = -1 , -- light_normal = -1 , -- light = -1 , -- -- -- Base name: Lower case, no spaces. -- basename = "red_punch" , -- -- -- Standard MT water source animation table -- animation_source = { -- type = "vertical_frames" , -- aspect_w = 16 , -- aspect_h = 16 , -- length = 2.0 , -- } , -- -- -- Standard MT water flowing animation table -- animation_flowing = { -- type = "vertical_frames" , -- aspect_w = 16 , -- aspect_h = 16 , -- length = 0.8 , -- } , -- -- -- "a" is post-effect alpha setting -- -- "r", "g", "b" are RGB integers ranging from 0 to 255 -- -- -- post_effect_color = { a=180, r=150, g=30, b=30 } -- } -- The preceding table plus the following call is all that's needed: -- -- default.register_water (defs) -- =================================================================== -- The "animation_source" parameter is optional. If it's omitted, the -- default table used is: -- -- animation_source = default.base_water_animation_source -- -- which provides the "animation_source" settings listed in the sample -- definitions block above. -- For the default table to work, the animation-source image used must -- be derived from the Final MT version of: -- -- default_water_source_animated.png -- =================================================================== -- The "animation_flowing" parameter is optional. If it's omitted, the -- default table used is: -- -- animation_flowing = default.base_water_animation_flowing -- -- which provides the "animation_flowing" settings listed in the sam- -- ple definitions block above. -- For the default table to work, the animation-flowing image used -- must be derived from the Final MT version of: -- -- default_water_flowing_animated.png -- =================================================================== -- If no "groups" table is provided in the definitions table, "regis- -- ter_water" uses the following default "groups" attributes for nor- -- mal water: -- -- groups = { -- water=3, liquid=3, puts_out_fire=1, -- not_in_creative_inventory=1 -- } , -- -- and the following default "groups" attributes for gel forms: -- -- groups = { water=3, liquid=3, puts_out_fire=1, water_gel=1 } , -- If you'd like normal water to be in the creative inventory, you can -- add the following setting to the definitions table: -- -- creative=1 , -- -- or you can specify "groups" explicitly and set "not_in_creative_ -- inventory" to 0 in "groups". -- Presently, gels are in the creative inventory regardless of any -- "creative" or "not_in_creative_inventory" setting. -- =================================================================== -- The following parameters are optional but may be set in the defini- -- tions table as well: -- damage_gel = 3 -- Gel damage/second (default: 0) -- damage_normal = 3 -- Normal water damage/second (default: 0) -- damage = 3 -- Sets the preceding two at once -- drowning_gel = 0 -- Gel drowning (default: 1) -- drowning_normal = 0 -- Normal water drowning (default: 1) -- drowning = 0 -- Sets the preceding two at once -- viscosity_gel = 3 -- Gel viscosity (default: 1) -- viscosity_normal = 3 -- Normal water viscosity (default: 1) -- viscosity = 3 -- Sets the preceding two at once -- These parameters don't apply to gels: -- -- range = 2 -- Flow range (default: engine) -- renewable = false -- "renewable" flag (default: engine) -- liquid_range = 2 -- Same as "range" -- liquid_renewable = false -- Same as "renewable" -- =================================================================== default.waters = {} default.base_water_animation_source = { type = "vertical_frames" , aspect_w = 16 , aspect_h = 16 , length = 2.0 , } default.base_water_animation_flowing = { type = "vertical_frames" , aspect_w = 16 , aspect_h = 16 , length = 0.8 , } -- =================================================================== function default.register_water (defs) local str local defs = ocutil.clone_table (defs) -- =================================================================== -- "basename" is required if defs.basename == nil then return end -- E.g. "red_punch", "river_water", "water" local base = defs.basename local imgbase = defs.imgbase if imgbase == nil then imgbase = base end local base_png = "default_" .. imgbase .. ".png" local base_source = imgbase .. "_source" local base_flowing = imgbase .. "_flowing" local node_source = "default:" .. base .. "_source" local node_flowing = "default:" .. base .. "_flowing" local node_gel = "default:" .. base .. "_gel" local node_slope = node_gel .. "_slope" -- =================================================================== if defs.animation_source == nil then defs.animation_source = default.base_water_animation_source end if defs.animation_flowing == nil then defs.animation_flowing = default.base_water_animation_flowing end -- =================================================================== if defs.alpha == nil then defs.alpha = 160 end -- =================================================================== if defs.damage_normal == nil then defs.damage_normal = defs.damage end if defs.damage_gel == nil then defs.damage_gel = defs.damage end -- =================================================================== if defs.light_normal == nil then defs.light_normal = defs.light end if defs.light_gel == nil then defs.light_gel = defs.light end -- =================================================================== if defs.liquid_range == nil then defs.liquid_range = defs.range end if defs.liquid_renewable == nil then defs.liquid_renewable = defs.renewable end -- =================================================================== if defs.drowning == nil then defs.drowning = 1 end if defs.drowning_normal == nil then defs.drowning_normal = defs.drowning end if defs.drowning_gel == nil then defs.drowning_gel = defs.drowning end -- =================================================================== if defs.viscosity == nil then defs.viscosity = 1 end if defs.viscosity_normal == nil then defs.viscosity_normal = defs.viscosity end if defs.viscosity_gel == nil then defs.viscosity_gel = defs.viscosity end -- =================================================================== local maxlight = default.LIGHT_MAX-1 if defs.light_normal ~= nil and defs.light_normal > maxlight then defs.light_normal = maxlight end if defs.light_gel ~= nil and defs.light_gel > maxlight then defs.light_gel = maxlight end if defs.light_normal ~= nil and defs.light_normal < 0 then defs.light_normal = maxlight end if defs.light_gel ~= nil and defs.light_gel < 0 then defs.light_gel = maxlight end -- =================================================================== if defs.ucname == nil then str = base str = string.upper (str:sub (1,1)) .. str:sub (2) str = string.gsub (str, "_", " ") str = string.gsub (str, " punch", " Punch") str = string.gsub (str, " water", " Water") defs.ucname = str end default.waters [base] = defs.ucname -- =================================================================== if defs.groups == nil then defs.groups = { water=3, liquid=3, puts_out_fire=1 } end defs.groups_normal = ocutil.clone_table (defs.groups) defs.groups_gel = ocutil.clone_table (defs.groups) -- =================================================================== -- Fix a misplaced "creative=...". if defs.groups_normal.creative ~= nil then defs.creative = defs.groups_normal.creative defs.groups_normal.creative = nil defs.groups_gel.creative = nil end -- =================================================================== defs.groups_gel.not_in_creative_inventory = nil if defs.creative == nil then defs.creative = false end if defs.creative ~= 1 and defs.creative ~= true and defs.groups_normal.not_in_creative_inventory == nil then defs.groups_normal.not_in_creative_inventory = 1 end -- =================================================================== if defs.post_effect_color == nil then defs.post_effect_color = { a=103, r=60, g=60, b=60 } end -- =================================================================== local amtiles_source = { name = "default_" .. base_source .. "_animated.png" , backface_culling = false , animation = defs.animation_source } -- =================================================================== minetest.register_node (node_source, { description = defs.ucname .. " Source" , alpha = defs.alpha , light_source = defs.light_normal , paramtype = "light" , tiles = { amtiles_source } , special_tiles = { amtiles_source } , buildable_to = true , diggable = false , is_ground_content = false , pointable = false , walkable = false , damage_per_second = defs.damage_normal , drop = "" , drowning = defs.drowning_normal , groups = defs.groups_normal , post_effect_color = defs.post_effect_color , drawtype = "liquid" , liquidtype = "source" , liquid_range = defs.liquid_range , liquid_renewable = defs.liquid_renewable , liquid_viscosity = defs.viscosity_normal , liquid_alternative_flowing = node_flowing , liquid_alternative_source = node_source , }) -- =================================================================== local amtiles_flowing_bc0 = { name = "default_" .. base_flowing .. "_animated.png" , backface_culling = false , animation = defs.animation_flowing } local amtiles_flowing_bc1 = ocutil.clone_table (amtiles_flowing_bc0) amtiles_flowing_bc1.backface_culling = true -- =================================================================== minetest.register_node (node_flowing, { description = "Flowing " .. defs.ucname , alpha = defs.alpha , light_source = defs.light_normal , paramtype = "light" , paramtype2 = "flowingliquid" , tiles = { base_png } , special_tiles = { amtiles_flowing_bc0 , amtiles_flowing_bc1 , } , buildable_to = true , diggable = false , is_ground_content = false , pointable = false , walkable = false , damage_per_second = defs.damage_normal , drop = "" , drowning = defs.drowning_normal , groups = defs.groups_normal , post_effect_color = defs.post_effect_color , drawtype = "flowingliquid" , liquidtype = "flowing" , liquid_range = defs.liquid_range , liquid_renewable = defs.liquid_renewable , liquid_viscosity = defs.viscosity_normal , liquid_alternative_flowing = node_flowing , liquid_alternative_source = node_source , }) -- =================================================================== -- For standard types of water: -- Water Gel resembles water, but it neither flows nor generates more -- water. It can be picked up and moved using a bucket. -- By default, the only source for Water Gel is WorldEdit. However, if -- you add the following setting to "world.conf": -- -- bucket_gels_water = true -- -- Water Source that is placed in a bucket will turn into Water Gel. -- Some world hosts may prefer this mode as an anti-griefing measure. -- =================================================================== minetest.register_node (node_gel, { description = defs.ucname .. " Gel" , alpha = defs.alpha , light_source = defs.light_gel , paramtype = "light" , tiles = { amtiles_source } , special_tiles = { amtiles_source } , buildable_to = true , diggable = false , is_ground_content = false , pointable = false , walkable = false , damage_per_second = defs.damage_gel , drop = "" , drowning = defs.drowning_gel , groups = defs.groups_gel , post_effect_color = defs.post_effect_color , drawtype = "liquid" , liquidtype = "source" , liquid_range = 0 , liquid_renewable = false , liquid_viscosity = defs.viscosity_gel , liquid_alternative_flowing = node_gel , liquid_alternative_source = node_gel , }) -- =================================================================== -- For standard types of water: -- Water Gel Slope, like Water Gel, is an alternative type of water -- used for anti-griefing and/or building purposes. Also like Water -- Gel, this type of water doesn't flow. -- Water Gel Slope is used with Water Gel but it doesn't come from -- Water Gel. Presently, it comes only from WorldEdit, but it could be -- added to Creative or possibly to crafting recipes. -- This node can be picked up and moved using a bucket. -- The purpose of Water Gel Slope is to add slopes to the edges of -- structures made out of Water Gel cubes. If a Water Gel Slope is -- placed next to a Water Gel cube, the Slope connects in a natural -- manner to the cube. -- =================================================================== minetest.register_node (node_slope, { description = defs.ucname .. " Gel Slope" , light_source = defs.light_gel , paramtype = "light" , tiles = { base_png } , special_tiles = { amtiles_flowing_bc0 , amtiles_flowing_bc1 , } , buildable_to = true , diggable = true , is_ground_content = false , pointable = true , walkable = false , damage_per_second = defs.damage_gel , drop = node_slope , drowning = defs.drowning_gel , groups = defs.groups_gel , post_effect_color = defs.post_effect_color , drawtype = "flowingliquid" , liquidtype = "liquid" , liquid_range = 0 , liquid_renewable = false , liquid_viscosity = defs.viscosity_gel , liquid_alternative_flowing = node_slope , liquid_alternative_source = node_gel , }) end -- =================================================================== local defs = {} -- =================================================================== -- Set up regular water. defs = { alpha = 160 , basename = "water" , light_gel = -1 , post_effect_color = { a=103, r=30, g=60, b=90 } , } default.register_water (defs) -- =================================================================== -- Set up River Water. defs = { alpha = 160 , basename = "river_water" , liquid_range = 2 , liquid_renewable = false , post_effect_color = { a=103, r=30, g=76, b=90 } , } default.register_water (defs) -- =================================================================== -- Set up Sewer Water. defs = { alpha = 160 , basename = "sewer_water" , imgbase = "brown_punch" , light = 4 , ucname = "Sewer Water" , post_effect_color = { a=103, r=40, g=20, b=0 } , } default.register_water (defs) -- =================================================================== -- Set up Toxic Waste. defs = { alpha = 160 , basename = "toxic_waste" , damage = 1 , imgbase = "green_punch" , light = -1 , ucname = "Toxic Waste" , groups = { water=3, liquid=3, toxic_waste=1, not_in_creative_inventory=1 } , post_effect_color = { a=180, r=30, g=150, b=30 } , } default.register_water (defs) -- =================================================================== -- Set up Green Punch. defs = { alpha = 200 , basename = "green_punch" , light = -1 , post_effect_color = { a=180, r=30, g=150, b=30 } , } default.register_water (defs) -- =================================================================== -- Set up Orange Punch. defs = { alpha = 200 , basename = "orange_punch" , light = -1 , post_effect_color = { a=120, r=190, g=140, b=90 } , } default.register_water (defs) -- =================================================================== -- Set up Purple Punch. defs = { alpha = 200 , basename = "purple_punch" , light = -1 , post_effect_color = { a=120, r=168, g=67, b=192 } , } default.register_water (defs) -- =================================================================== -- Set up Red Punch. defs = { alpha = 200 , basename = "red_punch" , light = -1 , post_effect_color = { a=180, r=150, g=30, b=30 } , } default.register_water (defs) -- =================================================================== -- Set up Yellow Punch. defs = { alpha = 200 , basename = "yellow_punch" , light = -1 , post_effect_color = { a=120, r=100, g=100, b=10 } , } default.register_water (defs) -- =================================================================== -- End of module.