Skip to content

Commit d08c173

Browse files
authored
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/
1 parent 8dd9258 commit d08c173

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
id 'eclipse'
44
id 'idea'
55
id 'maven-publish'
6-
id 'net.neoforged.gradle.userdev' version '7.0.26'
6+
id 'net.neoforged.gradle.userdev' version '7.0.45'
77
}
88

99
version = mod_version

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ minecraft_version=1.20.2
1313
# as they do not follow standard versioning conventions.
1414
minecraft_version_range=[1.20.2,1.21)
1515
# The Neo version must agree with the Minecraft version to get a valid artifact
16-
neo_version=20.2.35-beta
16+
neo_version=20.2.59-beta
1717
# The Neo version range can use any version of Neo as bounds or match the loader version range
1818
neo_version_range=[20.2,)
1919
# The loader version range can only use the major version of Neo/FML as bounds

src/main/java/com/example/examplemod/Config.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.example.examplemod;
22

3+
import net.minecraft.core.registries.BuiltInRegistries;
34
import net.minecraft.resources.ResourceLocation;
45
import net.minecraft.world.item.Item;
56
import net.neoforged.bus.api.SubscribeEvent;
67
import net.neoforged.fml.common.Mod;
78
import net.neoforged.fml.event.config.ModConfigEvent;
89
import net.neoforged.neoforge.common.ModConfigSpec;
9-
import net.neoforged.neoforge.registries.ForgeRegistries;
1010

1111
import java.util.List;
1212
import java.util.Set;
@@ -45,7 +45,7 @@ public class Config
4545

4646
private static boolean validateItemName(final Object obj)
4747
{
48-
return obj instanceof final String itemName && ForgeRegistries.ITEMS.containsKey(new ResourceLocation(itemName));
48+
return obj instanceof final String itemName && BuiltInRegistries.ITEM.containsKey(new ResourceLocation(itemName));
4949
}
5050

5151
@SubscribeEvent
@@ -57,7 +57,7 @@ static void onLoad(final ModConfigEvent event)
5757

5858
// convert the list of strings into a set of items
5959
items = ITEM_STRINGS.get().stream()
60-
.map(itemName -> ForgeRegistries.ITEMS.getValue(new ResourceLocation(itemName)))
60+
.map(itemName -> BuiltInRegistries.ITEM.get(new ResourceLocation(itemName)))
6161
.collect(Collectors.toSet());
6262
}
6363
}

src/main/java/com/example/examplemod/ExampleMod.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.mojang.logging.LogUtils;
44
import net.minecraft.client.Minecraft;
5+
import net.minecraft.core.registries.BuiltInRegistries;
56
import net.minecraft.core.registries.Registries;
67
import net.minecraft.world.food.FoodProperties;
78
import net.minecraft.world.item.BlockItem;
@@ -20,13 +21,13 @@
2021
import net.neoforged.fml.config.ModConfig;
2122
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
2223
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
23-
import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext;
2424
import net.neoforged.neoforge.common.NeoForge;
2525
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
2626
import net.neoforged.neoforge.event.server.ServerStartingEvent;
27+
import net.neoforged.neoforge.registries.DeferredBlock;
28+
import net.neoforged.neoforge.registries.DeferredHolder;
29+
import net.neoforged.neoforge.registries.DeferredItem;
2730
import net.neoforged.neoforge.registries.DeferredRegister;
28-
import net.neoforged.neoforge.registries.ForgeRegistries;
29-
import net.neoforged.neoforge.registries.RegistryObject;
3031
import org.slf4j.Logger;
3132

3233
// The value here should match an entry in the META-INF/mods.toml file
@@ -38,23 +39,23 @@ public class ExampleMod
3839
// Directly reference a slf4j logger
3940
private static final Logger LOGGER = LogUtils.getLogger();
4041
// Create a Deferred Register to hold Blocks which will all be registered under the "examplemod" namespace
41-
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
42+
public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(MODID);
4243
// Create a Deferred Register to hold Items which will all be registered under the "examplemod" namespace
43-
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
44+
public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MODID);
4445
// Create a Deferred Register to hold CreativeModeTabs which will all be registered under the "examplemod" namespace
4546
public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID);
4647

4748
// Creates a new Block with the id "examplemod:example_block", combining the namespace and path
48-
public static final RegistryObject<Block> EXAMPLE_BLOCK = BLOCKS.register("example_block", () -> new Block(BlockBehaviour.Properties.of().mapColor(MapColor.STONE)));
49+
public static final DeferredBlock<Block> EXAMPLE_BLOCK = BLOCKS.registerBlock("example_block", BlockBehaviour.Properties.of().mapColor(MapColor.STONE));
4950
// Creates a new BlockItem with the id "examplemod:example_block", combining the namespace and path
50-
public static final RegistryObject<Item> EXAMPLE_BLOCK_ITEM = ITEMS.register("example_block", () -> new BlockItem(EXAMPLE_BLOCK.get(), new Item.Properties()));
51+
public static final DeferredItem<BlockItem> EXAMPLE_BLOCK_ITEM = ITEMS.registerBlockItem("example_block", EXAMPLE_BLOCK);
5152

5253
// Creates a new food item with the id "examplemod:example_id", nutrition 1 and saturation 2
53-
public static final RegistryObject<Item> EXAMPLE_ITEM = ITEMS.register("example_item", () -> new Item(new Item.Properties().food(new FoodProperties.Builder()
54-
.alwaysEat().nutrition(1).saturationMod(2f).build())));
54+
public static final DeferredItem<Item> EXAMPLE_ITEM = ITEMS.registerItem("example_item", new Item.Properties().food(new FoodProperties.Builder()
55+
.alwaysEat().nutrition(1).saturationMod(2f).build()));
5556

5657
// Creates a creative tab with the id "examplemod:example_tab" for the example item, that is placed after the combat tab
57-
public static final RegistryObject<CreativeModeTab> EXAMPLE_TAB = CREATIVE_MODE_TABS.register("example_tab", () -> CreativeModeTab.builder()
58+
public static final DeferredHolder<CreativeModeTab, CreativeModeTab> EXAMPLE_TAB = CREATIVE_MODE_TABS.register("example_tab", () -> CreativeModeTab.builder()
5859
.withTabsBefore(CreativeModeTabs.COMBAT)
5960
.icon(() -> EXAMPLE_ITEM.get().getDefaultInstance())
6061
.displayItems((parameters, output) -> {
@@ -91,7 +92,7 @@ private void commonSetup(final FMLCommonSetupEvent event)
9192
LOGGER.info("HELLO FROM COMMON SETUP");
9293

9394
if (Config.logDirtBlock)
94-
LOGGER.info("DIRT BLOCK >> {}", ForgeRegistries.BLOCKS.getKey(Blocks.DIRT));
95+
LOGGER.info("DIRT BLOCK >> {}", BuiltInRegistries.BLOCK.getKey(Blocks.DIRT));
9596

9697
LOGGER.info(Config.magicNumberIntroduction + Config.magicNumber);
9798

0 commit comments

Comments
 (0)