mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 03:25:23 +09:00
Fix get_storage_for_stack errors with invalid stacks
Fixes `entity` is nil inside of `ExpUtil.get_storage_for_stack` #352
This commit is contained in:
@@ -403,6 +403,7 @@ end
|
|||||||
function ExpUtil.get_storage_for_stack(options)
|
function ExpUtil.get_storage_for_stack(options)
|
||||||
local surface = assert(options.surface, "A surface must be provided")
|
local surface = assert(options.surface, "A surface must be provided")
|
||||||
local item = assert(options.item, "An item stack must be provided")
|
local item = assert(options.item, "An item stack must be provided")
|
||||||
|
assert(type(item) ~= "userdata" or item.valid_for_read, "Invalid stack provided")
|
||||||
|
|
||||||
-- Perform a search if on has not been done already
|
-- Perform a search if on has not been done already
|
||||||
local cache = options.cache
|
local cache = options.cache
|
||||||
@@ -420,16 +421,6 @@ function ExpUtil.get_storage_for_stack(options)
|
|||||||
local current, count, entities = cache.current, cache.count, cache.entities
|
local current, count, entities = cache.current, cache.count, cache.entities
|
||||||
for i = 1, cache.count do
|
for i = 1, cache.count do
|
||||||
local entity = entities[((current + i - 1) % count) + 1]
|
local entity = entities[((current + i - 1) % count) + 1]
|
||||||
if entity == nil then
|
|
||||||
-- See Github Issue #352 <https://github.com/explosivegaming/ExpCluster/issues/352>
|
|
||||||
error("entity was nil, context:\n" .. ExpUtil.format_any({
|
|
||||||
cache = cache,
|
|
||||||
i = i,
|
|
||||||
}, {
|
|
||||||
max_line_count = 0,
|
|
||||||
no_locale_strings = true
|
|
||||||
}))
|
|
||||||
end
|
|
||||||
if entity.can_insert(item) then
|
if entity.can_insert(item) then
|
||||||
cache.current = current + 1
|
cache.current = current + 1
|
||||||
return entity
|
return entity
|
||||||
@@ -454,7 +445,7 @@ function ExpUtil.get_storage_for_stack(options)
|
|||||||
assert(entity, "Failed to create a new entity")
|
assert(entity, "Failed to create a new entity")
|
||||||
|
|
||||||
cache.count = count + 1
|
cache.count = count + 1
|
||||||
entities[count] = entity
|
entities[count + 1] = entity
|
||||||
return entity
|
return entity
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -468,9 +459,12 @@ end
|
|||||||
function ExpUtil.copy_items_to_surface(options)
|
function ExpUtil.copy_items_to_surface(options)
|
||||||
local entity
|
local entity
|
||||||
for item_index = 1, #options.items do
|
for item_index = 1, #options.items do
|
||||||
options.item = options.items[item_index]
|
local item = options.items[item_index]
|
||||||
entity = ExpUtil.get_storage_for_stack(options)
|
if type(item) ~= "userdata" or item.valid_for_read then
|
||||||
entity.insert(options.item)
|
options.item = item
|
||||||
|
entity = ExpUtil.get_storage_for_stack(options)
|
||||||
|
entity.insert(options.item)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return entity
|
return entity
|
||||||
end
|
end
|
||||||
@@ -485,10 +479,13 @@ end
|
|||||||
function ExpUtil.move_items_to_surface(options)
|
function ExpUtil.move_items_to_surface(options)
|
||||||
local entity
|
local entity
|
||||||
for item_index = 1, #options.items do
|
for item_index = 1, #options.items do
|
||||||
options.item = options.items[item_index]
|
local item = options.items[item_index]
|
||||||
entity = ExpUtil.get_storage_for_stack(options)
|
if type(item) ~= "userdata" or item.valid_for_read then
|
||||||
entity.insert(options.item)
|
options.item = item
|
||||||
options.item.clear()
|
entity = ExpUtil.get_storage_for_stack(options)
|
||||||
|
entity.insert(options.item)
|
||||||
|
options.item.clear()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return entity
|
return entity
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user