From ec64280f6ef9f2e353a199211af30b9e3fb89fe5 Mon Sep 17 00:00:00 2001 From: Crystal Spider Date: Wed, 10 Jul 2024 12:02:36 +0200 Subject: [PATCH] Port to 1.21 --- CHANGELOG.md | 5 +- README.md | 11 +- .../src/main/groovy/multiloader-common.gradle | 7 - common/build.gradle | 1 - .../soul_fire_d/CommonModLoader.java | 11 +- .../soul_fire_d/config/ModConfig.java | 205 ------------------ fabric/build.gradle | 1 - .../handler/LootTableEventsHandler.java | 8 +- fabric/src/main/resources/fabric.mod.json | 5 +- gradle.properties | 1 - .../soul_fire_d/loot/ChestLootModifier.java | 13 +- .../bastion_other_loot_modifier.json | 2 +- 12 files changed, 24 insertions(+), 246 deletions(-) delete mode 100644 common/src/main/java/it/crystalnest/soul_fire_d/config/ModConfig.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 5269f4ee..3e2d5b37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,9 @@ and this project adheres to [Crystal Nest Semantic Versioning](https://crystalne ## [Unreleased] -[//]: # (- Nothing new.) +- Nothing new. -[//]: # (## [5.0.0] - 2024/07/dd) +## [5.0.0] - 2024/07/10 - Ported to 1.21 - Dropped support for Forge. @@ -18,6 +18,7 @@ and this project adheres to [Crystal Nest Semantic Versioning](https://crystalne - Added new exclusive_set tags to easily add enchantment exclusion with other custom fire aspect and flame enchantments. - DDFires can now support enchantments (as enchantments are now separated from Fire instances and are server sided). - Added new Ignite EnchantmentEntityEffect to ignite while setting a fire type. +- Removed mod configuration, and FCAP dependency, since now enchantment configuration needs to be done via data pack. - Added support for upside down english and shakespearean english. - Removed mixins related to handling enchantment effects. - Added new fire property for the campfire damage source. diff --git a/README.md b/README.md index 17571b12..aca768e5 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,8 @@ This mod makes Soul Fire actually work as one would expect, all whilst providing ![Arrows](https://raw.githubusercontent.com/crystal-nest/mod-fancy-assets/main/soul-fire-d/arrow.gif) - **Two new enchantments: Soul Fire Aspect and Soul Flame.** As their name suggests, they work exactly the same as Fire Aspect and Flame with the only difference being the kind of fire the target will burn from, with the consequent damage increase. - Both these enchantments can be highly configured individually, enabling (default) or disabling them and more. + Both these enchantments can be highly configured individually, enabling (default) or disabling them and more. + *Configuration is done via data pack since `1.21`* - **API for custom fire types:** For mod/datapack creators who want to add their own custom fire(s), or implement another mod's fire, this mod provides an *easy-to-use* API to register your fire(s) and have it(them) behave consistently **automatically**. Furthermore for each new fire registered using this API there can be new custom Fire Aspect and Flame enchantments available in game **automatically**. @@ -50,10 +51,10 @@ If you want your mod to appear in this list, open an issue [here](https://github ## **Dependencies** -| Mod | Loader | Requirement | -|:------------------------------------------------------------------------|:----------------------:|:-----------:| -| [Cobweb](https://modrinth.com/mod/cobweb) | All | Required | -| [Forge Config API Port](https://modrinth.com/mod/forge-config-api-port) | Fabric; Forge ≥ 1.20.2 | Required | +| Mod | Loader | Requirement | +|:------------------------------------------------------------------------|:-----------------------------:|:-----------:| +| [Cobweb](https://modrinth.com/mod/cobweb) | All | Required | +| [Forge Config API Port](https://modrinth.com/mod/forge-config-api-port) | Fabric < 1.21; Forge ≥ 1.20.2 | Required | ## **License and right of use** diff --git a/buildSrc/src/main/groovy/multiloader-common.gradle b/buildSrc/src/main/groovy/multiloader-common.gradle index 2aaa900c..52a8cd7e 100644 --- a/buildSrc/src/main/groovy/multiloader-common.gradle +++ b/buildSrc/src/main/groovy/multiloader-common.gradle @@ -48,10 +48,6 @@ repositories { name = "Crystal Nest" url = "https://maven.crystalnest.it" } - maven { - name = "Fuzs Mod Resources" - url = "https://raw.githubusercontent.com/Fuzss/modresources/main/maven/" - } } if (name != "fabric") { @@ -119,7 +115,6 @@ processResources { "neoforge_version" : neoforge_version, "neoforge_loader_version_range": neoforge_loader_version_range, "cobweb_version" : cobweb_version, - "fcap_version" : fcap_version, ] filesMatching(["pack.mcmeta", "fabric.mod.json", "META-INF/neoforge.mods.toml", "*.mixins.json"]) { expand expandProps @@ -221,7 +216,6 @@ publisher { switch (loader) { case "Fabric": required "fabric-api" - required "forge-config-api-port" break case "NeoForge": break @@ -232,7 +226,6 @@ publisher { switch (loader) { case "Fabric": required "fabric-api" - required "forge-config-api-port-fabric" break case "NeoForge": break diff --git a/common/build.gradle b/common/build.gradle index 5ff31089..46197865 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -19,7 +19,6 @@ dependencies { compileOnly group: "org.spongepowered", name: "mixin", version: "0.8.5" compileOnly group: "io.github.llamalad7", name: "mixinextras-common", version: "0.3.5" annotationProcessor group: "io.github.llamalad7", name: "mixinextras-common", version: "0.3.5" - implementation "fuzs.forgeconfigapiport:forgeconfigapiport-common-neoforgeapi:$fcap_version" } configurations { diff --git a/common/src/main/java/it/crystalnest/soul_fire_d/CommonModLoader.java b/common/src/main/java/it/crystalnest/soul_fire_d/CommonModLoader.java index 0232c771..f2559a99 100644 --- a/common/src/main/java/it/crystalnest/soul_fire_d/CommonModLoader.java +++ b/common/src/main/java/it/crystalnest/soul_fire_d/CommonModLoader.java @@ -2,7 +2,6 @@ import it.crystalnest.soul_fire_d.api.FireManager; import it.crystalnest.soul_fire_d.api.enchantment.EnchantmentRegistry; -import it.crystalnest.soul_fire_d.config.ModConfig; import it.crystalnest.soul_fire_d.platform.Services; import org.jetbrains.annotations.ApiStatus; @@ -11,21 +10,13 @@ */ @ApiStatus.Internal public final class CommonModLoader { - static { - FireManager.registerFire(FireManager.fireBuilder(FireManager.SOUL_FIRE_TYPE) - .setLight(10) - .setDamage(2) - .build() - ); - } - private CommonModLoader() {} /** * Initialize common operations across loaders. */ public static void init() { - ModConfig.CONFIG.register(); + FireManager.registerFire(FireManager.fireBuilder(FireManager.SOUL_FIRE_TYPE).setLight(10).setDamage(2).build()); Services.NETWORK.register(); EnchantmentRegistry.register(); } diff --git a/common/src/main/java/it/crystalnest/soul_fire_d/config/ModConfig.java b/common/src/main/java/it/crystalnest/soul_fire_d/config/ModConfig.java deleted file mode 100644 index a230e8d6..00000000 --- a/common/src/main/java/it/crystalnest/soul_fire_d/config/ModConfig.java +++ /dev/null @@ -1,205 +0,0 @@ -package it.crystalnest.soul_fire_d.config; - -import it.crystalnest.cobweb.api.config.CommonConfig; -import it.crystalnest.soul_fire_d.Constants; -import net.neoforged.neoforge.common.ModConfigSpec; -import org.jetbrains.annotations.ApiStatus; - -/** - * Mod common configuration. - */ -@ApiStatus.Internal -public final class ModConfig extends CommonConfig { - /** - * Mod common configuration. - */ - public static final ModConfig CONFIG = register(Constants.MOD_ID, ModConfig::new); - - /** - * Soul fire aspect enchantment name. - */ - private static final String SOUL_FIRE_ASPECT = "Soul Fire Aspect"; - - /** - * Soul flame enchantment name. - */ - private static final String SOUL_FLAME = "Soul Flame"; - - /** - * Whether to enable Soul Fire Aspect enchantment. - */ - private ModConfigSpec.BooleanValue enableSoulFireAspect; - - /** - * Whether Soul Fire Aspect can appear in the enchanting table and loots. - */ - private ModConfigSpec.BooleanValue enableSoulFireAspectDiscovery; - - /** - * Whether Soul Fire Aspect can be traded with villagers. - */ - private ModConfigSpec.BooleanValue enableSoulFireAspectTrades; - - /** - * Whether Soul Fire Aspect is a treasure enchantment (like Vanilla Mending). - */ - private ModConfigSpec.BooleanValue enableSoulFireAspectTreasure; - - /** - * Whether to enable Soul Flame enchantment. - */ - private ModConfigSpec.BooleanValue enableSoulFlame; - - /** - * Whether Soul Flame can appear in the enchanting table and loots. - */ - private ModConfigSpec.BooleanValue enableSoulFlameDiscovery; - - /** - * Whether Soul Flame can be traded with villagers. - */ - private ModConfigSpec.BooleanValue enableSoulFlameTrades; - - /** - * Whether Soul Flame is a treasure enchantment (like Vanilla Mending). - */ - private ModConfigSpec.BooleanValue enableSoulFlameTreasure; - - /** - * @param builder configuration builder. - */ - private ModConfig(ModConfigSpec.Builder builder) { - super(builder); - } - - /** - * Returns the value of {@link #enableSoulFireAspect} as read from the configuration file. - * - * @return the value of {@link #enableSoulFireAspect} as read from the configuration file. - */ - public static Boolean getEnableSoulFireAspect() { - return CONFIG.enableSoulFireAspect.get(); - } - - /** - * Returns the value of {@link #enableSoulFireAspectDiscovery} as read from the configuration file. - * - * @return the value of {@link #enableSoulFireAspectDiscovery} as read from the configuration file. - */ - public static Boolean getEnableSoulFireAspectDiscovery() { - return CONFIG.enableSoulFireAspectDiscovery.get(); - } - - /** - * Returns the value of {@link #enableSoulFireAspectTrades} as read from the configuration file. - * - * @return the value of {@link #enableSoulFireAspectTrades} as read from the configuration file. - */ - public static Boolean getEnableSoulFireAspectTrades() { - return CONFIG.enableSoulFireAspectTrades.get(); - } - - /** - * Returns the value of {@link #enableSoulFireAspectTreasure} as read from the configuration file. - * - * @return the value of {@link #enableSoulFireAspectTreasure} as read from the configuration file. - */ - public static Boolean getEnableSoulFireAspectTreasure() { - return CONFIG.enableSoulFireAspectTreasure.get(); - } - - /** - * Returns the value of {@link #enableSoulFlame} as read from the configuration file. - * - * @return the value of {@link #enableSoulFlame} as read from the configuration file. - */ - public static Boolean getEnableSoulFlame() { - return CONFIG.enableSoulFlame.get(); - } - - /** - * Returns the value of {@link #enableSoulFlameDiscovery} as read from the configuration file. - * - * @return the value of {@link #enableSoulFlameDiscovery} as read from the configuration file. - */ - public static Boolean getEnableSoulFlameDiscovery() { - return CONFIG.enableSoulFlameDiscovery.get(); - } - - /** - * Returns the value of {@link #enableSoulFlameTrades} as read from the configuration file. - * - * @return the value of {@link #enableSoulFlameTrades} as read from the configuration file. - */ - public static Boolean getEnableSoulFlameTrades() { - return CONFIG.enableSoulFlameTrades.get(); - } - - /** - * Returns the value of {@link #enableSoulFlameTreasure} as read from the configuration file. - * - * @return the value of {@link #enableSoulFlameTreasure} as read from the configuration file. - */ - public static Boolean getEnableSoulFlameTreasure() { - return CONFIG.enableSoulFlameTreasure.get(); - } - - /** - * Defines the general enable flag for the specified enchantment. - * - * @param builder configuration builder. - * @param enchantment enchantment name. - * @return defined configuration property. - */ - private static ModConfigSpec.BooleanValue defineEnableEnchantment(ModConfigSpec.Builder builder, String enchantment) { - return builder.comment(" Whether to enable " + enchantment + " enchantment.", " Takes precedence over all other " + enchantment + " configs.").define("enable " + enchantment.toLowerCase(), true); - } - - /** - * Defined the enable treasure flag for the specified enchantment. - * - * @param builder configuration builder. - * @param enchantment enchantment name. - * @return defined configuration property. - */ - private static ModConfigSpec.BooleanValue defineEnableTreasure(ModConfigSpec.Builder builder, String enchantment) { - return builder.comment( - " Whether " + enchantment + " cannot appear in the enchanting table.", - " If enabled along with [enable " + enchantment.toLowerCase() + " discovery], the enchantment won't appear in the enchanting table, but can still be found in loots." - ).define("enable " + enchantment.toLowerCase() + " treasure", false); - } - - /** - * Defined the enable discovery flag for the specified enchantment. - * - * @param builder configuration builder. - * @param enchantment enchantment name. - * @return defined configuration property. - */ - private static ModConfigSpec.BooleanValue defineEnableDiscovery(ModConfigSpec.Builder builder, String enchantment) { - return builder.comment(" Whether " + enchantment + " can appear in the enchanting table and loots.", " [enable " + enchantment + " treasure] takes precedence.").define("enable " + enchantment + " discovery", true); - } - - /** - * Defined the enable trades flag for the specified enchantment. - * - * @param builder configuration builder. - * @param enchantment enchantment name. - * @return defined configuration property. - */ - private static ModConfigSpec.BooleanValue defineEnableTrades(ModConfigSpec.Builder builder, String enchantment) { - return builder.comment(" Whether " + enchantment + " can be found in villager trades.").define("enable " + enchantment + " trades", true); - } - - @Override - protected void define(ModConfigSpec.Builder builder) { - enableSoulFireAspect = defineEnableEnchantment(builder, SOUL_FIRE_ASPECT); - enableSoulFireAspectTreasure = defineEnableTreasure(builder, SOUL_FIRE_ASPECT); - enableSoulFireAspectDiscovery = defineEnableDiscovery(builder, SOUL_FIRE_ASPECT); - enableSoulFireAspectTrades = defineEnableTrades(builder, SOUL_FIRE_ASPECT); - enableSoulFlame = defineEnableEnchantment(builder, SOUL_FLAME); - enableSoulFlameTreasure = defineEnableTreasure(builder, SOUL_FLAME); - enableSoulFlameDiscovery = defineEnableDiscovery(builder, SOUL_FLAME); - enableSoulFlameTrades = defineEnableTrades(builder, SOUL_FLAME); - } -} diff --git a/fabric/build.gradle b/fabric/build.gradle index 4ff824fc..e7e35abf 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -12,7 +12,6 @@ dependencies { modImplementation "net.fabricmc:fabric-loader:$fabric_loader_version" modImplementation "net.fabricmc.fabric-api:fabric-api:$fabric_version" modImplementation "it.crystalnest:cobweb-$name:$minecraft_version-$cobweb_version" - modImplementation "fuzs.forgeconfigapiport:forgeconfigapiport-fabric:$fcap_version" } loom { diff --git a/fabric/src/main/java/it/crystalnest/soul_fire_d/handler/LootTableEventsHandler.java b/fabric/src/main/java/it/crystalnest/soul_fire_d/handler/LootTableEventsHandler.java index db458c10..c7efb7b7 100644 --- a/fabric/src/main/java/it/crystalnest/soul_fire_d/handler/LootTableEventsHandler.java +++ b/fabric/src/main/java/it/crystalnest/soul_fire_d/handler/LootTableEventsHandler.java @@ -1,13 +1,14 @@ package it.crystalnest.soul_fire_d.handler; -import it.crystalnest.soul_fire_d.config.ModConfig; import net.fabricmc.fabric.api.loot.v3.LootTableEvents; import net.fabricmc.fabric.api.loot.v3.LootTableSource; +import net.minecraft.core.Holder; import net.minecraft.core.HolderLookup; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Items; +import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.level.storage.loot.LootPool; import net.minecraft.world.level.storage.loot.LootTable; import net.minecraft.world.level.storage.loot.entries.LootItem; @@ -35,13 +36,14 @@ private LootTableEventsHandler() {} * @param source loot table source. */ public static void handle(ResourceKey key, LootTable.Builder builder, LootTableSource source, HolderLookup.Provider provider) { - if (ModConfig.getEnableSoulFlame() && key.location().equals(BASTION_CHEST_IDENTIFIER)) { + Holder.Reference soulFlame = provider.lookupOrThrow(Registries.ENCHANTMENT).getOrThrow(ResourceKey.create(Registries.ENCHANTMENT, ResourceLocation.withDefaultNamespace("soul_flame"))); + if (soulFlame.value().getSupportedItems().size() > 0 && key.location().equals(BASTION_CHEST_IDENTIFIER)) { builder.pool( LootPool.lootPool() .setRolls(ConstantValue.exactly(1)) .conditionally(LootItemRandomChanceCondition.randomChance(0.05F).build()) .with(LootItem.lootTableItem(Items.BOOK).build()) - .apply(new EnchantRandomlyFunction.Builder().withEnchantment(provider.lookupOrThrow(Registries.ENCHANTMENT).getOrThrow(ResourceKey.create(Registries.ENCHANTMENT, ResourceLocation.withDefaultNamespace("soul_flame"))))) + .apply(new EnchantRandomlyFunction.Builder().withEnchantment(soulFlame)) .apply(SetItemCountFunction.setCount(ConstantValue.exactly(1))) .build() ); diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 17371f2c..7b1ad31e 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -32,8 +32,7 @@ "fabricloader": ">=${fabric_loader_version}", "fabric-api": "*", "minecraft": "${minecraft_version}", - "java": ">=17", - "cobweb": "^${cobweb_version}", - "forgeconfigapiport": "~${fcap_version}" + "java": ">=${java_version}", + "cobweb": "^${cobweb_version}" } } diff --git a/gradle.properties b/gradle.properties index d35bc185..5f65aff5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,7 +30,6 @@ neoforge_loader_version_range = [21.0,) # Dependencies cobweb_version = 1.0.0 -fcap_version = 21.0.1 # Gradle org.gradle.jvmargs = -Xmx4G diff --git a/neoforge/src/main/java/it/crystalnest/soul_fire_d/loot/ChestLootModifier.java b/neoforge/src/main/java/it/crystalnest/soul_fire_d/loot/ChestLootModifier.java index 0716966c..7f173cbf 100644 --- a/neoforge/src/main/java/it/crystalnest/soul_fire_d/loot/ChestLootModifier.java +++ b/neoforge/src/main/java/it/crystalnest/soul_fire_d/loot/ChestLootModifier.java @@ -4,7 +4,6 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import it.crystalnest.soul_fire_d.config.ModConfig; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.minecraft.core.Holder; import net.minecraft.world.item.EnchantedBookItem; @@ -50,7 +49,7 @@ private ChestLootModifier(LootItemCondition[] conditionsIn, List addit @Nonnull protected ObjectArrayList doApply(@NotNull ObjectArrayList generatedLoot, @NotNull LootContext context) { for (Addition addition : additions) { - if (ModConfig.getEnableSoulFlame() && context.getRandom().nextFloat() <= addition.chance) { + if (addition.enchantment.value().getSupportedItems().size() > 0 && context.getRandom().nextFloat() <= addition.chance) { generatedLoot.add(addition.getEnchantedBook()); } } @@ -92,12 +91,12 @@ private static final class Addition { private final Integer level; /** - * @param item item. - * @param chance chance to add the item. - * @param quantity item quantity. + * @param enchantment enchantment. + * @param chance chance to add the enchantment. + * @param quantity enchantment quantity. */ - private Addition(Holder item, Float chance, Integer quantity) { - this.enchantment = item; + private Addition(Holder enchantment, Float chance, Integer quantity) { + this.enchantment = enchantment; this.chance = chance; this.level = quantity; } diff --git a/neoforge/src/main/resources/data/soul_fire_d/loot_modifiers/bastion_other_loot_modifier.json b/neoforge/src/main/resources/data/soul_fire_d/loot_modifiers/bastion_other_loot_modifier.json index 4aea66af..3f7446ed 100644 --- a/neoforge/src/main/resources/data/soul_fire_d/loot_modifiers/bastion_other_loot_modifier.json +++ b/neoforge/src/main/resources/data/soul_fire_d/loot_modifiers/bastion_other_loot_modifier.json @@ -10,7 +10,7 @@ { "enchantment": "minecraft:soul_flame", "level": 1, - "chance": 1 + "chance": 0.05 } ] } \ No newline at end of file