-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added a system for supporting other mods as well as re-implement support for Trinkets. * Fixed a bug where having the mod on without trinkets will crash the game.
- Loading branch information
1 parent
561c93f
commit 559b4ff
Showing
6 changed files
with
106 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/powercyphe/coffins/modsupport/ModSupportManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package powercyphe.coffins.modsupport; | ||
|
||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemStack; | ||
import powercyphe.coffins.modsupport.impl.TrinketsModSupportImpl; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ModSupportManager { | ||
public static final List<ModSupporter> modSupportClasses = List.of( | ||
// Mod support implementation classes go here. | ||
new TrinketsModSupportImpl() | ||
); | ||
|
||
public static List<ItemStack> getAllModSupportedDrops(PlayerEntity player) { | ||
List<ItemStack> modSupportDrops = new ArrayList<>(); | ||
modSupportClasses.forEach(clazz -> { | ||
// Only add the items if the mod is loaded | ||
if (clazz.isModLoaded()) modSupportDrops.addAll(clazz.getDrops(player)); | ||
}); | ||
return modSupportDrops; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/powercyphe/coffins/modsupport/ModSupporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package powercyphe.coffins.modsupport; | ||
|
||
import net.fabricmc.loader.api.FabricLoader; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemStack; | ||
|
||
import java.util.List; | ||
|
||
public interface ModSupporter { | ||
/** | ||
* Returns the mod ID of the mod the {@link ModSupporter} is supporting. | ||
* @return The supporting mod ID as a string. | ||
*/ | ||
String supportingModId(); | ||
|
||
/** | ||
* Called on the {@link powercyphe.coffins.Mod}'s onInitialize method if the mod is loaded. | ||
*/ | ||
void onInit(); | ||
|
||
/** | ||
* Returns a list of {@link ItemStack}s that the player has or owns, depending on the mod. | ||
* @param player The player that died. | ||
* @return A list of {@link ItemStack}s representing the player's drops. | ||
*/ | ||
List<ItemStack> getDrops(PlayerEntity player); | ||
|
||
/** | ||
* Checks if the mod is loaded by the client. | ||
* @return True if the mod is loaded, false otherwise. | ||
*/ | ||
default boolean isModLoaded() { | ||
return FabricLoader.getInstance().isModLoaded(supportingModId()); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/powercyphe/coffins/modsupport/impl/TrinketsModSupportImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package powercyphe.coffins.modsupport.impl; | ||
|
||
import dev.emi.trinkets.api.TrinketsApi; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemStack; | ||
import powercyphe.coffins.event.TrinketDropEvent; | ||
import powercyphe.coffins.modsupport.ModSupporter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Mod support for Trinkets | ||
* @author redvortex | ||
*/ | ||
public class TrinketsModSupportImpl implements ModSupporter { | ||
@Override | ||
public String supportingModId() { | ||
return "trinkets"; | ||
} | ||
|
||
@Override | ||
public void onInit() { | ||
TrinketDropEvent.registerCallback(); | ||
} | ||
|
||
@Override | ||
public List<ItemStack> getDrops(PlayerEntity player) { | ||
List<ItemStack> items = new ArrayList<>(); | ||
TrinketsApi.getTrinketComponent(player).ifPresent(trinkets -> trinkets.forEach((ref, stack) -> { | ||
if (!stack.isEmpty()) { | ||
items.add(stack); | ||
} | ||
})); | ||
return items; | ||
} | ||
} |