diff --git a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/Validator.java b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/Validator.java index 8652844b..8b9f7ea4 100644 --- a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/Validator.java +++ b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/Validator.java @@ -423,6 +423,40 @@ public BiFunction getRequiredIntRange(long min, long (array? NON_EMPTY_ARRAY_REQUIRED.apply(element, path): assertNotArray(element, path)) && getIntRange(min, max).apply(element, path); } + /** + * Used to get validator of Max Y Level range. Automatically changes the Int Range depending on the value of min field. + * @param minName Name of the min y level field. + * @return BiFunction used as validator. + */ + public BiFunction getMaxYLevelValidation(String minName) { + return (element, path) -> { + if (!assertParentObject(element, path)) return false; + JsonObject parent = element.getAsJsonObject(); + JsonElement value = parent.get(name); + JsonElement min = parent.get(minName); + int minValue = -64; + + if (!REQUIRED.apply(value, path)) return false; + + if (Objects.isNull(min)) { + LOGGER.warn("Field \"%s\" is missing! Can't accurately verify \"%s\" in file \"%s\".".formatted(minName, name, Validator.obfuscatePath(path))); + } else { + try { + if (!min.isJsonPrimitive()) throw new ClassCastException(); + minValue = min.getAsInt(); + if (minValue > 320) { + LOGGER.error("Field \"%s\" is above max 320! Can't accurately verify \"%s\" in file \"%s\".".formatted(minName, name, Validator.obfuscatePath(path))); + minValue = -64; + } + } catch (ClassCastException e) { + LOGGER.error("Field \"%s\" requires a Numeric value! Can't accurately verify \"%s\" in file \"%s\".".formatted(minName, name, Validator.obfuscatePath(path))); + } + } + + return getIntRange(minValue, 320, false).apply(value, path); + }; + } + /** * Used to get validator of another JsonObject. * @param validators Map with validators for JsonObject to verify. @@ -736,14 +770,78 @@ public BiFunction getPassParentToValidators(Map getIfOtherFieldSet(String fieldName, BiFunction validator) { + return (element, path) -> { + if (!assertParentObject(element, path)) return false; + JsonObject parent = element.getAsJsonObject(); + JsonElement validatedField = parent.get(name); + + if (isOtherFieldSet(fieldName, parent)) return validator.apply(validatedField, path); + if (Objects.nonNull(validatedField)) LOGGER.warn("\"%s\" should not be present when \"%s\" is not set in file \"%s\"".formatted(name, fieldName, Validator.obfuscatePath(path))); + return true; + }; + } + + /** + * Used to execute the specified validator only if the specified fieldName is present. + * Prints "Field x should not be present when x field is not present" if fieldName doesn't exist. + * @param fieldName Name of the Field which should be set. + * @param validator Validator to execute if fieldName is present. + * @return BiFunction used as a validator. + * @apiNote Requires use of _rg suffix. + */ + public BiFunction getIfOtherFieldPresent(String fieldName, BiFunction validator) { + return (element, path) -> { + if (!assertParentObject(element, path)) return false; + JsonObject parent = element.getAsJsonObject(); + JsonElement validatedField = parent.get(name); + + if (isOtherFieldPresent(fieldName, parent)) return validator.apply(validatedField, path); + if (Objects.nonNull(validatedField)) LOGGER.warn("\"%s\" should not be present when \"%s\" is not present in file \"%s\"".formatted(name, fieldName, Validator.obfuscatePath(path))); + return true; + }; + } + + /** + * Utility method for custom validators. Used to check if specified field is set in the provided object. + * @param fieldName Name of the field to check. + * @param object JsonObject to check if the specified field is set. + * @return Returns false if the value is not a boolean, otherwise returns set value of the field. + */ + public static boolean isOtherFieldSet(String fieldName, JsonObject object) { + JsonElement field = object.get(fieldName); + return Objects.nonNull(field) && field.isJsonPrimitive() && field.getAsJsonPrimitive().isBoolean() && field.getAsJsonPrimitive().getAsBoolean(); + } + + /** + * Utility method for custom validators. Used to check if specified field is present in the provided object. + * @param fieldName Name of the field to check. + * @param object JsonObject to check if the specified field is set. + * @return True if field exists, otherwise false. + * @apiNote If you need to also check if the boolean value of this field is true/false, use {@link Validator#isOtherFieldSet(String, JsonObject)} instead. + */ + public static boolean isOtherFieldPresent(String fieldName, JsonObject object) { + return Objects.nonNull(object.get(fieldName)); + } + /** * Used to pass a provided object to the validators by adding it to the TEMP field of the object * (or for all entries in the array) and validation will be launched as normal. + * @param tempObject Object to pass in the TEMP field. + * @param element JsonObject or JsonArray of JsonObject, to which TEMP field should be added. * @param validators Map with validators. * @param required Determines if the value is required or not. * @return BiFunction used as validator. @@ -752,7 +850,7 @@ public BiFunction getPassParentToValidators(Map> validators, boolean required) { if (Objects.isNull(element)) return (required? REQUIRED.apply(null, path): true); - if (element.isJsonPrimitive() || element.isJsonNull()) { + if (!element.isJsonObject() && !element.isJsonArray()) { LOGGER.error("Expected array or object for \"%s\" in file \"%s\".".formatted(name, obfuscatePath(path))); return false; } diff --git a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/DepositValidators.java b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/DepositValidators.java index 67da8592..12c88957 100644 --- a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/DepositValidators.java +++ b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/DepositValidators.java @@ -53,40 +53,6 @@ public class DepositValidators { validators.put(EEDeposits.DepositType.TEST.getType(), new LinkedHashMap<>(Map.of("config", new Validator("config").getRequiredObjectValidation(TestDepositConfigModel.validators, false)))); } - /** - * Provider of MaxYLevelValidation. Requires use of _rg suffix to work. - * @apiNote This is meant to be modified and moved to {@link Validator} class! - */ - public static BiFunction getMaxYLevelValidation(Validator validator, String minName) { - //TODO: Add additional configuration option and move it to validator - return (element, path) -> { - if (!validator.assertParentObject(element, path)) return false; - JsonObject parent = element.getAsJsonObject(); - JsonElement value = parent.get(validator.getName()); - JsonElement min = parent.get(minName); - int minValue = -64; - - if (!validator.REQUIRED.apply(value, path)) return false; - - if (Objects.isNull(min)) { - LOGGER.warn("Field \"%s\" is missing! Can't accurately verify \"%s\" in file \"%s\".".formatted(minName, validator.getName(), Validator.obfuscatePath(path))); - } else { - try { - if (!min.isJsonPrimitive()) throw new ClassCastException(); - minValue = min.getAsInt(); - if (minValue > 320) { - LOGGER.error("Field \"%s\" is above max 320! Can't accurately verify \"%s\" in file \"%s\".".formatted(minName, validator.getName(), Validator.obfuscatePath(path))); - minValue = -64; - } - } catch (ClassCastException e) { - LOGGER.error("Field \"%s\" requires a Numeric value! Can't accurately verify \"%s\" in file \"%s\".".formatted(minName, validator.getName(), Validator.obfuscatePath(path))); - } - } - - return validator.getIntRange(minValue, 320, false).apply(value, path); - }; - } - /** * Used to get a validator for Material Field, when Block and Tag fields are as an alternatives. * Requires usage of _rg suffix. diff --git a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/common/CommonBlockDefinitionModel.java b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/common/CommonBlockDefinitionModel.java index f08783d9..9718ce28 100644 --- a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/common/CommonBlockDefinitionModel.java +++ b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/common/CommonBlockDefinitionModel.java @@ -80,7 +80,7 @@ public class CommonBlockDefinitionModel { ); } - return DepositValidators.getMaxYLevelValidation(maxValidator, "min").apply(parent, path); + return maxValidator.getMaxYLevelValidation("min").apply(parent, path); }); } diff --git a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/dense/DenseDepositConfigModel.java b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/dense/DenseDepositConfigModel.java index e3149327..64c74d2c 100644 --- a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/dense/DenseDepositConfigModel.java +++ b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/dense/DenseDepositConfigModel.java @@ -28,7 +28,6 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import com.ridanisaurus.emendatusenigmatica.loader.Validator; -import com.ridanisaurus.emendatusenigmatica.loader.deposit.model.DepositValidators; import com.ridanisaurus.emendatusenigmatica.loader.deposit.model.common.CommonBlockDefinitionModel; import com.ridanisaurus.emendatusenigmatica.loader.deposit.model.sample.SampleBlockDefinitionModel; import com.ridanisaurus.emendatusenigmatica.plugin.DefaultConfigPlugin; @@ -77,11 +76,12 @@ public class DenseDepositConfigModel { validators.put("chance", new Validator("chance").getRequiredIntRange(1, 100, false)); validators.put("size", new Validator("size").getRequiredIntRange(1, 48, false)); validators.put("minYLevel", new Validator("minYLevel").getRequiredIntRange(-64, 320, false)); - validators.put("maxYLevel_rg", DepositValidators.getMaxYLevelValidation(new Validator("maxYLevel"), "minYLevel")); + validators.put("maxYLevel_rg", new Validator("maxYLevel").getMaxYLevelValidation("minYLevel")); validators.put("placement", new Validator("placement").getAcceptsOnlyValidation(List.of("uniform", "triangle"), false)); validators.put("rarity", new Validator("rarity").getAcceptsOnlyValidation(List.of("common", "rare"), false)); validators.put("generateSamples",new Validator("generateSamples").REQUIRES_BOOLEAN); - validators.put("sampleBlocks", new Validator("sampleBlocks").getObjectValidation(SampleBlockDefinitionModel.validators, true)); + Validator sampleValidator = new Validator("sampleBlocks"); + validators.put("sampleBlocks_rg", sampleValidator.getIfOtherFieldSet("generateSamples", sampleValidator.getRequiredObjectValidation(SampleBlockDefinitionModel.validators, true))); } public DenseDepositConfigModel(List blocks, List fillerTypes, int chance, int size, int minYLevel, int maxYLevel, String placement, String rarity, boolean generateSamples, List sampleBlocks) { diff --git a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/dense/DenseDepositModel.java b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/dense/DenseDepositModel.java index 84251328..0cf68671 100644 --- a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/dense/DenseDepositModel.java +++ b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/dense/DenseDepositModel.java @@ -53,7 +53,7 @@ public String getType() { } public int getChance() { - if (config.chance < 1 || config.chance > 100) throw new IllegalArgumentException("Chance for " + name + " is out of Range [1 - 100]"); +// if (config.chance < 1 || config.chance > 100) throw new IllegalArgumentException("Chance for " + name + " is out of Range [1 - 100]"); return config.chance; } @@ -62,37 +62,37 @@ public int getPlacementChance() { } public int getMaxYLevel() { - if (config.maxYLevel < -64 || config.maxYLevel > 320) throw new IllegalArgumentException("Max Y for " + name + " is out of Range [-64 - 320]"); +// if (config.maxYLevel < -64 || config.maxYLevel > 320) throw new IllegalArgumentException("Max Y for " + name + " is out of Range [-64 - 320]"); return config.maxYLevel; } public int getMinYLevel() { - if (config.minYLevel < -64 || config.minYLevel > 320) throw new IllegalArgumentException("Min Y for " + name + " is out of Range [-64 - 320]"); +// if (config.minYLevel < -64 || config.minYLevel > 320) throw new IllegalArgumentException("Min Y for " + name + " is out of Range [-64 - 320]"); return config.minYLevel; } public List getBlocks() { - if (config.blocks.isEmpty()) throw new IllegalArgumentException("Blocks for " + name + " cannot be empty."); +// if (config.blocks.isEmpty()) throw new IllegalArgumentException("Blocks for " + name + " cannot be empty."); return config.blocks; } public List getFillerTypes() { - if (config.fillerTypes.isEmpty()) throw new IllegalArgumentException("Filler Types for " + name + " cannot be empty."); +// if (config.fillerTypes.isEmpty()) throw new IllegalArgumentException("Filler Types for " + name + " cannot be empty."); return config.fillerTypes; } public int getSize() { - if (config.size < 1 || config.size > 48) throw new IllegalArgumentException("Size for " + name + " is out of Range [1 - 48]"); +// if (config.size < 1 || config.size > 48) throw new IllegalArgumentException("Size for " + name + " is out of Range [1 - 48]"); return config.size; } public String getPlacement() { - if (!config.placement.equals("uniform") && !config.placement.equals("triangle")) throw new IllegalArgumentException("Placement for " + name + " is invalid."); +// if (!config.placement.equals("uniform") && !config.placement.equals("triangle")) throw new IllegalArgumentException("Placement for " + name + " is invalid."); return config.placement; } public String getRarity() { - if (!config.rarity.equals("common") && !config.rarity.equals("rare")) throw new IllegalArgumentException("Rarity for " + name + " is invalid."); +// if (!config.rarity.equals("common") && !config.rarity.equals("rare")) throw new IllegalArgumentException("Rarity for " + name + " is invalid."); return config.rarity; } @@ -101,7 +101,7 @@ public boolean hasSamples() { } public List getSampleBlocks() { - if (hasSamples() && config.sampleBlocks.isEmpty()) throw new IllegalArgumentException("Sample Blocks for " + name + " cannot be empty if generateSamples is set to true."); +// if (hasSamples() && config.sampleBlocks.isEmpty()) throw new IllegalArgumentException("Sample Blocks for " + name + " cannot be empty if generateSamples is set to true."); return config.sampleBlocks; } } \ No newline at end of file diff --git a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/dike/DikeDepositConfigModel.java b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/dike/DikeDepositConfigModel.java index 05377960..02644624 100644 --- a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/dike/DikeDepositConfigModel.java +++ b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/dike/DikeDepositConfigModel.java @@ -54,11 +54,12 @@ public class DikeDepositConfigModel { //TODO: Verify the real maximum size for dikes. validators.put("size", new Validator("size").getRequiredIntRange(1, 64, false)); validators.put("minYLevel", new Validator("minYLevel").getRequiredIntRange(-64, 320, false)); - validators.put("maxYLevel_rg", DepositValidators.getMaxYLevelValidation(new Validator("maxYLevel"), "minYLevel")); + validators.put("maxYLevel_rg", new Validator("maxYLevel").getMaxYLevelValidation("minYLevel")); validators.put("placement", new Validator("placement").getAcceptsOnlyValidation(List.of("uniform", "triangle"), false)); validators.put("rarity", new Validator("rarity").getAcceptsOnlyValidation(List.of("common", "rare"), false)); validators.put("generateSamples",new Validator("generateSamples").REQUIRES_BOOLEAN); - validators.put("sampleBlocks", new Validator("sampleBlocks").getObjectValidation(SampleBlockDefinitionModel.validators, true)); + Validator sampleValidator = new Validator("sampleBlocks"); + validators.put("sampleBlocks_rg", sampleValidator.getIfOtherFieldSet("generateSamples", sampleValidator.getRequiredObjectValidation(SampleBlockDefinitionModel.validators, true))); } public DikeDepositConfigModel(List blocks, List fillerTypes, int chance, int size, int minYLevel, int maxYLevel, String placement, String rarity, boolean generateSamples, List sampleBlocks) { diff --git a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/dike/DikeDepositModel.java b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/dike/DikeDepositModel.java index f98a2252..a832f8f7 100644 --- a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/dike/DikeDepositModel.java +++ b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/dike/DikeDepositModel.java @@ -29,7 +29,7 @@ public String getType() { } public int getChance() { - if (config.chance < 1 || config.chance > 100) throw new IllegalArgumentException("Chance for " + name + " is out of Range [1 - 100]"); +// if (config.chance < 1 || config.chance > 100) throw new IllegalArgumentException("Chance for " + name + " is out of Range [1 - 100]"); return config.chance; } @@ -38,38 +38,37 @@ public int getPlacementChance() { } public int getMaxYLevel() { - if (config.maxYLevel < -64 || config.maxYLevel > 320) throw new IllegalArgumentException("Max Y for " + name + " is out of Range [-64 - 320]"); +// if (config.maxYLevel < -64 || config.maxYLevel > 320) throw new IllegalArgumentException("Max Y for " + name + " is out of Range [-64 - 320]"); return config.maxYLevel; } public int getMinYLevel() { - if (config.minYLevel < -64 || config.minYLevel > 320) throw new IllegalArgumentException("Min Y for " + name + " is out of Range [-64 - 320]"); +// if (config.minYLevel < -64 || config.minYLevel > 320) throw new IllegalArgumentException("Min Y for " + name + " is out of Range [-64 - 320]"); return config.minYLevel; } public List getBlocks() { - if (config.blocks.isEmpty()) throw new IllegalArgumentException("Blocks for " + name + " cannot be empty."); +// if (config.blocks.isEmpty()) throw new IllegalArgumentException("Blocks for " + name + " cannot be empty."); return config.blocks; } public List getFillerTypes() { - if (config.fillerTypes.isEmpty()) throw new IllegalArgumentException("Filler Types for " + name + " cannot be empty."); +// if (config.fillerTypes.isEmpty()) throw new IllegalArgumentException("Filler Types for " + name + " cannot be empty."); return config.fillerTypes; } public int getSize() { - // See loader/deposit/model/dike/DikeDepositConfigModel.javaDikeDepositConfigModel for validation of the size. // if (config.size < 1 || config.size > 16) throw new IllegalArgumentException("Size for " + name + " is out of Range [1 - 16]"); return config.size; } public String getPlacement() { - if (!config.placement.equals("uniform") && !config.placement.equals("triangle")) throw new IllegalArgumentException("Placement for " + name + " is invalid."); +// if (!config.placement.equals("uniform") && !config.placement.equals("triangle")) throw new IllegalArgumentException("Placement for " + name + " is invalid."); return config.placement; } public String getRarity() { - if (!config.rarity.equals("common") && !config.rarity.equals("rare")) throw new IllegalArgumentException("Rarity for " + name + " is invalid."); +// if (!config.rarity.equals("common") && !config.rarity.equals("rare")) throw new IllegalArgumentException("Rarity for " + name + " is invalid."); return config.rarity; } @@ -78,7 +77,7 @@ public boolean hasSamples() { } public List getSampleBlocks() { - if (hasSamples() && config.sampleBlocks.isEmpty()) throw new IllegalArgumentException("Sample Blocks for " + name + " cannot be empty if generateSamples is set to true."); +// if (hasSamples() && config.sampleBlocks.isEmpty()) throw new IllegalArgumentException("Sample Blocks for " + name + " cannot be empty if generateSamples is set to true."); return config.sampleBlocks; } } \ No newline at end of file diff --git a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/geode/GeodeDepositConfigModel.java b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/geode/GeodeDepositConfigModel.java index 02cf0d78..46584ab0 100644 --- a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/geode/GeodeDepositConfigModel.java +++ b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/geode/GeodeDepositConfigModel.java @@ -4,7 +4,6 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import com.ridanisaurus.emendatusenigmatica.loader.Validator; -import com.ridanisaurus.emendatusenigmatica.loader.deposit.model.DepositValidators; import com.ridanisaurus.emendatusenigmatica.loader.deposit.model.common.CommonBlockDefinitionModel; import com.ridanisaurus.emendatusenigmatica.loader.deposit.model.sample.SampleBlockDefinitionModel; import com.ridanisaurus.emendatusenigmatica.plugin.DefaultConfigPlugin; @@ -65,11 +64,12 @@ public class GeodeDepositConfigModel { validators.put("chance", new Validator("chance").getRequiredIntRange(1, 100, false)); validators.put("crackChance", new Validator("crackChance").getRequiredRange(0, 1, false)); validators.put("minYLevel", new Validator("minYLevel").getRequiredIntRange(-64, 320, false)); - validators.put("maxYLevel_rg", DepositValidators.getMaxYLevelValidation(new Validator("maxYLevel"), "minYLevel")); - validators.put("placement", new Validator("placement").getAcceptsOnlyValidation(List.of("uniform", "triangle"), false)); + validators.put("maxYLevel_rg", new Validator("maxYLevel").getMaxYLevelValidation("minYLevel")); + validators.put("placement", new Validator("placement").getAcceptsOnlyValidation(List.of("uniform", "triangle"), false)); validators.put("rarity", new Validator("rarity").getAcceptsOnlyValidation(List.of("common", "rare"), false)); validators.put("generateSamples", new Validator("generateSamples").REQUIRES_BOOLEAN); - validators.put("sampleBlocks", new Validator("sampleBlocks").getObjectValidation(SampleBlockDefinitionModel.validators, true)); + Validator sampleValidator = new Validator("sampleBlocks"); + validators.put("sampleBlocks_rg", sampleValidator.getIfOtherFieldSet("generateSamples", sampleValidator.getRequiredObjectValidation(SampleBlockDefinitionModel.validators, true))); } public GeodeDepositConfigModel(List outerShellBlocks, List innerShellBlocks, List innerBlocks, List fillBlocks, List fillerTypes, List clusters, int chance, double crackChance, int minYLevel, int maxYLevel, String placement, String rarity, boolean generateSamples, List sampleBlocks) { diff --git a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/geode/GeodeDepositModel.java b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/geode/GeodeDepositModel.java index 799842f1..b8f65291 100644 --- a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/geode/GeodeDepositModel.java +++ b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/geode/GeodeDepositModel.java @@ -29,7 +29,7 @@ public String getType() { } public List getFillerTypes() { - if (config.fillerTypes.isEmpty()) throw new IllegalArgumentException("Filler Types for " + name + " cannot be empty."); +// if (config.fillerTypes.isEmpty()) throw new IllegalArgumentException("Filler Types for " + name + " cannot be empty."); return config.fillerTypes; } @@ -38,17 +38,17 @@ public List getClusters() { } public int getMaxYLevel() { - if (config.maxYLevel < -64 || config.maxYLevel > 320) throw new IllegalArgumentException("Max Y for " + name + " is out of Range [-64 - 320]"); +// if (config.maxYLevel < -64 || config.maxYLevel > 320) throw new IllegalArgumentException("Max Y for " + name + " is out of Range [-64 - 320]"); return config.maxYLevel; } public int getMinYLevel() { - if (config.minYLevel < -64 || config.minYLevel > 320) throw new IllegalArgumentException("Min Y for " + name + " is out of Range [-64 - 320]"); +// if (config.minYLevel < -64 || config.minYLevel > 320) throw new IllegalArgumentException("Min Y for " + name + " is out of Range [-64 - 320]"); return config.minYLevel; } public int getChance() { - if (config.chance < 1 || config.chance > 100) throw new IllegalArgumentException("Chance for " + name + " is out of Range [1 - 100]"); +// if (config.chance < 1 || config.chance > 100) throw new IllegalArgumentException("Chance for " + name + " is out of Range [1 - 100]"); return config.chance; } @@ -57,38 +57,39 @@ public int getPlacementChance() { } public double getCrackChance() { - if (config.crackChance < 0.0D || config.crackChance > 1.0D) throw new IllegalArgumentException("Crack Chance for " + name + " is out of Range [0.0 - 1.0]"); +// if (config.crackChance < 0.0D || config.crackChance > 1.0D) throw new IllegalArgumentException("Crack Chance for " + name + " is out of Range [0.0 - 1.0]"); return config.crackChance; } public List getOuterShellBlocks() { - if (config.outerShellBlocks.isEmpty()) throw new IllegalArgumentException("Outer Shell Blocks for " + name + " cannot be empty."); +// if (config.outerShellBlocks.isEmpty()) throw new IllegalArgumentException("Outer Shell Blocks for " + name + " cannot be empty."); return config.outerShellBlocks; } public List getInnerShellBlocks() { - if (config.innerShellBlocks.isEmpty()) throw new IllegalArgumentException("Inner Shell Blocks for " + name + " cannot be empty."); +// if (config.innerShellBlocks.isEmpty()) throw new IllegalArgumentException("Inner Shell Blocks for " + name + " cannot be empty."); return config.innerShellBlocks; } public List getInnerBlocks() { - if (config.innerBlocks.isEmpty()) throw new IllegalArgumentException("Inner Blocks for " + name + " cannot be empty."); +// if (config.innerBlocks.isEmpty()) throw new IllegalArgumentException("Inner Blocks for " + name + " cannot be empty."); return config.innerBlocks; } public List getFillBlocks() { // TODO: Check to see if this can be empty - if (config.fillBlocks.isEmpty()) throw new IllegalArgumentException("Fill Blocks for " + name + " cannot be empty."); + // NOTE: Currently checked if not empty in the validation step. See #218 *Kanzaji +// if (config.fillBlocks.isEmpty()) throw new IllegalArgumentException("Fill Blocks for " + name + " cannot be empty."); return config.fillBlocks; } public String getPlacement() { - if (!config.placement.equals("uniform") && !config.placement.equals("triangle")) throw new IllegalArgumentException("Placement for " + name + " is invalid."); +// if (!config.placement.equals("uniform") && !config.placement.equals("triangle")) throw new IllegalArgumentException("Placement for " + name + " is invalid."); return config.placement; } public String getRarity() { - if (!config.rarity.equals("common") && !config.rarity.equals("rare")) throw new IllegalArgumentException("Rarity for " + name + " is invalid."); +// if (!config.rarity.equals("common") && !config.rarity.equals("rare")) throw new IllegalArgumentException("Rarity for " + name + " is invalid."); return config.rarity; } @@ -97,7 +98,7 @@ public boolean hasSamples() { } public List getSampleBlocks() { - if (hasSamples() && config.sampleBlocks.isEmpty()) throw new IllegalArgumentException("Sample Blocks for " + name + " cannot be empty if generateSamples is set to true."); +// if (hasSamples() && config.sampleBlocks.isEmpty()) throw new IllegalArgumentException("Sample Blocks for " + name + " cannot be empty if generateSamples is set to true."); return config.sampleBlocks; } } diff --git a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/sample/SampleBlockDefinitionModel.java b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/sample/SampleBlockDefinitionModel.java index 674bd845..3b380490 100644 --- a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/sample/SampleBlockDefinitionModel.java +++ b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/sample/SampleBlockDefinitionModel.java @@ -12,7 +12,6 @@ import java.nio.file.Path; import java.util.LinkedHashMap; import java.util.Map; -import java.util.Objects; import java.util.Optional; import java.util.function.BiFunction; @@ -47,12 +46,14 @@ public class SampleBlockDefinitionModel { validators.put("strata_rg", (element, path) -> { if (!strataValidator.assertParentObject(element, path)) return false; JsonObject parent = element.getAsJsonObject(); - if (Objects.isNull(parent.get("material"))) { - Validator.LOGGER.warn( - "\"%s\" should not be present when specified sample is not material based in file \"%s\"." - .formatted(strataValidator.getName(), Validator.obfuscatePath(path)) - ); - } + + if (Validator.isOtherFieldPresent("material", parent)) + return strataValidator.getRequiredRegisteredIDValidation(DefaultConfigPlugin.STRATA_IDS, "Strata Registry", false).apply(parent.get(strataValidator.getName()), path); + + Validator.LOGGER.warn( + "\"%s\" should not be present when specified sample is not material based in file \"%s\"." + .formatted(strataValidator.getName(), Validator.obfuscatePath(path)) + ); return strataValidator.getRegisteredIDValidation(DefaultConfigPlugin.STRATA_IDS, "Strata Registry", false).apply(parent.get(strataValidator.getName()), path); }); } diff --git a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/sphere/SphereDepositConfigModel.java b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/sphere/SphereDepositConfigModel.java index 746e7983..a8158ff0 100644 --- a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/sphere/SphereDepositConfigModel.java +++ b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/sphere/SphereDepositConfigModel.java @@ -4,7 +4,6 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import com.ridanisaurus.emendatusenigmatica.loader.Validator; -import com.ridanisaurus.emendatusenigmatica.loader.deposit.model.DepositValidators; import com.ridanisaurus.emendatusenigmatica.loader.deposit.model.common.CommonBlockDefinitionModel; import com.ridanisaurus.emendatusenigmatica.loader.deposit.model.sample.SampleBlockDefinitionModel; import com.ridanisaurus.emendatusenigmatica.plugin.DefaultConfigPlugin; @@ -53,11 +52,12 @@ public class SphereDepositConfigModel { validators.put("chance", new Validator("chance").getRequiredIntRange(1, 100, false)); validators.put("radius", new Validator("radius").getRequiredIntRange(1, 16, false)); validators.put("minYLevel", new Validator("minYLevel").getRequiredIntRange(-64, 320, false)); - validators.put("maxYLevel_rg", DepositValidators.getMaxYLevelValidation(new Validator("maxYLevel"), "minYLevel")); + validators.put("maxYLevel_rg", new Validator("maxYLevel").getMaxYLevelValidation("minYLevel")); validators.put("placement", new Validator("placement").getAcceptsOnlyValidation(List.of("uniform", "triangle"), false)); validators.put("rarity", new Validator("rarity").getAcceptsOnlyValidation(List.of("common", "rare"), false)); validators.put("generateSamples",new Validator("generateSamples").REQUIRES_BOOLEAN); - validators.put("sampleBlocks", new Validator("sampleBlocks").getObjectValidation(SampleBlockDefinitionModel.validators, true)); + Validator sampleValidator = new Validator("sampleBlocks"); + validators.put("sampleBlocks_rg", sampleValidator.getIfOtherFieldSet("generateSamples", sampleValidator.getRequiredObjectValidation(SampleBlockDefinitionModel.validators, true))); } public SphereDepositConfigModel(List blocks, List fillerTypes, int chance, int radius, int minYLevel, int maxYLevel, String placement, String rarity, boolean generateSamples, List sampleBlocks) { diff --git a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/sphere/SphereDepositModel.java b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/sphere/SphereDepositModel.java index a71bf7f7..ac6c1ad3 100644 --- a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/sphere/SphereDepositModel.java +++ b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/sphere/SphereDepositModel.java @@ -29,7 +29,7 @@ public String getType() { } public int getChance() { - if (config.chance < 1 || config.chance > 100) throw new IllegalArgumentException("Chance for " + name + " is out of Range [1 - 100]"); +// if (config.chance < 1 || config.chance > 100) throw new IllegalArgumentException("Chance for " + name + " is out of Range [1 - 100]"); return config.chance; } @@ -38,37 +38,37 @@ public int getPlacementChance() { } public int getMaxYLevel() { - if (config.maxYLevel < -64 || config.maxYLevel > 320) throw new IllegalArgumentException("Max Y for " + name + " is out of Range [-64 - 320]"); +// if (config.maxYLevel < -64 || config.maxYLevel > 320) throw new IllegalArgumentException("Max Y for " + name + " is out of Range [-64 - 320]"); return config.maxYLevel; } public int getMinYLevel() { - if (config.minYLevel < -64 || config.minYLevel > 320) throw new IllegalArgumentException("Min Y for " + name + " is out of Range [-64 - 320]"); +// if (config.minYLevel < -64 || config.minYLevel > 320) throw new IllegalArgumentException("Min Y for " + name + " is out of Range [-64 - 320]"); return config.minYLevel; } public List getBlocks() { - if (config.blocks.isEmpty()) throw new IllegalArgumentException("Blocks for " + name + " cannot be empty."); +// if (config.blocks.isEmpty()) throw new IllegalArgumentException("Blocks for " + name + " cannot be empty."); return config.blocks; } public List getFillerTypes() { - if (config.fillerTypes.isEmpty()) throw new IllegalArgumentException("Filler Types for " + name + " cannot be empty."); +// if (config.fillerTypes.isEmpty()) throw new IllegalArgumentException("Filler Types for " + name + " cannot be empty."); return config.fillerTypes; } public int getRadius() { - if (config.radius < 1 || config.radius > 16) throw new IllegalArgumentException("Radius for " + name + " is out of Range [1 - 16]"); +// if (config.radius < 1 || config.radius > 16) throw new IllegalArgumentException("Radius for " + name + " is out of Range [1 - 16]"); return config.radius; } public String getPlacement() { - if (!config.placement.equals("uniform") && !config.placement.equals("triangle")) throw new IllegalArgumentException("Placement for " + name + " is invalid."); +// if (!config.placement.equals("uniform") && !config.placement.equals("triangle")) throw new IllegalArgumentException("Placement for " + name + " is invalid."); return config.placement; } public String getRarity() { - if (!config.rarity.equals("common") && !config.rarity.equals("rare")) throw new IllegalArgumentException("Rarity for " + name + " is invalid."); +// if (!config.rarity.equals("common") && !config.rarity.equals("rare")) throw new IllegalArgumentException("Rarity for " + name + " is invalid."); return config.rarity; } @@ -77,7 +77,7 @@ public boolean hasSamples() { } public List getSampleBlocks() { - if (hasSamples() && config.sampleBlocks.isEmpty()) throw new IllegalArgumentException("Sample Blocks for " + name + " cannot be empty if generateSamples is set to true."); +// if (hasSamples() && config.sampleBlocks.isEmpty()) throw new IllegalArgumentException("Sample Blocks for " + name + " cannot be empty if generateSamples is set to true."); return config.sampleBlocks; } } \ No newline at end of file diff --git a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/test/TestDepositConfigModel.java b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/test/TestDepositConfigModel.java index 85aa3d80..cffacb58 100644 --- a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/test/TestDepositConfigModel.java +++ b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/test/TestDepositConfigModel.java @@ -68,7 +68,7 @@ public class TestDepositConfigModel { validators.put("chance", new Validator("chance").getRequiredIntRange(1, 100, false)); validators.put("size", new Validator("size").getRequiredIntRange(1, Integer.MAX_VALUE, false)); validators.put("minYLevel", new Validator("minYLevel").getRequiredIntRange(-64, 320, false)); - validators.put("maxYLevel_rg", DepositValidators.getMaxYLevelValidation(new Validator("maxYLevel"), "minYLevel")); + validators.put("maxYLevel_rg", new Validator("maxYLevel").getMaxYLevelValidation("minYLevel")); } public TestDepositConfigModel(List blocks, List fillerTypes, int chance, int size, int minYLevel, int maxYLevel) { diff --git a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/vanilla/VanillaDepositConfigModel.java b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/vanilla/VanillaDepositConfigModel.java index d61beb69..6310eb1b 100644 --- a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/vanilla/VanillaDepositConfigModel.java +++ b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/vanilla/VanillaDepositConfigModel.java @@ -52,7 +52,7 @@ public class VanillaDepositConfigModel { validators.put("chance", new Validator("chance").getRequiredIntRange(1, 100, false)); validators.put("size", new Validator("size").getRequiredIntRange(1, 16, false)); validators.put("minYLevel", new Validator("minYLevel").getRequiredIntRange(-64, 320, false)); - validators.put("maxYLevel_rg", DepositValidators.getMaxYLevelValidation(new Validator("maxYLevel"), "minYLevel")); + validators.put("maxYLevel_rg", new Validator("maxYLevel").getMaxYLevelValidation("minYLevel")); validators.put("placement", new Validator("placement").getAcceptsOnlyValidation(List.of("uniform", "triangle"), false)); validators.put("rarity", new Validator("rarity").getAcceptsOnlyValidation(List.of("common", "rare"), false)); } diff --git a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/vanilla/VanillaDepositModel.java b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/vanilla/VanillaDepositModel.java index 9032bd6d..0e559b62 100644 --- a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/vanilla/VanillaDepositModel.java +++ b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/deposit/model/vanilla/VanillaDepositModel.java @@ -3,7 +3,6 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import com.ridanisaurus.emendatusenigmatica.loader.deposit.model.common.CommonDepositModelBase; -import com.ridanisaurus.emendatusenigmatica.loader.deposit.model.sample.SampleBlockDefinitionModel; import javax.annotation.Nullable; import java.util.List; @@ -17,7 +16,7 @@ public class VanillaDepositModel extends CommonDepositModelBase { VanillaDepositConfigModel.CODEC.fieldOf("config").forGetter(it -> it.config) ).apply(x, VanillaDepositModel::new)); - private VanillaDepositConfigModel config; + private final VanillaDepositConfigModel config; public VanillaDepositModel(String type, String dimension, List biomes, String name, VanillaDepositConfigModel config) { super(type, dimension, biomes, name); @@ -29,27 +28,27 @@ public String getType() { } public int getMinYLevel() { - if (config.minYLevel < -64 || config.minYLevel > 320) throw new IllegalArgumentException("Min Y for " + name + " is out of Range [-64 - 320]"); +// if (config.minYLevel < -64 || config.minYLevel > 320) throw new IllegalArgumentException("Min Y for " + name + " is out of Range [-64 - 320]"); return config.minYLevel; } public int getMaxYLevel() { - if (config.maxYLevel < -64 || config.maxYLevel > 320) throw new IllegalArgumentException("Max Y for " + name + " is out of Range [-64 - 320]"); +// if (config.maxYLevel < -64 || config.maxYLevel > 320) throw new IllegalArgumentException("Max Y for " + name + " is out of Range [-64 - 320]"); return config.maxYLevel; } public String getPlacement() { - if (!config.placement.equals("uniform") && !config.placement.equals("triangle")) throw new IllegalArgumentException("Placement for " + name + " contains an invalid option."); +// if (!config.placement.equals("uniform") && !config.placement.equals("triangle")) throw new IllegalArgumentException("Placement for " + name + " contains an invalid option."); return config.placement; } public String getRarity() { - if (!config.rarity.equals("common") && !config.rarity.equals("rare")) throw new IllegalArgumentException("Rarity for " + name + " contains an invalid option."); +// if (!config.rarity.equals("common") && !config.rarity.equals("rare")) throw new IllegalArgumentException("Rarity for " + name + " contains an invalid option."); return config.rarity; } public int getChance() { - if (config.chance < 1 || config.chance > 100) throw new IllegalArgumentException("Chance for " + name + " is out of Range [1 - 100]"); +// if (config.chance < 1 || config.chance > 100) throw new IllegalArgumentException("Chance for " + name + " is out of Range [1 - 100]"); return config.chance; } @@ -58,12 +57,12 @@ public int getPlacementChance() { } public int getSize() { - if (config.size < 1 || config.size > 16) throw new IllegalArgumentException("Size for " + name + " is out of Range [1 - 16]"); +// if (config.size < 1 || config.size > 16) throw new IllegalArgumentException("Size for " + name + " is out of Range [1 - 16]"); return config.size; } public List getFillerTypes() { - if (config.fillerTypes.isEmpty()) throw new IllegalArgumentException("Filler Types for " + name + " cannot be empty."); +// if (config.fillerTypes.isEmpty()) throw new IllegalArgumentException("Filler Types for " + name + " cannot be empty."); return config.fillerTypes; } diff --git a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/parser/model/CompatModel.java b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/parser/model/CompatModel.java index 17d837af..4bedac07 100644 --- a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/parser/model/CompatModel.java +++ b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/parser/model/CompatModel.java @@ -121,7 +121,7 @@ public static class CompatRecipesModel { validators.put("values_rg", (element_rg, path_rg) -> { if (!( valuesValidator.assertParentObject(element_rg, path_rg) && - valuesValidator.assertArray(element_rg.getAsJsonObject().get("values"), path_rg) + valuesValidator.NON_EMPTY_ARRAY_REQUIRED.apply(element_rg.getAsJsonObject().get("values"), path_rg) )) return false; JsonObject element = element_rg.getAsJsonObject(); @@ -248,36 +248,47 @@ public static class CompatValuesModel { if (!inputValidator.assertParentObject(element_rg, path)) return false; JsonObject element = element_rg.getAsJsonObject(); - //TODO: Should this be required when the material is alloy -> Mod Thermal -> Machine Induction Smelter? - if (Objects.isNull(element.get("input"))) return true; - if (LOGGER.shouldLog) { - JsonObject temp = element.get("TEMP").getAsJsonObject(); - String mod = temp.get("mod").getAsString(); - String machine = temp.get("machine").getAsString(); - String type = "NONE"; - - if (mod.equals("NONE")) LOGGER.warn("Mod is none! Can't accurately verify values of input for \"%s\"".formatted(Validator.obfuscatePath(path))); - if (machine.equals("NONE")) LOGGER.warn("Machine is none! Can't accurately verify values of input for \"%s\"".formatted(Validator.obfuscatePath(path))); - - try { - type = element.get("type").getAsString(); - } catch (ClassCastException e) { - LOGGER.error("Type is not a string! Can't accurately verify values of input for \"%s\".".formatted(Validator.obfuscatePath(path))); - } catch (NullPointerException e) { - LOGGER.warn("Type is null! Can't accurately verify values of input for \"%s\"".formatted(Validator.obfuscatePath(path))); - } + JsonObject temp = element.get("TEMP").getAsJsonObject(); + String mod = temp.get("mod").getAsString(); + String machine = temp.get("machine").getAsString(); + String type = "NONE"; + boolean required = true; + + if (mod.equals("NONE")) LOGGER.warn("Mod is none! Can't accurately verify values of input for \"%s\"".formatted(Validator.obfuscatePath(path))); + if (machine.equals("NONE")) LOGGER.warn("Machine is none! Can't accurately verify values of input for \"%s\"".formatted(Validator.obfuscatePath(path))); + try { + type = element.get("type").getAsString(); + } catch (ClassCastException e) { + LOGGER.error("Type is not a string! Can't accurately verify values of input for \"%s\".".formatted(Validator.obfuscatePath(path))); + } catch (NullPointerException e) { + LOGGER.warn("Type is null! Can't accurately verify values of input for \"%s\"".formatted(Validator.obfuscatePath(path))); + } - if (!mod.equals("thermal")) LOGGER.warn("Input should not be present when selected mod is different than thermal (Currently: %s). Found in file \"%s\".".formatted(mod, Validator.obfuscatePath(path))); - if (!machine.equals("induction_smelter")) LOGGER.warn("Input should not be present when selected machine is different than induction_smelter (Currently: %s). Found in file \"%s\".".formatted(machine, Validator.obfuscatePath(path))); - if (!type.equals("alloy")) LOGGER.warn("Input should not be present when selected type is different than alloy (Currently: %s). Found in file \"%s\".".formatted(type, Validator.obfuscatePath(path))); - element.get("input").getAsJsonArray().forEach(entry -> { - if (Objects.nonNull(entry.getAsJsonObject().get("chance"))) LOGGER.warn("Chance should not be present in input object! Found in file \"%s\".".formatted(Validator.obfuscatePath(path))); - }); + if (!mod.equals("thermal")) { + LOGGER.warn("Input should not be present when selected mod is different than thermal (Currently: %s). Found in file \"%s\".".formatted(mod, Validator.obfuscatePath(path))); + required = false; + } + if (!machine.equals("induction_smelter")) { + LOGGER.warn("Input should not be present when selected machine is different than induction_smelter (Currently: %s). Found in file \"%s\".".formatted(machine, Validator.obfuscatePath(path))); + required = false; + } + if (!type.equals("alloy")) { + LOGGER.warn("Input should not be present when selected type is different than alloy (Currently: %s). Found in file \"%s\".".formatted(type, Validator.obfuscatePath(path))); + required = false; } - return inputValidator.getObjectValidation(CompatIOModel.validators, true).apply(element.get("input"), path); + if (LOGGER.shouldLog) element.get("input").getAsJsonArray().forEach(entry -> { + if (Validator.isOtherFieldPresent("chance", entry.getAsJsonObject())) + LOGGER.warn("Chance should not be present in input object! Found in file \"%s\".".formatted(Validator.obfuscatePath(path))); + }); + + if (required) { + return inputValidator.getRequiredObjectValidation(CompatIOModel.validators, true).apply(element.get("input"), path); + } else { + return inputValidator.getObjectValidation(CompatIOModel.validators, true).apply(element.get("input"), path); + } }); validators.put("output", outputValidator.getObjectValidation(CompatIOModel.validators, true)); diff --git a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/parser/model/MaterialColorsModel.java b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/parser/model/MaterialColorsModel.java index 35244d72..3f8105f7 100644 --- a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/parser/model/MaterialColorsModel.java +++ b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/parser/model/MaterialColorsModel.java @@ -83,22 +83,23 @@ public class MaterialColorsModel { if (!gasValidator.assertParentObject(element, path)) return false; JsonObject obj = element.getAsJsonObject(); JsonElement valueJson = obj.get(gasValidator.getName()); - - if (!LOGGER.shouldLog || !Validator.checkForTEMP(obj, path, false)) { - LOGGER.warn( - "Parent data is missing while verifying \"%s\" in file \"%s\", something is not right." + Runnable warnValidation = () -> { + if (!Validator.checkForTEMP(obj, path, false)) { + LOGGER.warn( + "Parent data is missing while verifying \"%s\" in file \"%s\", something is not right." .formatted(gasValidator.getName(), Validator.obfuscatePath(path)) - ); - } else { + ); + return; + } JsonElement requiredJson = obj.get("TEMP").getAsJsonObject().get("processedTypes"); if (Objects.isNull(requiredJson)) { - LOGGER.warn("\"processedTypes\" are missing from file \"%s\". Can't accurately verify values of \"%s\"." - .formatted(Validator.obfuscatePath(path), gasValidator.getName()) - ); - } else if (!requiredJson.isJsonArray()) { - LOGGER.warn("Expected \"processedTypes\" to be an array! Can't accurately verify values of \"%s\" in file \"%s\".".formatted(gasValidator.getName(), Validator.obfuscatePath(path))); + LOGGER.warn("\"processedTypes\" are missing from file \"%s\". Can't accurately verify values of \"%s\".".formatted(Validator.obfuscatePath(path), gasValidator.getName())); + return; + } + if (!requiredJson.isJsonArray()) { + LOGGER.warn("Expected \"processedTypes\" to be an array! Can't accurately verify values of \"%s\" in file \"%s\".".formatted(gasValidator.getName(), Validator.obfuscatePath(path))); + return; } - JsonArray types = requiredJson.getAsJsonArray(); boolean infuse = types.contains(new JsonPrimitive("infuse_type")); boolean slurry = types.contains(new JsonPrimitive("slurry")); @@ -112,7 +113,9 @@ public class MaterialColorsModel { .formatted(gasValidator.getName(), Validator.obfuscatePath(path)) ); } - } + }; + + if (LOGGER.shouldLog) warnValidation.run(); return gasValidator.getHexColorValidation(false).apply(obj.get(gasValidator.getName()), path); }); @@ -121,40 +124,38 @@ public class MaterialColorsModel { if (!validator.assertParentObject(element, path)) return false; JsonObject obj = element.getAsJsonObject(); JsonElement valueJson = obj.get(validator.getName()); + Runnable warnValidation = () -> { + if (!Validator.checkForTEMP(obj, path, false)) { + LOGGER.warn("Parent data is missing while verifying \"%s\" in file \"%s\", something is not right.".formatted(validator.getName(), Validator.obfuscatePath(path))); + return; + } - if (!LOGGER.shouldLog || !Validator.checkForTEMP(obj, path, false)) { - LOGGER.warn("Parent data is missing while verifying \"%s\" in file \"%s\", something is not right.".formatted(validator.getName(), Validator.obfuscatePath(path))); - } else { JsonElement requiredJson = obj.get("TEMP").getAsJsonObject().get("properties"); - if (Objects.nonNull(requiredJson)) { - if (!requiredJson.isJsonObject()) { - LOGGER.warn("Expected \"properties\" to be an object! Can't accurately verify values of \"%s\" in file \"%s\"." - .formatted(validator.getName(), Validator.obfuscatePath(path)) + if (Objects.isNull(requiredJson)) return; + if (!requiredJson.isJsonObject()) { + LOGGER.warn("Expected \"properties\" to be an object! Can't accurately verify values of \"%s\" in file \"%s\".".formatted(validator.getName(), Validator.obfuscatePath(path))); + return; + } + + JsonElement requiredValue = requiredJson.getAsJsonObject().get(fieldName); + boolean required = false; + if (Objects.nonNull(requiredValue)) { + try { + required = requiredValue.getAsBoolean(); + } catch (Exception e) { + LOGGER.error("\"%s\" in Properties is not a boolean! Can't accurately verify values of \"%s\" in file \"%s\"." + .formatted(fieldName, validator.getName(), Validator.obfuscatePath(path)) ); - } else { - JsonElement requiredValue = requiredJson.getAsJsonObject().get(fieldName); - boolean required = false; - if (Objects.nonNull(requiredValue)) { - try { - required = requiredValue.getAsBoolean(); - } catch (Exception e) { - LOGGER.error("\"%s\" in Properties is not a boolean! Can't accurately verify values of \"%s\" in file \"%s\"." - .formatted(fieldName, validator.getName(), Validator.obfuscatePath(path)) - ); - } - } - if (Objects.nonNull(valueJson) && !required) { - LOGGER.warn("\"%s\" should not be present when \"%s\" is set to false in file \"%s\"." - .formatted(validator.getName(), fieldName, Validator.obfuscatePath(path)) - ); - } else if (Objects.isNull(valueJson) && required) { - LOGGER.warn("\"%s\" should be set when \"%s\" is set to true in file \"%s\"." - .formatted(validator.getName(), fieldName, Validator.obfuscatePath(path)) - ); - } } } - } + if (Objects.nonNull(valueJson) && !required) { + LOGGER.warn("\"%s\" should not be present when \"%s\" is set to false in file \"%s\".".formatted(validator.getName(), fieldName, Validator.obfuscatePath(path))); + } else if (Objects.isNull(valueJson) && required) { + LOGGER.warn("\"%s\" should be set when \"%s\" is set to true in file \"%s\".".formatted(validator.getName(), fieldName, Validator.obfuscatePath(path))); + } + }; + + if (LOGGER.shouldLog) warnValidation.run(); return validator.getHexColorValidation(false).apply(obj.get(gasValidator.getName()), path); }; diff --git a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/parser/model/MaterialPropertiesModel.java b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/parser/model/MaterialPropertiesModel.java index f0783fcf..8a1ba1f1 100644 --- a/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/parser/model/MaterialPropertiesModel.java +++ b/src/main/java/com/ridanisaurus/emendatusenigmatica/loader/parser/model/MaterialPropertiesModel.java @@ -159,9 +159,12 @@ public class MaterialPropertiesModel { try { if (!valueJson.isJsonPrimitive()) throw new ClassCastException(); double value = valueJson.getAsDouble(); - if (LOGGER.shouldLog && Math.ceil(value) > value) { - LOGGER.warn("\"%s\" in file \"%s\" should be an integer. Floating-point values are not supported for this field.".formatted(blockRecipeValidator.getName(), Validator.obfuscatePath(path))); + + if (Math.ceil(value) > value) { + LOGGER.error("\"%s\" in file \"%s\" has to be an integer. Floating-point values are not supported for this field.".formatted(blockRecipeValidator.getName(), Validator.obfuscatePath(path))); + return false; } + int val = Double.valueOf(value).intValue(); boolean validation = acceptedValues.contains(val); if (!validation) {