Fixed @unit not saving in logic blocks

This commit is contained in:
Anuken
2025-08-27 18:15:41 -04:00
parent 8613fc098c
commit e62c414efb
3 changed files with 21 additions and 7 deletions

View File

@@ -703,19 +703,25 @@ public class LogicBlock extends Block{
write.i(compressed.length);
write.b(compressed);
//write only the non-constant variables
int count = Structs.count(executor.vars, v -> (!v.constant || v == executor.unit) && !(v.isobj && v.objval == null));
boolean writeUnit = executor.unit.objval != null;
//only write non-null values; constants cannot be contained in executor.vars
int count = Structs.count(executor.vars, v -> !(v.isobj && v.objval == null)) + (writeUnit ? 1 : 0);
write.i(count);
//the unit is technically a constant that isn't the variable pool, so write that separately
if(writeUnit){
write.str("@unit");
TypeIO.writeObject(write, executor.unit.objval);
}
for(int i = 0; i < executor.vars.length; i++){
LVar v = executor.vars[i];
//null is the default variable value, so waste no time serializing that
if(v.isobj && v.objval == null) continue;
//skip constants
if(v.constant && v != executor.unit) continue;
//write the name and the object value
write.str(v.name);