From d08c1736e3a32f36d387ffb433a71badb23583d3 Mon Sep 17 00:00:00 2001 From: AterAnimAvis Date: Mon, 20 Nov 2023 12:06:39 +0000 Subject: [PATCH] Update to 20.2.59-beta (Registry Rework) (#19) For more details on updating check out the blogpost at https://neoforged.net/news/20.2registry-rework/ --- build.gradle | 2 +- gradle.properties | 2 +- .../java/com/example/examplemod/Config.java | 6 ++--- .../com/example/examplemod/ExampleMod.java | 23 ++++++++++--------- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index f8de59d..a20ec77 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { id 'eclipse' id 'idea' id 'maven-publish' - id 'net.neoforged.gradle.userdev' version '7.0.26' + id 'net.neoforged.gradle.userdev' version '7.0.45' } version = mod_version diff --git a/gradle.properties b/gradle.properties index 8b9cb0e..ff26558 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ minecraft_version=1.20.2 # as they do not follow standard versioning conventions. minecraft_version_range=[1.20.2,1.21) # The Neo version must agree with the Minecraft version to get a valid artifact -neo_version=20.2.35-beta +neo_version=20.2.59-beta # The Neo version range can use any version of Neo as bounds or match the loader version range neo_version_range=[20.2,) # The loader version range can only use the major version of Neo/FML as bounds diff --git a/src/main/java/com/example/examplemod/Config.java b/src/main/java/com/example/examplemod/Config.java index cc381bb..334387f 100644 --- a/src/main/java/com/example/examplemod/Config.java +++ b/src/main/java/com/example/examplemod/Config.java @@ -1,12 +1,12 @@ package com.example.examplemod; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.Mod; import net.neoforged.fml.event.config.ModConfigEvent; import net.neoforged.neoforge.common.ModConfigSpec; -import net.neoforged.neoforge.registries.ForgeRegistries; import java.util.List; import java.util.Set; @@ -45,7 +45,7 @@ public class Config private static boolean validateItemName(final Object obj) { - return obj instanceof final String itemName && ForgeRegistries.ITEMS.containsKey(new ResourceLocation(itemName)); + return obj instanceof final String itemName && BuiltInRegistries.ITEM.containsKey(new ResourceLocation(itemName)); } @SubscribeEvent @@ -57,7 +57,7 @@ public class Config // convert the list of strings into a set of items items = ITEM_STRINGS.get().stream() - .map(itemName -> ForgeRegistries.ITEMS.getValue(new ResourceLocation(itemName))) + .map(itemName -> BuiltInRegistries.ITEM.get(new ResourceLocation(itemName))) .collect(Collectors.toSet()); } } diff --git a/src/main/java/com/example/examplemod/ExampleMod.java b/src/main/java/com/example/examplemod/ExampleMod.java index f6a02a8..e967e83 100644 --- a/src/main/java/com/example/examplemod/ExampleMod.java +++ b/src/main/java/com/example/examplemod/ExampleMod.java @@ -2,6 +2,7 @@ package com.example.examplemod; import com.mojang.logging.LogUtils; import net.minecraft.client.Minecraft; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.world.food.FoodProperties; import net.minecraft.world.item.BlockItem; @@ -20,13 +21,13 @@ import net.neoforged.fml.common.Mod; import net.neoforged.fml.config.ModConfig; import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; -import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext; import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; import net.neoforged.neoforge.event.server.ServerStartingEvent; +import net.neoforged.neoforge.registries.DeferredBlock; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredItem; import net.neoforged.neoforge.registries.DeferredRegister; -import net.neoforged.neoforge.registries.ForgeRegistries; -import net.neoforged.neoforge.registries.RegistryObject; import org.slf4j.Logger; // The value here should match an entry in the META-INF/mods.toml file @@ -38,23 +39,23 @@ public class ExampleMod // Directly reference a slf4j logger private static final Logger LOGGER = LogUtils.getLogger(); // Create a Deferred Register to hold Blocks which will all be registered under the "examplemod" namespace - public static final DeferredRegister BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID); + public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(MODID); // Create a Deferred Register to hold Items which will all be registered under the "examplemod" namespace - public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID); + public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MODID); // Create a Deferred Register to hold CreativeModeTabs which will all be registered under the "examplemod" namespace public static final DeferredRegister CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID); // Creates a new Block with the id "examplemod:example_block", combining the namespace and path - public static final RegistryObject EXAMPLE_BLOCK = BLOCKS.register("example_block", () -> new Block(BlockBehaviour.Properties.of().mapColor(MapColor.STONE))); + public static final DeferredBlock EXAMPLE_BLOCK = BLOCKS.registerBlock("example_block", BlockBehaviour.Properties.of().mapColor(MapColor.STONE)); // Creates a new BlockItem with the id "examplemod:example_block", combining the namespace and path - public static final RegistryObject EXAMPLE_BLOCK_ITEM = ITEMS.register("example_block", () -> new BlockItem(EXAMPLE_BLOCK.get(), new Item.Properties())); + public static final DeferredItem EXAMPLE_BLOCK_ITEM = ITEMS.registerBlockItem("example_block", EXAMPLE_BLOCK); // Creates a new food item with the id "examplemod:example_id", nutrition 1 and saturation 2 - public static final RegistryObject EXAMPLE_ITEM = ITEMS.register("example_item", () -> new Item(new Item.Properties().food(new FoodProperties.Builder() - .alwaysEat().nutrition(1).saturationMod(2f).build()))); + public static final DeferredItem EXAMPLE_ITEM = ITEMS.registerItem("example_item", new Item.Properties().food(new FoodProperties.Builder() + .alwaysEat().nutrition(1).saturationMod(2f).build())); // Creates a creative tab with the id "examplemod:example_tab" for the example item, that is placed after the combat tab - public static final RegistryObject EXAMPLE_TAB = CREATIVE_MODE_TABS.register("example_tab", () -> CreativeModeTab.builder() + public static final DeferredHolder EXAMPLE_TAB = CREATIVE_MODE_TABS.register("example_tab", () -> CreativeModeTab.builder() .withTabsBefore(CreativeModeTabs.COMBAT) .icon(() -> EXAMPLE_ITEM.get().getDefaultInstance()) .displayItems((parameters, output) -> { @@ -91,7 +92,7 @@ public class ExampleMod LOGGER.info("HELLO FROM COMMON SETUP"); if (Config.logDirtBlock) - LOGGER.info("DIRT BLOCK >> {}", ForgeRegistries.BLOCKS.getKey(Blocks.DIRT)); + LOGGER.info("DIRT BLOCK >> {}", BuiltInRegistries.BLOCK.getKey(Blocks.DIRT)); LOGGER.info(Config.magicNumberIntroduction + Config.magicNumber);