From 5ab05684f0fc00f5f54af75f04e62b992abda998 Mon Sep 17 00:00:00 2001 From: MightyKnight <38622942+MightyKnight@users.noreply.github.com> Date: Fri, 9 Dec 2022 17:14:17 +0100 Subject: [PATCH] Add #c:shields tag to default disabled items More compatibility with mods adding new shields (if they add shields to this tag) --- build.gradle | 6 ++--- .../heyzeer0/sd/configs/GeneralConfig.java | 25 ++++++++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index f663a5c..5d76d18 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java' - id 'fabric-loom' version '0.12-SNAPSHOT' + id 'fabric-loom' version '1.0-SNAPSHOT' } repositories { @@ -8,8 +8,8 @@ repositories { maven { url "https://maven.terraformersmc.com/releases/"} } -sourceCompatibility = JavaVersion.VERSION_1_8 -targetCompatibility = JavaVersion.VERSION_1_8 +sourceCompatibility = JavaVersion.VERSION_16 +targetCompatibility = JavaVersion.VERSION_16 group = project.maven_group version = "${project.mod_version}+${project.minecraft_version}" diff --git a/src/main/java/net/heyzeer0/sd/configs/GeneralConfig.java b/src/main/java/net/heyzeer0/sd/configs/GeneralConfig.java index cae0cbc..4e96ade 100644 --- a/src/main/java/net/heyzeer0/sd/configs/GeneralConfig.java +++ b/src/main/java/net/heyzeer0/sd/configs/GeneralConfig.java @@ -1,21 +1,27 @@ package net.heyzeer0.sd.configs; import me.shedaniel.autoconfig.ConfigData; +import me.shedaniel.autoconfig.annotation.ConfigEntry; import me.shedaniel.autoconfig.annotation.Config; import net.minecraft.item.Items; import net.minecraft.registry.Registries; import java.util.Arrays; import java.util.List; +import java.util.function.Predicate; @Config(name = "shieldisruptor_general") public class GeneralConfig implements ConfigData { + @ConfigEntry.Gui.Excluded + String modVersion = ""; + public boolean isEnabled = true; public List hiddenItems = Arrays.asList( Registries.ITEM.getId(Items.SHIELD).toString(), - Registries.ITEM.getId(Items.TOTEM_OF_UNDYING).toString()); + Registries.ITEM.getId(Items.TOTEM_OF_UNDYING).toString(), + "#c:shields"); // Ignore case and leading/trailing whitespaces when checking if entry is in config public boolean contains(String s) { @@ -27,4 +33,21 @@ public boolean contains(String s) { return false; } + @Override + public void validatePostLoad() throws ValidationException { + + // Upgrade from <=1.4.0, adding new tag "#c:shields" + if(modVersion == "") { + if(!hiddenItems.contains("#c:shields")) { + hiddenItems.add("#c:shields"); + } + modVersion = "1.5.0"; + } + + // Remove empty list items and trim strings + hiddenItems.removeIf(String::isBlank); + hiddenItems.replaceAll(String::trim); + + ConfigData.super.validatePostLoad(); + } }