diff --git a/api.lua b/api.lua index 647cd0d..b1ed4a7 100644 --- a/api.lua +++ b/api.lua @@ -40,6 +40,18 @@ function liquid_physics.get_liquid_at(pos) return { liquid_id = lpn.liquid_id, liquid_level = lpn.liquid_level } end +-- Returns the node names for a liquid ordered by the corresponding liquid level +-- Useful if you want to register an ABM or LBM +-- @param liquid_id number ID of the liquid +-- @return table Table of liquid node names for that id +function liquid_physics.get_liquid_node_names(liquid_id) + local nodes = {} + for i = 2, 9 do + table.insert(nodes, liquid_physics._registered_liquids[liquid_id][i]) + end + return nodes +end + -- Sets the liquid at the position specified -- Returns true if the operation was successful -- @param pos table Position of the Node @@ -96,6 +108,7 @@ function liquid_physics.register_liquid(namespace, source_name, flowing_name) local node_name = "liquid_physics:" .. namespace .. "_" .. source_name .. "_level_" .. i local level_def = { + name = node_name, description = source_liquid_def.description .. " Level " .. i, tiles = source_liquid_def.tiles, use_texture_alpha = source_liquid_def.use_texture_alpha, @@ -131,13 +144,15 @@ function liquid_physics.register_liquid(namespace, source_name, flowing_name) sounds = source_liquid_def.sounds, } - core.register_node(node_name, level_def) + core.register_node(":" .. node_name, level_def) liquid_physics._liquid_ids[node_name] = id table.insert(liquids, node_name) + table.insert(liquid_physics._liquids, node_name) end table.insert(liquids, source_liquid_name) + table.insert(liquid_physics._liquids, source_liquid_name) -- Finally, stop flowing core.override_item(flowing_liquid_name, { liquid_range = 0, liquid_renewable = false }, nil) diff --git a/init.lua b/init.lua index ccb32e9..de19499 100644 --- a/init.lua +++ b/init.lua @@ -17,32 +17,33 @@ local modpath = core.get_modpath(core.get_current_modname()) liquid_physics = {} ---INTERNAL USE ONLY - Stores all nodes which need to checked +-- INTERNAL USE ONLY - Stores all nodes which need to checked liquid_physics._nodes_to_check = {} ---INTERNAL USE ONLY - Stores liquid_id and the corresponding liquid node names +-- INTERNAL USE ONLY - Stores liquid_id and the corresponding liquid node names liquid_physics._registered_liquids = {} ---INTERNAL USE ONLY - Stores all liquid node names and their corresponding liquid_id +-- INTERNAL USE ONLY - Stores all liquid node names and their corresponding liquid_id liquid_physics._liquid_ids = {} +-- INTERNAL USE ONLY - All liquid nodes for ABM and LBM +liquid_physics._liquids = {} local internal = dofile(modpath .. "/internal.lua") dofile(modpath .. "/api.lua") +local namespace = "" + if core.get_modpath("default") then - liquid_physics.register_liquid("default", "water_source", "water_flowing") - liquid_physics.register_liquid("default", "lava_source", "lava_flowing") + namespace = "default" +elseif core.get_modpath("mcl_core") then + namespace = "mcl_core" +else + error("Liquid Physics only supports VoxeLibre or Minetest") end -if core.get_modpath("mcl_core") then - liquid_physics.register_liquid("mcl_core", "water_source", "water_flowing") - liquid_physics.register_liquid("mcl_core", "lava_source", "lava_flowing") +if core.settings:get_bool("liquid_physics_enable_water_physics") then + liquid_physics.register_liquid(namespace, "water_source", "water_flowing") end - --- Remove "air" from registered_liquids for lbm and abm -local source_names = {} -for key, value in pairs(liquid_physics._registered_liquids) do - for i = 2, table.getn(value) do - table.insert(source_names, value[i]) - end +if minetest.settings:get_bool("liquid_physics_enable_lava_physics") then + liquid_physics.register_liquid(namespace, "lava_source", "lava_flowing") end core.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing) @@ -53,7 +54,7 @@ end) core.register_lbm { name = "liquid_physics:update", - nodenames = source_names, + nodenames = liquid_physics._liquids, run_at_every_load = true, action = function(pos, node, dtime_s) internal.add_node_to_check(pos) @@ -61,7 +62,7 @@ core.register_lbm { } core.register_abm({ - nodenames = source_names, + nodenames = liquid_physics._liquids, neighbors = { "air" }, interval = 0.2, chance = 0, diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..e3da911 --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,2 @@ +liquid_physics_enable_water_physics (Enable physics for water) bool true +liquid_physics_enable_lava_physics (Enable physics for lava) bool true