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

@@ -115,4 +115,8 @@ public class LVar{
return Double.isNaN(d) || Double.isInfinite(d);
}
@Override
public String toString(){
return name + ": " + (isobj ? objval : numval) + (constant ? " [const]" : "");
}
}

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);

View File

@@ -369,6 +369,10 @@ public class StatValues{
}
public static <T extends UnlockableContent> StatValue content(Seq<T> list, Boolf<T> check){
return content(list, check, "@none.inmap");
}
public static <T extends UnlockableContent> StatValue content(Seq<T> list, Boolf<T> check, String noneText){
return table -> table.table(l -> {
l.left();
@@ -387,7 +391,7 @@ public class StatValues{
}
if(!any){
l.add("@none.inmap");
l.add(noneText);
}
});
}
@@ -401,7 +405,7 @@ public class StatValues{
}
public static StatValue statusEffects(Seq<StatusEffect> list){
return content(list.as());
return content(list.as(), t -> true, "@none");
}
public static StatValue drillables(float drillTime, float drillMultiplier, float size, ObjectFloatMap<Item> multipliers, Boolf<Block> filter){