Merge pull request #21 from x2605/Blackhole-unstable-&-desync

Fix Blackhole MP desync and load game glitchy
This commit is contained in:
PreLeyZero 2022-04-26 20:05:25 +02:00 committed by GitHub
commit e335e86ed8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -23,15 +23,17 @@
--=================================================================================================================== --===================================================================================================================
function gr_black_hole_init() function gr_black_hole_init()
global.black_hole = {} if not global.black_hole then --init is not guaranteed to run only once during whole game(?)
global.black_hole.base = {} global.black_hole = {}
global.black_hole.energy = {} global.black_hole.base = {}
global.black_hole.dirty = false global.black_hole.energy = {}
global.black_hole.counter = 0 global.black_hole.dirty = false
global.black_hole.counter = 0
global.black_hole.gui = {} global.black_hole.gui = {}
global.black_hole.gui.frame = nil global.black_hole.gui.frame = nil
global.black_hole.gui.id = nil global.black_hole.gui.id = nil
end
end end
--=================================================================================================================== --===================================================================================================================
@ -266,7 +268,7 @@ function black_hole_base_update()
stable = stable - 1 stable = stable - 1
if total then if total then
if stabilizer then if new_stabilizer then --have no idea why "stabilizer" stated here
stable = stable + new_stabilizer stable = stable + new_stabilizer
end end
end end
@ -311,9 +313,10 @@ end
function can_make_black_hole_energy(entity) function can_make_black_hole_energy(entity)
if entity.valid then if entity.valid then
inv = entity.get_inventory(defines.inventory.chest) -- local statement is very important to avoid MP desync and save/load cycle mismatch
total = inv.get_item_count() - inv.get_item_count("gr_materials_stabilizer_item") local inv = entity.get_inventory(defines.inventory.chest)
stabilizer = inv.get_item_count("gr_materials_stabilizer_item") local total = inv.get_item_count() - inv.get_item_count("gr_materials_stabilizer_item")
local stabilizer = inv.get_item_count("gr_materials_stabilizer_item")
if (stabilizer >= 100) and (total >= 1000) then if (stabilizer >= 100) and (total >= 1000) then
return true return true
else else