Skip to content

Commit

Permalink
[FF]: Data Driven Fire (Datapacks) #4 and Minor irks about enchants #25
Browse files Browse the repository at this point in the history
… with minor changes to backport to 1.18.2
  • Loading branch information
Crystal-Spider committed Jul 4, 2023
1 parent 8ec4c9b commit 6de46c4
Show file tree
Hide file tree
Showing 24 changed files with 1,154 additions and 26 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![Soul Fire'd banner](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/soul-fire-d/banner.gif)

---
![Minecraft](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/minecraft/minecraft.svg)[![1.19.4](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/minecraft/1-19-4.svg)](https://modrinth.com/mod/soul-fire-d/versions?g=1.19.4)![Separator](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/separator.svg)[![1.19.3](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/minecraft/1-19-3.svg)](https://modrinth.com/mod/soul-fire-d/versions?g=1.19.3)![Separator](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/separator.svg)[![1.19.2](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/minecraft/1-19-2.svg)](https://modrinth.com/mod/soul-fire-d/versions?g=1.19.2)![Separator](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/separator.svg)[![1.18.2](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/minecraft/1-18-2.svg)](https://modrinth.com/mod/soul-fire-d/versions?g=1.18.2)![Separator](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/separator.svg)[![1.16.5](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/minecraft/1-16-5.svg)](https://modrinth.com/mod/soul-fire-d/versions?g=1.16.5)
![Minecraft](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/minecraft/minecraft.svg)[![1.20.1](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/minecraft/1-20-1.svg)](https://modrinth.com/mod/soul-fire-d/versions?g=1.20.1)![Separator](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/separator.svg)[![1.19.4](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/minecraft/1-19-4.svg)](https://modrinth.com/mod/soul-fire-d/versions?g=1.19.4)![Separator](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/separator.svg)[![1.19.3](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/minecraft/1-19-3.svg)](https://modrinth.com/mod/soul-fire-d/versions?g=1.19.3)![Separator](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/separator.svg)[![1.19.2](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/minecraft/1-19-2.svg)](https://modrinth.com/mod/soul-fire-d/versions?g=1.19.2)![Separator](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/separator.svg)[![1.18.2](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/minecraft/1-18-2.svg)](https://modrinth.com/mod/soul-fire-d/versions?g=1.18.2)![Separator](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/separator.svg)[![1.16.5](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/minecraft/1-16-5.svg)](https://modrinth.com/mod/soul-fire-d/versions?g=1.16.5)

![Loader](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/loader/loader.svg)[![Forge](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/loader/forge.svg)](https://modrinth.com/mod/soul-fire-d/versions?l=forge)![Separator](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/separator.svg)[![Fabric](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/loader/fabric.svg)](https://modrinth.com/mod/soul-fire-d/versions?l=fabric)

Expand All @@ -25,9 +25,10 @@ For instance, but not limited to, zombies burning from Soul Fire and arrows pass
![Arrows](https://raw.githubusercontent.com/Nyphet/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 individually enabled (default) or disabled, having each a configuration option.
Both these enchantments can be highly configured individually, enabling (default) or disabling them and more.
- **API for custom fire types:**
For modders 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**.
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**.
See the bottom section *For developers* to know more.

## **Dependencies**
Expand All @@ -40,7 +41,8 @@ Feel free to use this mod for any modpack or video, just be sure to give credit
This project is published under the [GNU General Public License v3.0](https://github.com/Nyphet/soul-fire-d/blob/master/LICENSE).

## **For developers**
To learn how to use the provided API follow the [Wiki](https://github.com/Nyphet/soul-fire-d/wiki) on [GitHub](https://github.com/Nyphet/soul-fire-d).
To learn how to use the provided API follow the [Wiki](https://github.com/Nyphet/soul-fire-d/wiki) on [GitHub](https://github.com/Nyphet/soul-fire-d).
Please note that the API is available even with datapacks, to know more follow the [dedicated Wiki page](https://github.com/Nyphet/soul-fire-d/wiki/Data-Driven-Fires).

## **Support me**
[![Twitch](https://raw.githubusercontent.com/Nyphet/mod-fancy-assets/main/twitch/twitch64.png "Twitch")](https://www.twitch.tv/crystal_spider_)
Expand Down
2 changes: 1 addition & 1 deletion 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.1.0.0
mod_version = 3.2.0.0
author = Crystal Spider
group = crystalspider
modid = soulfired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import crystalspider.soulfired.api.FireManager;
import crystalspider.soulfired.api.client.FireClientManager;
import crystalspider.soulfired.network.SoulFiredNetwork;
import net.fabricmc.api.ClientModInitializer;

/**
Expand All @@ -11,5 +12,6 @@ public final class SoulFiredClientLoader implements ClientModInitializer {
@Override
public void onInitializeClient() {
FireClientManager.registerFires(FireManager.getFires());
SoulFiredNetwork.register();
}
}
20 changes: 17 additions & 3 deletions fabric/src/main/java/crystalspider/soulfired/SoulFiredLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import crystalspider.soulfired.api.FireManager;
import crystalspider.soulfired.config.SoulFiredConfig;
import crystalspider.soulfired.handlers.FireResourceReloadListener;
import crystalspider.soulfired.handlers.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.fml.config.ModConfig.Type;
import net.minecraftforge.api.ModLoadingContext;

Expand All @@ -21,12 +24,23 @@ public final class SoulFiredLoader implements ModInitializer {
public void onInitialize() {
ModLoadingContext.registerConfig(MODID, Type.COMMON, SoulFiredConfig.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(SoulFiredConfig::getEnableSoulFireAspect))
.setFlameConfig(builder -> builder.setEnabled(SoulFiredConfig::getEnableSoulFlame))
.setFireAspectConfig(builder -> builder
.setEnabled(SoulFiredConfig::getEnableSoulFireAspect)
.setIsDiscoverable(SoulFiredConfig::getEnableSoulFireAspectDiscovery)
.setIsTradeable(SoulFiredConfig::getEnableSoulFireAspectTrades)
.setIsTreasure(SoulFiredConfig::getEnableSoulFireAspectTreasure)
)
.setFlameConfig(builder -> builder
.setEnabled(SoulFiredConfig::getEnableSoulFlame)
.setIsDiscoverable(SoulFiredConfig::getEnableSoulFlameDiscovery)
.setIsTradeable(SoulFiredConfig::getEnableSoulFlameTrades)
.setIsTreasure(SoulFiredConfig::getEnableSoulFlameTreasure)
)
.build()
);
}
}
}
25 changes: 19 additions & 6 deletions fabric/src/main/java/crystalspider/soulfired/api/FireManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ public static synchronized boolean registerFire(Fire fire) {
Optional<Identifier> source = fire.getSource();
Optional<Identifier> campfire = fire.getCampfire();
if (source.isPresent()) {
Block sourceBlock = Registry.BLOCK.get(source.get());
if (sourceBlock != null) {
((FireTypeChanger) sourceBlock).setFireType(fireType);
Optional<Block> sourceBlock = Registry.BLOCK.getOrEmpty(source.get());
if (sourceBlock.isPresent()) {
((FireTypeChanger) sourceBlock.get()).setFireType(fireType);
}
}
if (campfire.isPresent()) {
Block campfireBlock = Registry.BLOCK.get(campfire.get());
if (campfireBlock != null) {
((FireTypeChanger) campfireBlock).setFireType(fireType);
Optional<Block> campfireBlock = Registry.BLOCK.getOrEmpty(campfire.get());
if (campfireBlock.isPresent()) {
((FireTypeChanger) campfireBlock.get()).setFireType(fireType);
}
}
return true;
Expand Down Expand Up @@ -146,6 +146,19 @@ public static synchronized HashMap<Identifier, Boolean> registerFires(List<Fire>
return outcomes;
}

/**
* Unregisters the specified fire.
* <p>
* To be used only internally, do not use elsewhere!
*
* @param fireType
* @return whether the fire was previously registered.
*/
@Deprecated
public static synchronized boolean unregisterFire(Identifier fireType) {
return fires.remove(fireType) != null;
}

/**
* Returns the list of all registered {@link Fire Fires}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ public static synchronized HashMap<Identifier, Boolean> registerFires(List<Fire>
return outcomes;
}

/**
* Unregisters the specified fire.
* <p>
* To be used only internally, do not use elsewhere!
*
* @param fireType
* @return whether the fire was previously registered.
*/
@Deprecated
public static synchronized boolean unregisterFire(Identifier fireType) {
return fires.remove(fireType) != null;
}

/**
* Attempts to register the given {@link FireClient}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,33 @@ public static Boolean getEnableSoulFireAspect() {
return COMMON.enableSoulFireAspect.get();
}

/**
* Returns the value of {@link CommonConfig#enableSoulFireAspectDiscovery}.
*
* @return {@link CommonConfig#enableSoulFireAspectDiscovery} as read from the {@link #COMMON common} configuration file.
*/
public static Boolean getEnableSoulFireAspectDiscovery() {
return COMMON.enableSoulFireAspectDiscovery.get();
}

/**
* Returns the value of {@link CommonConfig#enableSoulFireAspectTrades}.
*
* @return {@link CommonConfig#enableSoulFireAspectTrades} as read from the {@link #COMMON common} configuration file.
*/
public static Boolean getEnableSoulFireAspectTrades() {
return COMMON.enableSoulFireAspectTrades.get();
}

/**
* Returns the value of {@link CommonConfig#enableSoulFireAspectTreasure}.
*
* @return {@link CommonConfig#enableSoulFireAspectTreasure} as read from the {@link #COMMON common} configuration file.
*/
public static Boolean getEnableSoulFireAspectTreasure() {
return COMMON.enableSoulFireAspectTreasure.get();
}

/**
* Returns the value of {@link CommonConfig#enableSoulFlame}.
*
Expand All @@ -38,6 +65,33 @@ public static Boolean getEnableSoulFlame() {
return COMMON.enableSoulFlame.get();
}

/**
* Returns the value of {@link CommonConfig#enableSoulFlameDiscovery}.
*
* @return {@link CommonConfig#enableSoulFlameDiscovery} as read from the {@link #COMMON common} configuration file.
*/
public static Boolean getEnableSoulFlameDiscovery() {
return COMMON.enableSoulFlameDiscovery.get();
}

/**
* Returns the value of {@link CommonConfig#enableSoulFlameTrades}.
*
* @return {@link CommonConfig#enableSoulFlameTrades} as read from the {@link #COMMON common} configuration file.
*/
public static Boolean getEnableSoulFlameTrades() {
return COMMON.enableSoulFlameTrades.get();
}

/**
* Returns the value of {@link CommonConfig#enableSoulFlameTreasure}.
*
* @return {@link CommonConfig#enableSoulFlameTreasure} as read from the {@link #COMMON common} configuration file.
*/
public static Boolean getEnableSoulFlameTreasure() {
return COMMON.enableSoulFlameTreasure.get();
}

/**
* Common Configuration for Torch hit!.
*/
Expand All @@ -46,19 +100,50 @@ public static final class CommonConfig {
* Whether to enable Soul Fire Aspect enchantment.
*/
private final BooleanValue enableSoulFireAspect;
/**
* Whether Soul Fire Aspect can appear in the enchanting table and loots.
*/
private final BooleanValue enableSoulFireAspectDiscovery;
/**
* Whether Soul Fire Aspect can be traded with villagers.
*/
private final BooleanValue enableSoulFireAspectTrades;
/**
* Whether Soul Fire Aspect is a treasure enchantment (like Vanilla Mending).
*/
private final BooleanValue enableSoulFireAspectTreasure;

/**
* Whether to enable Soul Flame enchantment.
*/
private final BooleanValue enableSoulFlame;
/**
* Whether Soul Flame can appear in the enchanting table and loots.
*/
private final BooleanValue enableSoulFlameDiscovery;
/**
* Whether Soul Flame can be traded with villagers.
*/
private final BooleanValue enableSoulFlameTrades;
/**
* Whether Soul Flame is a treasure enchantment (like Vanilla Mending).
*/
private final BooleanValue enableSoulFlameTreasure;

/**
* Defines the configuration options, their default values and their comments.
*
* @param builder
*/
public CommonConfig(ForgeConfigSpec.Builder builder) {
enableSoulFireAspect = builder.comment("Whether to enable Soul Fire Aspect enchantment.").define("enable soul fire aspect", true);
enableSoulFireAspect = builder.comment("Whether to enable Soul Fire Aspect enchantment.", "Has higher priority than all other Soul Fire Aspect configs.").define("enable soul fire aspect", true);
enableSoulFireAspectDiscovery = builder.comment("Whether Soul Fire Aspect can appear in the enchanting table and loots.").define("enable soul fire aspect discovery", true);
enableSoulFireAspectTrades = builder.comment("Whether Soul Fire Aspect can be traded with villagers.").define("enable soul fire aspect trades", true);
enableSoulFireAspectTreasure = builder.comment("Whether Soul Fire Aspect is a treasure enchantment (like Vanilla Mending).").define("enable soul fire aspect treasure", false);
enableSoulFlame = builder.comment("Whether to enable Soul Flame enchantment.").define("enable soul flame", true);
enableSoulFlameDiscovery = builder.comment("Whether Soul Flame can appear in the enchanting table and loots.").define("enable soul flame discovery", true);
enableSoulFlameTrades = builder.comment("Whether Soul Flame can be traded with villagers.").define("enable soul flame trades", true);
enableSoulFlameTreasure = builder.comment("Whether Soul Flame is a treasure enchantment (like Vanilla Mending).").define("enable soul flame treasure", false);
}
}
}
Loading

0 comments on commit 6de46c4

Please sign in to comment.