From 3638ad475bcba3de7be761d7461cc3264e3349fa Mon Sep 17 00:00:00 2001 From: FOlkvangrField Date: Tue, 30 Jan 2024 21:58:43 +0800 Subject: [PATCH] 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. --- .../hbm/config/CustomMachineConfigJSON.java | 15 +++++++-- .../recipes/CustomMachineRecipes.java | 33 +++++++++++++++---- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/hbm/config/CustomMachineConfigJSON.java b/src/main/java/com/hbm/config/CustomMachineConfigJSON.java index 83fda4ef5..adbd60981 100644 --- a/src/main/java/com/hbm/config/CustomMachineConfigJSON.java +++ b/src/main/java/com/hbm/config/CustomMachineConfigJSON.java @@ -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(); diff --git a/src/main/java/com/hbm/inventory/recipes/CustomMachineRecipes.java b/src/main/java/com/hbm/inventory/recipes/CustomMachineRecipes.java index 965593025..132a48bca 100644 --- a/src/main/java/com/hbm/inventory/recipes/CustomMachineRecipes.java +++ b/src/main/java/com/hbm/inventory/recipes/CustomMachineRecipes.java @@ -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); }