From 5224fddcbcdf3f05b8d2c6b99ac9a26c5a71f358 Mon Sep 17 00:00:00 2001 From: cardillan <122014763+cardillan@users.noreply.github.com> Date: Fri, 5 Sep 2025 18:41:53 +0200 Subject: [PATCH] Enable non-linked blocks on processor deletion --- core/src/mindustry/logic/LExecutor.java | 3 ++ .../world/blocks/logic/LogicBlock.java | 47 ++++++++++++++----- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index ab2bbe6fcc..0e0dc57beb 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 @@ -520,7 +521,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 834919f4f3..40e6b11f6c 100644 --- a/core/src/mindustry/world/blocks/logic/LogicBlock.java +++ b/core/src/mindustry/world/blocks/logic/LogicBlock.java @@ -423,7 +423,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; } @@ -692,7 +692,7 @@ public class LogicBlock extends Block{ @Override public byte version(){ - return 3; + return 4; } @Override @@ -738,6 +738,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 @@ -776,6 +784,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++){ @@ -793,17 +819,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(); - } - } } }