From fa610bebe31412c5f4ecee904096188d886c913a Mon Sep 17 00:00:00 2001 From: Vitaliy Olkhin Date: Wed, 6 Nov 2024 13:52:14 +0500 Subject: [PATCH] small fix, added the ability to enable debug for debugging code --- default_settings.lua | 1 + luaentity.lua | 74 ++++++++++++++++++++++++-------------------- settingtypes.txt | 2 ++ 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/default_settings.lua b/default_settings.lua index ccc091e..6861022 100644 --- a/default_settings.lua +++ b/default_settings.lua @@ -32,6 +32,7 @@ local settings = { use_real_entities = true, entity_update_interval = 0, enable_vertical_digilines_connectivity = true, + enable_debug = false, } pipeworks.toggles = {} diff --git a/luaentity.lua b/luaentity.lua index ef9a4ca..9aa2638 100644 --- a/luaentity.lua +++ b/luaentity.lua @@ -349,53 +349,61 @@ function luaentity.get_objects_inside_radius(pos, radius) end local move_entities_globalstep_part2 = function(dtime) + local object = {} if not luaentity.entities then luaentity.entities = read_entities() end --minetest.log("action", "Dump: " .. dump(luaentity.entities)) for _, entity in pairs(luaentity.entities) do --minetest.log("action", "entity " .. type(entity.owner)) + --minetest.chat_send_all("online: " .. dump(entity.owner)) + if entity.owner ~= nil then - local object = minetest.env:get_player_by_name(entity.owner) - if object then - --minetest.chat_send_all("online: " .. dump(entity.owner)) - --minetest.log("action", "pipeworks: активная передача по трубам игрок в сети: " .. entity.owner) - local master = entity._attached_entities_master - local master_def = master and entity._attached_entities[master] - local master_entity = master_def and master_def.entity - local master_entity_pos = master_entity and master_entity:get_pos() - if master_entity_pos then - entity._pos = vector.subtract(master_entity_pos, master_def.offset) - entity._velocity = master_entity:get_velocity() - entity._acceleration = master_entity:get_acceleration() - else - entity._velocity = entity._velocity or vector.new(0,0,0) - entity._acceleration = entity._acceleration or vector.new(0,0,0) - entity._pos = vector.add(vector.add( - entity._pos, - vector.multiply(entity._velocity, dtime)), - vector.multiply(entity._acceleration, 0.5 * dtime * dtime)) - entity._velocity = vector.add( - entity._velocity, - vector.multiply(entity._acceleration, dtime)) - end - if master and not master_entity_pos then -- The entity has somehow been cleared - if pipeworks.delete_item_on_clearobject then - entity:remove() - else - entity:_remove_attached(master) - entity:_add_loaded() - if entity.on_step then - entity:on_step(dtime) - end - end + object = minetest.env:get_player_by_name(entity.owner) + end + + if object or entity.owner ~= nil then + --minetest.chat_send_all("online: " .. dump(entity.owner)) + if pipeworks.enable_debug then + minetest.log("action", "pipeworks: активная передача по трубам игрок в сети: " .. entity.owner) + end + + local master = entity._attached_entities_master + local master_def = master and entity._attached_entities[master] + local master_entity = master_def and master_def.entity + local master_entity_pos = master_entity and master_entity:get_pos() + if master_entity_pos then + entity._pos = vector.subtract(master_entity_pos, master_def.offset) + entity._velocity = master_entity:get_velocity() + entity._acceleration = master_entity:get_acceleration() + else + entity._velocity = entity._velocity or vector.new(0,0,0) + entity._acceleration = entity._acceleration or vector.new(0,0,0) + entity._pos = vector.add(vector.add( + entity._pos, + vector.multiply(entity._velocity, dtime)), + vector.multiply(entity._acceleration, 0.5 * dtime * dtime)) + entity._velocity = vector.add( + entity._velocity, + vector.multiply(entity._acceleration, dtime)) + end + if master and not master_entity_pos then -- The entity has somehow been cleared + if pipeworks.delete_item_on_clearobject then + entity:remove() else + entity:_remove_attached(master) entity:_add_loaded() if entity.on_step then entity:on_step(dtime) end end + else + entity:_add_loaded() + if entity.on_step then + entity:on_step(dtime) + end end + end end end diff --git a/settingtypes.txt b/settingtypes.txt index 88a6cfe..7783530 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -100,3 +100,5 @@ pipeworks_log_teleport_tubes (Log Teleport Tubes) bool false # Behavior of print() inside a lua tube. By default, this emits a message into actionstream. # Set it to noop if you wish to disable that behavior. pipeworks_lua_tube_print_behavior (Behavior of print in Lua Tube) enum log log,noop + +pipeworks_enable_debug (Enable debug) bool false