Compatibility with old configs

Add compatibility with old configs. If the newly added option is not read, it will be automatically written to the default value.
This commit is contained in:
FOlkvangrField 2024-01-30 21:58:43 +08:00
parent 7473278dab
commit 3638ad475b
2 changed files with 38 additions and 10 deletions

View File

@ -159,12 +159,21 @@ public class CustomMachineConfigJSON {
configuration.fluidOutCap = machineObject.get("fluidOutCap").getAsInt();
configuration.itemOutCount = machineObject.get("itemOutCount").getAsInt();
configuration.generatorMode = machineObject.get("generatorMode").getAsBoolean();
configuration.maxPollutionCap = machineObject.get("maxPollutionCap").getAsInt();
configuration.fluxMode = machineObject.get("fluxMode").getAsBoolean();
if(machineObject.get("maxPollutionCap")!=null) {
configuration.maxPollutionCap = machineObject.get("maxPollutionCap").getAsInt();
}
else configuration.maxPollutionCap = 0;
if(machineObject.get("fluxMode")!=null) {
configuration.fluxMode = machineObject.get("fluxMode").getAsBoolean();
}
else configuration.fluxMode = false;
configuration.recipeSpeedMult = machineObject.get("recipeSpeedMult").getAsDouble();
configuration.recipeConsumptionMult = machineObject.get("recipeConsumptionMult").getAsDouble();
configuration.maxPower = machineObject.get("maxPower").getAsLong();
configuration.maxHeat = machineObject.get("maxHeat").getAsInt();
if(machineObject.get("maxHeat")!=null) {
configuration.maxHeat = machineObject.get("maxHeat").getAsInt();
}
else configuration.maxHeat = 0;
if(machineObject.has("recipeShape") && machineObject.has("recipeParts")) {
JsonArray recipeShape = machineObject.get("recipeShape").getAsJsonArray();

View File

@ -79,14 +79,33 @@ public class CustomMachineRecipes extends SerializableRecipe {
recipeInstance.outputItems = this.readItemStackArrayChance(rec.get("outputItems").getAsJsonArray());
recipeInstance.duration = rec.get("duration").getAsInt();
recipeInstance.consumptionPerTick = rec.get("consumptionPerTick").getAsInt();
recipeInstance.pollutionMode = rec.get("pollutionMode").getAsBoolean();
recipeInstance.pollutionType = rec.get("pollutionType").getAsString();
recipeInstance.pollutionAmount = rec.get("pollutionAmount").getAsFloat();
recipeInstance.radiationMode = rec.get("radiationMode").getAsBoolean();
recipeInstance.radiationAmount = rec.get("radiationAmount").getAsFloat();
recipeInstance.flux = rec.get("flux").getAsInt();
recipeInstance.heat = rec.get("heat").getAsInt();
if(rec.get("pollutionMode")!=null) {
recipeInstance.pollutionMode = rec.get("pollutionMode").getAsBoolean();
recipeInstance.pollutionType = rec.get("pollutionType").getAsString();
recipeInstance.pollutionAmount = rec.get("pollutionAmount").getAsFloat();
}
else {
recipeInstance.pollutionMode = false;
recipeInstance.pollutionType = "";
recipeInstance.pollutionAmount = 0;
}
if(rec.get("radiationMode")!=null) {
recipeInstance.radiationMode = rec.get("radiationMode").getAsBoolean();
recipeInstance.radiationAmount = rec.get("radiationAmount").getAsFloat();
}
else {
recipeInstance.radiationMode = false;
recipeInstance.radiationAmount = 0;
}
if(rec.get("flux")!=null) {
recipeInstance.flux = rec.get("flux").getAsInt();
}
else recipeInstance.flux = 0;
if(rec.get("heat")!=null) {
recipeInstance.heat = rec.get("heat").getAsInt();
}
else recipeInstance.heat = 0;
list.add(recipeInstance);
}