diff --git a/fabric-api-lookup-api-v1/src/testmod/java/net/fabricmc/fabric/test/lookup/FabricApiLookupTest.java b/fabric-api-lookup-api-v1/src/testmod/java/net/fabricmc/fabric/test/lookup/FabricApiLookupTest.java index f670dda169..20feb970eb 100644 --- a/fabric-api-lookup-api-v1/src/testmod/java/net/fabricmc/fabric/test/lookup/FabricApiLookupTest.java +++ b/fabric-api-lookup-api-v1/src/testmod/java/net/fabricmc/fabric/test/lookup/FabricApiLookupTest.java @@ -16,6 +16,11 @@ package net.fabricmc.fabric.test.lookup; +import net.minecraft.block.Block; +import net.minecraft.registry.RegistryKey; + +import net.minecraft.registry.RegistryKeys; + import org.jetbrains.annotations.NotNull; import net.minecraft.block.AbstractBlock; @@ -41,30 +46,35 @@ public class FabricApiLookupTest implements ModInitializer { public static final String MOD_ID = "fabric-lookup-api-v1-testmod"; // Chute - Block without model that transfers item from the container above to the container below. // It's meant to work with unsided containers: chests, dispensers, droppers and hoppers. - public static final ChuteBlock CHUTE_BLOCK = new ChuteBlock(AbstractBlock.Settings.create()); + public static final RegistryKey CHUTE_BLOCK_KEY = keyOf("chute"); + public static final ChuteBlock CHUTE_BLOCK = new ChuteBlock(AbstractBlock.Settings.create().registryKey(CHUTE_BLOCK_KEY)); public static final BlockItem CHUTE_ITEM = new BlockItem(CHUTE_BLOCK, new Item.Settings()); public static BlockEntityType CHUTE_BLOCK_ENTITY_TYPE; // Cobble gen - Block without model that can generate infinite cobblestone when placed above a chute. // It's meant to test BlockApiLookup#registerSelf. - public static final CobbleGenBlock COBBLE_GEN_BLOCK = new CobbleGenBlock(AbstractBlock.Settings.create()); + public static final RegistryKey COBBLE_GEN_BLOCK_KEY = keyOf("cobble_gen"); + public static final CobbleGenBlock COBBLE_GEN_BLOCK = new CobbleGenBlock(AbstractBlock.Settings.create().registryKey(COBBLE_GEN_BLOCK_KEY)); public static final BlockItem COBBLE_GEN_ITEM = new BlockItem(COBBLE_GEN_BLOCK, new Item.Settings()); public static BlockEntityType COBBLE_GEN_BLOCK_ENTITY_TYPE; // Testing for item api lookups is done in the `item` package. - public static final InspectorBlock INSPECTOR_BLOCK = new InspectorBlock(AbstractBlock.Settings.create()); + public static final RegistryKey INSPECTOR_BLOCK_KEY = keyOf("inspector"); + public static final InspectorBlock INSPECTOR_BLOCK = new InspectorBlock(AbstractBlock.Settings.create().registryKey(INSPECTOR_BLOCK_KEY)); public static final BlockItem INSPECTOR_ITEM = new BlockItem(INSPECTOR_BLOCK, new Item.Settings()); + private static RegistryKey keyOf(String id) { + return RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(MOD_ID, id)); + } + @Override public void onInitialize() { - Identifier chute = Identifier.of(MOD_ID, "chute"); - Registry.register(Registries.BLOCK, chute, CHUTE_BLOCK); - Registry.register(Registries.ITEM, chute, CHUTE_ITEM); - CHUTE_BLOCK_ENTITY_TYPE = Registry.register(Registries.BLOCK_ENTITY_TYPE, chute, FabricBlockEntityTypeBuilder.create(ChuteBlockEntity::new, CHUTE_BLOCK).build()); + Registry.register(Registries.BLOCK, CHUTE_BLOCK_KEY, CHUTE_BLOCK); + Registry.register(Registries.ITEM, CHUTE_BLOCK_KEY.getValue(), CHUTE_ITEM); + CHUTE_BLOCK_ENTITY_TYPE = Registry.register(Registries.BLOCK_ENTITY_TYPE, CHUTE_BLOCK_KEY.getValue(), FabricBlockEntityTypeBuilder.create(ChuteBlockEntity::new, CHUTE_BLOCK).build()); - Identifier cobbleGen = Identifier.of(MOD_ID, "cobble_gen"); - Registry.register(Registries.BLOCK, cobbleGen, COBBLE_GEN_BLOCK); - Registry.register(Registries.ITEM, cobbleGen, COBBLE_GEN_ITEM); - COBBLE_GEN_BLOCK_ENTITY_TYPE = Registry.register(Registries.BLOCK_ENTITY_TYPE, cobbleGen, FabricBlockEntityTypeBuilder.create(CobbleGenBlockEntity::new, COBBLE_GEN_BLOCK).build()); + Registry.register(Registries.BLOCK, COBBLE_GEN_BLOCK_KEY, COBBLE_GEN_BLOCK); + Registry.register(Registries.ITEM, COBBLE_GEN_BLOCK_KEY.getValue(), COBBLE_GEN_ITEM); + COBBLE_GEN_BLOCK_ENTITY_TYPE = Registry.register(Registries.BLOCK_ENTITY_TYPE, COBBLE_GEN_BLOCK_KEY.getValue(), FabricBlockEntityTypeBuilder.create(CobbleGenBlockEntity::new, COBBLE_GEN_BLOCK).build()); InventoryExtractableProvider extractableProvider = new InventoryExtractableProvider(); InventoryInsertableProvider insertableProvider = new InventoryInsertableProvider(); @@ -76,9 +86,8 @@ public void onInitialize() { testLookupRegistry(); testSelfRegistration(); - Identifier inspector = Identifier.of(FabricApiLookupTest.MOD_ID, "inspector"); - Registry.register(Registries.BLOCK, inspector, INSPECTOR_BLOCK); - Registry.register(Registries.ITEM, inspector, INSPECTOR_ITEM); + Registry.register(Registries.BLOCK, INSPECTOR_BLOCK_KEY, INSPECTOR_BLOCK); + Registry.register(Registries.ITEM, INSPECTOR_BLOCK_KEY.getValue(), INSPECTOR_ITEM); FabricItemApiLookupTest.onInitialize(); FabricEntityApiLookupTest.onInitialize(); diff --git a/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BiomeModificationContextImpl.java b/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BiomeModificationContextImpl.java index d65c804739..85fce82e54 100644 --- a/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BiomeModificationContextImpl.java +++ b/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BiomeModificationContextImpl.java @@ -194,8 +194,8 @@ public void setMusic(Optional sound) { } private class GenerationSettingsContextImpl implements GenerationSettingsContext { - private final Registry> carvers = registries.get(RegistryKeys.CONFIGURED_CARVER); - private final Registry features = registries.get(RegistryKeys.PLACED_FEATURE); + private final Registry> carvers = registries.getOrThrow(RegistryKeys.CONFIGURED_CARVER); + private final Registry features = registries.getOrThrow(RegistryKeys.PLACED_FEATURE); private final GenerationSettings generationSettings = biome.getGenerationSettings(); boolean rebuildFeatures; @@ -316,7 +316,7 @@ private RegistryEntryList plus(@Nullable RegistryEntryList values, Reg * forgot to data-gen the JSONs corresponding to their built-in objects. */ private static RegistryEntry.Reference getEntry(Registry registry, RegistryKey key) { - RegistryEntry.Reference entry = registry.getEntry(key).orElse(null); + RegistryEntry.Reference entry = registry.getOptional(key).orElse(null); if (entry == null) { // The key doesn't exist in the data packs diff --git a/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BiomeModificationImpl.java b/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BiomeModificationImpl.java index 2adaaf425f..da76580757 100644 --- a/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BiomeModificationImpl.java +++ b/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BiomeModificationImpl.java @@ -114,13 +114,13 @@ public void finalizeWorldGen(DynamicRegistryManager impl) { BiomeModificationMarker modificationTracker = (BiomeModificationMarker) impl; modificationTracker.fabric_markModified(); - Registry biomes = impl.get(RegistryKeys.BIOME); + Registry biomes = impl.getOrThrow(RegistryKeys.BIOME); // Build a list of all biome keys in ascending order of their raw-id to get a consistent result in case // someone does something stupid. List> keys = biomes.getEntrySet().stream() .map(Map.Entry::getKey) - .sorted(Comparator.comparingInt(key -> biomes.getRawId(biomes.getOrThrow(key)))) + .sorted(Comparator.comparingInt(key -> biomes.getRawId(biomes.getValueOrThrow(key)))) .toList(); List sortedModifiers = getSortedModifiers(); @@ -130,7 +130,7 @@ public void finalizeWorldGen(DynamicRegistryManager impl) { int modifiersApplied = 0; for (RegistryKey key : keys) { - Biome biome = biomes.getOrThrow(key); + Biome biome = biomes.getValueOrThrow(key); biomesProcessed++; @@ -159,7 +159,7 @@ public void finalizeWorldGen(DynamicRegistryManager impl) { modificationContext.freeze(); if (modificationContext.shouldRebuildFeatures()) { - impl.get(RegistryKeys.DIMENSION).stream().forEach(dimensionOptions -> { + impl.getOrThrow(RegistryKeys.DIMENSION).stream().forEach(dimensionOptions -> { dimensionOptions.chunkGenerator().indexedFeaturesListSupplier = Suppliers.memoize( () -> PlacedFeatureIndexer.collectIndexedFeatures( List.copyOf(dimensionOptions.chunkGenerator().getBiomeSource().getBiomes()), diff --git a/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BiomeSelectionContextImpl.java b/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BiomeSelectionContextImpl.java index 98ca243568..f3a58d5f72 100644 --- a/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BiomeSelectionContextImpl.java +++ b/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BiomeSelectionContextImpl.java @@ -42,7 +42,7 @@ public BiomeSelectionContextImpl(DynamicRegistryManager dynamicRegistries, Regis this.dynamicRegistries = dynamicRegistries; this.key = key; this.biome = biome; - this.entry = dynamicRegistries.get(RegistryKeys.BIOME).getEntry(this.key).orElseThrow(); + this.entry = dynamicRegistries.getOrThrow(RegistryKeys.BIOME).getOrThrow(this.key); } @Override @@ -62,19 +62,19 @@ public RegistryEntry getBiomeRegistryEntry() { @Override public Optional>> getFeatureKey(ConfiguredFeature configuredFeature) { - Registry> registry = dynamicRegistries.get(RegistryKeys.CONFIGURED_FEATURE); + Registry> registry = dynamicRegistries.getOrThrow(RegistryKeys.CONFIGURED_FEATURE); return registry.getKey(configuredFeature); } @Override public Optional> getPlacedFeatureKey(PlacedFeature placedFeature) { - Registry registry = dynamicRegistries.get(RegistryKeys.PLACED_FEATURE); + Registry registry = dynamicRegistries.getOrThrow(RegistryKeys.PLACED_FEATURE); return registry.getKey(placedFeature); } @Override public boolean validForStructure(RegistryKey key) { - Structure instance = dynamicRegistries.get(RegistryKeys.STRUCTURE).get(key); + Structure instance = dynamicRegistries.getOrThrow(RegistryKeys.STRUCTURE).get(key); if (instance == null) { return false; @@ -85,13 +85,13 @@ public boolean validForStructure(RegistryKey key) { @Override public Optional> getStructureKey(Structure structure) { - Registry registry = dynamicRegistries.get(RegistryKeys.STRUCTURE); + Registry registry = dynamicRegistries.getOrThrow(RegistryKeys.STRUCTURE); return registry.getKey(structure); } @Override public boolean canGenerateIn(RegistryKey dimensionKey) { - DimensionOptions dimension = dynamicRegistries.get(RegistryKeys.DIMENSION).get(dimensionKey); + DimensionOptions dimension = dynamicRegistries.getOrThrow(RegistryKeys.DIMENSION).get(dimensionKey); if (dimension == null) { return false; @@ -102,7 +102,7 @@ public boolean canGenerateIn(RegistryKey dimensionKey) { @Override public boolean hasTag(TagKey tag) { - Registry biomeRegistry = dynamicRegistries.get(RegistryKeys.BIOME); - return biomeRegistry.entryOf(getBiomeKey()).isIn(tag); + Registry biomeRegistry = dynamicRegistries.getOrThrow(RegistryKeys.BIOME); + return biomeRegistry.getOrThrow(getBiomeKey()).isIn(tag); } } diff --git a/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BuiltInRegistryKeys.java b/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BuiltInRegistryKeys.java index 3424ae937c..c523909cdb 100644 --- a/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BuiltInRegistryKeys.java +++ b/fabric-biome-api-v1/src/main/java/net/fabricmc/fabric/impl/biome/modification/BuiltInRegistryKeys.java @@ -37,6 +37,6 @@ public static boolean isBuiltinBiome(RegistryKey key) { } public static RegistryEntryLookup biomeRegistryWrapper() { - return vanillaRegistries.getWrapperOrThrow(RegistryKeys.BIOME); + return vanillaRegistries.getOrThrow(RegistryKeys.BIOME); } } diff --git a/fabric-client-tags-api-v1/src/client/java/net/fabricmc/fabric/impl/tag/client/ClientTagsImpl.java b/fabric-client-tags-api-v1/src/client/java/net/fabricmc/fabric/impl/tag/client/ClientTagsImpl.java index 1700242200..8a6106a903 100644 --- a/fabric-client-tags-api-v1/src/client/java/net/fabricmc/fabric/impl/tag/client/ClientTagsImpl.java +++ b/fabric-client-tags-api-v1/src/client/java/net/fabricmc/fabric/impl/tag/client/ClientTagsImpl.java @@ -50,7 +50,7 @@ private static boolean isInWithLocalFallback(TagKey tagKey, RegistryEntry if (maybeRegistry.isPresent()) { // Check the synced tag exists and use that - if (maybeRegistry.get().getEntryList(tagKey).isPresent()) { + if (maybeRegistry.get().getOptional(tagKey).isPresent()) { return registryEntry.isIn(tagKey); } } @@ -93,7 +93,7 @@ public static Optional> getRegistry(TagKey tagKey) } } - return (Optional>) Registries.REGISTRIES.getOrEmpty(tagKey.registry().getValue()); + return (Optional>) Registries.REGISTRIES.getOptionalValue(tagKey.registry().getValue()); } @SuppressWarnings("unchecked") @@ -108,7 +108,7 @@ public static Optional> getRegistryEntry(TagKey tagKey, Optional> maybeKey = registry.getKey(entry); - return maybeKey.map(registry::entryOf); + return maybeKey.map(registry::getOrThrow); } public static ClientTagsLoader.LoadedTag getOrCreatePartiallySyncedTag(TagKey tagKey) { diff --git a/fabric-content-registries-v0/src/testmod/java/net/fabricmc/fabric/test/content/registry/ContentRegistryTest.java b/fabric-content-registries-v0/src/testmod/java/net/fabricmc/fabric/test/content/registry/ContentRegistryTest.java index 4e888e29d1..56590d07da 100644 --- a/fabric-content-registries-v0/src/testmod/java/net/fabricmc/fabric/test/content/registry/ContentRegistryTest.java +++ b/fabric-content-registries-v0/src/testmod/java/net/fabricmc/fabric/test/content/registry/ContentRegistryTest.java @@ -65,6 +65,7 @@ public final class ContentRegistryTest implements ModInitializer { public static final Logger LOGGER = LoggerFactory.getLogger(ContentRegistryTest.class); public static final Identifier TEST_EVENT_ID = Identifier.of("fabric-content-registries-v0-testmod", "test_event"); + public static final RegistryKey TEST_EVENT_BLOCK_KEY = RegistryKey.of(RegistryKeys.BLOCK, TEST_EVENT_ID); public static final RegistryEntry.Reference TEST_EVENT = Registry.registerReference(Registries.GAME_EVENT, TEST_EVENT_ID, new GameEvent(GameEvent.DEFAULT_RANGE)); @Override @@ -136,7 +137,7 @@ public void onInitialize() { VillagerInteractionRegistries.registerGiftLootTable(VillagerProfession.NITWIT, RegistryKey.of(RegistryKeys.LOOT_TABLE, Identifier.ofVanilla("fake_loot_table"))); - Registry.register(Registries.BLOCK, TEST_EVENT_ID, new TestEventBlock(AbstractBlock.Settings.copy(Blocks.STONE))); + Registry.register(Registries.BLOCK, TEST_EVENT_BLOCK_KEY, new TestEventBlock(AbstractBlock.Settings.copy(Blocks.STONE).registryKey(TEST_EVENT_BLOCK_KEY))); SculkSensorFrequencyRegistry.register(TEST_EVENT.registryKey(), 2); // assert that SculkSensorFrequencyRegistry throws when registering a frequency outside the allowed range @@ -156,8 +157,8 @@ public void onInitialize() { * This testmod uses an accessor due to Loom limitations that prevent TAWs from applying across Gradle subproject boundaries */ FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> { builder.registerPotionType(dirtyPotion); - builder.registerItemRecipe(Items.POTION, Ingredient.fromTag(Registries.ITEM.getEntryList(ItemTags.DIRT).get()), dirtyPotion); - builder.registerPotionRecipe(Potions.AWKWARD, Ingredient.fromTag(Registries.ITEM.getEntryList(ItemTags.SMALL_FLOWERS).get()), Potions.HEALING); + builder.registerItemRecipe(Items.POTION, Ingredient.fromTag(Registries.ITEM.getOrThrow(ItemTags.DIRT)), dirtyPotion); + builder.registerPotionRecipe(Potions.AWKWARD, Ingredient.fromTag(Registries.ITEM.getOrThrow(ItemTags.SMALL_FLOWERS)), Potions.HEALING); if (builder.getEnabledFeatures().contains(FeatureFlags.BUNDLE)) { builder.registerPotionRecipe(Potions.AWKWARD, Ingredient.ofItems(Items.BUNDLE), Potions.LUCK); diff --git a/fabric-convention-tags-v2/src/main/java/net/fabricmc/fabric/api/tag/convention/v2/TagUtil.java b/fabric-convention-tags-v2/src/main/java/net/fabricmc/fabric/api/tag/convention/v2/TagUtil.java index 98289d65e4..7d3a5c686c 100644 --- a/fabric-convention-tags-v2/src/main/java/net/fabricmc/fabric/api/tag/convention/v2/TagUtil.java +++ b/fabric-convention-tags-v2/src/main/java/net/fabricmc/fabric/api/tag/convention/v2/TagUtil.java @@ -66,7 +66,7 @@ public static boolean isIn(@Nullable DynamicRegistryManager registryManager, if (registryManager != null) { maybeRegistry = registryManager.getOptional(tagKey.registry()); } else { - maybeRegistry = Registries.REGISTRIES.getOrEmpty(tagKey.registry().getValue()); + maybeRegistry = Registries.REGISTRIES.getOptionalValue(tagKey.registry().getValue()); } if (maybeRegistry.isPresent()) { @@ -77,7 +77,7 @@ public static boolean isIn(@Nullable DynamicRegistryManager registryManager, // Check synced tag if (maybeKey.isPresent()) { - return registry.entryOf(maybeKey.get()).isIn(tagKey); + return registry.getOrThrow(maybeKey.get()).isIn(tagKey); } } } diff --git a/fabric-convention-tags-v2/src/main/java/net/fabricmc/fabric/impl/tag/convention/v2/TranslationConventionLogWarnings.java b/fabric-convention-tags-v2/src/main/java/net/fabricmc/fabric/impl/tag/convention/v2/TranslationConventionLogWarnings.java index 2663dbd041..3b1c196677 100644 --- a/fabric-convention-tags-v2/src/main/java/net/fabricmc/fabric/impl/tag/convention/v2/TranslationConventionLogWarnings.java +++ b/fabric-convention-tags-v2/src/main/java/net/fabricmc/fabric/impl/tag/convention/v2/TranslationConventionLogWarnings.java @@ -77,7 +77,7 @@ private static void setupUntranslatedItemTagWarning() { // Log missing item tag translations only when world is started. ServerLifecycleEvents.SERVER_STARTED.register(server -> { Language language = Language.getInstance(); - Registry itemRegistry = server.getRegistryManager().get(RegistryKeys.ITEM); + Registry itemRegistry = server.getRegistryManager().getOrThrow(RegistryKeys.ITEM); List> untranslatedItemTags = new ObjectArrayList<>(); itemRegistry.streamTags().forEach(itemTagKey -> { // We do not translate vanilla's tags at this moment. diff --git a/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/provider/FabricBlockLootTableProvider.java b/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/provider/FabricBlockLootTableProvider.java index 49e5102687..17110b80ff 100644 --- a/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/provider/FabricBlockLootTableProvider.java +++ b/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/provider/FabricBlockLootTableProvider.java @@ -19,6 +19,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.function.BiConsumer; @@ -29,7 +30,6 @@ import net.minecraft.data.DataWriter; import net.minecraft.data.server.loottable.BlockLootTableGenerator; import net.minecraft.loot.LootTable; -import net.minecraft.loot.LootTables; import net.minecraft.loot.context.LootContextTypes; import net.minecraft.registry.Registries; import net.minecraft.registry.RegistryKey; @@ -79,10 +79,6 @@ public void accept(BiConsumer, LootTable.Builder> biConsu for (Map.Entry, LootTable.Builder> entry : lootTables.entrySet()) { RegistryKey registryKey = entry.getKey(); - if (registryKey == LootTables.EMPTY) { - continue; - } - biConsumer.accept(registryKey, entry.getValue()); } @@ -91,10 +87,10 @@ public void accept(BiConsumer, LootTable.Builder> biConsu for (Identifier blockId : Registries.BLOCK.getIds()) { if (blockId.getNamespace().equals(output.getModId())) { - RegistryKey blockLootTableId = Registries.BLOCK.get(blockId).getLootTableKey(); + Optional> blockLootTableId = Registries.BLOCK.get(blockId).getLootTableKey(); - if (blockLootTableId.getValue().getNamespace().equals(output.getModId())) { - if (!lootTables.containsKey(blockLootTableId)) { + if (blockLootTableId.isPresent() && blockLootTableId.get().getValue().getNamespace().equals(output.getModId())) { + if (!lootTables.containsKey(blockLootTableId.get())) { missing.add(blockId); } } diff --git a/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/provider/FabricDynamicRegistryProvider.java b/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/provider/FabricDynamicRegistryProvider.java index a917d6a45c..387f31ed96 100644 --- a/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/provider/FabricDynamicRegistryProvider.java +++ b/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/provider/FabricDynamicRegistryProvider.java @@ -85,7 +85,7 @@ public static final class Entries { this.registries = registries; this.queuedEntries = DynamicRegistries.getDynamicRegistries().stream() // Some modded dynamic registries might not be in the wrapper lookup, filter them out - .filter(e -> registries.getOptionalWrapper(e.key()).isPresent()) + .filter(e -> registries.getOptional(e.key()).isPresent()) .collect(Collectors.toMap( e -> e.key().getValue(), e -> RegistryEntries.create(registries, e) @@ -104,7 +104,7 @@ public RegistryWrapper.WrapperLookup getLookups() { * Gets a lookup for entries from the given registry. */ public RegistryEntryLookup getLookup(RegistryKey> registryKey) { - return registries.getWrapperOrThrow(registryKey); + return registries.getOrThrow(registryKey); } /** @@ -232,7 +232,7 @@ private static class RegistryEntries { } static RegistryEntries create(RegistryWrapper.WrapperLookup lookups, RegistryLoader.Entry loaderEntry) { - RegistryWrapper.Impl lookup = lookups.getWrapperOrThrow(loaderEntry.key()); + RegistryWrapper.Impl lookup = lookups.getOrThrow(loaderEntry.key()); return new RegistryEntries<>(lookup, loaderEntry.key(), loaderEntry.elementCodec()); } diff --git a/fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen/DataGeneratorTestContent.java b/fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen/DataGeneratorTestContent.java index 7b52736ccc..3c99bc692d 100644 --- a/fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen/DataGeneratorTestContent.java +++ b/fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen/DataGeneratorTestContent.java @@ -69,7 +69,7 @@ public void onInitialize() { SIMPLE_BLOCK = createBlock("simple_block", true, AbstractBlock.Settings.create()); BLOCK_WITHOUT_ITEM = createBlock("block_without_item", false, AbstractBlock.Settings.create()); BLOCK_WITHOUT_LOOT_TABLE = createBlock("block_without_loot_table", false, AbstractBlock.Settings.create()); - BLOCK_WITH_VANILLA_LOOT_TABLE = createBlock("block_with_vanilla_loot_table", false, AbstractBlock.Settings.create().dropsLike(Blocks.STONE)); + BLOCK_WITH_VANILLA_LOOT_TABLE = createBlock("block_with_vanilla_loot_table", false, AbstractBlock.Settings.create().lootTable(Blocks.STONE.getLootTableKey())); BLOCK_THAT_DROPS_NOTHING = createBlock("block_that_drops_nothing", false, AbstractBlock.Settings.create().dropsNothing()); ItemGroupEvents.modifyEntriesEvent(SIMPLE_ITEM_GROUP).register(entries -> entries.add(SIMPLE_BLOCK)); @@ -85,7 +85,7 @@ public void onInitialize() { private static Block createBlock(String name, boolean hasItem, AbstractBlock.Settings settings) { Identifier identifier = Identifier.of(MOD_ID, name); - Block block = Registry.register(Registries.BLOCK, identifier, new Block(settings)); + Block block = Registry.register(Registries.BLOCK, identifier, new Block(settings.registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)))); if (hasItem) { Registry.register(Registries.ITEM, identifier, new BlockItem(block, new Item.Settings())); diff --git a/fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen/DataGeneratorTestEntrypoint.java b/fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen/DataGeneratorTestEntrypoint.java index 97ac9668b7..86af5fd0e2 100644 --- a/fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen/DataGeneratorTestEntrypoint.java +++ b/fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen/DataGeneratorTestEntrypoint.java @@ -444,7 +444,7 @@ private static class TestDynamicRegistryProvider extends FabricDynamicRegistryPr @Override protected void configure(RegistryWrapper.WrapperLookup registries, Entries entries) { entries.add( - registries.getWrapperOrThrow(TEST_DATAGEN_DYNAMIC_REGISTRY_KEY), TEST_DYNAMIC_REGISTRY_ITEM_KEY, + registries.getOrThrow(TEST_DATAGEN_DYNAMIC_REGISTRY_KEY), TEST_DYNAMIC_REGISTRY_ITEM_KEY, ResourceConditions.allModsLoaded(MOD_ID) ); } @@ -465,7 +465,7 @@ private static class TestExtraDynamicRegistryProvider extends FabricDynamicRegis @Override protected void configure(RegistryWrapper.WrapperLookup registries, Entries entries) { - entries.add(registries.getWrapperOrThrow(TEST_DATAGEN_DYNAMIC_REGISTRY_KEY), TEST_DYNAMIC_REGISTRY_EXTRA_ITEM_KEY); + entries.add(registries.getOrThrow(TEST_DATAGEN_DYNAMIC_REGISTRY_KEY), TEST_DYNAMIC_REGISTRY_EXTRA_ITEM_KEY); } @Override @@ -481,7 +481,7 @@ private TestPredicateProvider(FabricDataOutput dataOutput, CompletableFuture provider, RegistryWrapper.WrapperLookup lookup) { - RegistryEntryLookup blocks = lookup.createRegistryLookup().getOrThrow(RegistryKeys.BLOCK); + RegistryEntryLookup blocks = lookup.getOrThrow(RegistryKeys.BLOCK); provider.accept(Identifier.of(MOD_ID, "predicate_test"), BlockStatePropertyLootCondition.builder( blocks.getOrThrow(BlockKeys.MELON).value()).build()); // Pretend this actually does something and we cannot access the blocks directly } @@ -499,7 +499,7 @@ private TestCustomCodecProvider(FabricDataOutput dataOutput, CompletableFuture provider, RegistryWrapper.WrapperLookup lookup) { - RegistryEntryLookup biomes = lookup.createRegistryLookup().getOrThrow(RegistryKeys.BIOME); + RegistryEntryLookup biomes = lookup.getOrThrow(RegistryKeys.BIOME); provider.accept(Identifier.of(MOD_ID, "custom_codec_test"), new Entry(biomes.getOrThrow(BiomeKeys.PLAINS))); } diff --git a/fabric-entity-events-v1/src/testmod/java/net/fabricmc/fabric/test/entity/event/EntityEventTests.java b/fabric-entity-events-v1/src/testmod/java/net/fabricmc/fabric/test/entity/event/EntityEventTests.java index f6e1779ed5..fee1d46141 100644 --- a/fabric-entity-events-v1/src/testmod/java/net/fabricmc/fabric/test/entity/event/EntityEventTests.java +++ b/fabric-entity-events-v1/src/testmod/java/net/fabricmc/fabric/test/entity/event/EntityEventTests.java @@ -32,6 +32,8 @@ import net.minecraft.item.Items; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.server.command.CommandManager; import net.minecraft.text.Text; import net.minecraft.util.ActionResult; @@ -51,13 +53,17 @@ public final class EntityEventTests implements ModInitializer { private static final Logger LOGGER = LoggerFactory.getLogger(EntityEventTests.class); - public static final Block TEST_BED = new TestBedBlock(AbstractBlock.Settings.create().strength(1, 1)); + public static final RegistryKey TEST_BED_KEY = RegistryKey.of( + RegistryKeys.BLOCK, + Identifier.of("fabric-entity-events-v1-testmod", "test_bed") + ); + public static final Block TEST_BED = new TestBedBlock(AbstractBlock.Settings.create().strength(1, 1).registryKey(TEST_BED_KEY)); public static final Item DIAMOND_ELYTRA = new DiamondElytraItem(); @Override public void onInitialize() { - Registry.register(Registries.BLOCK, Identifier.of("fabric-entity-events-v1-testmod", "test_bed"), TEST_BED); - Registry.register(Registries.ITEM, Identifier.of("fabric-entity-events-v1-testmod", "test_bed"), new BlockItem(TEST_BED, new Item.Settings())); + Registry.register(Registries.BLOCK, TEST_BED_KEY, TEST_BED); + Registry.register(Registries.ITEM, TEST_BED_KEY.getValue(), new BlockItem(TEST_BED, new Item.Settings())); Registry.register(Registries.ITEM, Identifier.of("fabric-entity-events-v1-testmod", "diamond_elytra"), DIAMOND_ELYTRA); ServerEntityCombatEvents.AFTER_KILLED_OTHER_ENTITY.register((world, entity, killed) -> { diff --git a/fabric-loot-api-v3/src/main/java/net/fabricmc/fabric/mixin/loot/ReloadableRegistriesMixin.java b/fabric-loot-api-v3/src/main/java/net/fabricmc/fabric/mixin/loot/ReloadableRegistriesMixin.java index 6d44ed5144..f4bf120cdb 100644 --- a/fabric-loot-api-v3/src/main/java/net/fabricmc/fabric/mixin/loot/ReloadableRegistriesMixin.java +++ b/fabric-loot-api-v3/src/main/java/net/fabricmc/fabric/mixin/loot/ReloadableRegistriesMixin.java @@ -89,11 +89,6 @@ private static void modifyLootTable(Optional optionalTable, Consumer T modifyLootTable(T value, Identifier id, RegistryOps ops) { if (!(value instanceof LootTable table)) return value; - if (table == LootTable.EMPTY) { - // This is a special table and cannot be modified. - return value; - } - RegistryKey key = RegistryKey.of(RegistryKeys.LOOT_TABLE, id); // Populated above. RegistryWrapper.WrapperLookup registries = WRAPPERS.get(ops); diff --git a/fabric-loot-api-v3/src/testmod/java/net/fabricmc/fabric/test/loot/LootTest.java b/fabric-loot-api-v3/src/testmod/java/net/fabricmc/fabric/test/loot/LootTest.java index 292206ab51..cb7dfb9d56 100644 --- a/fabric-loot-api-v3/src/testmod/java/net/fabricmc/fabric/test/loot/LootTest.java +++ b/fabric-loot-api-v3/src/testmod/java/net/fabricmc/fabric/test/loot/LootTest.java @@ -45,7 +45,7 @@ public void onInitialize() { // The LootTable.Builder LootPool.Builder methods here should use // prebuilt entries and pools to test the injected methods. LootTableEvents.REPLACE.register((key, original, source, registries) -> { - if (Blocks.BLACK_WOOL.getLootTableKey() == key) { + if (Blocks.BLACK_WOOL.getLootTableKey().orElse(null) == key) { if (source != LootTableSource.VANILLA) { throw new AssertionError("black wool loot table should have LootTableSource.VANILLA, got " + source); } @@ -63,7 +63,7 @@ public void onInitialize() { // Test that the event is stopped when the loot table is replaced LootTableEvents.REPLACE.register((key, original, source, registries) -> { - if (Blocks.BLACK_WOOL.getLootTableKey() == key) { + if (Blocks.BLACK_WOOL.getLootTableKey().orElse(null) == key) { throw new AssertionError("Event should have been stopped from replaced loot table"); } @@ -71,11 +71,11 @@ public void onInitialize() { }); LootTableEvents.MODIFY.register((key, tableBuilder, source, registries) -> { - if (Blocks.BLACK_WOOL.getLootTableKey() == key && source != LootTableSource.REPLACED) { + if (Blocks.BLACK_WOOL.getLootTableKey().orElse(null) == key && source != LootTableSource.REPLACED) { throw new AssertionError("black wool loot table should have LootTableSource.REPLACED, got " + source); } - if (Blocks.WHITE_WOOL.getLootTableKey() == key) { + if (Blocks.WHITE_WOOL.getLootTableKey().orElse(null) == key) { if (source != LootTableSource.VANILLA) { throw new AssertionError("white wool loot table should have LootTableSource.VANILLA, got " + source); } @@ -91,20 +91,20 @@ public void onInitialize() { } // We modify red wool to drop diamonds in the test mod resources. - if (Blocks.RED_WOOL.getLootTableKey() == key && source != LootTableSource.MOD) { + if (Blocks.RED_WOOL.getLootTableKey().orElse(null) == key && source != LootTableSource.MOD) { throw new AssertionError("red wool loot table should have LootTableSource.MOD, got " + source); } // Modify yellow wool to drop *either* yellow wool or emeralds by adding // emeralds to the same loot pool. - if (Blocks.YELLOW_WOOL.getLootTableKey() == key) { + if (Blocks.YELLOW_WOOL.getLootTableKey().orElse(null) == key) { tableBuilder.modifyPools(poolBuilder -> poolBuilder.with(ItemEntry.builder(Items.EMERALD))); } }); LootTableEvents.MODIFY.register((key, tableBuilder, source, registries) -> { - if (EntityType.SALMON.getLootTableId() == key) { - Optional> lure = registries.getOptionalWrapper(RegistryKeys.ENCHANTMENT).flatMap(registry -> registry.getOptional(Enchantments.LURE)); + if (EntityType.SALMON.getLootTable().orElse(null) == key) { + Optional> lure = registries.getOptional(RegistryKeys.ENCHANTMENT).flatMap(registry -> registry.getOptional(Enchantments.LURE)); lure.ifPresent((lureEnchantment) -> tableBuilder.pool(LootPool.builder().with( ItemEntry.builder(Items.FISHING_ROD) @@ -115,9 +115,9 @@ public void onInitialize() { }); LootTableEvents.ALL_LOADED.register((resourceManager, lootRegistry) -> { - LootTable blackWoolTable = lootRegistry.get(Blocks.BLACK_WOOL.getLootTableKey()); + Optional blackWoolTable = lootRegistry.getOptionalValue(Blocks.BLACK_WOOL.getLootTableKey().orElse(null)); - if (blackWoolTable == LootTable.EMPTY) { + if (blackWoolTable.isEmpty() || blackWoolTable.get() == LootTable.EMPTY) { throw new AssertionError("black wool loot table should not be empty"); } }); diff --git a/fabric-object-builder-api-v1/src/testmod/java/net/fabricmc/fabric/test/object/builder/BlockEntityTypeBuilderTest.java b/fabric-object-builder-api-v1/src/testmod/java/net/fabricmc/fabric/test/object/builder/BlockEntityTypeBuilderTest.java index 3c32af58e4..43743e1ef8 100644 --- a/fabric-object-builder-api-v1/src/testmod/java/net/fabricmc/fabric/test/object/builder/BlockEntityTypeBuilderTest.java +++ b/fabric-object-builder-api-v1/src/testmod/java/net/fabricmc/fabric/test/object/builder/BlockEntityTypeBuilderTest.java @@ -29,6 +29,7 @@ import net.minecraft.item.Item; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; import net.minecraft.text.Text; import net.minecraft.util.ActionResult; import net.minecraft.util.Identifier; @@ -40,19 +41,19 @@ import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; public class BlockEntityTypeBuilderTest implements ModInitializer { - private static final Identifier INITIAL_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.id("initial_betrayal_block"); - static final Block INITIAL_BETRAYAL_BLOCK = new BetrayalBlock(MapColor.BLUE); + private static final RegistryKey INITIAL_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.block("initial_betrayal_block"); + static final Block INITIAL_BETRAYAL_BLOCK = createBetrayalBlock(INITIAL_BETRAYAL_BLOCK_ID, MapColor.BLUE); - private static final Identifier ADDED_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.id("added_betrayal_block"); - static final Block ADDED_BETRAYAL_BLOCK = new BetrayalBlock(MapColor.GREEN); + private static final RegistryKey ADDED_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.block("added_betrayal_block"); + static final Block ADDED_BETRAYAL_BLOCK = createBetrayalBlock(ADDED_BETRAYAL_BLOCK_ID, MapColor.GREEN); - private static final Identifier FIRST_MULTI_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.id("first_multi_betrayal_block"); - static final Block FIRST_MULTI_BETRAYAL_BLOCK = new BetrayalBlock(MapColor.RED); + private static final RegistryKey FIRST_MULTI_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.block("first_multi_betrayal_block"); + static final Block FIRST_MULTI_BETRAYAL_BLOCK = createBetrayalBlock(FIRST_MULTI_BETRAYAL_BLOCK_ID, MapColor.RED); - private static final Identifier SECOND_MULTI_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.id("second_multi_betrayal_block"); - static final Block SECOND_MULTI_BETRAYAL_BLOCK = new BetrayalBlock(MapColor.YELLOW); + private static final RegistryKey SECOND_MULTI_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.block("second_multi_betrayal_block"); + static final Block SECOND_MULTI_BETRAYAL_BLOCK = createBetrayalBlock(SECOND_MULTI_BETRAYAL_BLOCK_ID, MapColor.YELLOW); - private static final Identifier BLOCK_ENTITY_TYPE_ID = ObjectBuilderTestConstants.id("betrayal_block"); + private static final RegistryKey BLOCK_ENTITY_TYPE_ID = ObjectBuilderTestConstants.block("betrayal_block"); public static final BlockEntityType BLOCK_ENTITY_TYPE = FabricBlockEntityTypeBuilder.create(BetrayalBlockEntity::new, INITIAL_BETRAYAL_BLOCK, ADDED_BETRAYAL_BLOCK, FIRST_MULTI_BETRAYAL_BLOCK, SECOND_MULTI_BETRAYAL_BLOCK).build(); @Override @@ -62,19 +63,23 @@ public void onInitialize() { register(FIRST_MULTI_BETRAYAL_BLOCK_ID, FIRST_MULTI_BETRAYAL_BLOCK); register(SECOND_MULTI_BETRAYAL_BLOCK_ID, SECOND_MULTI_BETRAYAL_BLOCK); - Registry.register(Registries.BLOCK_ENTITY_TYPE, BLOCK_ENTITY_TYPE_ID, BLOCK_ENTITY_TYPE); + Registry.register(Registries.BLOCK_ENTITY_TYPE, BLOCK_ENTITY_TYPE_ID.getValue(), BLOCK_ENTITY_TYPE); } - private static void register(Identifier id, Block block) { + private static Block createBetrayalBlock(RegistryKey key, MapColor color) { + return new BetrayalBlock(AbstractBlock.Settings.copy(Blocks.STONE).mapColor(color).registryKey(key)); + } + + private static void register(RegistryKey id, Block block) { Registry.register(Registries.BLOCK, id, block); Item item = new BlockItem(block, new Item.Settings()); - Registry.register(Registries.ITEM, id, item); + Registry.register(Registries.ITEM, id.getValue(), item); } private static class BetrayalBlock extends Block implements BlockEntityProvider { - private BetrayalBlock(MapColor color) { - super(AbstractBlock.Settings.copy(Blocks.STONE).mapColor(color)); + private BetrayalBlock(AbstractBlock.Settings settings) { + super(settings); } @Override diff --git a/fabric-object-builder-api-v1/src/testmod/java/net/fabricmc/fabric/test/object/builder/ObjectBuilderTestConstants.java b/fabric-object-builder-api-v1/src/testmod/java/net/fabricmc/fabric/test/object/builder/ObjectBuilderTestConstants.java index 4ab50d8f1f..b0c62c9e17 100644 --- a/fabric-object-builder-api-v1/src/testmod/java/net/fabricmc/fabric/test/object/builder/ObjectBuilderTestConstants.java +++ b/fabric-object-builder-api-v1/src/testmod/java/net/fabricmc/fabric/test/object/builder/ObjectBuilderTestConstants.java @@ -16,6 +16,11 @@ package net.fabricmc.fabric.test.object.builder; +import net.minecraft.block.Block; +import net.minecraft.registry.RegistryKey; + +import net.minecraft.registry.RegistryKeys; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,4 +33,8 @@ public final class ObjectBuilderTestConstants { public static Identifier id(String name) { return Identifier.of(MOD_ID, name); } + + public static RegistryKey block(String name) { + return RegistryKey.of(RegistryKeys.BLOCK, id(name)); + } } diff --git a/fabric-object-builder-api-v1/src/testmod/java/net/fabricmc/fabric/test/object/builder/TealSignTest.java b/fabric-object-builder-api-v1/src/testmod/java/net/fabricmc/fabric/test/object/builder/TealSignTest.java index 9fd58c691e..8992f9f47c 100644 --- a/fabric-object-builder-api-v1/src/testmod/java/net/fabricmc/fabric/test/object/builder/TealSignTest.java +++ b/fabric-object-builder-api-v1/src/testmod/java/net/fabricmc/fabric/test/object/builder/TealSignTest.java @@ -17,6 +17,7 @@ package net.fabricmc.fabric.test.object.builder; import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; import net.minecraft.block.BlockSetType; import net.minecraft.block.Blocks; import net.minecraft.block.HangingSignBlock; @@ -30,6 +31,7 @@ import net.minecraft.item.SignItem; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; import net.minecraft.util.Identifier; import net.fabricmc.api.ModInitializer; @@ -40,10 +42,14 @@ public class TealSignTest implements ModInitializer { public static final Identifier TEAL_TYPE_ID = ObjectBuilderTestConstants.id("teal"); public static final BlockSetType TEAL_BLOCK_SET_TYPE = BlockSetTypeBuilder.copyOf(BlockSetType.OAK).build(TEAL_TYPE_ID); public static final WoodType TEAL_WOOD_TYPE = WoodTypeBuilder.copyOf(WoodType.OAK).build(TEAL_TYPE_ID, TEAL_BLOCK_SET_TYPE); - public static final SignBlock TEAL_SIGN = new SignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_SIGN)); - public static final WallSignBlock TEAL_WALL_SIGN = new WallSignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_SIGN)); - public static final HangingSignBlock TEAL_HANGING_SIGN = new HangingSignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_HANGING_SIGN)); - public static final WallHangingSignBlock TEAL_WALL_HANGING_SIGN = new WallHangingSignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_HANGING_SIGN)); + public static final RegistryKey TEAL_SIGN_KEY = ObjectBuilderTestConstants.block("teal_sign"); + public static final SignBlock TEAL_SIGN = new SignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_SIGN).registryKey(TEAL_SIGN_KEY)); + public static final RegistryKey TEAL_WALL_SIGN_KEY = ObjectBuilderTestConstants.block("teal_wall_sign"); + public static final WallSignBlock TEAL_WALL_SIGN = new WallSignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_SIGN).registryKey(TEAL_WALL_SIGN_KEY)); + public static final RegistryKey TEAL_HANGING_SIGN_KEY = ObjectBuilderTestConstants.block("teal_hanging_sign"); + public static final HangingSignBlock TEAL_HANGING_SIGN = new HangingSignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_HANGING_SIGN).registryKey(TEAL_HANGING_SIGN_KEY)); + public static final RegistryKey TEAL_WALL_HANGING_SIGN_KEY = ObjectBuilderTestConstants.block("teal_wall_hanging_sign"); + public static final WallHangingSignBlock TEAL_WALL_HANGING_SIGN = new WallHangingSignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_HANGING_SIGN).registryKey(TEAL_WALL_HANGING_SIGN_KEY)); public static final SignItem TEAL_SIGN_ITEM = new SignItem(new Item.Settings(), TEAL_SIGN, TEAL_WALL_SIGN); public static final HangingSignItem TEAL_HANGING_SIGN_ITEM = new HangingSignItem(TEAL_HANGING_SIGN, TEAL_WALL_HANGING_SIGN, new Item.Settings()); @@ -51,13 +57,13 @@ public class TealSignTest implements ModInitializer { public void onInitialize() { WoodType.register(TEAL_WOOD_TYPE); - Registry.register(Registries.BLOCK, ObjectBuilderTestConstants.id("teal_sign"), TEAL_SIGN); - Registry.register(Registries.BLOCK, ObjectBuilderTestConstants.id("teal_wall_sign"), TEAL_WALL_SIGN); - Registry.register(Registries.BLOCK, ObjectBuilderTestConstants.id("teal_hanging_sign"), TEAL_HANGING_SIGN); - Registry.register(Registries.BLOCK, ObjectBuilderTestConstants.id("teal_wall_hanging_sign"), TEAL_WALL_HANGING_SIGN); + Registry.register(Registries.BLOCK, TEAL_SIGN_KEY, TEAL_SIGN); + Registry.register(Registries.BLOCK, TEAL_WALL_SIGN_KEY, TEAL_WALL_SIGN); + Registry.register(Registries.BLOCK, TEAL_HANGING_SIGN_KEY, TEAL_HANGING_SIGN); + Registry.register(Registries.BLOCK, TEAL_WALL_HANGING_SIGN_KEY, TEAL_WALL_HANGING_SIGN); - Registry.register(Registries.ITEM, ObjectBuilderTestConstants.id("teal_sign"), TEAL_SIGN_ITEM); - Registry.register(Registries.ITEM, ObjectBuilderTestConstants.id("teal_hanging_sign"), TEAL_HANGING_SIGN_ITEM); + Registry.register(Registries.ITEM, TEAL_SIGN_KEY.getValue(), TEAL_SIGN_ITEM); + Registry.register(Registries.ITEM, TEAL_HANGING_SIGN_KEY.getValue(), TEAL_HANGING_SIGN_ITEM); BlockEntityType.SIGN.addSupportedBlock(TEAL_SIGN); BlockEntityType.HANGING_SIGN.addSupportedBlock(TEAL_HANGING_SIGN); diff --git a/fabric-particles-v1/src/testmod/java/net/fabricmc/fabric/test/particle/ParticleTestSetup.java b/fabric-particles-v1/src/testmod/java/net/fabricmc/fabric/test/particle/ParticleTestSetup.java index 0d658fd65e..aff5a71a2d 100644 --- a/fabric-particles-v1/src/testmod/java/net/fabricmc/fabric/test/particle/ParticleTestSetup.java +++ b/fabric-particles-v1/src/testmod/java/net/fabricmc/fabric/test/particle/ParticleTestSetup.java @@ -26,6 +26,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.server.command.CommandManager; import net.minecraft.util.Identifier; @@ -34,17 +36,20 @@ public final class ParticleTestSetup implements ModInitializer { // The dust particles of this block are always tinted (default). - public static final Block ALWAYS_TINTED = new ParticleTintTestBlock(AbstractBlock.Settings.create().breakInstantly(), 0xFF00FF); + public static final RegistryKey ALWAYS_TINTED_KEY = block("always_tinted"); + public static final Block ALWAYS_TINTED = new ParticleTintTestBlock(AbstractBlock.Settings.create().breakInstantly().registryKey(ALWAYS_TINTED_KEY), 0xFF00FF); // The dust particles of this block are only tinted when the block is broken over water. - public static final Block TINTED_OVER_WATER = new ParticleTintTestBlock(AbstractBlock.Settings.create().breakInstantly(), 0xFFFF00); + public static final RegistryKey TINTED_OVER_WATER_KEY = block("tinted_over_water"); + public static final Block TINTED_OVER_WATER = new ParticleTintTestBlock(AbstractBlock.Settings.create().breakInstantly().registryKey(TINTED_OVER_WATER_KEY), 0xFFFF00); // The dust particles of this block are never tinted. - public static final Block NEVER_TINTED = new ParticleTintTestBlock(AbstractBlock.Settings.create().breakInstantly(), 0x00FFFF); + public static final RegistryKey NEVER_TINTED_KEY = block("never_tinted"); + public static final Block NEVER_TINTED = new ParticleTintTestBlock(AbstractBlock.Settings.create().breakInstantly().registryKey(NEVER_TINTED_KEY), 0x00FFFF); @Override public void onInitialize() { - registerBlock("always_tinted", ALWAYS_TINTED); - registerBlock("tinted_over_water", TINTED_OVER_WATER); - registerBlock("never_tinted", NEVER_TINTED); + registerBlock(ALWAYS_TINTED_KEY, ALWAYS_TINTED); + registerBlock(TINTED_OVER_WATER_KEY, TINTED_OVER_WATER); + registerBlock(NEVER_TINTED_KEY, NEVER_TINTED); CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { dispatcher.register(CommandManager.literal("addparticletestblocks").executes(context -> { @@ -57,9 +62,12 @@ public void onInitialize() { }); } - private static void registerBlock(String path, Block block) { - Identifier id = Identifier.of("fabric-particles-v1-testmod", path); - Registry.register(Registries.BLOCK, id, block); - Registry.register(Registries.ITEM, id, new BlockItem(block, new Item.Settings())); + private static RegistryKey block(String path) { + return RegistryKey.of(RegistryKeys.BLOCK, Identifier.of("fabric-particles-v1-testmod", path)); + } + + private static void registerBlock(RegistryKey key, Block block) { + Registry.register(Registries.BLOCK, key, block); + Registry.register(Registries.ITEM, key.getValue(), new BlockItem(block, new Item.Settings())); } } diff --git a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/FabricRegistryInit.java b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/FabricRegistryInit.java index 6d2fe03fad..b8be829a3e 100644 --- a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/FabricRegistryInit.java +++ b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/FabricRegistryInit.java @@ -209,7 +209,7 @@ public void onInitialize() { .addAttribute(RegistryAttribute.SYNCED); // Synced via PacketCodecs.registry - RegistryAttributeHolder.get(Registries.field_53967) + RegistryAttributeHolder.get(Registries.CONSUME_EFFECT_TYPE) .addAttribute(RegistryAttribute.SYNCED); } } diff --git a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/trackers/vanilla/BlockInitTracker.java b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/trackers/vanilla/BlockInitTracker.java index ad49d98bf8..f1990a7bd4 100644 --- a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/trackers/vanilla/BlockInitTracker.java +++ b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/trackers/vanilla/BlockInitTracker.java @@ -28,26 +28,7 @@ import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback; import net.fabricmc.fabric.mixin.registry.sync.DebugChunkGeneratorAccessor; -public final class BlockInitTracker implements RegistryEntryAddedCallback { - private final Registry registry; - - private BlockInitTracker(Registry registry) { - this.registry = registry; - } - - public static void register(Registry registry) { - BlockInitTracker tracker = new BlockInitTracker(registry); - RegistryEntryAddedCallback.event(registry).register(tracker); - } - - @Override - public void onEntryAdded(int rawId, Identifier id, Block object) { - // if false, getLootTableKey() will generate an invalid loot table key - assert id.equals(registry.getId(object)); - - object.getLootTableKey(); - } - +public final class BlockInitTracker { public static void postFreeze() { final List blockStateList = Registries.BLOCK.stream() .flatMap((block) -> block.getStateManager().getStates().stream()) diff --git a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/BootstrapMixin.java b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/BootstrapMixin.java index b7078ff7f3..414ca11685 100644 --- a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/BootstrapMixin.java +++ b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/mixin/registry/sync/BootstrapMixin.java @@ -54,9 +54,6 @@ private static void initialize(CallbackInfo info) { // map tracking BlockItemTracker.register(Registries.ITEM); - // block initialization, like Blocks - BlockInitTracker.register(Registries.BLOCK); - RegistrySyncManager.bootstrapRegistries(); } diff --git a/fabric-registry-sync-v0/src/testmod/java/net/fabricmc/fabric/test/registry/sync/CustomDynamicRegistryTest.java b/fabric-registry-sync-v0/src/testmod/java/net/fabricmc/fabric/test/registry/sync/CustomDynamicRegistryTest.java index ae20a47275..7c6edc6cc2 100644 --- a/fabric-registry-sync-v0/src/testmod/java/net/fabricmc/fabric/test/registry/sync/CustomDynamicRegistryTest.java +++ b/fabric-registry-sync-v0/src/testmod/java/net/fabricmc/fabric/test/registry/sync/CustomDynamicRegistryTest.java @@ -67,9 +67,8 @@ public void onInitialize() { CommonLifecycleEvents.TAGS_LOADED.register((registries, client) -> { // Check that the tag has applied - RegistryEntry.Reference entry = registries.get(TEST_SYNCED_1_DYNAMIC_REGISTRY_KEY) - .getEntry(SYNCED_ENTRY_KEY) - .orElseThrow(); + RegistryEntry.Reference entry = registries.getOrThrow(TEST_SYNCED_1_DYNAMIC_REGISTRY_KEY) + .getOrThrow(SYNCED_ENTRY_KEY); if (!entry.isIn(TEST_DYNAMIC_OBJECT_TAG)) { LOGGER.error("Required dynamic registry entry is not in the expected tag! client: " + client); diff --git a/fabric-renderer-api-v1/src/testmod/java/net/fabricmc/fabric/test/renderer/Registration.java b/fabric-renderer-api-v1/src/testmod/java/net/fabricmc/fabric/test/renderer/Registration.java index dc9546ac91..24ca3ef795 100644 --- a/fabric-renderer-api-v1/src/testmod/java/net/fabricmc/fabric/test/renderer/Registration.java +++ b/fabric-renderer-api-v1/src/testmod/java/net/fabricmc/fabric/test/renderer/Registration.java @@ -27,13 +27,19 @@ import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.util.Identifier; + +import java.util.function.Function; + public final class Registration { - public static final FrameBlock FRAME_BLOCK = register("frame", new FrameBlock(AbstractBlock.Settings.copy(Blocks.IRON_BLOCK).nonOpaque())); - public static final FrameBlock FRAME_MULTIPART_BLOCK = register("frame_multipart", new FrameBlock(AbstractBlock.Settings.copy(Blocks.IRON_BLOCK).nonOpaque())); - public static final FrameBlock FRAME_VARIANT_BLOCK = register("frame_variant", new FrameBlock(AbstractBlock.Settings.copy(Blocks.IRON_BLOCK).nonOpaque())); - public static final Block PILLAR_BLOCK = register("pillar", new Block(AbstractBlock.Settings.create())); - public static final Block OCTAGONAL_COLUMN_BLOCK = register("octagonal_column", new OctagonalColumnBlock(AbstractBlock.Settings.create().nonOpaque().strength(1.8F))); - public static final Block RIVERSTONE_BLOCK = register("riverstone", new Block(AbstractBlock.Settings.copy(Blocks.STONE))); + public static final FrameBlock FRAME_BLOCK = register("frame", FrameBlock::new, AbstractBlock.Settings.copy(Blocks.IRON_BLOCK).nonOpaque()); + public static final FrameBlock FRAME_MULTIPART_BLOCK = register("frame_multipart", FrameBlock::new, AbstractBlock.Settings.copy(Blocks.IRON_BLOCK).nonOpaque()); + public static final FrameBlock FRAME_VARIANT_BLOCK = register("frame_variant", FrameBlock::new, AbstractBlock.Settings.copy(Blocks.IRON_BLOCK).nonOpaque()); + public static final Block PILLAR_BLOCK = register("pillar", Block::new, AbstractBlock.Settings.create()); + public static final Block OCTAGONAL_COLUMN_BLOCK = register("octagonal_column", OctagonalColumnBlock::new, AbstractBlock.Settings.create().nonOpaque().strength(1.8F)); + public static final Block RIVERSTONE_BLOCK = register("riverstone", Block::new, AbstractBlock.Settings.copy(Blocks.STONE)); public static final FrameBlock[] FRAME_BLOCKS = new FrameBlock[] { FRAME_BLOCK, @@ -50,8 +56,10 @@ public final class Registration { public static final BlockEntityType FRAME_BLOCK_ENTITY_TYPE = register("frame", FabricBlockEntityTypeBuilder.create(FrameBlockEntity::new, FRAME_BLOCKS).build()); - private static T register(String path, T block) { - return Registry.register(Registries.BLOCK, RendererTest.id(path), block); + // see also Blocks#register, which is functionally the same + private static T register(String path, Function constructor, AbstractBlock.Settings settings) { + Identifier id = RendererTest.id(path); + return Registry.register(Registries.BLOCK, id, constructor.apply(settings.registryKey(RegistryKey.of(RegistryKeys.BLOCK, id)))); } private static T register(String path, T item) { diff --git a/fabric-rendering-fluids-v1/src/testmod/java/net/fabricmc/fabric/test/client/rendering/fluid/TestFluids.java b/fabric-rendering-fluids-v1/src/testmod/java/net/fabricmc/fabric/test/client/rendering/fluid/TestFluids.java index c8da4732fa..2166b2ba73 100644 --- a/fabric-rendering-fluids-v1/src/testmod/java/net/fabricmc/fabric/test/client/rendering/fluid/TestFluids.java +++ b/fabric-rendering-fluids-v1/src/testmod/java/net/fabricmc/fabric/test/client/rendering/fluid/TestFluids.java @@ -17,33 +17,50 @@ package net.fabricmc.fabric.test.client.rendering.fluid; import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.block.FluidBlock; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.util.Identifier; public class TestFluids { - public static final NoOverlayFluid NO_OVERLAY = Registry.register(Registries.FLUID, "fabric-rendering-fluids-v1-testmod:no_overlay", new NoOverlayFluid.Still()); - public static final NoOverlayFluid NO_OVERLAY_FLOWING = Registry.register(Registries.FLUID, "fabric-rendering-fluids-v1-testmod:no_overlay_flowing", new NoOverlayFluid.Flowing()); + public static final String MOD_ID = "fabric-rendering-fluids-v1-testmod"; + public static final RegistryKey NO_OVERLAY_KEY = block("no_overlay"); + public static final NoOverlayFluid NO_OVERLAY = Registry.register(Registries.FLUID, NO_OVERLAY_KEY.getValue(), new NoOverlayFluid.Still()); + public static final NoOverlayFluid NO_OVERLAY_FLOWING = Registry.register(Registries.FLUID, id("no_overlay_flowing"), new NoOverlayFluid.Flowing()); - public static final FluidBlock NO_OVERLAY_BLOCK = Registry.register(Registries.BLOCK, "fabric-rendering-fluids-v1-testmod:no_overlay", new FluidBlock(NO_OVERLAY, AbstractBlock.Settings.copy(Blocks.WATER)) { + public static final FluidBlock NO_OVERLAY_BLOCK = Registry.register(Registries.BLOCK, NO_OVERLAY_KEY, new FluidBlock(NO_OVERLAY, AbstractBlock.Settings.copy(Blocks.WATER).registryKey(NO_OVERLAY_KEY)) { }); - public static final OverlayFluid OVERLAY = Registry.register(Registries.FLUID, "fabric-rendering-fluids-v1-testmod:overlay", new OverlayFluid.Still()); - public static final OverlayFluid OVERLAY_FLOWING = Registry.register(Registries.FLUID, "fabric-rendering-fluids-v1-testmod:overlay_flowing", new OverlayFluid.Flowing()); + public static final RegistryKey OVERLAY_KEY = block("overlay"); + public static final OverlayFluid OVERLAY = Registry.register(Registries.FLUID, OVERLAY_KEY.getValue(), new OverlayFluid.Still()); + public static final OverlayFluid OVERLAY_FLOWING = Registry.register(Registries.FLUID, id("overlay_flowing"), new OverlayFluid.Flowing()); - public static final FluidBlock OVERLAY_BLOCK = Registry.register(Registries.BLOCK, "fabric-rendering-fluids-v1-testmod:overlay", new FluidBlock(OVERLAY, AbstractBlock.Settings.copy(Blocks.WATER)) { + public static final FluidBlock OVERLAY_BLOCK = Registry.register(Registries.BLOCK, OVERLAY_KEY, new FluidBlock(OVERLAY, AbstractBlock.Settings.copy(Blocks.WATER).registryKey(OVERLAY_KEY)) { }); - public static final UnregisteredFluid UNREGISTERED = Registry.register(Registries.FLUID, "fabric-rendering-fluids-v1-testmod:unregistered", new UnregisteredFluid.Still()); - public static final UnregisteredFluid UNREGISTERED_FLOWING = Registry.register(Registries.FLUID, "fabric-rendering-fluids-v1-testmod:unregistered_flowing", new UnregisteredFluid.Flowing()); + public static final RegistryKey UNREGISTERED_KEY = block("unregistered"); + public static final UnregisteredFluid UNREGISTERED = Registry.register(Registries.FLUID, UNREGISTERED_KEY.getValue(), new UnregisteredFluid.Still()); + public static final UnregisteredFluid UNREGISTERED_FLOWING = Registry.register(Registries.FLUID, id("unregistered_flowing"), new UnregisteredFluid.Flowing()); - public static final FluidBlock UNREGISTERED_BLOCK = Registry.register(Registries.BLOCK, "fabric-rendering-fluids-v1-testmod:unregistered", new FluidBlock(UNREGISTERED, AbstractBlock.Settings.copy(Blocks.WATER)) { + public static final FluidBlock UNREGISTERED_BLOCK = Registry.register(Registries.BLOCK, UNREGISTERED_KEY, new FluidBlock(UNREGISTERED, AbstractBlock.Settings.copy(Blocks.WATER).registryKey(UNREGISTERED_KEY)) { }); - public static final CustomFluid CUSTOM = Registry.register(Registries.FLUID, "fabric-rendering-fluids-v1-testmod:custom", new CustomFluid.Still()); - public static final CustomFluid CUSTOM_FLOWING = Registry.register(Registries.FLUID, "fabric-rendering-fluids-v1-testmod:custom_flowing", new CustomFluid.Flowing()); + public static final RegistryKey CUSTOM_KEY = block("custom"); + public static final CustomFluid CUSTOM = Registry.register(Registries.FLUID, CUSTOM_KEY.getValue(), new CustomFluid.Still()); + public static final CustomFluid CUSTOM_FLOWING = Registry.register(Registries.FLUID, id("custom_flowing"), new CustomFluid.Flowing()); - public static final FluidBlock CUSTOM_BLOCK = Registry.register(Registries.BLOCK, "fabric-rendering-fluids-v1-testmod:custom", new FluidBlock(CUSTOM, AbstractBlock.Settings.copy(Blocks.WATER)) { + public static final FluidBlock CUSTOM_BLOCK = Registry.register(Registries.BLOCK, CUSTOM_KEY, new FluidBlock(CUSTOM, AbstractBlock.Settings.copy(Blocks.WATER).registryKey(CUSTOM_KEY)) { }); + + private static Identifier id(String path) { + return Identifier.of(MOD_ID, path); + } + + private static RegistryKey block(String path) { + return RegistryKey.of(RegistryKeys.BLOCK, id(path)); + } } diff --git a/fabric-rendering-v1/src/testmod/java/net/fabricmc/fabric/test/rendering/CustomColorResolverTestInit.java b/fabric-rendering-v1/src/testmod/java/net/fabricmc/fabric/test/rendering/CustomColorResolverTestInit.java index 4113c1e5d8..188387bd0e 100644 --- a/fabric-rendering-v1/src/testmod/java/net/fabricmc/fabric/test/rendering/CustomColorResolverTestInit.java +++ b/fabric-rendering-v1/src/testmod/java/net/fabricmc/fabric/test/rendering/CustomColorResolverTestInit.java @@ -22,17 +22,20 @@ import net.minecraft.item.Item; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.util.Identifier; import net.fabricmc.api.ModInitializer; public class CustomColorResolverTestInit implements ModInitializer { - public static final Block CUSTOM_COLOR_BLOCK = new Block(AbstractBlock.Settings.create()); + public static final RegistryKey KEY = RegistryKey.of(RegistryKeys.BLOCK, Identifier.of("fabric-rendering-v1-testmod", "custom_color_block")); + public static final Block CUSTOM_COLOR_BLOCK = new Block(AbstractBlock.Settings.create().registryKey(KEY)); public static final Item CUSTOM_COLOR_BLOCK_ITEM = new BlockItem(CUSTOM_COLOR_BLOCK, new Item.Settings()); @Override public void onInitialize() { - Registry.register(Registries.BLOCK, Identifier.of("fabric-rendering-v1-testmod", "custom_color_block"), CUSTOM_COLOR_BLOCK); - Registry.register(Registries.ITEM, Identifier.of("fabric-rendering-v1-testmod", "custom_color_block"), CUSTOM_COLOR_BLOCK_ITEM); + Registry.register(Registries.BLOCK, KEY, CUSTOM_COLOR_BLOCK); + Registry.register(Registries.ITEM, KEY.getValue(), CUSTOM_COLOR_BLOCK_ITEM); } } diff --git a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/ResourceConditionsImpl.java b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/ResourceConditionsImpl.java index 2e1a090dc7..de2219c4aa 100644 --- a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/ResourceConditionsImpl.java +++ b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/ResourceConditionsImpl.java @@ -108,8 +108,7 @@ public static boolean modsLoaded(List modIds, boolean and) { } /** - * Stores the tags deserialized by {@link TagManagerLoader} before they are bound, to use them in the tags_populated conditions. - * The tags are set at the end of the "apply" phase in {@link TagManagerLoader}, and cleared in {@link net.minecraft.server.DataPackContents#refresh}. + * Stores the tags deserialized before they are bound, to use them in the tags_populated conditions. * If the resource reload fails, the thread local is not cleared and: * - the map will remain in memory until the next reload; * - any call to {@link #tagsPopulated} will check the tags from the failed reload instead of failing directly. diff --git a/fabric-resource-conditions-api-v1/src/testmod/java/net/fabricmc/fabric/test/resource/conditions/ConditionalResourcesTest.java b/fabric-resource-conditions-api-v1/src/testmod/java/net/fabricmc/fabric/test/resource/conditions/ConditionalResourcesTest.java index 9ffcbe2cbe..5acd63330b 100644 --- a/fabric-resource-conditions-api-v1/src/testmod/java/net/fabricmc/fabric/test/resource/conditions/ConditionalResourcesTest.java +++ b/fabric-resource-conditions-api-v1/src/testmod/java/net/fabricmc/fabric/test/resource/conditions/ConditionalResourcesTest.java @@ -82,11 +82,11 @@ public void conditionalPredicates(TestContext context) { RegistryEntryLookup.RegistryLookup registries = context.getWorld().getServer().getReloadableRegistries().createRegistryLookup(); - if (registries.getOptionalEntry(RegistryKeys.PREDICATE, RegistryKey.of(RegistryKeys.PREDICATE, id("loaded"))).isEmpty()) { + if (registries.getOptionalEntry(RegistryKey.of(RegistryKeys.PREDICATE, id("loaded"))).isEmpty()) { throw new AssertionError("loaded predicate should have been loaded."); } - if (registries.getOptionalEntry(RegistryKeys.PREDICATE, RegistryKey.of(RegistryKeys.PREDICATE, id("not_loaded"))).isPresent()) { + if (registries.getOptionalEntry(RegistryKey.of(RegistryKeys.PREDICATE, id("not_loaded"))).isPresent()) { throw new AssertionError("not_loaded predicate should not have been loaded."); } @@ -110,7 +110,7 @@ public void conditionalLootTables(TestContext context) { @GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE) public void conditionalDynamicRegistry(TestContext context) { - Registry registry = context.getWorld().getRegistryManager().get(RegistryKeys.BANNER_PATTERN); + Registry registry = context.getWorld().getRegistryManager().getOrThrow(RegistryKeys.BANNER_PATTERN); if (registry.get(id("loaded")) == null) { throw new AssertionError("loaded banner pattern should have been loaded."); @@ -127,11 +127,11 @@ public void conditionalDynamicRegistry(TestContext context) { public void conditionalOverlays(TestContext context) { RegistryEntryLookup.RegistryLookup registries = context.getWorld().getServer().getReloadableRegistries().createRegistryLookup(); - if (registries.getOptionalEntry(RegistryKeys.PREDICATE, RegistryKey.of(RegistryKeys.PREDICATE, id("do_overlay"))).isEmpty()) { + if (registries.getOptionalEntry(RegistryKey.of(RegistryKeys.PREDICATE, id("do_overlay"))).isEmpty()) { throw new AssertionError("do_overlay predicate should have been overlayed."); } - if (registries.getOptionalEntry(RegistryKeys.PREDICATE, RegistryKey.of(RegistryKeys.PREDICATE, id("dont_overlay"))).isPresent()) { + if (registries.getOptionalEntry(RegistryKey.of(RegistryKeys.PREDICATE, id("dont_overlay"))).isPresent()) { throw new AssertionError("dont_overlay predicate should not have been overlayed."); } diff --git a/fabric-resource-loader-v0/src/testmod/java/net/fabricmc/fabric/test/resource/loader/ResourceReloadListenerTestMod.java b/fabric-resource-loader-v0/src/testmod/java/net/fabricmc/fabric/test/resource/loader/ResourceReloadListenerTestMod.java index bbbfc8a333..39493f7053 100644 --- a/fabric-resource-loader-v0/src/testmod/java/net/fabricmc/fabric/test/resource/loader/ResourceReloadListenerTestMod.java +++ b/fabric-resource-loader-v0/src/testmod/java/net/fabricmc/fabric/test/resource/loader/ResourceReloadListenerTestMod.java @@ -135,7 +135,7 @@ public Identifier getFabricId() { @Override public void reload(ResourceManager manager) { Objects.requireNonNull(wrapperLookup); - wrapperLookup.getWrapperOrThrow(RegistryKeys.ENCHANTMENT).getOrThrow(Enchantments.FORTUNE); + wrapperLookup.getOrThrow(RegistryKeys.ENCHANTMENT).getOrThrow(Enchantments.FORTUNE); } } } diff --git a/fabric-screen-handler-api-v1/src/testmod/java/net/fabricmc/fabric/test/screenhandler/ScreenHandlerTest.java b/fabric-screen-handler-api-v1/src/testmod/java/net/fabricmc/fabric/test/screenhandler/ScreenHandlerTest.java index 955bcbd29f..7cfb8ae6b6 100644 --- a/fabric-screen-handler-api-v1/src/testmod/java/net/fabricmc/fabric/test/screenhandler/ScreenHandlerTest.java +++ b/fabric-screen-handler-api-v1/src/testmod/java/net/fabricmc/fabric/test/screenhandler/ScreenHandlerTest.java @@ -24,6 +24,8 @@ import net.minecraft.item.Item; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.resource.featuretoggle.FeatureFlags; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.util.Identifier; @@ -45,7 +47,8 @@ public class ScreenHandlerTest implements ModInitializer { public static final Item BAG = new BagItem(new Item.Settings().maxCount(1)); public static final Item POSITIONED_BAG = new PositionedBagItem(new Item.Settings().maxCount(1)); - public static final Block BOX = new BoxBlock(AbstractBlock.Settings.copy(Blocks.OAK_WOOD)); + public static final RegistryKey BOX_KEY = RegistryKey.of(RegistryKeys.BLOCK, id("box")); + public static final Block BOX = new BoxBlock(AbstractBlock.Settings.copy(Blocks.OAK_WOOD).registryKey(BOX_KEY)); public static final Item BOX_ITEM = new BlockItem(BOX, new Item.Settings()); public static final BlockEntityType BOX_ENTITY = FabricBlockEntityTypeBuilder.create(BoxBlockEntity::new, BOX).build(); public static final ScreenHandlerType BAG_SCREEN_HANDLER = new ScreenHandlerType<>(BagScreenHandler::new, FeatureFlags.VANILLA_FEATURES); @@ -60,8 +63,8 @@ public static Identifier id(String path) { public void onInitialize() { Registry.register(Registries.ITEM, id("bag"), BAG); Registry.register(Registries.ITEM, id("positioned_bag"), POSITIONED_BAG); - Registry.register(Registries.BLOCK, id("box"), BOX); - Registry.register(Registries.ITEM, id("box"), BOX_ITEM); + Registry.register(Registries.BLOCK, BOX_KEY, BOX); + Registry.register(Registries.ITEM, BOX_KEY.getValue(), BOX_ITEM); Registry.register(Registries.BLOCK_ENTITY_TYPE, id("box"), BOX_ENTITY); Registry.register(Registries.SCREEN_HANDLER, id("bag"), BAG_SCREEN_HANDLER); Registry.register(Registries.SCREEN_HANDLER, id("positioned_bag"), POSITIONED_BAG_SCREEN_HANDLER); diff --git a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/ingame/FluidChuteBlock.java b/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/ingame/FluidChuteBlock.java index 7d7bddde69..333e2cb49a 100644 --- a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/ingame/FluidChuteBlock.java +++ b/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/ingame/FluidChuteBlock.java @@ -41,8 +41,8 @@ import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributes; public class FluidChuteBlock extends Block implements BlockEntityProvider { - public FluidChuteBlock() { - super(Settings.create()); + public FluidChuteBlock(Settings settings) { + super(settings); } private static final VoxelShape SHAPE = VoxelShapes.cuboid( diff --git a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/ingame/TransferTestInitializer.java b/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/ingame/TransferTestInitializer.java index d9a81ffd7c..c8bcc2fa10 100644 --- a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/ingame/TransferTestInitializer.java +++ b/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/ingame/TransferTestInitializer.java @@ -24,6 +24,8 @@ import net.minecraft.item.Item; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.util.Identifier; import net.fabricmc.api.ModInitializer; @@ -34,17 +36,20 @@ public class TransferTestInitializer implements ModInitializer { public static final String MOD_ID = "fabric-transfer-api-v1-testmod"; - private static final Block INFINITE_WATER_SOURCE = new Block(AbstractBlock.Settings.create()); - private static final Block INFINITE_LAVA_SOURCE = new Block(AbstractBlock.Settings.create()); - private static final Block FLUID_CHUTE = new FluidChuteBlock(); + private static final RegistryKey INFINITE_WATER_SOURCE_KEY = block("infinite_water_source"); + private static final Block INFINITE_WATER_SOURCE = new Block(AbstractBlock.Settings.create().registryKey(INFINITE_WATER_SOURCE_KEY)); + private static final RegistryKey INFINITE_LAVA_SOURCE_KEY = block("infinite_lava_source"); + private static final Block INFINITE_LAVA_SOURCE = new Block(AbstractBlock.Settings.create().registryKey(INFINITE_LAVA_SOURCE_KEY)); + private static final RegistryKey FLUID_CHUTE_KEY = block("fluid_chute"); + private static final Block FLUID_CHUTE = new FluidChuteBlock(AbstractBlock.Settings.create().registryKey(FLUID_CHUTE_KEY)); private static final Item EXTRACT_STICK = new ExtractStickItem(); public static BlockEntityType FLUID_CHUTE_TYPE; @Override public void onInitialize() { - registerBlock(INFINITE_WATER_SOURCE, "infinite_water_source"); - registerBlock(INFINITE_LAVA_SOURCE, "infinite_lava_source"); - registerBlock(FLUID_CHUTE, "fluid_chute"); + registerBlock(INFINITE_WATER_SOURCE_KEY, INFINITE_WATER_SOURCE); + registerBlock(INFINITE_LAVA_SOURCE_KEY, INFINITE_LAVA_SOURCE); + registerBlock(FLUID_CHUTE_KEY, FLUID_CHUTE); Registry.register(Registries.ITEM, Identifier.of(MOD_ID, "extract_stick"), EXTRACT_STICK); FLUID_CHUTE_TYPE = FabricBlockEntityTypeBuilder.create(FluidChuteBlockEntity::new, FLUID_CHUTE).build(); @@ -59,9 +64,12 @@ public void onInitialize() { ItemStorage.SIDED.registerForBlocks((world, pos, state, be, direction) -> CreativeStorage.DIAMONDS, Blocks.DIAMOND_ORE); } - private static void registerBlock(Block block, String name) { - Identifier id = Identifier.of(MOD_ID, name); - Registry.register(Registries.BLOCK, id, block); - Registry.register(Registries.ITEM, id, new BlockItem(block, new Item.Settings())); + private static RegistryKey block(String name) { + return RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(MOD_ID, name)); + } + + private static void registerBlock(RegistryKey key, Block block) { + Registry.register(Registries.BLOCK, key, block); + Registry.register(Registries.ITEM, key.getValue(), new BlockItem(block, new Item.Settings())); } } diff --git a/fabric-transitive-access-wideners-v1/src/testmod/java/net/fabricmc/fabric/test/access/SignBlockEntityTest.java b/fabric-transitive-access-wideners-v1/src/testmod/java/net/fabricmc/fabric/test/access/SignBlockEntityTest.java index a375859295..3d8415f353 100644 --- a/fabric-transitive-access-wideners-v1/src/testmod/java/net/fabricmc/fabric/test/access/SignBlockEntityTest.java +++ b/fabric-transitive-access-wideners-v1/src/testmod/java/net/fabricmc/fabric/test/access/SignBlockEntityTest.java @@ -17,6 +17,7 @@ package net.fabricmc.fabric.test.access; import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.SignBlock; @@ -29,6 +30,8 @@ import net.minecraft.item.SignItem; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; @@ -37,13 +40,15 @@ public final class SignBlockEntityTest implements ModInitializer { public static final String MOD_ID = "fabric-transitive-access-wideners-v1-testmod"; - public static final SignBlock TEST_SIGN = new SignBlock(WoodType.OAK, AbstractBlock.Settings.copy(Blocks.OAK_SIGN)) { + public static final RegistryKey TEST_SIGN_KEY = keyOf("test_sign"); + public static final SignBlock TEST_SIGN = new SignBlock(WoodType.OAK, AbstractBlock.Settings.copy(Blocks.OAK_SIGN).registryKey(TEST_SIGN_KEY)) { @Override public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { return new TestSign(pos, state); } }; - public static final WallSignBlock TEST_WALL_SIGN = new WallSignBlock(WoodType.OAK, AbstractBlock.Settings.copy(Blocks.OAK_SIGN)) { + public static final RegistryKey TEST_WALL_SIGN_KEY = keyOf("test_wall_sign"); + public static final WallSignBlock TEST_WALL_SIGN = new WallSignBlock(WoodType.OAK, AbstractBlock.Settings.copy(Blocks.OAK_SIGN).registryKey(TEST_WALL_SIGN_KEY)) { @Override public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { return new TestSign(pos, state); @@ -52,11 +57,15 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { public static final SignItem TEST_SIGN_ITEM = new SignItem(new Item.Settings(), TEST_SIGN, TEST_WALL_SIGN); public static final BlockEntityType TEST_SIGN_BLOCK_ENTITY = FabricBlockEntityTypeBuilder.create(TestSign::new, TEST_SIGN, TEST_WALL_SIGN).build(); + private static RegistryKey keyOf(String id) { + return RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(MOD_ID, id)); + } + @Override public void onInitialize() { - Registry.register(Registries.BLOCK, Identifier.of(MOD_ID, "test_sign"), TEST_SIGN); - Registry.register(Registries.BLOCK, Identifier.of(MOD_ID, "test_wall_sign"), TEST_WALL_SIGN); - Registry.register(Registries.ITEM, Identifier.of(MOD_ID, "test_sign"), TEST_SIGN_ITEM); + Registry.register(Registries.BLOCK, TEST_SIGN_KEY, TEST_SIGN); + Registry.register(Registries.BLOCK, TEST_WALL_SIGN_KEY, TEST_WALL_SIGN); + Registry.register(Registries.ITEM, TEST_SIGN_KEY.getValue(), TEST_SIGN_ITEM); Registry.register(Registries.BLOCK_ENTITY_TYPE, Identifier.of(MOD_ID, "test_sign"), TEST_SIGN_BLOCK_ENTITY); } diff --git a/fabric-transitive-access-wideners-v1/template.accesswidener b/fabric-transitive-access-wideners-v1/template.accesswidener index a81a28f52b..cdf4976f45 100644 --- a/fabric-transitive-access-wideners-v1/template.accesswidener +++ b/fabric-transitive-access-wideners-v1/template.accesswidener @@ -116,13 +116,11 @@ transitive-accessible method net/minecraft/entity/damage/DamageSources create (L transitive-accessible field net/minecraft/client/MinecraftClient attackCooldown I # Creating certain types of blocks -transitive-accessible method net/minecraft/block/Blocks createFlowerPotBlock (Lnet/minecraft/block/Block;)Lnet/minecraft/block/Block; -transitive-accessible method net/minecraft/block/Blocks createLeavesBlock (Lnet/minecraft/sound/BlockSoundGroup;)Lnet/minecraft/block/Block; -transitive-accessible method net/minecraft/block/Blocks createLogBlock (Lnet/minecraft/block/MapColor;Lnet/minecraft/block/MapColor;)Lnet/minecraft/block/Block; -transitive-accessible method net/minecraft/block/Blocks createLogBlock (Lnet/minecraft/block/MapColor;Lnet/minecraft/block/MapColor;Lnet/minecraft/sound/BlockSoundGroup;)Lnet/minecraft/block/Block; -transitive-accessible method net/minecraft/block/Blocks createNetherStemBlock (Lnet/minecraft/block/MapColor;)Lnet/minecraft/block/Block; -transitive-accessible method net/minecraft/block/Blocks createStoneButtonBlock ()Lnet/minecraft/block/Block; -transitive-accessible method net/minecraft/block/Blocks createWoodenButtonBlock (Lnet/minecraft/block/BlockSetType;)Lnet/minecraft/block/Block; +transitive-accessible method net/minecraft/block/Blocks createLogSettings (Lnet/minecraft/block/MapColor;Lnet/minecraft/block/MapColor;Lnet/minecraft/sound/BlockSoundGroup;)Lnet/minecraft/block/AbstractBlock$Settings; +transitive-accessible method net/minecraft/block/Blocks createNetherStemSettings (Lnet/minecraft/block/MapColor;)Lnet/minecraft/block/AbstractBlock$Settings; +transitive-accessible method net/minecraft/block/Blocks createLeavesSettings (Lnet/minecraft/sound/BlockSoundGroup;)Lnet/minecraft/block/AbstractBlock$Settings; +transitive-accessible method net/minecraft/block/Blocks createButtonSettings ()Lnet/minecraft/block/AbstractBlock$Settings; +transitive-accessible method net/minecraft/block/Blocks createFlowerPotSettings ()Lnet/minecraft/block/AbstractBlock$Settings; # Methods used in block creation transitive-accessible method net/minecraft/block/Blocks always (Lnet/minecraft/block/BlockState;Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)Z @@ -132,4 +130,8 @@ transitive-accessible method net/minecraft/block/Blocks createLightLevelFromLitB transitive-accessible method net/minecraft/block/Blocks never (Lnet/minecraft/block/BlockState;Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)Z transitive-accessible method net/minecraft/block/Blocks never (Lnet/minecraft/block/BlockState;Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/EntityType;)Ljava/lang/Boolean; +# Methods used in block registration +transitive-accessible method net/minecraft/block/Blocks register (Lnet/minecraft/registry/RegistryKey;Ljava/util/function/Function;Lnet/minecraft/block/AbstractBlock$Settings;)Lnet/minecraft/block/Block; +transitive-accessible method net/minecraft/block/Blocks register (Lnet/minecraft/registry/RegistryKey;Lnet/minecraft/block/AbstractBlock$Settings;)Lnet/minecraft/block/Block; + ### Generated access wideners below diff --git a/gradle.properties b/gradle.properties index 09ad0a108b..4c3627555e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,8 +3,8 @@ org.gradle.parallel=true fabric.loom.multiProjectOptimisation=true version=0.103.0 -minecraft_version=24w34a -yarn_version=+build.1 +minecraft_version=24w35a +yarn_version=+build.4 loader_version=0.16.2 installer_version=1.0.1