diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index b4324fa446..cc3a6cd4de 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -55,6 +55,7 @@ public class LExecutor{ public Building[] links = {}; public @Nullable LogicBuild build; public IntSet linkIds = new IntSet(); + public ObjectSet disabledBlocks = new ObjectSet<>(); public Team team = Team.derelict; public boolean privileged = false; //maps variable name to index in vars; lazily initialized @@ -571,7 +572,9 @@ public class LExecutor{ if(p1.bool()){ b.noSleep(); }else{ + // Note: it might be a good idea to remove invalid blocks from the set here b.lastDisabler = exec.build; + exec.disabledBlocks.add(b); } } diff --git a/core/src/mindustry/world/blocks/logic/LogicBlock.java b/core/src/mindustry/world/blocks/logic/LogicBlock.java index 0f6e713350..46c95df3f8 100644 --- a/core/src/mindustry/world/blocks/logic/LogicBlock.java +++ b/core/src/mindustry/world/blocks/logic/LogicBlock.java @@ -429,7 +429,7 @@ public class LogicBlock extends Block{ public void removeFromProximity(){ super.removeFromProximity(); - for(var link : executor.links){ + for(var link : executor.disabledBlocks){ if(!link.enabled && link.lastDisabler == this){ link.enabled = true; } @@ -700,7 +700,7 @@ public class LogicBlock extends Block{ @Override public byte version(){ - return 3; + return 4; } @Override @@ -746,6 +746,14 @@ public class LogicBlock extends Block{ TypeIO.writeString(write, tag); write.s(iconTag); + + for(var link : executor.disabledBlocks){ + // Only store the necessary blocks + if(link.isValid() && !link.enabled && link.lastDisabler == this){ + write.i(link.pos()); + } + } + write.i(-1); } @Override @@ -784,6 +792,24 @@ public class LogicBlock extends Block{ //skip memory, it isn't used anymore read.skip(memory * 8); + if(privileged && revision >= 2){ + ipt = Mathf.clamp(read.s(), 1, maxInstructionsPerTick); + } + + if(revision >= 3){ + tag = TypeIO.readString(read); + iconTag = (char)read.us(); + } + + IntSeq tiles = new IntSeq(); + if(revision >= 4){ + while(true){ + int tile = read.i(); + if(tile == -1) break; + tiles.add(tile); + } + } + loadBlock = () -> updateCode(code, false, asm -> { //load up the variables that were stored for(int i = 0; i < varcount; i++){ @@ -801,17 +827,16 @@ public class LogicBlock extends Block{ } } } + + //load up disabled blocks + tiles.each(pos -> { + Building build = world.build(Point2.x(pos), Point2.y(pos)); + if(build != null){ + executor.disabledBlocks.add(build); + } + }); }); - if(privileged && revision >= 2){ - ipt = Mathf.clamp(read.s(), 1, maxInstructionsPerTick); - } - - if(revision >= 3){ - tag = TypeIO.readString(read); - iconTag = (char)read.us(); - } - } } }