From 10dcd9cb2d39bfe4bc0438edfb3959cb0643433c Mon Sep 17 00:00:00 2001 From: Patrick 'Quezler' Mounier Date: Wed, 30 Jun 2021 18:59:09 +0200 Subject: [PATCH] outlaw separator desycning (#5516) * Seed separators * Sync separators * Seed from tile position --- .../world/blocks/production/Separator.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/core/src/mindustry/world/blocks/production/Separator.java b/core/src/mindustry/world/blocks/production/Separator.java index eb6acdd878..a863178208 100644 --- a/core/src/mindustry/world/blocks/production/Separator.java +++ b/core/src/mindustry/world/blocks/production/Separator.java @@ -30,6 +30,7 @@ public class Separator extends Block{ solid = true; hasItems = true; hasLiquids = true; + sync = true; } @Override @@ -45,6 +46,12 @@ public class Separator extends Block{ public float progress; public float totalProgress; public float warmup; + public int seed; + + @Override + public void created(){ + seed = Mathf.randomSeed(tile.pos(), 0, Integer.MAX_VALUE - 1); + } @Override public boolean shouldAmbientSound(){ @@ -91,7 +98,7 @@ public class Separator extends Block{ int sum = 0; for(ItemStack stack : results) sum += stack.amount; - int i = Mathf.random(sum); + int i = Mathf.randomSeed(seed++, 0, sum); int count = 0; Item item = null; @@ -121,11 +128,17 @@ public class Separator extends Block{ return !consumes.itemFilters.get(item.id); } + @Override + public byte version(){ + return 1; + } + @Override public void write(Writes write){ super.write(write); write.f(progress); write.f(warmup); + write.i(seed); } @Override @@ -133,6 +146,7 @@ public class Separator extends Block{ super.read(read, revision); progress = read.f(); warmup = read.f(); + if(revision == 1) seed = read.i(); } } }