1
0
mirror of https://github.com/mt-mods/pipeworks.git synced 2025-06-29 23:00:49 +02:00

Replace minetest namespace with core (#158)

Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com>
This commit is contained in:
The4codeblocks
2025-06-26 02:41:04 -05:00
committed by GitHub
parent d39ff8a097
commit 2ebc4ac92d
34 changed files with 619 additions and 617 deletions

View File

@ -1,11 +1,11 @@
local luaentity = pipeworks.luaentity
local enable_max_limit = minetest.settings:get_bool("pipeworks_enable_items_per_tube_limit")
local max_tube_limit = tonumber(minetest.settings:get("pipeworks_max_items_per_tube")) or 30
local enable_max_limit = core.settings:get_bool("pipeworks_enable_items_per_tube_limit")
local max_tube_limit = tonumber(core.settings:get("pipeworks_max_items_per_tube")) or 30
if enable_max_limit == nil then enable_max_limit = true end
if pipeworks.enable_item_tags then
local max_tag_length = tonumber(minetest.settings:get("pipeworks_max_item_tag_length")) or 32
local max_tags = tonumber(minetest.settings:get("pipeworks_max_item_tags")) or 16
local max_tag_length = tonumber(core.settings:get("pipeworks_max_item_tag_length")) or 32
local max_tags = tonumber(core.settings:get("pipeworks_max_item_tags")) or 16
function pipeworks.sanitize_tags(tags)
if type(tags) == "string" then
@ -36,10 +36,10 @@ function pipeworks.tube_inject_item(pos, start_pos, velocity, item, owner, tags)
-- Take item in any format
local stack = ItemStack(item)
local to_pos = vector.add(pos, velocity)
local def = minetest.registered_nodes[minetest.get_node(to_pos).name]
local def = core.registered_nodes[core.get_node(to_pos).name]
if not def or not def.groups or not (def.groups.tube
or def.groups.tubedevice or def.groups.tubedevice_receiver) then
local dropped_item = minetest.add_item(pos, stack)
local dropped_item = core.add_item(pos, stack)
if dropped_item then
dropped_item:set_velocity(vector.multiply(velocity, 5))
end
@ -74,14 +74,14 @@ end
local tube_item_count = {}
minetest.register_globalstep(function(dtime)
core.register_globalstep(function(dtime)
if not luaentity.entities then
return
end
tube_item_count = {}
for _, entity in pairs(luaentity.entities) do
if entity.name == "pipeworks:tubed_item" then
local h = minetest.hash_node_position(vector.round(entity._pos))
local h = core.hash_node_position(vector.round(entity._pos))
tube_item_count[h] = (tube_item_count[h] or 0) + 1
end
end
@ -94,20 +94,20 @@ end)
-- exceeds the limit configured per tube, replace it with a broken one.
function pipeworks.break_tube(pos)
local node = minetest.get_node(pos)
local node = core.get_node(pos)
if core.get_item_group(node.name, "tube") ~= 1 then return end
local meta = minetest.get_meta(pos)
meta:set_string("the_tube_was", minetest.serialize(node))
minetest.swap_node(pos, {name = "pipeworks:broken_tube_1"})
local meta = core.get_meta(pos)
meta:set_string("the_tube_was", core.serialize(node))
core.swap_node(pos, {name = "pipeworks:broken_tube_1"})
pipeworks.scan_for_tube_objects(pos)
end
local crunch_tube = function(pos, cnode, cmeta)
if enable_max_limit then
local h = minetest.hash_node_position(pos)
local h = core.hash_node_position(pos)
local itemcount = tube_item_count[h] or 0
if itemcount > max_tube_limit then
pipeworks.logger("Warning - a tube at "..minetest.pos_to_string(pos).." broke due to too many items ("..itemcount..")")
pipeworks.logger("Warning - a tube at "..core.pos_to_string(pos).." broke due to too many items ("..itemcount..")")
pipeworks.break_tube(pos)
end
end
@ -122,12 +122,12 @@ local function go_next_compat(pos, cnode, cmeta, cycledir, vel, stack, owner, ta
local max_priority = 0
local can_go
local def = minetest.registered_nodes[cnode.name]
local def = core.registered_nodes[cnode.name]
if def and def.tube and def.tube.can_go then
can_go = def.tube.can_go(pos, cnode, vel, stack, tags)
else
local adjlist_string = minetest.get_meta(pos):get_string("adjlist")
local adjlist = minetest.deserialize(adjlist_string) or default_adjlist -- backward compat: if not found, use old behavior: all directions
local adjlist_string = core.get_meta(pos):get_string("adjlist")
local adjlist = core.deserialize(adjlist_string) or default_adjlist -- backward compat: if not found, use old behavior: all directions
can_go = pipeworks.notvel(adjlist, vel)
end
@ -140,11 +140,11 @@ local function go_next_compat(pos, cnode, cmeta, cycledir, vel, stack, owner, ta
for _, vect in ipairs(can_go) do
local npos = vector.add(pos, vect)
pipeworks.load_position(npos)
local node = minetest.get_node(npos)
local reg_node = minetest.registered_nodes[node.name]
local node = core.get_node(npos)
local reg_node = core.registered_nodes[node.name]
if reg_node then
local tube_def = reg_node.tube
local tubedevice = minetest.get_item_group(node.name, "tubedevice")
local tubedevice = core.get_item_group(node.name, "tubedevice")
local tube_priority = (tube_def and tube_def.priority) or 100
if tubedevice > 0 and tube_priority >= max_priority then
if not tube_def or not tube_def.can_insert or
@ -184,8 +184,8 @@ end
-- if this is not nil, the luaentity spawns new tubed items for each new fragment stack,
-- then deletes itself (i.e. the original item stack).
local function go_next(pos, velocity, stack, owner, tags)
local cnode = minetest.get_node(pos)
local cmeta = minetest.get_meta(pos)
local cnode = core.get_node(pos)
local cmeta = core.get_meta(pos)
local speed = math.abs(velocity.x + velocity.y + velocity.z)
if speed == 0 then
speed = 1
@ -223,7 +223,7 @@ end
minetest.register_entity("pipeworks:tubed_item", {
core.register_entity("pipeworks:tubed_item", {
initial_properties = {
hp_max = 1,
physical = false,
@ -248,9 +248,9 @@ minetest.register_entity("pipeworks:tubed_item", {
end
local item_texture = nil
local item_type = ""
if minetest.registered_items[itemname] then
item_texture = minetest.registered_items[itemname].inventory_image
item_type = minetest.registered_items[itemname].type
if core.registered_items[itemname] then
item_texture = core.registered_items[itemname].inventory_image
item_type = core.registered_items[itemname].type
end
--]]
self.object:set_properties({
@ -270,13 +270,13 @@ minetest.register_entity("pipeworks:tubed_item", {
self.object:remove()
return
end
local item = minetest.deserialize(staticdata)
local item = core.deserialize(staticdata)
pipeworks.tube_inject_item(self.object:get_pos(), item.start_pos, item.velocity, item.itemstring)
self.object:remove()
end,
})
minetest.register_entity("pipeworks:color_entity", {
core.register_entity("pipeworks:color_entity", {
initial_properties = {
hp_max = 1,
physical = false,
@ -374,10 +374,10 @@ luaentity.register_entity("pipeworks:tubed_item", {
local stack = ItemStack(self.itemstring)
pipeworks.load_position(self.start_pos)
local node = minetest.get_node(self.start_pos)
if minetest.get_item_group(node.name, "tubedevice_receiver") == 1 then
local node = core.get_node(self.start_pos)
if core.get_item_group(node.name, "tubedevice_receiver") == 1 then
local leftover
local def = minetest.registered_nodes[node.name]
local def = core.registered_nodes[node.name]
if def.tube and def.tube.insert_object then
leftover = def.tube.insert_object(self.start_pos, node, stack, vel, self.owner)
else
@ -404,15 +404,15 @@ luaentity.register_entity("pipeworks:tubed_item", {
end
local rev_vel = vector.multiply(velocity, -1)
local rev_dir = vector.direction(self.start_pos,vector.add(self.start_pos,rev_vel))
local rev_node = minetest.get_node(vector.round(vector.add(self.start_pos,rev_dir)))
local tube_present = minetest.get_item_group(rev_node.name,"tubedevice") == 1
local rev_node = core.get_node(vector.round(vector.add(self.start_pos,rev_dir)))
local tube_present = core.get_item_group(rev_node.name,"tubedevice") == 1
if not found_next then
if pipeworks.drop_on_routing_fail or not tube_present or
minetest.get_item_group(rev_node.name,"tube") ~= 1 then
core.get_item_group(rev_node.name,"tube") ~= 1 then
-- Using add_item instead of item_drop since this makes pipeworks backward
-- compatible with Minetest 0.4.13.
-- Using item_drop here makes Minetest 0.4.13 crash.
local dropped_item = minetest.add_item(self.start_pos, stack)
local dropped_item = core.add_item(self.start_pos, stack)
if dropped_item then
dropped_item:set_velocity(vector.multiply(velocity, 5))
self:remove()
@ -442,19 +442,19 @@ luaentity.register_entity("pipeworks:tubed_item", {
end
})
if minetest.get_modpath("mesecons_mvps") then
if core.get_modpath("mesecons_mvps") then
mesecon.register_mvps_unmov("pipeworks:tubed_item")
mesecon.register_mvps_unmov("pipeworks:color_entity")
mesecon.register_on_mvps_move(function(moved_nodes)
local moved = {}
for _, n in ipairs(moved_nodes) do
moved[minetest.hash_node_position(n.oldpos)] = vector.subtract(n.pos, n.oldpos)
moved[core.hash_node_position(n.oldpos)] = vector.subtract(n.pos, n.oldpos)
end
for _, entity in pairs(luaentity.entities) do
if entity.name == "pipeworks:tubed_item" then
local pos = entity:get_pos()
local rpos = vector.round(pos)
local dir = moved[minetest.hash_node_position(rpos)]
local dir = moved[core.hash_node_position(rpos)]
if dir then
entity:set_pos(vector.add(pos, dir))
entity.start_pos = vector.add(entity.start_pos, dir)