Line 9: |
Line 9: |
| #* This will contain all of the data about your modification and allows data packs to tweak your effect. | | #* This will contain all of the data about your modification and allows data packs to tweak your effect. |
| # A class that extends <code>LootModifier</code> | | # A class that extends <code>LootModifier</code> |
− | #* The operational code that makes your modifier work and associated serializer. | + | #* The operational code that makes your modifier work and associated codec. |
| | | |
− | Finally, the serializer for your operational class is [[Registration|registered]] as any other registry object. | + | Finally, the codec for your operational class is [[Registration|registered]] as any other registry object. |
| | | |
| ==The global_loot_modifiers.json== | | ==The global_loot_modifiers.json== |
Line 66: |
Line 66: |
| == The LootModifier Subclass == | | == The LootModifier Subclass == |
| | | |
− | You will also need a static child class that extends <code>GlobalLootModifierSerializer<T></code> where <code>T</code> is your LootModifier subclass in order to deserialize your json data file into operational code. | + | You will also need a <code>Codec<T></code> where <code>T</code> is your LootModifier subclass in order to deserialize your json data file into operational code. The codec must be [[Registration|registered]]. |
| | | |
| <syntaxhighlight lang="java"> | | <syntaxhighlight lang="java"> |
Line 74: |
Line 74: |
| * | | * |
| */ | | */ |
| + | // Assume there exists a <code>IForgeRegistry<Codec<T extends LootModifier>></code> LOOT_MODIFIER_REGISTRAR added by a mod |
| private static class WheatSeedsConverterModifier extends LootModifier | | private static class WheatSeedsConverterModifier extends LootModifier |
| { | | { |
− | public static final Supplier<Codec<WheatSeedsConverterModifier>> CODEC = Suppliers.memoize(() -> | + | public static final RegistryObject<Codec<WheatSeedsConverterModifier>> CODEC = LOOT_MODIFIER_REGISTRAR.register("wheat_seeds_converter", () -> |
| RecordCodecBuilder.create(inst -> codecStart(inst).and( | | RecordCodecBuilder.create(inst -> codecStart(inst).and( |
| inst.group( | | inst.group( |
Line 128: |
Line 129: |
| This method is only called if the <code>conditions</code> specified return <code>true</code> and the modder is now able to make the modifications they desire. In this case we can see that the number of <code>itemToCheck</code> meets or exceeds the <code>numSeedsToConvert</code> before modifying the list by adding an <code>itemReward</code> and removing any excess <code>itemToCheck</code> stacks, matching the previously mentioned effects: ''When a wheat block is harvested with shears, if enough seeds are generated as loot, they are converted to additional wheat instead''. | | This method is only called if the <code>conditions</code> specified return <code>true</code> and the modder is now able to make the modifications they desire. In this case we can see that the number of <code>itemToCheck</code> meets or exceeds the <code>numSeedsToConvert</code> before modifying the list by adding an <code>itemReward</code> and removing any excess <code>itemToCheck</code> stacks, matching the previously mentioned effects: ''When a wheat block is harvested with shears, if enough seeds are generated as loot, they are converted to additional wheat instead''. |
| | | |
− | Utilize <code>GlobalLootModifierProvider</code> for [[datageneration|data generation]].
| + | The codec can also be used for [[datageneration|data generation]] with a <code>GlobalLootModifierProvider</code>. |
| | | |
| Additional [https://github.com/MinecraftForge/MinecraftForge/blob/1.19.x/src/test/java/net/minecraftforge/debug/gameplay/loot/GlobalLootModifiersTest.java examples] can be found on the Forge Git repository, including silk touch and smelting effects. | | Additional [https://github.com/MinecraftForge/MinecraftForge/blob/1.19.x/src/test/java/net/minecraftforge/debug/gameplay/loot/GlobalLootModifiersTest.java examples] can be found on the Forge Git repository, including silk touch and smelting effects. |