From 97903327a55c975492d33961b6f7b829dff06a8d Mon Sep 17 00:00:00 2001 From: Jude Melton-Houghton Date: Fri, 6 May 2022 11:25:02 -0400 Subject: [PATCH] Add option to forego real entities (#26) --- default_settings.lua | 1 + luaentity.lua | 52 +++++++++++++++++++++++++++----------------- settingtypes.txt | 3 +++ 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/default_settings.lua b/default_settings.lua index 9f21778..975b1d6 100644 --- a/default_settings.lua +++ b/default_settings.lua @@ -27,6 +27,7 @@ local settings = { enable_cyclic_mode = true, drop_on_routing_fail = false, delete_item_on_clearobject = true, + use_real_entities = true, } pipeworks.toggles = {} diff --git a/luaentity.lua b/luaentity.lua index 83fb4d9..27799dd 100644 --- a/luaentity.lua +++ b/luaentity.lua @@ -73,31 +73,43 @@ local function get_blockpos(pos) z = math.floor(pos.z / 16)} end -local active_blocks = {} -- These only contain active blocks near players (i.e., not forceloaded ones) +local move_entities_globalstep_part1 +local is_active -local move_entities_globalstep_part1 = function(dtime) - local active_block_range = tonumber(minetest.settings:get("active_block_range")) or 2 - local new_active_blocks = {} - for _, player in ipairs(minetest.get_connected_players()) do - local blockpos = get_blockpos(player:get_pos()) - local minp = vector.subtract(blockpos, active_block_range) - local maxp = vector.add(blockpos, active_block_range) +if pipeworks.use_real_entities then + local active_blocks = {} -- These only contain active blocks near players (i.e., not forceloaded ones) - for x = minp.x, maxp.x do - for y = minp.y, maxp.y do - for z = minp.z, maxp.z do - local pos = {x = x, y = y, z = z} - new_active_blocks[minetest.hash_node_position(pos)] = pos - end - end + move_entities_globalstep_part1 = function(dtime) + local active_block_range = tonumber(minetest.settings:get("active_block_range")) or 2 + local new_active_blocks = {} + for _, player in ipairs(minetest.get_connected_players()) do + local blockpos = get_blockpos(player:get_pos()) + local minp = vector.subtract(blockpos, active_block_range) + local maxp = vector.add(blockpos, active_block_range) + + for x = minp.x, maxp.x do + for y = minp.y, maxp.y do + for z = minp.z, maxp.z do + local pos = {x = x, y = y, z = z} + new_active_blocks[minetest.hash_node_position(pos)] = pos + end + end + end end + active_blocks = new_active_blocks + -- todo: callbacks on block load/unload end - active_blocks = new_active_blocks - -- todo: callbacks on block load/unload -end -local function is_active(pos) - return active_blocks[minetest.hash_node_position(get_blockpos(pos))] ~= nil + is_active = function(pos) + return active_blocks[minetest.hash_node_position(get_blockpos(pos))] ~= nil + end +else + move_entities_globalstep_part1 = function() + end + + is_active = function() + return false + end end local entitydef_default = { diff --git a/settingtypes.txt b/settingtypes.txt index cd6efbc..bfe7735 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -75,3 +75,6 @@ pipeworks_drop_on_routing_fail (Drop On Routing Fail) bool false #Delete item on clearobject. pipeworks_delete_item_on_clearobject (Delete Item On Clearobject) bool true + +#Use real visible entities in tubes within active areas. +pipeworks_use_real_entities (Use real entities) bool true