From d689c325d6f8489448731538c738fc5399aae96a Mon Sep 17 00:00:00 2001 From: Davide Albiero Date: Wed, 8 Jun 2022 22:52:21 +0200 Subject: [PATCH] LootItemFunctionType now use LootItemFunctionType --- build.gradle | 4 +- .../com/refinedmods/refinedstorage/RS.java | 1 + .../refinedstorage/RSLootFunctions.java | 42 ++++++++----------- .../loottable/ControllerLootFunction.java | 2 +- .../loottable/CrafterLootFunction.java | 2 +- .../PortableGridBlockLootFunction.java | 2 +- .../loottable/StorageBlockLootFunction.java | 2 +- .../refinedstorage/setup/CommonSetup.java | 3 -- src/main/resources/META-INF/mods.toml | 6 +++ 9 files changed, 30 insertions(+), 34 deletions(-) diff --git a/build.gradle b/build.gradle index d9213c73b..b7276c143 100755 --- a/build.gradle +++ b/build.gradle @@ -102,7 +102,7 @@ processResources { } dependencies { - minecraft 'net.minecraftforge:forge:1.18.2-40.0.32' + minecraft 'net.minecraftforge:forge:1.18.2-40.1.48' compileOnly fg.deobf("mezz.jei:jei-1.18.2:9.5.4.171:api") runtimeOnly fg.deobf("mezz.jei:jei-1.18.2:9.5.4.171") @@ -122,7 +122,7 @@ jar { "Specification-Vendor" : "refinedmods", "Specification-Version" : "1", "Implementation-Title" : project.name, - "Implementation-Version" : "${version}", + "Implementation-Version" : project.jar.archiveVersion, "Implementation-Vendor" : "refinedmods", "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") ]) diff --git a/src/main/java/com/refinedmods/refinedstorage/RS.java b/src/main/java/com/refinedmods/refinedstorage/RS.java index 5c54ddc46..a6a48c117 100644 --- a/src/main/java/com/refinedmods/refinedstorage/RS.java +++ b/src/main/java/com/refinedmods/refinedstorage/RS.java @@ -48,6 +48,7 @@ public final class RS { RSBlocks.register(); RSItems.register(); + RSLootFunctions.register(); FMLJavaModLoadingContext.get().getModEventBus().addListener(CommonSetup::onCommonSetup); FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(BlockEntityType.class, CommonSetup::onRegisterBlockEntities); diff --git a/src/main/java/com/refinedmods/refinedstorage/RSLootFunctions.java b/src/main/java/com/refinedmods/refinedstorage/RSLootFunctions.java index ab4384483..69e4eeabb 100644 --- a/src/main/java/com/refinedmods/refinedstorage/RSLootFunctions.java +++ b/src/main/java/com/refinedmods/refinedstorage/RSLootFunctions.java @@ -5,38 +5,30 @@ import com.refinedmods.refinedstorage.loottable.CrafterLootFunction; import com.refinedmods.refinedstorage.loottable.PortableGridBlockLootFunction; import com.refinedmods.refinedstorage.loottable.StorageBlockLootFunction; import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.registries.DeferredRegister; +import net.minecraftforge.registries.RegistryObject; public final class RSLootFunctions { - private static LootItemFunctionType storageBlock; - private static LootItemFunctionType portableGrid; - private static LootItemFunctionType crafter; - private static LootItemFunctionType controller; + public static final RegistryObject STORAGE_BLOCK; + public static final RegistryObject PORTABLE_GRID; + public static final RegistryObject CRAFTER; + public static final RegistryObject CONTROLLER; + + private static final DeferredRegister LOOT_ITEM_FUNCTIONS = DeferredRegister.create(Registry.LOOT_FUNCTION_REGISTRY, RS.ID); + + static { + STORAGE_BLOCK = LOOT_ITEM_FUNCTIONS.register("storage_block", () -> new LootItemFunctionType(new StorageBlockLootFunction.Serializer())); + PORTABLE_GRID = LOOT_ITEM_FUNCTIONS.register("portable_grid", () -> new LootItemFunctionType(new PortableGridBlockLootFunction.Serializer())); + CRAFTER = LOOT_ITEM_FUNCTIONS.register("crafter", () -> new LootItemFunctionType(new CrafterLootFunction.Serializer())); + CONTROLLER = LOOT_ITEM_FUNCTIONS.register("controller", () -> new LootItemFunctionType(new ControllerLootFunction.Serializer())); + } private RSLootFunctions() { } public static void register() { - storageBlock = Registry.register(Registry.LOOT_FUNCTION_TYPE, new ResourceLocation(RS.ID, "storage_block"), new LootItemFunctionType(new StorageBlockLootFunction.Serializer())); - portableGrid = Registry.register(Registry.LOOT_FUNCTION_TYPE, new ResourceLocation(RS.ID, "portable_grid"), new LootItemFunctionType(new PortableGridBlockLootFunction.Serializer())); - crafter = Registry.register(Registry.LOOT_FUNCTION_TYPE, new ResourceLocation(RS.ID, "crafter"), new LootItemFunctionType(new CrafterLootFunction.Serializer())); - controller = Registry.register(Registry.LOOT_FUNCTION_TYPE, new ResourceLocation(RS.ID, "controller"), new LootItemFunctionType(new ControllerLootFunction.Serializer())); - } - - public static LootItemFunctionType getStorageBlock() { - return storageBlock; - } - - public static LootItemFunctionType getPortableGrid() { - return portableGrid; - } - - public static LootItemFunctionType getCrafter() { - return crafter; - } - - public static LootItemFunctionType getController() { - return controller; + LOOT_ITEM_FUNCTIONS.register(FMLJavaModLoadingContext.get().getModEventBus()); } } diff --git a/src/main/java/com/refinedmods/refinedstorage/loottable/ControllerLootFunction.java b/src/main/java/com/refinedmods/refinedstorage/loottable/ControllerLootFunction.java index 55bb76cec..c4b62c13a 100644 --- a/src/main/java/com/refinedmods/refinedstorage/loottable/ControllerLootFunction.java +++ b/src/main/java/com/refinedmods/refinedstorage/loottable/ControllerLootFunction.java @@ -38,7 +38,7 @@ public class ControllerLootFunction extends LootItemConditionalFunction { @Override public LootItemFunctionType getType() { - return RSLootFunctions.getController(); + return RSLootFunctions.CONTROLLER.get(); } public static class Serializer extends LootItemConditionalFunction.Serializer { diff --git a/src/main/java/com/refinedmods/refinedstorage/loottable/CrafterLootFunction.java b/src/main/java/com/refinedmods/refinedstorage/loottable/CrafterLootFunction.java index 090dbacad..117e316bb 100644 --- a/src/main/java/com/refinedmods/refinedstorage/loottable/CrafterLootFunction.java +++ b/src/main/java/com/refinedmods/refinedstorage/loottable/CrafterLootFunction.java @@ -40,7 +40,7 @@ public class CrafterLootFunction extends LootItemConditionalFunction { @Override public LootItemFunctionType getType() { - return RSLootFunctions.getCrafter(); + return RSLootFunctions.CRAFTER.get(); } public static class Serializer extends LootItemConditionalFunction.Serializer { diff --git a/src/main/java/com/refinedmods/refinedstorage/loottable/PortableGridBlockLootFunction.java b/src/main/java/com/refinedmods/refinedstorage/loottable/PortableGridBlockLootFunction.java index 101c24bbc..b16062938 100644 --- a/src/main/java/com/refinedmods/refinedstorage/loottable/PortableGridBlockLootFunction.java +++ b/src/main/java/com/refinedmods/refinedstorage/loottable/PortableGridBlockLootFunction.java @@ -30,7 +30,7 @@ public class PortableGridBlockLootFunction extends LootItemConditionalFunction { @Override public LootItemFunctionType getType() { - return RSLootFunctions.getPortableGrid(); + return RSLootFunctions.PORTABLE_GRID.get(); } public static class Serializer extends LootItemConditionalFunction.Serializer { diff --git a/src/main/java/com/refinedmods/refinedstorage/loottable/StorageBlockLootFunction.java b/src/main/java/com/refinedmods/refinedstorage/loottable/StorageBlockLootFunction.java index 8a2f0414d..cd2582423 100644 --- a/src/main/java/com/refinedmods/refinedstorage/loottable/StorageBlockLootFunction.java +++ b/src/main/java/com/refinedmods/refinedstorage/loottable/StorageBlockLootFunction.java @@ -51,7 +51,7 @@ public class StorageBlockLootFunction extends LootItemConditionalFunction { @Override public LootItemFunctionType getType() { - return RSLootFunctions.getStorageBlock(); + return RSLootFunctions.STORAGE_BLOCK.get(); } public static class Serializer extends LootItemConditionalFunction.Serializer { diff --git a/src/main/java/com/refinedmods/refinedstorage/setup/CommonSetup.java b/src/main/java/com/refinedmods/refinedstorage/setup/CommonSetup.java index 57d08073b..0828b11be 100644 --- a/src/main/java/com/refinedmods/refinedstorage/setup/CommonSetup.java +++ b/src/main/java/com/refinedmods/refinedstorage/setup/CommonSetup.java @@ -159,9 +159,6 @@ public final class CommonSetup { @SubscribeEvent public static void onRegisterBlockEntities(RegistryEvent.Register> e) { - // Register here, there seems to be no specific register event for loot function types. - RSLootFunctions.register(); - e.getRegistry().register(registerSynchronizationParameters(BlockEntityType.Builder.of((pos, state) -> new ControllerBlockEntity(NetworkType.NORMAL, pos, state), RSBlocks.CONTROLLER.getBlocks()).build(null).setRegistryName(RS.ID, "controller"))); e.getRegistry().register(registerSynchronizationParameters(BlockEntityType.Builder.of((pos, state) -> new ControllerBlockEntity(NetworkType.CREATIVE, pos, state), RSBlocks.CREATIVE_CONTROLLER.getBlocks()).build(null).setRegistryName(RS.ID, "creative_controller"))); e.getRegistry().register(BlockEntityType.Builder.of(CableBlockEntity::new, RSBlocks.CABLE.get()).build(null).setRegistryName(RS.ID, "cable")); diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index de6a82fec..51ca61878 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -12,3 +12,9 @@ authors = "Refined Mods" description = ''' An elegant solution to your hoarding problem ''' +[[dependencies.refinedstorage]] +modId="forge" +mandatory=true +versionRange="[40.1,)" +ordering="NONE" +side="BOTH" \ No newline at end of file