Skip to content

Commit

Permalink
[FF]: Add new tweaking enchantment option and fix modIds getter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Crystal-Spider committed Nov 17, 2023
1 parent 53b0f26 commit cca2806
Show file tree
Hide file tree
Showing 40 changed files with 450 additions and 155 deletions.
4 changes: 4 additions & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions fabric/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,4 +25,4 @@ org.gradle.daemon = false
# Miscellaneous
github_user = Nyphet
curseforge_id = 662413
api_keys = {}
api_keys = {}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public static List<String> getFireIds() {
* @return the list of all registered mod ids.
*/
public static List<String> getModIds() {
return fires.keySet().stream().map(fireType -> fireType.getPath()).collect(Collectors.toList());
return fires.keySet().stream().map(fireType -> fireType.getNamespace()).collect(Collectors.toList());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -29,6 +31,10 @@ public abstract class FireEnchantmentBuilder<T extends Enchantment & FireTyped>
* Defaults to {@code (enchantment) -> true}.
*/
protected Function<Enchantment, Boolean> compatibility = (enchantment) -> true;
/**
* {@link TriFunction} to tweak the flame duration.
*/
protected TriFunction<Entity, Entity, Integer, Integer> duration = (attacker, target, duration) -> duration;
/**
* {@link Rarity} for the enchantment.
* <p>
Expand Down Expand Up @@ -197,6 +203,30 @@ public final <B extends FireEnchantmentBuilder<T>> B setEnabled(Supplier<Boolean
return (B) this;
}

/**
* Sets the {@link #duration} {@link TriFunction}.
*
* @param <B> builder type.
* @param duration
* @return this Builder to either set other properties or {@link #build}.
*/
public final <B extends FireEnchantmentBuilder<T>> B setDuration(TriFunction<Entity, Entity, Integer, Integer> duration) {
this.duration = duration;
return (B) this;
}

/**
* Sets the {@link #duration}.
*
* @param <B> builder type.
* @param duration
* @return this Builder to either set other properties or {@link #build}.
*/
public final <B extends FireEnchantmentBuilder<T>> B setDuration(int duration) {
this.duration = (attacker, target, base) -> duration;
return (B) this;
}

/**
* Builds a {@link T} instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*/
Expand All @@ -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<Enchantment, Boolean> compatibility;
/**
* {@link TriFunction} to tweak the flame duration.
*/
private final TriFunction<Entity, Entity, Integer, Integer> duration;

/**
* Whether the enchantment is treasure only.
Expand Down Expand Up @@ -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<Boolean> isTreasure, Supplier<Boolean> isCurse, Supplier<Boolean> isTradeable, Supplier<Boolean> isDiscoverable, Supplier<Boolean> enabled, Function<Enchantment, Boolean> compatibility) {
FireTypedFireAspectEnchantment(
Identifier fireType,
Rarity rarity,
Supplier<Boolean> isTreasure,
Supplier<Boolean> isCurse,
Supplier<Boolean> isTradeable,
Supplier<Boolean> isDiscoverable,
Supplier<Boolean> enabled,
Function<Enchantment, Boolean> compatibility,
TriFunction<Entity, Entity, Integer, Integer> duration
) {
super(rarity, EquipmentSlot.MAINHAND);
this.fireType = FireManager.sanitize(fireType);
this.isTreasure = isTreasure;
Expand All @@ -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));
}
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
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;

/**
* 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.
*/
Expand All @@ -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<Enchantment, Boolean> compatibility;
/**
* {@link TriFunction} to tweak the flame duration.
*/
private final TriFunction<Entity, Entity, Integer, Integer> duration;

/**
* Whether the enchantment is treasure only.
Expand Down Expand Up @@ -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<Boolean> isTreasure, Supplier<Boolean> isCurse, Supplier<Boolean> isTradeable, Supplier<Boolean> isDiscoverable, Supplier<Boolean> enabled, Function<Enchantment, Boolean> compatibility) {
FireTypedFlameEnchantment(
Identifier fireType,
Rarity rarity,
Supplier<Boolean> isTreasure,
Supplier<Boolean> isCurse,
Supplier<Boolean> isTradeable,
Supplier<Boolean> isDiscoverable,
Supplier<Boolean> enabled,
Function<Enchantment, Boolean> compatibility,
TriFunction<Entity, Entity, Integer, Integer> duration
) {
super(rarity, EquipmentSlot.MAINHAND);
this.fireType = FireManager.sanitize(fireType);
this.isTreasure = isTreasure;
Expand All @@ -67,6 +84,7 @@ public final class FireTypedFlameEnchantment extends FlameEnchantment implements
this.isDiscoverable = isDiscoverable;
this.enabled = enabled;
this.compatibility = compatibility;
this.duration = duration;
}

@Override
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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}.
*
* <p>
* This is a <a href="package-summary.html">functional interface</a> whose functional method is
* {@link #apply(Object, Object, Object)}.
* </p>
*
* @param <T> the type of the first argument to the function
* @param <U> the type of the second argument to the function
* @param <V> the type of the third argument to the function
* @param <R> the type of the result of the function
*
* @see Function
* @since 3.12.0
*/
@FunctionalInterface
public interface TriFunction<T, U, V, R> {

/**
* 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 <W> 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 <W> TriFunction<T, U, V, W> andThen(final Function<? super R, ? extends W> after) {
Objects.requireNonNull(after);
return (final T t, final U u, final V v) -> after.apply(apply(t, u, v));
}
}
Loading

0 comments on commit cca2806

Please sign in to comment.