Update API and Add Settings
This commit is contained in:
parent
6c74c3de5c
commit
2d6c43e69f
17
api.lua
17
api.lua
@ -40,6 +40,18 @@ function liquid_physics.get_liquid_at(pos)
|
|||||||
return { liquid_id = lpn.liquid_id, liquid_level = lpn.liquid_level }
|
return { liquid_id = lpn.liquid_id, liquid_level = lpn.liquid_level }
|
||||||
end
|
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
|
-- Sets the liquid at the position specified
|
||||||
-- Returns true if the operation was successful
|
-- Returns true if the operation was successful
|
||||||
-- @param pos table Position of the Node
|
-- @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 node_name = "liquid_physics:" .. namespace .. "_" .. source_name .. "_level_" .. i
|
||||||
|
|
||||||
local level_def = {
|
local level_def = {
|
||||||
|
name = node_name,
|
||||||
description = source_liquid_def.description .. " Level " .. i,
|
description = source_liquid_def.description .. " Level " .. i,
|
||||||
tiles = source_liquid_def.tiles,
|
tiles = source_liquid_def.tiles,
|
||||||
use_texture_alpha = source_liquid_def.use_texture_alpha,
|
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,
|
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
|
liquid_physics._liquid_ids[node_name] = id
|
||||||
|
|
||||||
table.insert(liquids, node_name)
|
table.insert(liquids, node_name)
|
||||||
|
table.insert(liquid_physics._liquids, node_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(liquids, source_liquid_name)
|
table.insert(liquids, source_liquid_name)
|
||||||
|
table.insert(liquid_physics._liquids, source_liquid_name)
|
||||||
|
|
||||||
-- Finally, stop flowing
|
-- Finally, stop flowing
|
||||||
core.override_item(flowing_liquid_name, { liquid_range = 0, liquid_renewable = false }, nil)
|
core.override_item(flowing_liquid_name, { liquid_range = 0, liquid_renewable = false }, nil)
|
||||||
|
29
init.lua
29
init.lua
@ -23,26 +23,27 @@ liquid_physics._nodes_to_check = {}
|
|||||||
liquid_physics._registered_liquids = {}
|
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 = {}
|
liquid_physics._liquid_ids = {}
|
||||||
|
-- INTERNAL USE ONLY - All liquid nodes for ABM and LBM
|
||||||
|
liquid_physics._liquids = {}
|
||||||
|
|
||||||
local internal = dofile(modpath .. "/internal.lua")
|
local internal = dofile(modpath .. "/internal.lua")
|
||||||
dofile(modpath .. "/api.lua")
|
dofile(modpath .. "/api.lua")
|
||||||
|
|
||||||
|
local namespace = ""
|
||||||
|
|
||||||
if core.get_modpath("default") then
|
if core.get_modpath("default") then
|
||||||
liquid_physics.register_liquid("default", "water_source", "water_flowing")
|
namespace = "default"
|
||||||
liquid_physics.register_liquid("default", "lava_source", "lava_flowing")
|
elseif core.get_modpath("mcl_core") then
|
||||||
|
namespace = "mcl_core"
|
||||||
|
else
|
||||||
|
error("Liquid Physics only supports VoxeLibre or Minetest")
|
||||||
end
|
end
|
||||||
|
|
||||||
if core.get_modpath("mcl_core") then
|
if core.settings:get_bool("liquid_physics_enable_water_physics") then
|
||||||
liquid_physics.register_liquid("mcl_core", "water_source", "water_flowing")
|
liquid_physics.register_liquid(namespace, "water_source", "water_flowing")
|
||||||
liquid_physics.register_liquid("mcl_core", "lava_source", "lava_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
|
end
|
||||||
|
if minetest.settings:get_bool("liquid_physics_enable_lava_physics") then
|
||||||
|
liquid_physics.register_liquid(namespace, "lava_source", "lava_flowing")
|
||||||
end
|
end
|
||||||
|
|
||||||
core.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing)
|
core.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing)
|
||||||
@ -53,7 +54,7 @@ end)
|
|||||||
|
|
||||||
core.register_lbm {
|
core.register_lbm {
|
||||||
name = "liquid_physics:update",
|
name = "liquid_physics:update",
|
||||||
nodenames = source_names,
|
nodenames = liquid_physics._liquids,
|
||||||
run_at_every_load = true,
|
run_at_every_load = true,
|
||||||
action = function(pos, node, dtime_s)
|
action = function(pos, node, dtime_s)
|
||||||
internal.add_node_to_check(pos)
|
internal.add_node_to_check(pos)
|
||||||
@ -61,7 +62,7 @@ core.register_lbm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
core.register_abm({
|
core.register_abm({
|
||||||
nodenames = source_names,
|
nodenames = liquid_physics._liquids,
|
||||||
neighbors = { "air" },
|
neighbors = { "air" },
|
||||||
interval = 0.2,
|
interval = 0.2,
|
||||||
chance = 0,
|
chance = 0,
|
||||||
|
2
settingtypes.txt
Normal file
2
settingtypes.txt
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user