liquid_physics/init.lua

65 lines
2.2 KiB
Lua
Raw Normal View History

2025-01-05 18:19:30 +00:00
-- Copyright (C) 2025 snoutie
-- Authors: snoutie (copyright@achtarmig.org)
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU Affero General Public License as published
-- by the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU Affero General Public License for more details.
-- You should have received a copy of the GNU Affero General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
2025-01-05 17:11:50 +00:00
local modpath = core.get_modpath(core.get_current_modname())
liquid_physics = {}
2025-01-08 15:51:43 +00:00
-- INTERNAL USE ONLY - Stores all nodes which need to checked
2025-01-06 21:18:15 +00:00
liquid_physics._nodes_to_check = {}
2025-01-08 15:51:43 +00:00
-- INTERNAL USE ONLY - Stores liquid_id and the corresponding liquid node names
2025-01-06 21:18:15 +00:00
liquid_physics._registered_liquids = {}
2025-01-08 15:51:43 +00:00
-- INTERNAL USE ONLY - Stores all liquid node names and their corresponding liquid_id
2025-01-06 21:18:15 +00:00
liquid_physics._liquid_ids = {}
local internal = dofile(modpath .. "/internal.lua")
2025-01-05 17:11:50 +00:00
2025-01-11 21:57:44 +00:00
dofile(modpath .. "/api.lua")
2025-01-08 15:51:43 +00:00
2025-01-05 17:11:50 +00:00
if core.get_modpath("default") then
2025-01-11 21:57:44 +00:00
dofile(modpath .. "/game/default.lua")
2025-01-08 15:51:43 +00:00
elseif core.get_modpath("mcl_core") then
2025-01-11 21:57:44 +00:00
dofile(modpath .. "/game/voxelibre.lua")
2025-01-08 15:51:43 +00:00
else
error("Liquid Physics only supports VoxeLibre or Minetest")
2025-01-05 17:11:50 +00:00
end
2025-01-06 21:18:15 +00:00
core.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing)
if internal.get_liquid_id(core.get_node(pos).name) ~= nil then
internal.add_node_to_check(pos)
end
end)
core.register_lbm {
name = "liquid_physics:update",
2025-01-11 21:57:44 +00:00
nodenames = "group:liquid_physics",
2025-01-06 21:18:15 +00:00
run_at_every_load = true,
action = function(pos, node, dtime_s)
internal.add_node_to_check(pos)
end,
}
core.register_abm({
2025-01-11 21:57:44 +00:00
nodenames = "group:liquid_physics",
2025-01-06 21:18:15 +00:00
neighbors = { "air" },
interval = 0.2,
chance = 0,
action = function(pos, node, active_object_count, active_object_count_wider)
internal.add_node_to_check(pos)
end
})
2025-01-05 17:11:50 +00:00
dofile(modpath .. "/physics.lua")