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 90cf1a7 commit 957e6a9
Show file tree
Hide file tree
Showing 37 changed files with 385 additions and 185 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
46 changes: 46 additions & 0 deletions fabric/src/main/java/crystalspider/soulfired/ModLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package crystalspider.soulfired;

import crystalspider.soulfired.api.FireManager;
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.v2.LootTableEvents;
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 ModLoader implements ModInitializer {
/**
* ID of this mod.
*/
public static final String MOD_ID = "soulfired";

@Override
public void onInitialize() {
ModLoadingContext.registerConfig(MOD_ID, Type.COMMON, ModConfig.SPEC);
LootTableEvents.MODIFY.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(ModConfig::getEnableSoulFireAspect)
.setIsDiscoverable(ModConfig::getEnableSoulFireAspectDiscovery)
.setIsTradeable(ModConfig::getEnableSoulFireAspectTrades)
.setIsTreasure(ModConfig::getEnableSoulFireAspectTreasure)
)
.setFlameConfig(builder -> builder
.setEnabled(ModConfig::getEnableSoulFlame)
.setIsDiscoverable(ModConfig::getEnableSoulFlameDiscovery)
.setIsTradeable(ModConfig::getEnableSoulFlameTrades)
.setIsTreasure(ModConfig::getEnableSoulFlameTreasure)
)
.build()
);
}
}
46 changes: 0 additions & 46 deletions fabric/src/main/java/crystalspider/soulfired/SoulFiredLoader.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,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()).toList();
return fires.keySet().stream().map(fireType -> fireType.getNamespace()).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 @@ -3,9 +3,12 @@
import java.util.function.Function;
import java.util.function.Supplier;

import org.apache.commons.lang3.function.TriFunction;

import crystalspider.soulfired.api.type.FireTyped;
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 +32,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 +204,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 @@ -3,9 +3,11 @@
import java.util.function.Function;
import java.util.function.Supplier;

import org.apache.commons.lang3.function.TriFunction;

import crystalspider.soulfired.api.FireManager;
import crystalspider.soulfired.api.type.FireTypeChanger;
import crystalspider.soulfired.api.type.FireTyped;
import crystalspider.soulfired.api.type.FireTypedEnchantment;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.FireAspectEnchantment;
import net.minecraft.entity.Entity;
Expand All @@ -18,7 +20,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 +34,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 +67,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 +88,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 +149,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 @@ -3,18 +3,21 @@
import java.util.function.Function;
import java.util.function.Supplier;

import org.apache.commons.lang3.function.TriFunction;

import crystalspider.soulfired.api.FireManager;
import crystalspider.soulfired.api.type.FireTyped;
import crystalspider.soulfired.api.type.FireTypedEnchantment;
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 +31,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 +64,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 +85,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 +122,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
Expand Up @@ -6,7 +6,7 @@
/**
* Soul Fire'd Configuration.
*/
public final class SoulFiredConfig {
public final class ModConfig {
/**
* {@link ForgeConfigSpec} {@link ForgeConfigSpec.Builder Builder}.
*/
Expand Down
Loading

0 comments on commit 957e6a9

Please sign in to comment.