From cca2806963ed8a434c5fb1325d53f7780fc837a4 Mon Sep 17 00:00:00 2001 From: Crystal Spider Date: Fri, 17 Nov 2023 15:52:30 +0100 Subject: [PATCH] [FF]: Add new tweaking enchantment option and fix modIds getter. --- fabric/build.gradle | 4 ++ fabric/gradle.properties | 4 +- ...ClientLoader.java => ClientModLoader.java} | 2 +- .../{SoulFiredLoader.java => ModLoader.java} | 30 +++++----- .../soulfired/api/FireManager.java | 2 +- .../api/enchantment/FireAspectBuilder.java | 2 +- .../enchantment/FireEnchantmentBuilder.java | 30 ++++++++++ .../FireTypedFireAspectEnchantment.java | 30 ++++++++-- .../FireTypedFlameEnchantment.java | 29 +++++++++- .../api/enchantment/FlameBuilder.java | 2 +- .../api/type/FireTypedEnchantment.java | 18 ++++++ .../soulfired/api/type/TriFunction.java | 50 +++++++++++++++++ .../soulfired/config/ModConfig.java | 2 +- .../FireResourceReloadListener.java | 12 ++-- .../LootTableEventsHandler.java | 6 +- .../PersistentProjectileEntityMixin.java | 13 ++++- .../soulfired/network/SoulFiredNetwork.java | 8 +-- fabric/src/main/resources/fabric.mod.json | 7 ++- .../main/resources/soulfired.accesswidener | 2 + forge/build.gradle | 2 +- forge/gradle.properties | 4 +- .../{SoulFiredLoader.java => ModLoader.java} | 36 ++++++------ .../crystalspider/soulfired/api/Fire.java | 14 ++--- .../soulfired/api/FireBuilder.java | 11 ++-- .../soulfired/api/FireManager.java | 10 ++-- .../api/enchantment/FireAspectBuilder.java | 6 +- .../enchantment/FireEnchantmentBuilder.java | 55 ++++++++++++++++++- .../FireTypedFireAspectEnchantment.java | 31 +++++++++-- .../FireTypedFlameEnchantment.java | 30 ++++++++-- .../api/enchantment/FlameBuilder.java | 6 +- .../api/type/FireTypedEnchantment.java | 18 ++++++ .../soulfired/api/type/TriFunction.java | 50 +++++++++++++++++ .../soulfired/config/ModConfig.java | 2 +- .../DatapacksEventHandler.java | 12 ++-- .../FMLClientSetupEventHandler.java | 5 +- .../handlers/RegistryEventHandler.java | 36 ------------ .../soulfired/loot/ChestLootModifier.java | 4 +- .../mixin/AbstractArrowEntityMixin.java | 13 ++++- .../soulfired/network/SoulFiredNetwork.java | 6 +- .../resources/META-INF/accesstransformer.cfg | 1 + 40 files changed, 450 insertions(+), 155 deletions(-) rename fabric/src/main/java/crystalspider/soulfired/{SoulFiredClientLoader.java => ClientModLoader.java} (85%) rename fabric/src/main/java/crystalspider/soulfired/{SoulFiredLoader.java => ModLoader.java} (50%) create mode 100644 fabric/src/main/java/crystalspider/soulfired/api/type/FireTypedEnchantment.java create mode 100644 fabric/src/main/java/crystalspider/soulfired/api/type/TriFunction.java rename forge/src/main/java/crystalspider/soulfired/config/SoulFiredConfig.java => fabric/src/main/java/crystalspider/soulfired/config/ModConfig.java (99%) rename fabric/src/main/java/crystalspider/soulfired/{handlers => handler}/FireResourceReloadListener.java (93%) rename fabric/src/main/java/crystalspider/soulfired/{handlers => handler}/LootTableEventsHandler.java (90%) create mode 100644 fabric/src/main/resources/soulfired.accesswidener rename forge/src/main/java/crystalspider/soulfired/{SoulFiredLoader.java => ModLoader.java} (62%) create mode 100644 forge/src/main/java/crystalspider/soulfired/api/type/FireTypedEnchantment.java create mode 100644 forge/src/main/java/crystalspider/soulfired/api/type/TriFunction.java rename fabric/src/main/java/crystalspider/soulfired/config/SoulFiredConfig.java => forge/src/main/java/crystalspider/soulfired/config/ModConfig.java (99%) rename forge/src/main/java/crystalspider/soulfired/{handlers => handler}/DatapacksEventHandler.java (92%) rename forge/src/main/java/crystalspider/soulfired/{handlers => handler}/FMLClientSetupEventHandler.java (84%) delete mode 100644 forge/src/main/java/crystalspider/soulfired/handlers/RegistryEventHandler.java create mode 100644 forge/src/main/resources/META-INF/accesstransformer.cfg diff --git a/fabric/build.gradle b/fabric/build.gradle index 41c7a98..db91542 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -12,6 +12,10 @@ archivesBaseName = modid version = "${minecraft_version}-${mod_version}-${loader.toLowerCase()}" group = project.group +loom { + accessWidenerPath = file("src/main/resources/${modid}.accesswidener") +} + repositories { maven { name = "Fuzs Mod Resources" diff --git a/fabric/gradle.properties b/fabric/gradle.properties index 181c2e9..6b9a555 100644 --- a/fabric/gradle.properties +++ b/fabric/gradle.properties @@ -12,7 +12,7 @@ org.gradle.daemon = false # Mod Properties mod_title = Soul fire'd - mod_version = 3.2.0.1 + mod_version = 3.2.1.0 author = Crystal Spider group = crystalspider modid = soulfired @@ -25,4 +25,4 @@ org.gradle.daemon = false # Miscellaneous github_user = Nyphet curseforge_id = 662413 - api_keys = {} \ No newline at end of file + api_keys = {} diff --git a/fabric/src/main/java/crystalspider/soulfired/SoulFiredClientLoader.java b/fabric/src/main/java/crystalspider/soulfired/ClientModLoader.java similarity index 85% rename from fabric/src/main/java/crystalspider/soulfired/SoulFiredClientLoader.java rename to fabric/src/main/java/crystalspider/soulfired/ClientModLoader.java index c096fe8..806018b 100644 --- a/fabric/src/main/java/crystalspider/soulfired/SoulFiredClientLoader.java +++ b/fabric/src/main/java/crystalspider/soulfired/ClientModLoader.java @@ -8,7 +8,7 @@ /** * Soul fire'd mod client loader. */ -public final class SoulFiredClientLoader implements ClientModInitializer { +public final class ClientModLoader implements ClientModInitializer { @Override public void onInitializeClient() { FireClientManager.registerFires(FireManager.getFires()); diff --git a/fabric/src/main/java/crystalspider/soulfired/SoulFiredLoader.java b/fabric/src/main/java/crystalspider/soulfired/ModLoader.java similarity index 50% rename from fabric/src/main/java/crystalspider/soulfired/SoulFiredLoader.java rename to fabric/src/main/java/crystalspider/soulfired/ModLoader.java index 1dd63a1..196b1fa 100644 --- a/fabric/src/main/java/crystalspider/soulfired/SoulFiredLoader.java +++ b/fabric/src/main/java/crystalspider/soulfired/ModLoader.java @@ -1,44 +1,44 @@ package crystalspider.soulfired; import crystalspider.soulfired.api.FireManager; -import crystalspider.soulfired.config.SoulFiredConfig; -import crystalspider.soulfired.handlers.FireResourceReloadListener; -import crystalspider.soulfired.handlers.LootTableEventsHandler; +import crystalspider.soulfired.config.ModConfig; +import crystalspider.soulfired.handler.FireResourceReloadListener; +import crystalspider.soulfired.handler.LootTableEventsHandler; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.loot.v1.event.LootTableLoadingCallback; -import net.minecraftforge.api.ModLoadingContext; import net.fabricmc.fabric.api.resource.ResourceManagerHelper; import net.minecraft.resource.ResourceType; +import net.minecraftforge.api.ModLoadingContext; import net.minecraftforge.fml.config.ModConfig.Type; /** * Soul fire'd mod loader. */ -public final class SoulFiredLoader implements ModInitializer { +public final class ModLoader implements ModInitializer { /** * ID of this mod. */ - public static final String MODID = "soulfired"; + public static final String MOD_ID = "soulfired"; @Override public void onInitialize() { - ModLoadingContext.registerConfig(MODID, Type.COMMON, SoulFiredConfig.SPEC); + ModLoadingContext.registerConfig(MOD_ID, Type.COMMON, ModConfig.SPEC); LootTableLoadingCallback.EVENT.register(LootTableEventsHandler::handle); ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new FireResourceReloadListener()); FireManager.registerFire( FireManager.fireBuilder(FireManager.SOUL_FIRE_TYPE) .setDamage(2) .setFireAspectConfig(builder -> builder - .setEnabled(SoulFiredConfig::getEnableSoulFireAspect) - .setIsDiscoverable(SoulFiredConfig::getEnableSoulFireAspectDiscovery) - .setIsTradeable(SoulFiredConfig::getEnableSoulFireAspectTrades) - .setIsTreasure(SoulFiredConfig::getEnableSoulFireAspectTreasure) + .setEnabled(ModConfig::getEnableSoulFireAspect) + .setIsDiscoverable(ModConfig::getEnableSoulFireAspectDiscovery) + .setIsTradeable(ModConfig::getEnableSoulFireAspectTrades) + .setIsTreasure(ModConfig::getEnableSoulFireAspectTreasure) ) .setFlameConfig(builder -> builder - .setEnabled(SoulFiredConfig::getEnableSoulFlame) - .setIsDiscoverable(SoulFiredConfig::getEnableSoulFlameDiscovery) - .setIsTradeable(SoulFiredConfig::getEnableSoulFlameTrades) - .setIsTreasure(SoulFiredConfig::getEnableSoulFlameTreasure) + .setEnabled(ModConfig::getEnableSoulFlame) + .setIsDiscoverable(ModConfig::getEnableSoulFlameDiscovery) + .setIsTradeable(ModConfig::getEnableSoulFlameTrades) + .setIsTreasure(ModConfig::getEnableSoulFlameTreasure) ) .build() ); diff --git a/fabric/src/main/java/crystalspider/soulfired/api/FireManager.java b/fabric/src/main/java/crystalspider/soulfired/api/FireManager.java index f987537..04f5618 100644 --- a/fabric/src/main/java/crystalspider/soulfired/api/FireManager.java +++ b/fabric/src/main/java/crystalspider/soulfired/api/FireManager.java @@ -375,7 +375,7 @@ public static List getFireIds() { * @return the list of all registered mod ids. */ public static List getModIds() { - return fires.keySet().stream().map(fireType -> fireType.getPath()).collect(Collectors.toList()); + return fires.keySet().stream().map(fireType -> fireType.getNamespace()).collect(Collectors.toList()); } /** diff --git a/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FireAspectBuilder.java b/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FireAspectBuilder.java index 6e9c43f..d0b5edd 100644 --- a/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FireAspectBuilder.java +++ b/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FireAspectBuilder.java @@ -15,6 +15,6 @@ public FireAspectBuilder(Identifier fireType) { @Override public final FireTypedFireAspectEnchantment build() { - return new FireTypedFireAspectEnchantment(fireType, rarity, isTreasure, isCurse, isTradeable, isDiscoverable, enabled, compatibility); + return new FireTypedFireAspectEnchantment(fireType, rarity, isTreasure, isCurse, isTradeable, isDiscoverable, enabled, compatibility, duration); } } diff --git a/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FireEnchantmentBuilder.java b/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FireEnchantmentBuilder.java index c2acabe..0455f63 100644 --- a/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FireEnchantmentBuilder.java +++ b/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FireEnchantmentBuilder.java @@ -4,8 +4,10 @@ import java.util.function.Supplier; import crystalspider.soulfired.api.type.FireTyped; +import crystalspider.soulfired.api.type.TriFunction; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.Enchantment.Rarity; +import net.minecraft.entity.Entity; import net.minecraft.util.Identifier; /** @@ -29,6 +31,10 @@ public abstract class FireEnchantmentBuilder * Defaults to {@code (enchantment) -> true}. */ protected Function compatibility = (enchantment) -> true; + /** + * {@link TriFunction} to tweak the flame duration. + */ + protected TriFunction duration = (attacker, target, duration) -> duration; /** * {@link Rarity} for the enchantment. *

@@ -197,6 +203,30 @@ public final > B setEnabled(Supplier builder type. + * @param duration + * @return this Builder to either set other properties or {@link #build}. + */ + public final > B setDuration(TriFunction duration) { + this.duration = duration; + return (B) this; + } + + /** + * Sets the {@link #duration}. + * + * @param builder type. + * @param duration + * @return this Builder to either set other properties or {@link #build}. + */ + public final > B setDuration(int duration) { + this.duration = (attacker, target, base) -> duration; + return (B) this; + } + /** * Builds a {@link T} instance. * diff --git a/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FireTypedFireAspectEnchantment.java b/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FireTypedFireAspectEnchantment.java index 74ea550..3d72750 100644 --- a/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FireTypedFireAspectEnchantment.java +++ b/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FireTypedFireAspectEnchantment.java @@ -5,7 +5,8 @@ import crystalspider.soulfired.api.FireManager; import crystalspider.soulfired.api.type.FireTypeChanger; -import crystalspider.soulfired.api.type.FireTyped; +import crystalspider.soulfired.api.type.FireTypedEnchantment; +import crystalspider.soulfired.api.type.TriFunction; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.FireAspectEnchantment; import net.minecraft.entity.Entity; @@ -18,7 +19,7 @@ /** * Fire Aspect Enchantment sensitive to the Fire Type. */ -public final class FireTypedFireAspectEnchantment extends FireAspectEnchantment implements FireTyped { +public final class FireTypedFireAspectEnchantment extends FireAspectEnchantment implements FireTypedEnchantment { /** * {@link Identifier} to uniquely identify the associated Fire. */ @@ -32,6 +33,10 @@ public final class FireTypedFireAspectEnchantment extends FireAspectEnchantment * Addtional compatibility {@link Function} to call and check for when checking compatibility with other enchantments. */ private final Function compatibility; + /** + * {@link TriFunction} to tweak the flame duration. + */ + private final TriFunction duration; /** * Whether the enchantment is treasure only. @@ -61,8 +66,19 @@ public final class FireTypedFireAspectEnchantment extends FireAspectEnchantment * @param isDiscoverable {@link #isDiscoverable}. * @param enabled {@link #enabled}. * @param compatibility {@link #compatibility}. + * @param duration {@link #duration}. */ - FireTypedFireAspectEnchantment(Identifier fireType, Rarity rarity, Supplier isTreasure, Supplier isCurse, Supplier isTradeable, Supplier isDiscoverable, Supplier enabled, Function compatibility) { + FireTypedFireAspectEnchantment( + Identifier fireType, + Rarity rarity, + Supplier isTreasure, + Supplier isCurse, + Supplier isTradeable, + Supplier isDiscoverable, + Supplier enabled, + Function compatibility, + TriFunction duration + ) { super(rarity, EquipmentSlot.MAINHAND); this.fireType = FireManager.sanitize(fireType); this.isTreasure = isTreasure; @@ -71,13 +87,14 @@ public final class FireTypedFireAspectEnchantment extends FireAspectEnchantment this.isDiscoverable = isDiscoverable; this.enabled = enabled; this.compatibility = compatibility; + this.duration = duration; } @Override public void onTargetDamaged(LivingEntity attacker, Entity target, int level) { if (!wasLastHitByProjectile(target)) { if (!attacker.world.isClient) { - target.setOnFireFor(level * 4); + target.setOnFireFor(this.duration(attacker, target, level * 4)); } ((FireTypeChanger) target).setFireType(FireManager.ensure(fireType)); } @@ -131,4 +148,9 @@ public boolean isAvailableForRandomSelection() { public Identifier getFireType() { return fireType; } + + @Override + public int duration(Entity attacker, Entity target, Integer duration) { + return this.duration.apply(attacker, target, duration); + } } diff --git a/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FireTypedFlameEnchantment.java b/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FireTypedFlameEnchantment.java index 914a3cc..723cb32 100644 --- a/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FireTypedFlameEnchantment.java +++ b/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FireTypedFlameEnchantment.java @@ -4,9 +4,11 @@ import java.util.function.Supplier; import crystalspider.soulfired.api.FireManager; -import crystalspider.soulfired.api.type.FireTyped; +import crystalspider.soulfired.api.type.FireTypedEnchantment; +import crystalspider.soulfired.api.type.TriFunction; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.FlameEnchantment; +import net.minecraft.entity.Entity; import net.minecraft.entity.EquipmentSlot; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; @@ -14,7 +16,7 @@ /** * Flame Enchantment sensitive to the Fire Type. */ -public final class FireTypedFlameEnchantment extends FlameEnchantment implements FireTyped { +public final class FireTypedFlameEnchantment extends FlameEnchantment implements FireTypedEnchantment { /** * {@link Identifier} to uniquely identify the associated Fire. */ @@ -28,6 +30,10 @@ public final class FireTypedFlameEnchantment extends FlameEnchantment implements * Addtional compatibility {@link Function} to call and check for when checking compatibility with other enchantments. */ private final Function compatibility; + /** + * {@link TriFunction} to tweak the flame duration. + */ + private final TriFunction duration; /** * Whether the enchantment is treasure only. @@ -57,8 +63,19 @@ public final class FireTypedFlameEnchantment extends FlameEnchantment implements * @param isDiscoverable {@link #isDiscoverable}. * @param enabled {@link #enabled}. * @param compatibility {@link #compatibility}. + * @param duration {@link #duration}. */ - FireTypedFlameEnchantment(Identifier fireType, Rarity rarity, Supplier isTreasure, Supplier isCurse, Supplier isTradeable, Supplier isDiscoverable, Supplier enabled, Function compatibility) { + FireTypedFlameEnchantment( + Identifier fireType, + Rarity rarity, + Supplier isTreasure, + Supplier isCurse, + Supplier isTradeable, + Supplier isDiscoverable, + Supplier enabled, + Function compatibility, + TriFunction duration + ) { super(rarity, EquipmentSlot.MAINHAND); this.fireType = FireManager.sanitize(fireType); this.isTreasure = isTreasure; @@ -67,6 +84,7 @@ public final class FireTypedFlameEnchantment extends FlameEnchantment implements this.isDiscoverable = isDiscoverable; this.enabled = enabled; this.compatibility = compatibility; + this.duration = duration; } @Override @@ -103,4 +121,9 @@ public boolean isAvailableForRandomSelection() { public Identifier getFireType() { return fireType; } + + @Override + public int duration(Entity attacker, Entity target, Integer duration) { + return this.duration.apply(attacker, target, duration); + } } \ No newline at end of file diff --git a/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FlameBuilder.java b/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FlameBuilder.java index ceb67b8..d8084a1 100644 --- a/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FlameBuilder.java +++ b/fabric/src/main/java/crystalspider/soulfired/api/enchantment/FlameBuilder.java @@ -15,6 +15,6 @@ public FlameBuilder(Identifier fireType) { @Override public final FireTypedFlameEnchantment build() { - return new FireTypedFlameEnchantment(fireType, rarity, isTreasure, isCurse, isTradeable, isDiscoverable, enabled, compatibility); + return new FireTypedFlameEnchantment(fireType, rarity, isTreasure, isCurse, isTradeable, isDiscoverable, enabled, compatibility, duration); } } diff --git a/fabric/src/main/java/crystalspider/soulfired/api/type/FireTypedEnchantment.java b/fabric/src/main/java/crystalspider/soulfired/api/type/FireTypedEnchantment.java new file mode 100644 index 0000000..38cda32 --- /dev/null +++ b/fabric/src/main/java/crystalspider/soulfired/api/type/FireTypedEnchantment.java @@ -0,0 +1,18 @@ +package crystalspider.soulfired.api.type; + +import net.minecraft.entity.Entity; + +/** + * Fire typed enchantment. + */ +public interface FireTypedEnchantment extends FireTyped { + /** + * Returns the duration for the applied flame. + * + * @param attacker {@link Entity} attacking with the enchantment. + * @param target {@link Entity} being attacked. + * @param duration default duration that would be applied. + * @return the duration for the applied flame. + */ + public int duration(Entity attacker, Entity target, Integer duration); +} diff --git a/fabric/src/main/java/crystalspider/soulfired/api/type/TriFunction.java b/fabric/src/main/java/crystalspider/soulfired/api/type/TriFunction.java new file mode 100644 index 0000000..f4fb5b9 --- /dev/null +++ b/fabric/src/main/java/crystalspider/soulfired/api/type/TriFunction.java @@ -0,0 +1,50 @@ +package crystalspider.soulfired.api.type; + +import java.util.Objects; +import java.util.function.Function; + +/** + * Represents a function that accepts three arguments and produces a result. This is the three-arity specialization of + * {@link Function}. + * + *

+ * This is a functional interface whose functional method is + * {@link #apply(Object, Object, Object)}. + *

+ * + * @param the type of the first argument to the function + * @param the type of the second argument to the function + * @param the type of the third argument to the function + * @param the type of the result of the function + * + * @see Function + * @since 3.12.0 + */ +@FunctionalInterface +public interface TriFunction { + + /** + * Applies this function to the given arguments. + * + * @param t the first function argument + * @param u the second function argument + * @param v the third function argument + * @return the function result + */ + R apply(T t, U u, V v); + + /** + * Returns a composed function that first applies this function to its input, and then applies the {@code after} + * function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the + * composed function. + * + * @param the type of output of the {@code after} function, and of the composed function + * @param after the function to apply after this function is applied + * @return a composed function that first applies this function and then applies the {@code after} function + * @throws NullPointerException if after is null + */ + default TriFunction andThen(final Function after) { + Objects.requireNonNull(after); + return (final T t, final U u, final V v) -> after.apply(apply(t, u, v)); + } +} diff --git a/forge/src/main/java/crystalspider/soulfired/config/SoulFiredConfig.java b/fabric/src/main/java/crystalspider/soulfired/config/ModConfig.java similarity index 99% rename from forge/src/main/java/crystalspider/soulfired/config/SoulFiredConfig.java rename to fabric/src/main/java/crystalspider/soulfired/config/ModConfig.java index 5588b28..e6878b2 100644 --- a/forge/src/main/java/crystalspider/soulfired/config/SoulFiredConfig.java +++ b/fabric/src/main/java/crystalspider/soulfired/config/ModConfig.java @@ -6,7 +6,7 @@ /** * Soul Fire'd Configuration. */ -public final class SoulFiredConfig { +public final class ModConfig { /** * {@link ForgeConfigSpec} {@link ForgeConfigSpec.Builder Builder}. */ diff --git a/fabric/src/main/java/crystalspider/soulfired/handlers/FireResourceReloadListener.java b/fabric/src/main/java/crystalspider/soulfired/handler/FireResourceReloadListener.java similarity index 93% rename from fabric/src/main/java/crystalspider/soulfired/handlers/FireResourceReloadListener.java rename to fabric/src/main/java/crystalspider/soulfired/handler/FireResourceReloadListener.java index f3baf58..8b094d5 100644 --- a/fabric/src/main/java/crystalspider/soulfired/handlers/FireResourceReloadListener.java +++ b/fabric/src/main/java/crystalspider/soulfired/handler/FireResourceReloadListener.java @@ -1,4 +1,4 @@ -package crystalspider.soulfired.handlers; +package crystalspider.soulfired.handler; import java.io.IOException; import java.io.InputStreamReader; @@ -19,7 +19,7 @@ import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; -import crystalspider.soulfired.SoulFiredLoader; +import crystalspider.soulfired.ModLoader; import crystalspider.soulfired.api.Fire; import crystalspider.soulfired.api.FireBuilder; import crystalspider.soulfired.api.FireManager; @@ -65,7 +65,7 @@ public static void handle(ServerPlayerEntity player, boolean joined) { @Override public Identifier getFabricId() { - return new Identifier(SoulFiredLoader.MODID, "ddfires"); + return new Identifier(ModLoader.MOD_ID, "ddfires"); } @Override @@ -139,7 +139,7 @@ private JsonObject getJsonObject(String identifier, JsonElement element) throws try { return element.getAsJsonObject(); } catch (IllegalStateException e) { - LOGGER.error(SoulFiredLoader.MODID + " encountered a non-blocking DDFire error!\nError parsing ddfire [" + identifier + "]: not a JSON object."); + LOGGER.error(ModLoader.MOD_ID + " encountered a non-blocking DDFire error!\nError parsing ddfire [" + identifier + "]: not a JSON object."); throw e; } } @@ -162,7 +162,7 @@ private T parse(String identifier, String field, JsonObject data, Function T parse(String identifier, String field, JsonObject data, Function entityType, World world) { + super(entityType, world); + } + /** * Redirects the call to {@link Entity#setOnFireFor(int)} inside the method {@link PersistentProjectileEntity#onEntityHit(EntityHitResult)}. *

@@ -28,7 +36,8 @@ public abstract class PersistentProjectileEntityMixin implements FireTypeChanger */ @Redirect(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setOnFireFor(I)V")) private void redirectSetOnFireFor(Entity caller, int seconds) { - FireManager.setOnFire(caller, seconds, getFireType()); + FireTypedFlameEnchantment flame = FireManager.getFlame(getFireType()); + FireManager.setOnFire(caller, flame != null ? flame.duration(this.getOwner(), caller, seconds) : seconds, getFireType()); } /** diff --git a/fabric/src/main/java/crystalspider/soulfired/network/SoulFiredNetwork.java b/fabric/src/main/java/crystalspider/soulfired/network/SoulFiredNetwork.java index b5c2ddb..e354c94 100644 --- a/fabric/src/main/java/crystalspider/soulfired/network/SoulFiredNetwork.java +++ b/fabric/src/main/java/crystalspider/soulfired/network/SoulFiredNetwork.java @@ -1,9 +1,9 @@ package crystalspider.soulfired.network; -import crystalspider.soulfired.SoulFiredLoader; +import crystalspider.soulfired.ModLoader; import crystalspider.soulfired.api.Fire; import crystalspider.soulfired.api.events.ServerLifecycleEvents; -import crystalspider.soulfired.handlers.FireResourceReloadListener; +import crystalspider.soulfired.handler.FireResourceReloadListener; import crystalspider.soulfired.network.packets.RegisterFirePacket; import crystalspider.soulfired.network.packets.UnregisterFirePacket; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; @@ -20,11 +20,11 @@ public final class SoulFiredNetwork { /** * {@link RegisterFirePacket} {@link Identifier}. */ - public static final Identifier REGISTER_FIRE = new Identifier(SoulFiredLoader.MODID, "register_fire"); + public static final Identifier REGISTER_FIRE = new Identifier(ModLoader.MOD_ID, "register_fire"); /** * {@link UnregisterFirePacket} {@link Identifier}. */ - public static final Identifier UNREGISTER_FIRE = new Identifier(SoulFiredLoader.MODID, "unregister_fire"); + public static final Identifier UNREGISTER_FIRE = new Identifier(ModLoader.MOD_ID, "unregister_fire"); /** * Register packets identifiers and event to send them.1 diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index cbf4c37..1683d7e 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -17,15 +17,16 @@ "environment": "*", "entrypoints": { "main": [ - "${group}.${modid}.SoulFiredLoader" + "${group}.${modid}.ModLoader" ], "client": [ - "${group}.${modid}.SoulFiredClientLoader" + "${group}.${modid}.ClientModLoader" ] }, "mixins": [ - "soulfired.mixins.json" + "${modid}.mixins.json" ], + "accessWidener": "${modid}.accesswidener", "depends": { "fabricloader": ">=${loader_version}", "fabric": "*", diff --git a/fabric/src/main/resources/soulfired.accesswidener b/fabric/src/main/resources/soulfired.accesswidener new file mode 100644 index 0000000..5a3c0f1 --- /dev/null +++ b/fabric/src/main/resources/soulfired.accesswidener @@ -0,0 +1,2 @@ +accessWidener v2 named +extendable method net/minecraft/entity/projectile/ProjectileEntity (Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V diff --git a/forge/build.gradle b/forge/build.gradle index 37a80c6..bb1bccd 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -25,7 +25,7 @@ java.toolchain.languageVersion = JavaLanguageVersion.of(8) minecraft { mappings channel: "official", version: minecraft_version - // accessTransformer = file("src/main/resources/META-INF/accesstransformer.cfg") // Currently, this location cannot be changed from the default. + accessTransformer = file("src/main/resources/META-INF/accesstransformer.cfg") // Currently, this location cannot be changed from the default. runs { client { workingDirectory project.file("run") diff --git a/forge/gradle.properties b/forge/gradle.properties index 30fff2b..6d588af 100644 --- a/forge/gradle.properties +++ b/forge/gradle.properties @@ -10,7 +10,7 @@ org.gradle.daemon = false # Mod Properties mod_title = Soul fire'd - mod_version = 3.2.0.1 + mod_version = 3.2.1.0 author = Crystal Spider group = crystalspider modid = soulfired @@ -22,4 +22,4 @@ org.gradle.daemon = false # Miscellaneous github_user = Nyphet curseforge_id = 662413 - api_keys = {} \ No newline at end of file + api_keys = {} diff --git a/forge/src/main/java/crystalspider/soulfired/SoulFiredLoader.java b/forge/src/main/java/crystalspider/soulfired/ModLoader.java similarity index 62% rename from forge/src/main/java/crystalspider/soulfired/SoulFiredLoader.java rename to forge/src/main/java/crystalspider/soulfired/ModLoader.java index 507cde5..b4736b2 100644 --- a/forge/src/main/java/crystalspider/soulfired/SoulFiredLoader.java +++ b/forge/src/main/java/crystalspider/soulfired/ModLoader.java @@ -1,7 +1,7 @@ package crystalspider.soulfired; import crystalspider.soulfired.api.FireManager; -import crystalspider.soulfired.config.SoulFiredConfig; +import crystalspider.soulfired.config.ModConfig; import crystalspider.soulfired.loot.ChestLootModifier; import crystalspider.soulfired.network.SoulFiredNetwork; import net.minecraft.util.ResourceLocation; @@ -19,26 +19,26 @@ /** * Soul fire'd mod loader. */ -@Mod(SoulFiredLoader.MODID) -public final class SoulFiredLoader { +@Mod(ModLoader.MOD_ID) +public final class ModLoader { /** * ID of this mod. */ - public static final String MODID = "soulfired"; + public static final String MOD_ID = "soulfired"; /** * Network channel protocol version. */ - public static final String PROTOCOL_VERSION = "1.16-3.2"; + public static final String PROTOCOL_VERSION = "1.16.5-3.2"; /** * {@link SimpleChannel} instance for compatibility client-server. */ - public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(new ResourceLocation(MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals); + public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(new ResourceLocation(MOD_ID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals); /** * {@link GlobalLootModifierSerializer} {@link DeferredRegister deferred register}. */ - public static final DeferredRegister> LOOT_MODIFIERS = DeferredRegister.create(ForgeRegistries.LOOT_MODIFIER_SERIALIZERS, MODID); + public static final DeferredRegister> LOOT_MODIFIERS = DeferredRegister.create(ForgeRegistries.LOOT_MODIFIER_SERIALIZERS, MOD_ID); /** * {@link RegistryObject} for {@link ChestLootModifier} {@link ChestLootModifier.Serializer Serializer}. @@ -46,25 +46,25 @@ public final class SoulFiredLoader { public static final RegistryObject CHEST_LOOT_MODIFIER = LOOT_MODIFIERS.register("chest_loot_modifier", ChestLootModifier.Serializer::new); /** - * Registers {@link SoulFiredConfig}, {@link #LOOT_MODIFIERS}, Soul Fire and {@link SoulFiredNetwork}. + * Registers {@link ModConfig}, {@link #LOOT_MODIFIERS}, Soul Fire and {@link SoulFiredNetwork}. */ - public SoulFiredLoader() { - ModLoadingContext.get().registerConfig(Type.COMMON, SoulFiredConfig.SPEC); + public ModLoader() { + ModLoadingContext.get().registerConfig(Type.COMMON, ModConfig.SPEC); LOOT_MODIFIERS.register(FMLJavaModLoadingContext.get().getModEventBus()); FireManager.registerFire( FireManager.fireBuilder(FireManager.SOUL_FIRE_TYPE) .setDamage(2) .setFireAspectConfig(builder -> builder - .setEnabled(SoulFiredConfig::getEnableSoulFireAspect) - .setIsDiscoverable(SoulFiredConfig::getEnableSoulFireAspectDiscovery) - .setIsTradeable(SoulFiredConfig::getEnableSoulFireAspectTrades) - .setIsTreasure(SoulFiredConfig::getEnableSoulFireAspectTreasure) + .setEnabled(ModConfig::getEnableSoulFireAspect) + .setIsDiscoverable(ModConfig::getEnableSoulFireAspectDiscovery) + .setIsTradeable(ModConfig::getEnableSoulFireAspectTrades) + .setIsTreasure(ModConfig::getEnableSoulFireAspectTreasure) ) .setFlameConfig(builder -> builder - .setEnabled(SoulFiredConfig::getEnableSoulFlame) - .setIsDiscoverable(SoulFiredConfig::getEnableSoulFlameDiscovery) - .setIsTradeable(SoulFiredConfig::getEnableSoulFlameTrades) - .setIsTreasure(SoulFiredConfig::getEnableSoulFlameTreasure) + .setEnabled(ModConfig::getEnableSoulFlame) + .setIsDiscoverable(ModConfig::getEnableSoulFlameDiscovery) + .setIsTradeable(ModConfig::getEnableSoulFlameTrades) + .setIsTreasure(ModConfig::getEnableSoulFlameTreasure) ) .build() ); diff --git a/forge/src/main/java/crystalspider/soulfired/api/Fire.java b/forge/src/main/java/crystalspider/soulfired/api/Fire.java index a58e564..b335917 100644 --- a/forge/src/main/java/crystalspider/soulfired/api/Fire.java +++ b/forge/src/main/java/crystalspider/soulfired/api/Fire.java @@ -53,13 +53,13 @@ public final class Fire { private final Optional campfire; /** - * {@link Optional} Fire Aspect {@link FireTypedFireAspectEnchantment}. + * {@link Optional} Fire Aspect {@link FireTypedFireAspectEnchantment} {@link ResourceLocation}. */ - private final Optional fireAspect; + private final Optional fireAspect; /** - * {@link Optional} Flame {@link FireTypedFlameEnchantment}. + * {@link Optional} Flame {@link FireTypedFlameEnchantment} {@link ResourceLocation}. */ - private final Optional flame; + private final Optional flame; /** * @param fireType {@link #fireType}. @@ -73,7 +73,7 @@ public final class Fire { * @param fireAspect {@link #fireAspect}. * @param flame {@link #flame}. */ - Fire(ResourceLocation fireType, float damage, boolean invertHealAndHarm, DamageSource inFire, DamageSource onFire, SoundEvent hurtSound, ResourceLocation source, ResourceLocation campfire, FireTypedFireAspectEnchantment fireAspect, FireTypedFlameEnchantment flame) { + Fire(ResourceLocation fireType, float damage, boolean invertHealAndHarm, DamageSource inFire, DamageSource onFire, SoundEvent hurtSound, ResourceLocation source, ResourceLocation campfire, ResourceLocation fireAspect, ResourceLocation flame) { this.fireType = fireType; this.damage = damage; this.invertHealAndHarm = invertHealAndHarm; @@ -163,7 +163,7 @@ public Optional getCampfire() { * * @return this {@link #fireAspect}. */ - public Optional getFireAspect() { + public Optional getFireAspect() { return fireAspect; } @@ -172,7 +172,7 @@ public Optional getFireAspect() { * * @return this {@link #flame}. */ - public Optional getFlame() { + public Optional getFlame() { return flame; } diff --git a/forge/src/main/java/crystalspider/soulfired/api/FireBuilder.java b/forge/src/main/java/crystalspider/soulfired/api/FireBuilder.java index 75e52b2..394bcf2 100644 --- a/forge/src/main/java/crystalspider/soulfired/api/FireBuilder.java +++ b/forge/src/main/java/crystalspider/soulfired/api/FireBuilder.java @@ -398,7 +398,7 @@ public Fire build() throws IllegalStateException { if (flameConfigurator != null && !flameConfigurator.isPresent()) { flameConfigurator = Optional.of(builder -> builder); } - return new Fire(fireType, damage, invertHealAndHarm, inFire, onFire, hurtSound, get(source), get(campfire), build(fireAspectConfigurator, () -> new FireAspectBuilder(fireType)), build(flameConfigurator, () -> new FlameBuilder(fireType))); + return new Fire(fireType, damage, invertHealAndHarm, inFire, onFire, hurtSound, get(source), get(campfire), register(fireAspectConfigurator, () -> new FireAspectBuilder(fireType)), register(flameConfigurator, () -> new FlameBuilder(fireType))); } throw new IllegalStateException("Attempted to build a Fire with a non-valid fireId or modId"); } @@ -418,7 +418,7 @@ private T get(@Nullable Optional optional) { } /** - * Returns the value obtained by calling {@link FireEnchantmentBuilder#build()} for the given Builder. + * Returns the value obtained by calling {@link FireEnchantmentBuilder#register()} for the given Builder. *

* Returns {@code null} if the {@code optional} is either {@code null} or empty. * @@ -426,13 +426,12 @@ private T get(@Nullable Optional optional) { * @param enchantment type. * @param optional * @param supplier - * @return the value obtained by calling {@link FireEnchantmentBuilder#build()}. + * @return the value obtained by calling {@link FireEnchantmentBuilder#register()}. */ - @Nullable - private , E extends Enchantment & FireTyped> E build(@Nullable Optional> optional, Supplier supplier) { + private , E extends Enchantment & FireTyped> ResourceLocation register(@Nullable Optional> optional, Supplier supplier) { Function configurator = get(optional); if (configurator != null) { - return configurator.apply(supplier.get()).build(); + return configurator.apply(supplier.get()).register(); } return null; } diff --git a/forge/src/main/java/crystalspider/soulfired/api/FireManager.java b/forge/src/main/java/crystalspider/soulfired/api/FireManager.java index 1944cc3..b1f67f3 100644 --- a/forge/src/main/java/crystalspider/soulfired/api/FireManager.java +++ b/forge/src/main/java/crystalspider/soulfired/api/FireManager.java @@ -368,7 +368,7 @@ public static List getFireIds() { * @return the list of all registered mod ids. */ public static List getModIds() { - return fires.keySet().stream().map(fireType -> fireType.getPath()).collect(Collectors.toList()); + return fires.keySet().stream().map(fireType -> fireType.getNamespace()).collect(Collectors.toList()); } /** @@ -554,7 +554,7 @@ public static Block getCampfireBlock(ResourceLocation fireType) { * @return the list of all Fire Aspect enchantments registered. */ public static List getFireAspects() { - return fires.values().stream().map(fire -> fire.getFireAspect()).filter(optional -> optional.isPresent()).map(optional -> optional.get()).collect(Collectors.toList()); + return fires.values().stream().map(fire -> getFireAspect(fire.getFireType())).filter(enchantment -> enchantment != null).collect(Collectors.toList()); } /** @@ -563,7 +563,7 @@ public static List getFireAspects() { * @return the list of all Flame enchantments registered. */ public static List getFlames() { - return fires.values().stream().map(fire -> fire.getFlame()).filter(optional -> optional.isPresent()).map(optional -> optional.get()).collect(Collectors.toList()); + return fires.values().stream().map(fire -> getFlame(fire.getFireType())).filter(enchantment -> enchantment != null).collect(Collectors.toList()); } /** @@ -590,7 +590,7 @@ public static FireTypedFireAspectEnchantment getFireAspect(String modId, String */ @Nullable public static FireTypedFireAspectEnchantment getFireAspect(ResourceLocation fireType) { - return fires.getOrDefault(fireType, DEFAULT_FIRE).getFireAspect().orElse(null); + return (FireTypedFireAspectEnchantment) ForgeRegistries.ENCHANTMENTS.getValue(getFire(fireType).getFireAspect().orElse(null)); } /** @@ -617,7 +617,7 @@ public static FireTypedFlameEnchantment getFlame(String modId, String fireId) { */ @Nullable public static FireTypedFlameEnchantment getFlame(ResourceLocation fireType) { - return fires.getOrDefault(fireType, DEFAULT_FIRE).getFlame().orElse(null); + return (FireTypedFlameEnchantment) ForgeRegistries.ENCHANTMENTS.getValue(getFire(fireType).getFlame().orElse(null)); } /** diff --git a/forge/src/main/java/crystalspider/soulfired/api/enchantment/FireAspectBuilder.java b/forge/src/main/java/crystalspider/soulfired/api/enchantment/FireAspectBuilder.java index 3811afe..4b2416c 100644 --- a/forge/src/main/java/crystalspider/soulfired/api/enchantment/FireAspectBuilder.java +++ b/forge/src/main/java/crystalspider/soulfired/api/enchantment/FireAspectBuilder.java @@ -10,11 +10,11 @@ public final class FireAspectBuilder extends FireEnchantmentBuilder * Defaults to {@code (enchantment) -> true}. */ protected Function compatibility = (enchantment) -> true; + /** + * {@link TriFunction} to tweak the flame duration. + */ + protected TriFunction duration = (attacker, target, duration) -> duration; /** * {@link Rarity} for the enchantment. *

@@ -83,11 +92,18 @@ public abstract class FireEnchantmentBuilder */ protected Supplier isDiscoverable = () -> DEFAULT_IS_DISCOVERABLE; + /** + * Enchantment kind identifier. + * Will be used as suffix when registering the enchantment. + */ + private final String kind; + /** * @param fireType {@link #fireType}. */ - protected FireEnchantmentBuilder(ResourceLocation fireType) { + protected FireEnchantmentBuilder(ResourceLocation fireType, String kind) { this.fireType = fireType; + this.kind = kind; } /** @@ -218,10 +234,45 @@ public final > B setEnabled(Supplier builder type. + * @param duration + * @return this Builder to either set other properties or {@link #build}. + */ + public final > B setDuration(TriFunction duration) { + this.duration = duration; + return (B) this; + } + + /** + * Sets the {@link #duration}. + * + * @param builder type. + * @param duration + * @return this Builder to either set other properties or {@link #build}. + */ + public final > B setDuration(int duration) { + this.duration = (attacker, target, base) -> duration; + return (B) this; + } + + /** + * Builds and registers the enchantment instance. + */ + public ResourceLocation register() { + ResourceLocation key = new ResourceLocation(fireType.getNamespace(), fireType.getPath() + "_" + kind); + DeferredRegister enchantments = DeferredRegister.create(ForgeRegistries.ENCHANTMENTS, key.getNamespace()); + enchantments.register(FMLJavaModLoadingContext.get().getModEventBus()); + enchantments.register(key.getPath(), this::build); + return key; + } + /** * Builds a {@link T} instance. * * @return {@link T} instance. */ - public abstract T build(); + protected abstract T build(); } diff --git a/forge/src/main/java/crystalspider/soulfired/api/enchantment/FireTypedFireAspectEnchantment.java b/forge/src/main/java/crystalspider/soulfired/api/enchantment/FireTypedFireAspectEnchantment.java index 0bfcd25..45dcdf2 100644 --- a/forge/src/main/java/crystalspider/soulfired/api/enchantment/FireTypedFireAspectEnchantment.java +++ b/forge/src/main/java/crystalspider/soulfired/api/enchantment/FireTypedFireAspectEnchantment.java @@ -6,7 +6,8 @@ import crystalspider.soulfired.api.FireManager; import crystalspider.soulfired.api.compat.Ensorcellation; import crystalspider.soulfired.api.type.FireTypeChanger; -import crystalspider.soulfired.api.type.FireTyped; +import crystalspider.soulfired.api.type.FireTypedEnchantment; +import crystalspider.soulfired.api.type.TriFunction; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.FireAspectEnchantment; import net.minecraft.entity.Entity; @@ -20,7 +21,7 @@ /** * Fire Aspect Enchantment sensitive to the Fire Type. */ -public final class FireTypedFireAspectEnchantment extends FireAspectEnchantment implements FireTyped { +public final class FireTypedFireAspectEnchantment extends FireAspectEnchantment implements FireTypedEnchantment { /** * {@link ResourceLocation} to uniquely identify the associated Fire. */ @@ -34,6 +35,10 @@ public final class FireTypedFireAspectEnchantment extends FireAspectEnchantment * Addtional compatibility {@link Function} to call and check for when checking compatibility with other enchantments. */ private final Function compatibility; + /** + * {@link TriFunction} to tweak the flame duration. + */ + private final TriFunction duration; /** * Whether the enchantment is treasure only. @@ -63,8 +68,19 @@ public final class FireTypedFireAspectEnchantment extends FireAspectEnchantment * @param isDiscoverable {@link #isDiscoverable}. * @param enabled {@link #enabled}. * @param compatibility {@link #compatibility}. + * @param duration {@link #duration}. */ - FireTypedFireAspectEnchantment(ResourceLocation fireType, Rarity rarity, Supplier isTreasure, Supplier isCurse, Supplier isTradeable, Supplier isDiscoverable, Supplier enabled, Function compatibility) { + FireTypedFireAspectEnchantment( + ResourceLocation fireType, + Rarity rarity, + Supplier isTreasure, + Supplier isCurse, + Supplier isTradeable, + Supplier isDiscoverable, + Supplier enabled, + Function compatibility, + TriFunction duration + ) { super(rarity, EquipmentSlotType.MAINHAND); this.fireType = FireManager.sanitize(fireType); this.isTreasure = isTreasure; @@ -73,14 +89,14 @@ public final class FireTypedFireAspectEnchantment extends FireAspectEnchantment this.isDiscoverable = isDiscoverable; this.enabled = enabled; this.compatibility = compatibility; - setRegistryName(fireType.getNamespace(), fireType.getPath() + "_fire_aspect"); + this.duration = duration; } @Override public void doPostAttack(LivingEntity attacker, Entity target, int level) { if (!wasLastHitByProjectile(target)) { if (!attacker.level.isClientSide) { - target.setSecondsOnFire(level * 4); + target.setSecondsOnFire(this.duration(attacker, target, level * 4)); } ((FireTypeChanger) target).setFireType(FireManager.ensure(fireType)); } @@ -151,4 +167,9 @@ public boolean isDiscoverable() { public ResourceLocation getFireType() { return fireType; } + + @Override + public int duration(Entity attacker, Entity target, Integer duration) { + return this.duration.apply(attacker, target, duration); + } } diff --git a/forge/src/main/java/crystalspider/soulfired/api/enchantment/FireTypedFlameEnchantment.java b/forge/src/main/java/crystalspider/soulfired/api/enchantment/FireTypedFlameEnchantment.java index 30d127b..b688c38 100644 --- a/forge/src/main/java/crystalspider/soulfired/api/enchantment/FireTypedFlameEnchantment.java +++ b/forge/src/main/java/crystalspider/soulfired/api/enchantment/FireTypedFlameEnchantment.java @@ -4,9 +4,11 @@ import java.util.function.Supplier; import crystalspider.soulfired.api.FireManager; -import crystalspider.soulfired.api.type.FireTyped; +import crystalspider.soulfired.api.type.FireTypedEnchantment; +import crystalspider.soulfired.api.type.TriFunction; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.FlameEnchantment; +import net.minecraft.entity.Entity; import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; @@ -14,7 +16,7 @@ /** * Flame Enchantment sensitive to the Fire Type. */ -public final class FireTypedFlameEnchantment extends FlameEnchantment implements FireTyped { +public final class FireTypedFlameEnchantment extends FlameEnchantment implements FireTypedEnchantment { /** * {@link ResourceLocation} to uniquely identify the associated Fire. */ @@ -28,6 +30,10 @@ public final class FireTypedFlameEnchantment extends FlameEnchantment implements * Addtional compatibility {@link Function} to call and check for when checking compatibility with other enchantments. */ private final Function compatibility; + /** + * {@link TriFunction} to tweak the flame duration. + */ + private final TriFunction duration; /** * Whether the enchantment is treasure only. @@ -57,8 +63,19 @@ public final class FireTypedFlameEnchantment extends FlameEnchantment implements * @param isDiscoverable {@link #isDiscoverable}. * @param enabled {@link #enabled}. * @param compatibility {@link #compatibility}. + * @param duration {@link #duration}. */ - FireTypedFlameEnchantment(ResourceLocation fireType, Rarity rarity, Supplier isTreasure, Supplier isCurse, Supplier isTradeable, Supplier isDiscoverable, Supplier enabled, Function compatibility) { + FireTypedFlameEnchantment( + ResourceLocation fireType, + Rarity rarity, + Supplier isTreasure, + Supplier isCurse, + Supplier isTradeable, + Supplier isDiscoverable, + Supplier enabled, + Function compatibility, + TriFunction duration + ) { super(rarity, EquipmentSlotType.MAINHAND); this.fireType = FireManager.sanitize(fireType); this.isTreasure = isTreasure; @@ -67,7 +84,7 @@ public final class FireTypedFlameEnchantment extends FlameEnchantment implements this.isDiscoverable = isDiscoverable; this.enabled = enabled; this.compatibility = compatibility; - setRegistryName(fireType.getNamespace(), fireType.getPath() + "_flame"); + this.duration = duration; } @Override @@ -114,4 +131,9 @@ public boolean isDiscoverable() { public ResourceLocation getFireType() { return fireType; } + + @Override + public int duration(Entity attacker, Entity target, Integer duration) { + return this.duration.apply(attacker, target, duration); + } } \ No newline at end of file diff --git a/forge/src/main/java/crystalspider/soulfired/api/enchantment/FlameBuilder.java b/forge/src/main/java/crystalspider/soulfired/api/enchantment/FlameBuilder.java index c9ff96f..beafddf 100644 --- a/forge/src/main/java/crystalspider/soulfired/api/enchantment/FlameBuilder.java +++ b/forge/src/main/java/crystalspider/soulfired/api/enchantment/FlameBuilder.java @@ -10,11 +10,11 @@ public final class FlameBuilder extends FireEnchantmentBuilder + * This is a functional interface whose functional method is + * {@link #apply(Object, Object, Object)}. + *

+ * + * @param the type of the first argument to the function + * @param the type of the second argument to the function + * @param the type of the third argument to the function + * @param the type of the result of the function + * + * @see Function + * @since 3.12.0 + */ +@FunctionalInterface +public interface TriFunction { + + /** + * Applies this function to the given arguments. + * + * @param t the first function argument + * @param u the second function argument + * @param v the third function argument + * @return the function result + */ + R apply(T t, U u, V v); + + /** + * Returns a composed function that first applies this function to its input, and then applies the {@code after} + * function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the + * composed function. + * + * @param the type of output of the {@code after} function, and of the composed function + * @param after the function to apply after this function is applied + * @return a composed function that first applies this function and then applies the {@code after} function + * @throws NullPointerException if after is null + */ + default TriFunction andThen(final Function after) { + Objects.requireNonNull(after); + return (final T t, final U u, final V v) -> after.apply(apply(t, u, v)); + } +} diff --git a/fabric/src/main/java/crystalspider/soulfired/config/SoulFiredConfig.java b/forge/src/main/java/crystalspider/soulfired/config/ModConfig.java similarity index 99% rename from fabric/src/main/java/crystalspider/soulfired/config/SoulFiredConfig.java rename to forge/src/main/java/crystalspider/soulfired/config/ModConfig.java index 5588b28..e6878b2 100644 --- a/fabric/src/main/java/crystalspider/soulfired/config/SoulFiredConfig.java +++ b/forge/src/main/java/crystalspider/soulfired/config/ModConfig.java @@ -6,7 +6,7 @@ /** * Soul Fire'd Configuration. */ -public final class SoulFiredConfig { +public final class ModConfig { /** * {@link ForgeConfigSpec} {@link ForgeConfigSpec.Builder Builder}. */ diff --git a/forge/src/main/java/crystalspider/soulfired/handlers/DatapacksEventHandler.java b/forge/src/main/java/crystalspider/soulfired/handler/DatapacksEventHandler.java similarity index 92% rename from forge/src/main/java/crystalspider/soulfired/handlers/DatapacksEventHandler.java rename to forge/src/main/java/crystalspider/soulfired/handler/DatapacksEventHandler.java index fcb4c7a..c55df79 100644 --- a/forge/src/main/java/crystalspider/soulfired/handlers/DatapacksEventHandler.java +++ b/forge/src/main/java/crystalspider/soulfired/handler/DatapacksEventHandler.java @@ -1,4 +1,4 @@ -package crystalspider.soulfired.handlers; +package crystalspider.soulfired.handler; import java.util.ArrayList; import java.util.Map; @@ -14,7 +14,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; -import crystalspider.soulfired.SoulFiredLoader; +import crystalspider.soulfired.ModLoader; import crystalspider.soulfired.api.Fire; import crystalspider.soulfired.api.FireBuilder; import crystalspider.soulfired.api.FireManager; @@ -32,7 +32,7 @@ /** * Handles datapack reload events. */ -@EventBusSubscriber(bus = Bus.FORGE) +@EventBusSubscriber(modid = ModLoader.MOD_ID, bus = Bus.FORGE) public final class DatapacksEventHandler { /** * Logger. @@ -134,7 +134,7 @@ private JsonObject getJsonObject(String identifier, JsonElement element) throws try { return element.getAsJsonObject(); } catch (IllegalStateException e) { - LOGGER.error(SoulFiredLoader.MODID + " encountered a non-blocking DDFire error!\nError parsing ddfire [" + identifier + "]: not a JSON object."); + LOGGER.error(ModLoader.MOD_ID + " encountered a non-blocking DDFire error!\nError parsing ddfire [" + identifier + "]: not a JSON object."); throw e; } } @@ -157,7 +157,7 @@ private T parse(String identifier, String field, JsonObject data, Function T parse(String identifier, String field, JsonObject data, Function - * Registers Fire Aspect and Flame enchantments for all registered {@link Fire Fires} with such enchantments. - * - * @param event - */ - @SubscribeEvent - public static void handle(Register event) { - for (Fire fire : FireManager.getFires()) { - if (fire.getFireAspect().isPresent()) { - event.getRegistry().register(fire.getFireAspect().get()); - } - if (fire.getFlame().isPresent()) { - event.getRegistry().register(fire.getFlame().get()); - } - } - } -} diff --git a/forge/src/main/java/crystalspider/soulfired/loot/ChestLootModifier.java b/forge/src/main/java/crystalspider/soulfired/loot/ChestLootModifier.java index 4a5f5e3..4ca4386 100644 --- a/forge/src/main/java/crystalspider/soulfired/loot/ChestLootModifier.java +++ b/forge/src/main/java/crystalspider/soulfired/loot/ChestLootModifier.java @@ -10,7 +10,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import crystalspider.soulfired.config.SoulFiredConfig; +import crystalspider.soulfired.config.ModConfig; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentData; import net.minecraft.item.EnchantedBookItem; @@ -45,7 +45,7 @@ protected List doApply(List generatedLoot, LootContext con generatedLoot = new ArrayList<>(); } for (Entry entry : additions.entrySet()) { - if (SoulFiredConfig.getEnableSoulFlame() && context.getRandom().nextFloat() <= entry.getValue()) { + if (ModConfig.getEnableSoulFlame() && context.getRandom().nextFloat() <= entry.getValue()) { generatedLoot.add(entry.getKey()); } } diff --git a/forge/src/main/java/crystalspider/soulfired/mixin/AbstractArrowEntityMixin.java b/forge/src/main/java/crystalspider/soulfired/mixin/AbstractArrowEntityMixin.java index b388ec6..61aa5c6 100644 --- a/forge/src/main/java/crystalspider/soulfired/mixin/AbstractArrowEntityMixin.java +++ b/forge/src/main/java/crystalspider/soulfired/mixin/AbstractArrowEntityMixin.java @@ -7,17 +7,25 @@ import crystalspider.soulfired.api.FireManager; import crystalspider.soulfired.api.enchantment.FireEnchantmentHelper; import crystalspider.soulfired.api.enchantment.FireEnchantmentHelper.FireEnchantment; +import crystalspider.soulfired.api.enchantment.FireTypedFlameEnchantment; import crystalspider.soulfired.api.type.FireTypeChanger; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.projectile.AbstractArrowEntity; +import net.minecraft.entity.projectile.ProjectileEntity; import net.minecraft.util.math.EntityRayTraceResult; +import net.minecraft.world.World; /** * Injects into {@link AbstractArrowEntity} to alter Fire behavior for consistency. */ @Mixin(AbstractArrowEntity.class) -public abstract class AbstractArrowEntityMixin implements FireTypeChanger { +public abstract class AbstractArrowEntityMixin extends ProjectileEntity implements FireTypeChanger { + private AbstractArrowEntityMixin(EntityType entityType, World world) { + super(entityType, world); + } + /** * Redirects the call to {@link Entity#setSecondsOnFire(int)} inside the method {@link AbstractArrowEntity#onHitEntity(EntityRayTraceResult)}. *

@@ -28,7 +36,8 @@ public abstract class AbstractArrowEntityMixin implements FireTypeChanger { */ @Redirect(method = "onHitEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setSecondsOnFire(I)V")) private void redirectSetSecondsOnFire(Entity caller, int seconds) { - FireManager.setOnFire(caller, seconds, getFireType()); + FireTypedFlameEnchantment flame = FireManager.getFlame(getFireType()); + FireManager.setOnFire(caller, flame != null ? flame.duration(this.getOwner(), caller, seconds) : seconds, getFireType()); } /** diff --git a/forge/src/main/java/crystalspider/soulfired/network/SoulFiredNetwork.java b/forge/src/main/java/crystalspider/soulfired/network/SoulFiredNetwork.java index c478c01..a6b4784 100644 --- a/forge/src/main/java/crystalspider/soulfired/network/SoulFiredNetwork.java +++ b/forge/src/main/java/crystalspider/soulfired/network/SoulFiredNetwork.java @@ -2,7 +2,7 @@ import javax.annotation.Nullable; -import crystalspider.soulfired.SoulFiredLoader; +import crystalspider.soulfired.ModLoader; import crystalspider.soulfired.api.Fire; import crystalspider.soulfired.network.register.RegisterFirePacket; import crystalspider.soulfired.network.unregister.UnregisterFirePacket; @@ -19,8 +19,8 @@ public final class SoulFiredNetwork { /** * {@link SimpleChannel} instance for compatibility client-server. */ - private static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(new ResourceLocation(SoulFiredLoader.MODID, "ddfires"), () -> SoulFiredLoader.PROTOCOL_VERSION, SoulFiredLoader.PROTOCOL_VERSION::equals, SoulFiredLoader.PROTOCOL_VERSION::equals); - + private static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(new ResourceLocation(ModLoader.MOD_ID, "ddfires"), () -> ModLoader.PROTOCOL_VERSION, ModLoader.PROTOCOL_VERSION::equals, ModLoader.PROTOCOL_VERSION::equals); + /** * Last packet id used to register a packet kind. */ diff --git a/forge/src/main/resources/META-INF/accesstransformer.cfg b/forge/src/main/resources/META-INF/accesstransformer.cfg new file mode 100644 index 0000000..3e15d75 --- /dev/null +++ b/forge/src/main/resources/META-INF/accesstransformer.cfg @@ -0,0 +1 @@ +protected net.minecraft.entity.projectile.ProjectileEntity (Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V