This commit is contained in:
apple502j 2024-08-30 01:54:21 +09:00 committed by GitHub
parent 9c280a9ffa
commit 2cd4845256
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
68 changed files with 334 additions and 967 deletions

View file

@ -19,11 +19,14 @@ package net.fabricmc.fabric.test.lookup;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import net.minecraft.block.AbstractBlock; import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
@ -41,30 +44,35 @@ public class FabricApiLookupTest implements ModInitializer {
public static final String MOD_ID = "fabric-lookup-api-v1-testmod"; 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. // 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. // 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<Block> 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 final BlockItem CHUTE_ITEM = new BlockItem(CHUTE_BLOCK, new Item.Settings());
public static BlockEntityType<ChuteBlockEntity> CHUTE_BLOCK_ENTITY_TYPE; public static BlockEntityType<ChuteBlockEntity> CHUTE_BLOCK_ENTITY_TYPE;
// Cobble gen - Block without model that can generate infinite cobblestone when placed above a chute. // Cobble gen - Block without model that can generate infinite cobblestone when placed above a chute.
// It's meant to test BlockApiLookup#registerSelf. // It's meant to test BlockApiLookup#registerSelf.
public static final CobbleGenBlock COBBLE_GEN_BLOCK = new CobbleGenBlock(AbstractBlock.Settings.create()); public static final RegistryKey<Block> 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 final BlockItem COBBLE_GEN_ITEM = new BlockItem(COBBLE_GEN_BLOCK, new Item.Settings());
public static BlockEntityType<CobbleGenBlockEntity> COBBLE_GEN_BLOCK_ENTITY_TYPE; public static BlockEntityType<CobbleGenBlockEntity> COBBLE_GEN_BLOCK_ENTITY_TYPE;
// Testing for item api lookups is done in the `item` package. // 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<Block> 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()); public static final BlockItem INSPECTOR_ITEM = new BlockItem(INSPECTOR_BLOCK, new Item.Settings());
private static RegistryKey<Block> keyOf(String id) {
return RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(MOD_ID, id));
}
@Override @Override
public void onInitialize() { public void onInitialize() {
Identifier chute = Identifier.of(MOD_ID, "chute"); Registry.register(Registries.BLOCK, CHUTE_BLOCK_KEY, CHUTE_BLOCK);
Registry.register(Registries.BLOCK, chute, CHUTE_BLOCK); Registry.register(Registries.ITEM, CHUTE_BLOCK_KEY.getValue(), CHUTE_ITEM);
Registry.register(Registries.ITEM, chute, CHUTE_ITEM); CHUTE_BLOCK_ENTITY_TYPE = Registry.register(Registries.BLOCK_ENTITY_TYPE, CHUTE_BLOCK_KEY.getValue(), FabricBlockEntityTypeBuilder.create(ChuteBlockEntity::new, CHUTE_BLOCK).build());
CHUTE_BLOCK_ENTITY_TYPE = Registry.register(Registries.BLOCK_ENTITY_TYPE, chute, FabricBlockEntityTypeBuilder.create(ChuteBlockEntity::new, CHUTE_BLOCK).build());
Identifier cobbleGen = Identifier.of(MOD_ID, "cobble_gen"); Registry.register(Registries.BLOCK, COBBLE_GEN_BLOCK_KEY, COBBLE_GEN_BLOCK);
Registry.register(Registries.BLOCK, cobbleGen, COBBLE_GEN_BLOCK); Registry.register(Registries.ITEM, COBBLE_GEN_BLOCK_KEY.getValue(), COBBLE_GEN_ITEM);
Registry.register(Registries.ITEM, cobbleGen, 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());
COBBLE_GEN_BLOCK_ENTITY_TYPE = Registry.register(Registries.BLOCK_ENTITY_TYPE, cobbleGen, FabricBlockEntityTypeBuilder.create(CobbleGenBlockEntity::new, COBBLE_GEN_BLOCK).build());
InventoryExtractableProvider extractableProvider = new InventoryExtractableProvider(); InventoryExtractableProvider extractableProvider = new InventoryExtractableProvider();
InventoryInsertableProvider insertableProvider = new InventoryInsertableProvider(); InventoryInsertableProvider insertableProvider = new InventoryInsertableProvider();
@ -76,9 +84,8 @@ public class FabricApiLookupTest implements ModInitializer {
testLookupRegistry(); testLookupRegistry();
testSelfRegistration(); testSelfRegistration();
Identifier inspector = Identifier.of(FabricApiLookupTest.MOD_ID, "inspector"); Registry.register(Registries.BLOCK, INSPECTOR_BLOCK_KEY, INSPECTOR_BLOCK);
Registry.register(Registries.BLOCK, inspector, INSPECTOR_BLOCK); Registry.register(Registries.ITEM, INSPECTOR_BLOCK_KEY.getValue(), INSPECTOR_ITEM);
Registry.register(Registries.ITEM, inspector, INSPECTOR_ITEM);
FabricItemApiLookupTest.onInitialize(); FabricItemApiLookupTest.onInitialize();
FabricEntityApiLookupTest.onInitialize(); FabricEntityApiLookupTest.onInitialize();

View file

@ -23,6 +23,8 @@ import net.minecraft.entity.mob.CreeperEntity;
import net.minecraft.entity.passive.PigEntity; import net.minecraft.entity.passive.PigEntity;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@ -33,6 +35,7 @@ import net.fabricmc.fabric.test.lookup.FabricApiLookupTest;
import net.fabricmc.fabric.test.lookup.api.Inspectable; import net.fabricmc.fabric.test.lookup.api.Inspectable;
public class FabricEntityApiLookupTest { public class FabricEntityApiLookupTest {
public static final RegistryKey<EntityType<?>> INSPECTABLE_PIG_KEY = RegistryKey.of(RegistryKeys.ENTITY_TYPE, Identifier.of(FabricApiLookupTest.MOD_ID, "inspectable_pig"));
public static final EntityApiLookup<Inspectable, Void> INSPECTABLE = public static final EntityApiLookup<Inspectable, Void> INSPECTABLE =
EntityApiLookup.get(Identifier.of(FabricApiLookupTest.MOD_ID, "inspectable"), Inspectable.class, Void.class); EntityApiLookup.get(Identifier.of(FabricApiLookupTest.MOD_ID, "inspectable"), Inspectable.class, Void.class);
@ -41,10 +44,10 @@ public class FabricEntityApiLookupTest {
.entityFactory(InspectablePigEntity::new) .entityFactory(InspectablePigEntity::new)
.dimensions(EntityDimensions.changing(0.9F, 0.9F)) .dimensions(EntityDimensions.changing(0.9F, 0.9F))
.trackRangeChunks(10) .trackRangeChunks(10)
.build(); .build(INSPECTABLE_PIG_KEY);
public static void onInitialize() { public static void onInitialize() {
Registry.register(Registries.ENTITY_TYPE, Identifier.of(FabricApiLookupTest.MOD_ID, "inspectable_pig"), INSPECTABLE_PIG); Registry.register(Registries.ENTITY_TYPE, INSPECTABLE_PIG_KEY, INSPECTABLE_PIG);
FabricDefaultAttributeRegistry.register(INSPECTABLE_PIG, PigEntity.createPigAttributes()); FabricDefaultAttributeRegistry.register(INSPECTABLE_PIG, PigEntity.createPigAttributes());
INSPECTABLE.registerSelf(INSPECTABLE_PIG); INSPECTABLE.registerSelf(INSPECTABLE_PIG);

View file

@ -194,8 +194,8 @@ public class BiomeModificationContextImpl implements BiomeModificationContext {
} }
private class GenerationSettingsContextImpl implements GenerationSettingsContext { private class GenerationSettingsContextImpl implements GenerationSettingsContext {
private final Registry<ConfiguredCarver<?>> carvers = registries.get(RegistryKeys.CONFIGURED_CARVER); private final Registry<ConfiguredCarver<?>> carvers = registries.getOrThrow(RegistryKeys.CONFIGURED_CARVER);
private final Registry<PlacedFeature> features = registries.get(RegistryKeys.PLACED_FEATURE); private final Registry<PlacedFeature> features = registries.getOrThrow(RegistryKeys.PLACED_FEATURE);
private final GenerationSettings generationSettings = biome.getGenerationSettings(); private final GenerationSettings generationSettings = biome.getGenerationSettings();
boolean rebuildFeatures; boolean rebuildFeatures;
@ -316,7 +316,7 @@ public class BiomeModificationContextImpl implements BiomeModificationContext {
* forgot to data-gen the JSONs corresponding to their built-in objects. * forgot to data-gen the JSONs corresponding to their built-in objects.
*/ */
private static <T> RegistryEntry.Reference<T> getEntry(Registry<T> registry, RegistryKey<T> key) { private static <T> RegistryEntry.Reference<T> getEntry(Registry<T> registry, RegistryKey<T> key) {
RegistryEntry.Reference<T> entry = registry.getEntry(key).orElse(null); RegistryEntry.Reference<T> entry = registry.getOptional(key).orElse(null);
if (entry == null) { if (entry == null) {
// The key doesn't exist in the data packs // The key doesn't exist in the data packs

View file

@ -114,13 +114,13 @@ public class BiomeModificationImpl {
BiomeModificationMarker modificationTracker = (BiomeModificationMarker) impl; BiomeModificationMarker modificationTracker = (BiomeModificationMarker) impl;
modificationTracker.fabric_markModified(); modificationTracker.fabric_markModified();
Registry<Biome> biomes = impl.get(RegistryKeys.BIOME); Registry<Biome> 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 // 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. // someone does something stupid.
List<RegistryKey<Biome>> keys = biomes.getEntrySet().stream() List<RegistryKey<Biome>> keys = biomes.getEntrySet().stream()
.map(Map.Entry::getKey) .map(Map.Entry::getKey)
.sorted(Comparator.comparingInt(key -> biomes.getRawId(biomes.getOrThrow(key)))) .sorted(Comparator.comparingInt(key -> biomes.getRawId(biomes.getValueOrThrow(key))))
.toList(); .toList();
List<ModifierRecord> sortedModifiers = getSortedModifiers(); List<ModifierRecord> sortedModifiers = getSortedModifiers();
@ -130,7 +130,7 @@ public class BiomeModificationImpl {
int modifiersApplied = 0; int modifiersApplied = 0;
for (RegistryKey<Biome> key : keys) { for (RegistryKey<Biome> key : keys) {
Biome biome = biomes.getOrThrow(key); Biome biome = biomes.getValueOrThrow(key);
biomesProcessed++; biomesProcessed++;
@ -159,7 +159,7 @@ public class BiomeModificationImpl {
modificationContext.freeze(); modificationContext.freeze();
if (modificationContext.shouldRebuildFeatures()) { if (modificationContext.shouldRebuildFeatures()) {
impl.get(RegistryKeys.DIMENSION).stream().forEach(dimensionOptions -> { impl.getOrThrow(RegistryKeys.DIMENSION).stream().forEach(dimensionOptions -> {
dimensionOptions.chunkGenerator().indexedFeaturesListSupplier = Suppliers.memoize( dimensionOptions.chunkGenerator().indexedFeaturesListSupplier = Suppliers.memoize(
() -> PlacedFeatureIndexer.collectIndexedFeatures( () -> PlacedFeatureIndexer.collectIndexedFeatures(
List.copyOf(dimensionOptions.chunkGenerator().getBiomeSource().getBiomes()), List.copyOf(dimensionOptions.chunkGenerator().getBiomeSource().getBiomes()),

View file

@ -42,7 +42,7 @@ public class BiomeSelectionContextImpl implements BiomeSelectionContext {
this.dynamicRegistries = dynamicRegistries; this.dynamicRegistries = dynamicRegistries;
this.key = key; this.key = key;
this.biome = biome; this.biome = biome;
this.entry = dynamicRegistries.get(RegistryKeys.BIOME).getEntry(this.key).orElseThrow(); this.entry = dynamicRegistries.getOrThrow(RegistryKeys.BIOME).getOrThrow(this.key);
} }
@Override @Override
@ -62,19 +62,19 @@ public class BiomeSelectionContextImpl implements BiomeSelectionContext {
@Override @Override
public Optional<RegistryKey<ConfiguredFeature<?, ?>>> getFeatureKey(ConfiguredFeature<?, ?> configuredFeature) { public Optional<RegistryKey<ConfiguredFeature<?, ?>>> getFeatureKey(ConfiguredFeature<?, ?> configuredFeature) {
Registry<ConfiguredFeature<?, ?>> registry = dynamicRegistries.get(RegistryKeys.CONFIGURED_FEATURE); Registry<ConfiguredFeature<?, ?>> registry = dynamicRegistries.getOrThrow(RegistryKeys.CONFIGURED_FEATURE);
return registry.getKey(configuredFeature); return registry.getKey(configuredFeature);
} }
@Override @Override
public Optional<RegistryKey<PlacedFeature>> getPlacedFeatureKey(PlacedFeature placedFeature) { public Optional<RegistryKey<PlacedFeature>> getPlacedFeatureKey(PlacedFeature placedFeature) {
Registry<PlacedFeature> registry = dynamicRegistries.get(RegistryKeys.PLACED_FEATURE); Registry<PlacedFeature> registry = dynamicRegistries.getOrThrow(RegistryKeys.PLACED_FEATURE);
return registry.getKey(placedFeature); return registry.getKey(placedFeature);
} }
@Override @Override
public boolean validForStructure(RegistryKey<Structure> key) { public boolean validForStructure(RegistryKey<Structure> key) {
Structure instance = dynamicRegistries.get(RegistryKeys.STRUCTURE).get(key); Structure instance = dynamicRegistries.getOrThrow(RegistryKeys.STRUCTURE).get(key);
if (instance == null) { if (instance == null) {
return false; return false;
@ -85,13 +85,13 @@ public class BiomeSelectionContextImpl implements BiomeSelectionContext {
@Override @Override
public Optional<RegistryKey<Structure>> getStructureKey(Structure structure) { public Optional<RegistryKey<Structure>> getStructureKey(Structure structure) {
Registry<Structure> registry = dynamicRegistries.get(RegistryKeys.STRUCTURE); Registry<Structure> registry = dynamicRegistries.getOrThrow(RegistryKeys.STRUCTURE);
return registry.getKey(structure); return registry.getKey(structure);
} }
@Override @Override
public boolean canGenerateIn(RegistryKey<DimensionOptions> dimensionKey) { public boolean canGenerateIn(RegistryKey<DimensionOptions> dimensionKey) {
DimensionOptions dimension = dynamicRegistries.get(RegistryKeys.DIMENSION).get(dimensionKey); DimensionOptions dimension = dynamicRegistries.getOrThrow(RegistryKeys.DIMENSION).get(dimensionKey);
if (dimension == null) { if (dimension == null) {
return false; return false;
@ -102,7 +102,7 @@ public class BiomeSelectionContextImpl implements BiomeSelectionContext {
@Override @Override
public boolean hasTag(TagKey<Biome> tag) { public boolean hasTag(TagKey<Biome> tag) {
Registry<Biome> biomeRegistry = dynamicRegistries.get(RegistryKeys.BIOME); Registry<Biome> biomeRegistry = dynamicRegistries.getOrThrow(RegistryKeys.BIOME);
return biomeRegistry.entryOf(getBiomeKey()).isIn(tag); return biomeRegistry.getOrThrow(getBiomeKey()).isIn(tag);
} }
} }

View file

@ -37,6 +37,6 @@ public final class BuiltInRegistryKeys {
} }
public static RegistryEntryLookup<Biome> biomeRegistryWrapper() { public static RegistryEntryLookup<Biome> biomeRegistryWrapper() {
return vanillaRegistries.getWrapperOrThrow(RegistryKeys.BIOME); return vanillaRegistries.getOrThrow(RegistryKeys.BIOME);
} }
} }

View file

@ -31,9 +31,9 @@ public class WorldgenProvider extends FabricDynamicRegistryProvider {
@Override @Override
protected void configure(RegistryWrapper.WrapperLookup registries, Entries entries) { protected void configure(RegistryWrapper.WrapperLookup registries, Entries entries) {
entries.addAll(registries.getWrapperOrThrow(RegistryKeys.BIOME)); entries.addAll(registries.getOrThrow(RegistryKeys.BIOME));
entries.addAll(registries.getWrapperOrThrow(RegistryKeys.PLACED_FEATURE)); entries.addAll(registries.getOrThrow(RegistryKeys.PLACED_FEATURE));
entries.addAll(registries.getWrapperOrThrow(RegistryKeys.CONFIGURED_FEATURE)); entries.addAll(registries.getOrThrow(RegistryKeys.CONFIGURED_FEATURE));
} }
@Override @Override

View file

@ -50,7 +50,7 @@ public class ClientTagsImpl {
if (maybeRegistry.isPresent()) { if (maybeRegistry.isPresent()) {
// Check the synced tag exists and use that // Check the synced tag exists and use that
if (maybeRegistry.get().getEntryList(tagKey).isPresent()) { if (maybeRegistry.get().getOptional(tagKey).isPresent()) {
return registryEntry.isIn(tagKey); return registryEntry.isIn(tagKey);
} }
} }
@ -93,7 +93,7 @@ public class ClientTagsImpl {
} }
} }
return (Optional<? extends Registry<T>>) Registries.REGISTRIES.getOrEmpty(tagKey.registry().getValue()); return (Optional<? extends Registry<T>>) Registries.REGISTRIES.getOptionalValue(tagKey.registry().getValue());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -108,7 +108,7 @@ public class ClientTagsImpl {
Optional<RegistryKey<T>> maybeKey = registry.getKey(entry); Optional<RegistryKey<T>> maybeKey = registry.getKey(entry);
return maybeKey.map(registry::entryOf); return maybeKey.map(registry::getOrThrow);
} }
public static ClientTagsLoader.LoadedTag getOrCreatePartiallySyncedTag(TagKey<?> tagKey) { public static ClientTagsLoader.LoadedTag getOrCreatePartiallySyncedTag(TagKey<?> tagKey) {

View file

@ -65,6 +65,7 @@ public final class ContentRegistryTest implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger(ContentRegistryTest.class); 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 Identifier TEST_EVENT_ID = Identifier.of("fabric-content-registries-v0-testmod", "test_event");
public static final RegistryKey<Block> TEST_EVENT_BLOCK_KEY = RegistryKey.of(RegistryKeys.BLOCK, TEST_EVENT_ID);
public static final RegistryEntry.Reference<GameEvent> TEST_EVENT = Registry.registerReference(Registries.GAME_EVENT, TEST_EVENT_ID, new GameEvent(GameEvent.DEFAULT_RANGE)); public static final RegistryEntry.Reference<GameEvent> TEST_EVENT = Registry.registerReference(Registries.GAME_EVENT, TEST_EVENT_ID, new GameEvent(GameEvent.DEFAULT_RANGE));
@Override @Override
@ -136,7 +137,7 @@ public final class ContentRegistryTest implements ModInitializer {
VillagerInteractionRegistries.registerGiftLootTable(VillagerProfession.NITWIT, RegistryKey.of(RegistryKeys.LOOT_TABLE, Identifier.ofVanilla("fake_loot_table"))); 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); SculkSensorFrequencyRegistry.register(TEST_EVENT.registryKey(), 2);
// assert that SculkSensorFrequencyRegistry throws when registering a frequency outside the allowed range // assert that SculkSensorFrequencyRegistry throws when registering a frequency outside the allowed range
@ -156,8 +157,8 @@ public final class ContentRegistryTest implements ModInitializer {
* This testmod uses an accessor due to Loom limitations that prevent TAWs from applying across Gradle subproject boundaries */ * This testmod uses an accessor due to Loom limitations that prevent TAWs from applying across Gradle subproject boundaries */
FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> { FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> {
builder.registerPotionType(dirtyPotion); builder.registerPotionType(dirtyPotion);
builder.registerItemRecipe(Items.POTION, Ingredient.fromTag(Registries.ITEM.getEntryList(ItemTags.DIRT).get()), dirtyPotion); builder.registerItemRecipe(Items.POTION, Ingredient.fromTag(Registries.ITEM.getOrThrow(ItemTags.DIRT)), dirtyPotion);
builder.registerPotionRecipe(Potions.AWKWARD, Ingredient.fromTag(Registries.ITEM.getEntryList(ItemTags.SMALL_FLOWERS).get()), Potions.HEALING); builder.registerPotionRecipe(Potions.AWKWARD, Ingredient.fromTag(Registries.ITEM.getOrThrow(ItemTags.SMALL_FLOWERS)), Potions.HEALING);
if (builder.getEnabledFeatures().contains(FeatureFlags.BUNDLE)) { if (builder.getEnabledFeatures().contains(FeatureFlags.BUNDLE)) {
builder.registerPotionRecipe(Potions.AWKWARD, Ingredient.ofItems(Items.BUNDLE), Potions.LUCK); builder.registerPotionRecipe(Potions.AWKWARD, Ingredient.ofItems(Items.BUNDLE), Potions.LUCK);

View file

@ -66,7 +66,7 @@ public final class TagUtil {
if (registryManager != null) { if (registryManager != null) {
maybeRegistry = registryManager.getOptional(tagKey.registry()); maybeRegistry = registryManager.getOptional(tagKey.registry());
} else { } else {
maybeRegistry = Registries.REGISTRIES.getOrEmpty(tagKey.registry().getValue()); maybeRegistry = Registries.REGISTRIES.getOptionalValue(tagKey.registry().getValue());
} }
if (maybeRegistry.isPresent()) { if (maybeRegistry.isPresent()) {
@ -77,7 +77,7 @@ public final class TagUtil {
// Check synced tag // Check synced tag
if (maybeKey.isPresent()) { if (maybeKey.isPresent()) {
return registry.entryOf(maybeKey.get()).isIn(tagKey); return registry.getOrThrow(maybeKey.get()).isIn(tagKey);
} }
} }
} }

View file

@ -77,7 +77,7 @@ public class TranslationConventionLogWarnings implements ModInitializer {
// Log missing item tag translations only when world is started. // Log missing item tag translations only when world is started.
ServerLifecycleEvents.SERVER_STARTED.register(server -> { ServerLifecycleEvents.SERVER_STARTED.register(server -> {
Language language = Language.getInstance(); Language language = Language.getInstance();
Registry<Item> itemRegistry = server.getRegistryManager().get(RegistryKeys.ITEM); Registry<Item> itemRegistry = server.getRegistryManager().getOrThrow(RegistryKeys.ITEM);
List<TagKey<Item>> untranslatedItemTags = new ObjectArrayList<>(); List<TagKey<Item>> untranslatedItemTags = new ObjectArrayList<>();
itemRegistry.streamTags().forEach(itemTagKey -> { itemRegistry.streamTags().forEach(itemTagKey -> {
// We do not translate vanilla's tags at this moment. // We do not translate vanilla's tags at this moment.

View file

@ -156,16 +156,16 @@ public class TagUtilTest implements ModInitializer {
} }
ServerLifecycleEvents.SERVER_STARTED.register(server -> { ServerLifecycleEvents.SERVER_STARTED.register(server -> {
if (!TagUtil.isIn(server.getRegistryManager(), ConventionalEnchantmentTags.INCREASE_BLOCK_DROPS, server.getRegistryManager().get(RegistryKeys.ENCHANTMENT).get(Enchantments.FORTUNE))) { if (!TagUtil.isIn(server.getRegistryManager(), ConventionalEnchantmentTags.INCREASE_BLOCK_DROPS, server.getRegistryManager().getOrThrow(RegistryKeys.ENCHANTMENT).get(Enchantments.FORTUNE))) {
throw new AssertionError("Failed to find fortune in c:increase_block_drops!"); throw new AssertionError("Failed to find fortune in c:increase_block_drops!");
} }
if (TagUtil.isIn(ConventionalBiomeTags.IS_OVERWORLD, server.getRegistryManager().get(RegistryKeys.BIOME).get(BiomeKeys.BADLANDS))) { if (TagUtil.isIn(ConventionalBiomeTags.IS_OVERWORLD, server.getRegistryManager().getOrThrow(RegistryKeys.BIOME).get(BiomeKeys.BADLANDS))) {
throw new AssertionError("Found a dynamic entry in a static registry?!"); throw new AssertionError("Found a dynamic entry in a static registry?!");
} }
// If this fails, the tag is missing a biome or the util is broken // If this fails, the tag is missing a biome or the util is broken
if (!TagUtil.isIn(server.getRegistryManager(), ConventionalBiomeTags.IS_OVERWORLD, server.getRegistryManager().get(RegistryKeys.BIOME).get(BiomeKeys.BADLANDS))) { if (!TagUtil.isIn(server.getRegistryManager(), ConventionalBiomeTags.IS_OVERWORLD, server.getRegistryManager().getOrThrow(RegistryKeys.BIOME).get(BiomeKeys.BADLANDS))) {
throw new AssertionError("Failed to find an overworld biome (%s) in c:in_overworld!".formatted(BiomeKeys.BADLANDS)); throw new AssertionError("Failed to find an overworld biome (%s) in c:in_overworld!".formatted(BiomeKeys.BADLANDS));
} }

View file

@ -19,6 +19,7 @@ package net.fabricmc.fabric.api.datagen.v1.provider;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
@ -29,7 +30,6 @@ import net.minecraft.block.Block;
import net.minecraft.data.DataWriter; import net.minecraft.data.DataWriter;
import net.minecraft.data.server.loottable.BlockLootTableGenerator; import net.minecraft.data.server.loottable.BlockLootTableGenerator;
import net.minecraft.loot.LootTable; import net.minecraft.loot.LootTable;
import net.minecraft.loot.LootTables;
import net.minecraft.loot.context.LootContextTypes; import net.minecraft.loot.context.LootContextTypes;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKey;
@ -79,10 +79,6 @@ public abstract class FabricBlockLootTableProvider extends BlockLootTableGenerat
for (Map.Entry<RegistryKey<LootTable>, LootTable.Builder> entry : lootTables.entrySet()) { for (Map.Entry<RegistryKey<LootTable>, LootTable.Builder> entry : lootTables.entrySet()) {
RegistryKey<LootTable> registryKey = entry.getKey(); RegistryKey<LootTable> registryKey = entry.getKey();
if (registryKey == LootTables.EMPTY) {
continue;
}
biConsumer.accept(registryKey, entry.getValue()); biConsumer.accept(registryKey, entry.getValue());
} }
@ -91,10 +87,10 @@ public abstract class FabricBlockLootTableProvider extends BlockLootTableGenerat
for (Identifier blockId : Registries.BLOCK.getIds()) { for (Identifier blockId : Registries.BLOCK.getIds()) {
if (blockId.getNamespace().equals(output.getModId())) { if (blockId.getNamespace().equals(output.getModId())) {
RegistryKey<LootTable> blockLootTableId = Registries.BLOCK.get(blockId).getLootTableKey(); Optional<RegistryKey<LootTable>> blockLootTableId = Registries.BLOCK.get(blockId).getLootTableKey();
if (blockLootTableId.getValue().getNamespace().equals(output.getModId())) { if (blockLootTableId.isPresent() && blockLootTableId.get().getValue().getNamespace().equals(output.getModId())) {
if (!lootTables.containsKey(blockLootTableId)) { if (!lootTables.containsKey(blockLootTableId.get())) {
missing.add(blockId); missing.add(blockId);
} }
} }

View file

@ -85,7 +85,7 @@ public abstract class FabricDynamicRegistryProvider implements DataProvider {
this.registries = registries; this.registries = registries;
this.queuedEntries = DynamicRegistries.getDynamicRegistries().stream() this.queuedEntries = DynamicRegistries.getDynamicRegistries().stream()
// Some modded dynamic registries might not be in the wrapper lookup, filter them out // 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( .collect(Collectors.toMap(
e -> e.key().getValue(), e -> e.key().getValue(),
e -> RegistryEntries.create(registries, e) e -> RegistryEntries.create(registries, e)
@ -104,7 +104,7 @@ public abstract class FabricDynamicRegistryProvider implements DataProvider {
* Gets a lookup for entries from the given registry. * Gets a lookup for entries from the given registry.
*/ */
public <T> RegistryEntryLookup<T> getLookup(RegistryKey<? extends Registry<T>> registryKey) { public <T> RegistryEntryLookup<T> getLookup(RegistryKey<? extends Registry<T>> registryKey) {
return registries.getWrapperOrThrow(registryKey); return registries.getOrThrow(registryKey);
} }
/** /**
@ -232,7 +232,7 @@ public abstract class FabricDynamicRegistryProvider implements DataProvider {
} }
static <T> RegistryEntries<T> create(RegistryWrapper.WrapperLookup lookups, RegistryLoader.Entry<T> loaderEntry) { static <T> RegistryEntries<T> create(RegistryWrapper.WrapperLookup lookups, RegistryLoader.Entry<T> loaderEntry) {
RegistryWrapper.Impl<T> lookup = lookups.getWrapperOrThrow(loaderEntry.key()); RegistryWrapper.Impl<T> lookup = lookups.getOrThrow(loaderEntry.key());
return new RegistryEntries<>(lookup, loaderEntry.key(), loaderEntry.elementCodec()); return new RegistryEntries<>(lookup, loaderEntry.key(), loaderEntry.elementCodec());
} }

View file

@ -159,7 +159,7 @@ public abstract class FabricLanguageProvider implements DataProvider {
* @param value The value of the entry. * @param value The value of the entry.
*/ */
default void add(RegistryKey<ItemGroup> registryKey, String value) { default void add(RegistryKey<ItemGroup> registryKey, String value) {
final ItemGroup group = Registries.ITEM_GROUP.getOrThrow(registryKey); final ItemGroup group = Registries.ITEM_GROUP.getValueOrThrow(registryKey);
final TextContent content = group.getDisplayName().getContent(); final TextContent content = group.getDisplayName().getContent();
if (content instanceof TranslatableTextContent translatableTextContent) { if (content instanceof TranslatableTextContent translatableTextContent) {

View file

@ -32,7 +32,7 @@ public class ConditionBlockLootTableGenerator extends BlockLootTableGenerator {
private final ResourceCondition[] conditions; private final ResourceCondition[] conditions;
public ConditionBlockLootTableGenerator(BlockLootTableGenerator parent, ResourceCondition[] conditions) { public ConditionBlockLootTableGenerator(BlockLootTableGenerator parent, ResourceCondition[] conditions) {
super(Collections.emptySet(), FeatureFlags.FEATURE_MANAGER.getFeatureSet(), ((BlockLootTableGeneratorAccessor) parent).getRegistryLookup()); super(Collections.emptySet(), FeatureFlags.FEATURE_MANAGER.getFeatureSet(), ((BlockLootTableGeneratorAccessor) parent).getRegistries());
this.parent = parent; this.parent = parent;
this.conditions = conditions; this.conditions = conditions;

View file

@ -25,5 +25,5 @@ import net.minecraft.registry.RegistryWrapper;
@Mixin(BlockLootTableGenerator.class) @Mixin(BlockLootTableGenerator.class)
public interface BlockLootTableGeneratorAccessor { public interface BlockLootTableGeneratorAccessor {
@Accessor() @Accessor()
RegistryWrapper.WrapperLookup getRegistryLookup(); RegistryWrapper.WrapperLookup getRegistries();
} }

View file

@ -69,7 +69,7 @@ public class DataGeneratorTestContent implements ModInitializer {
SIMPLE_BLOCK = createBlock("simple_block", true, AbstractBlock.Settings.create()); SIMPLE_BLOCK = createBlock("simple_block", true, AbstractBlock.Settings.create());
BLOCK_WITHOUT_ITEM = createBlock("block_without_item", false, 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_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()); 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)); ItemGroupEvents.modifyEntriesEvent(SIMPLE_ITEM_GROUP).register(entries -> entries.add(SIMPLE_BLOCK));
@ -85,7 +85,7 @@ public class DataGeneratorTestContent implements ModInitializer {
private static Block createBlock(String name, boolean hasItem, AbstractBlock.Settings settings) { private static Block createBlock(String name, boolean hasItem, AbstractBlock.Settings settings) {
Identifier identifier = Identifier.of(MOD_ID, name); 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) { if (hasItem) {
Registry.register(Registries.ITEM, identifier, new BlockItem(block, new Item.Settings())); Registry.register(Registries.ITEM, identifier, new BlockItem(block, new Item.Settings()));

View file

@ -444,7 +444,7 @@ public class DataGeneratorTestEntrypoint implements DataGeneratorEntrypoint {
@Override @Override
protected void configure(RegistryWrapper.WrapperLookup registries, Entries entries) { protected void configure(RegistryWrapper.WrapperLookup registries, Entries entries) {
entries.add( 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) ResourceConditions.allModsLoaded(MOD_ID)
); );
} }
@ -465,7 +465,7 @@ public class DataGeneratorTestEntrypoint implements DataGeneratorEntrypoint {
@Override @Override
protected void configure(RegistryWrapper.WrapperLookup registries, Entries entries) { 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 @Override
@ -481,7 +481,7 @@ public class DataGeneratorTestEntrypoint implements DataGeneratorEntrypoint {
@Override @Override
protected void configure(BiConsumer<Identifier, LootCondition> provider, RegistryWrapper.WrapperLookup lookup) { protected void configure(BiConsumer<Identifier, LootCondition> provider, RegistryWrapper.WrapperLookup lookup) {
RegistryEntryLookup<Block> blocks = lookup.createRegistryLookup().getOrThrow(RegistryKeys.BLOCK); RegistryEntryLookup<Block> blocks = lookup.getOrThrow(RegistryKeys.BLOCK);
provider.accept(Identifier.of(MOD_ID, "predicate_test"), BlockStatePropertyLootCondition.builder( 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 blocks.getOrThrow(BlockKeys.MELON).value()).build()); // Pretend this actually does something and we cannot access the blocks directly
} }
@ -499,7 +499,7 @@ public class DataGeneratorTestEntrypoint implements DataGeneratorEntrypoint {
@Override @Override
protected void configure(BiConsumer<Identifier, Entry> provider, RegistryWrapper.WrapperLookup lookup) { protected void configure(BiConsumer<Identifier, Entry> provider, RegistryWrapper.WrapperLookup lookup) {
RegistryEntryLookup<Biome> biomes = lookup.createRegistryLookup().getOrThrow(RegistryKeys.BIOME); RegistryEntryLookup<Biome> biomes = lookup.getOrThrow(RegistryKeys.BIOME);
provider.accept(Identifier.of(MOD_ID, "custom_codec_test"), new Entry(biomes.getOrThrow(BiomeKeys.PLAINS))); provider.accept(Identifier.of(MOD_ID, "custom_codec_test"), new Entry(biomes.getOrThrow(BiomeKeys.PLAINS)));
} }

View file

@ -32,6 +32,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.CommandManager;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
@ -51,13 +53,17 @@ import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
public final class EntityEventTests implements ModInitializer { public final class EntityEventTests implements ModInitializer {
private static final Logger LOGGER = LoggerFactory.getLogger(EntityEventTests.class); 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<Block> 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(); public static final Item DIAMOND_ELYTRA = new DiamondElytraItem();
@Override @Override
public void onInitialize() { public void onInitialize() {
Registry.register(Registries.BLOCK, Identifier.of("fabric-entity-events-v1-testmod", "test_bed"), TEST_BED); Registry.register(Registries.BLOCK, TEST_BED_KEY, 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.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); Registry.register(Registries.ITEM, Identifier.of("fabric-entity-events-v1-testmod", "diamond_elytra"), DIAMOND_ELYTRA);
ServerEntityCombatEvents.AFTER_KILLED_OTHER_ENTITY.register((world, entity, killed) -> { ServerEntityCombatEvents.AFTER_KILLED_OTHER_ENTITY.register((world, entity, killed) -> {

View file

@ -38,7 +38,7 @@ public class FabricCreativeGuiComponents {
private static final Identifier BUTTON_TEX = Identifier.of("fabric", "textures/gui/creative_buttons.png"); private static final Identifier BUTTON_TEX = Identifier.of("fabric", "textures/gui/creative_buttons.png");
private static final double TABS_PER_PAGE = FabricItemGroupImpl.TABS_PER_PAGE; private static final double TABS_PER_PAGE = FabricItemGroupImpl.TABS_PER_PAGE;
public static final Set<ItemGroup> COMMON_GROUPS = Set.of(ItemGroups.SEARCH, ItemGroups.INVENTORY, ItemGroups.HOTBAR).stream() public static final Set<ItemGroup> COMMON_GROUPS = Set.of(ItemGroups.SEARCH, ItemGroups.INVENTORY, ItemGroups.HOTBAR).stream()
.map(Registries.ITEM_GROUP::getOrThrow) .map(Registries.ITEM_GROUP::getValueOrThrow)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
public static int getPageCount() { public static int getPageCount() {

View file

@ -109,7 +109,7 @@ public class ItemGroupsMixin {
var map = new HashMap<ItemGroupPosition, String>(); var map = new HashMap<ItemGroupPosition, String>();
for (RegistryKey<ItemGroup> registryKey : Registries.ITEM_GROUP.getKeys()) { for (RegistryKey<ItemGroup> registryKey : Registries.ITEM_GROUP.getKeys()) {
final ItemGroup itemGroup = Registries.ITEM_GROUP.getOrThrow(registryKey); final ItemGroup itemGroup = Registries.ITEM_GROUP.getValueOrThrow(registryKey);
final FabricItemGroupImpl fabricItemGroup = (FabricItemGroupImpl) itemGroup; final FabricItemGroupImpl fabricItemGroup = (FabricItemGroupImpl) itemGroup;
final String displayName = itemGroup.getDisplayName().getString(); final String displayName = itemGroup.getDisplayName().getString();
final var position = new ItemGroupPosition(itemGroup.getRow(), itemGroup.getColumn(), fabricItemGroup.fabric_getPage()); final var position = new ItemGroupPosition(itemGroup.getRow(), itemGroup.getColumn(), fabricItemGroup.fabric_getPage());

View file

@ -89,11 +89,6 @@ abstract class ReloadableRegistriesMixin {
private static <T> T modifyLootTable(T value, Identifier id, RegistryOps<JsonElement> ops) { private static <T> T modifyLootTable(T value, Identifier id, RegistryOps<JsonElement> ops) {
if (!(value instanceof LootTable table)) return value; if (!(value instanceof LootTable table)) return value;
if (table == LootTable.EMPTY) {
// This is a special table and cannot be modified.
return value;
}
RegistryKey<LootTable> key = RegistryKey.of(RegistryKeys.LOOT_TABLE, id); RegistryKey<LootTable> key = RegistryKey.of(RegistryKeys.LOOT_TABLE, id);
// Populated above. // Populated above.
RegistryWrapper.WrapperLookup registries = WRAPPERS.get(ops); RegistryWrapper.WrapperLookup registries = WRAPPERS.get(ops);

View file

@ -45,7 +45,7 @@ public class LootTest implements ModInitializer {
// The LootTable.Builder LootPool.Builder methods here should use // The LootTable.Builder LootPool.Builder methods here should use
// prebuilt entries and pools to test the injected methods. // prebuilt entries and pools to test the injected methods.
LootTableEvents.REPLACE.register((key, original, source, registries) -> { 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) { if (source != LootTableSource.VANILLA) {
throw new AssertionError("black wool loot table should have LootTableSource.VANILLA, got " + source); throw new AssertionError("black wool loot table should have LootTableSource.VANILLA, got " + source);
} }
@ -63,7 +63,7 @@ public class LootTest implements ModInitializer {
// Test that the event is stopped when the loot table is replaced // Test that the event is stopped when the loot table is replaced
LootTableEvents.REPLACE.register((key, original, source, registries) -> { 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"); throw new AssertionError("Event should have been stopped from replaced loot table");
} }
@ -71,11 +71,11 @@ public class LootTest implements ModInitializer {
}); });
LootTableEvents.MODIFY.register((key, tableBuilder, source, registries) -> { 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); 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) { if (source != LootTableSource.VANILLA) {
throw new AssertionError("white wool loot table should have LootTableSource.VANILLA, got " + source); throw new AssertionError("white wool loot table should have LootTableSource.VANILLA, got " + source);
} }
@ -91,20 +91,20 @@ public class LootTest implements ModInitializer {
} }
// We modify red wool to drop diamonds in the test mod resources. // 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); 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 // Modify yellow wool to drop *either* yellow wool or emeralds by adding
// emeralds to the same loot pool. // 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))); tableBuilder.modifyPools(poolBuilder -> poolBuilder.with(ItemEntry.builder(Items.EMERALD)));
} }
}); });
LootTableEvents.MODIFY.register((key, tableBuilder, source, registries) -> { LootTableEvents.MODIFY.register((key, tableBuilder, source, registries) -> {
if (EntityType.SALMON.getLootTableId() == key) { if (EntityType.SALMON.getLootTable().orElse(null) == key) {
Optional<RegistryEntry<Enchantment>> lure = registries.getOptionalWrapper(RegistryKeys.ENCHANTMENT).flatMap(registry -> registry.getOptional(Enchantments.LURE)); Optional<RegistryEntry<Enchantment>> lure = registries.getOptional(RegistryKeys.ENCHANTMENT).flatMap(registry -> registry.getOptional(Enchantments.LURE));
lure.ifPresent((lureEnchantment) -> tableBuilder.pool(LootPool.builder().with( lure.ifPresent((lureEnchantment) -> tableBuilder.pool(LootPool.builder().with(
ItemEntry.builder(Items.FISHING_ROD) ItemEntry.builder(Items.FISHING_ROD)
@ -115,9 +115,9 @@ public class LootTest implements ModInitializer {
}); });
LootTableEvents.ALL_LOADED.register((resourceManager, lootRegistry) -> { LootTableEvents.ALL_LOADED.register((resourceManager, lootRegistry) -> {
LootTable blackWoolTable = lootRegistry.get(Blocks.BLACK_WOOL.getLootTableKey()); Optional<LootTable> 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"); throw new AssertionError("black wool loot table should not be empty");
} }
}); });

View file

@ -1,447 +0,0 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.api.object.builder.v1.block;
import java.util.function.Function;
import java.util.function.ToIntFunction;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.MapColor;
import net.minecraft.block.enums.NoteBlockInstrument;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.entity.EntityType;
import net.minecraft.loot.LootTable;
import net.minecraft.registry.RegistryKey;
import net.minecraft.resource.featuretoggle.FeatureFlag;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.DyeColor;
import net.fabricmc.fabric.mixin.object.builder.AbstractBlockAccessor;
import net.fabricmc.fabric.mixin.object.builder.AbstractBlockSettingsAccessor;
/**
* @deprecated replace with {@link AbstractBlock.Settings}
*/
@Deprecated
public class FabricBlockSettings extends AbstractBlock.Settings {
protected FabricBlockSettings() {
super();
}
protected FabricBlockSettings(AbstractBlock.Settings settings) {
this();
// Mostly Copied from vanilla's copy method
// Note: If new methods are added to Block settings, an accessor must be added here
AbstractBlockSettingsAccessor thisAccessor = (AbstractBlockSettingsAccessor) this;
AbstractBlockSettingsAccessor otherAccessor = (AbstractBlockSettingsAccessor) settings;
// Copied in vanilla: sorted by vanilla copy order
this.hardness(otherAccessor.getHardness());
this.resistance(otherAccessor.getResistance());
this.collidable(otherAccessor.getCollidable());
thisAccessor.setRandomTicks(otherAccessor.getRandomTicks());
this.luminance(otherAccessor.getLuminance());
thisAccessor.setMapColorProvider(otherAccessor.getMapColorProvider());
this.sounds(otherAccessor.getSoundGroup());
this.slipperiness(otherAccessor.getSlipperiness());
this.velocityMultiplier(otherAccessor.getVelocityMultiplier());
thisAccessor.setDynamicBounds(otherAccessor.getDynamicBounds());
thisAccessor.setOpaque(otherAccessor.getOpaque());
thisAccessor.setIsAir(otherAccessor.getIsAir());
thisAccessor.setBurnable(otherAccessor.getBurnable());
thisAccessor.setLiquid(otherAccessor.getLiquid());
thisAccessor.setForceNotSolid(otherAccessor.getForceNotSolid());
thisAccessor.setForceSolid(otherAccessor.getForceSolid());
this.pistonBehavior(otherAccessor.getPistonBehavior());
thisAccessor.setToolRequired(otherAccessor.isToolRequired());
thisAccessor.setOffsetter(otherAccessor.getOffsetter());
thisAccessor.setBlockBreakParticles(otherAccessor.getBlockBreakParticles());
thisAccessor.setRequiredFeatures(otherAccessor.getRequiredFeatures());
this.emissiveLighting(otherAccessor.getEmissiveLightingPredicate());
this.instrument(otherAccessor.getInstrument());
thisAccessor.setReplaceable(otherAccessor.getReplaceable());
// Vanilla did not copy those fields until 23w45a, which introduced
// copyShallow method (maintaining the behavior previously used by the copy method)
// and the copy method that copies those fields as well. copyShallow is now
// deprecated. To maintain compatibility and since this behavior seems to be the
// more proper way, this copies all the fields, not just the shallow ones.
// Fields are added by field definition order.
this.jumpVelocityMultiplier(otherAccessor.getJumpVelocityMultiplier());
this.drops(otherAccessor.getLootTableKey());
this.allowsSpawning(otherAccessor.getAllowsSpawningPredicate());
this.solidBlock(otherAccessor.getSolidBlockPredicate());
this.suffocates(otherAccessor.getSuffocationPredicate());
this.blockVision(otherAccessor.getBlockVisionPredicate());
this.postProcess(otherAccessor.getPostProcessPredicate());
}
/**
* @deprecated replace with {@link AbstractBlock.Settings#create()}
*/
@Deprecated
public static FabricBlockSettings create() {
return new FabricBlockSettings();
}
/**
* @deprecated replace with {@link AbstractBlock.Settings#create()}
*/
@Deprecated
public static FabricBlockSettings of() {
return create();
}
/**
* @deprecated replace with {@link AbstractBlock.Settings#copy(AbstractBlock)}
*/
@Deprecated
public static FabricBlockSettings copyOf(AbstractBlock block) {
return new FabricBlockSettings(((AbstractBlockAccessor) block).getSettings());
}
/**
* @deprecated replace with {@link AbstractBlock.Settings#copy(AbstractBlock)}
*/
@Deprecated
public static FabricBlockSettings copyOf(AbstractBlock.Settings settings) {
return new FabricBlockSettings(settings);
}
@Deprecated
@Override
public FabricBlockSettings noCollision() {
super.noCollision();
return this;
}
@Deprecated
@Override
public FabricBlockSettings nonOpaque() {
super.nonOpaque();
return this;
}
@Deprecated
@Override
public FabricBlockSettings slipperiness(float value) {
super.slipperiness(value);
return this;
}
@Deprecated
@Override
public FabricBlockSettings velocityMultiplier(float velocityMultiplier) {
super.velocityMultiplier(velocityMultiplier);
return this;
}
@Deprecated
@Override
public FabricBlockSettings jumpVelocityMultiplier(float jumpVelocityMultiplier) {
super.jumpVelocityMultiplier(jumpVelocityMultiplier);
return this;
}
@Deprecated
@Override
public FabricBlockSettings sounds(BlockSoundGroup group) {
super.sounds(group);
return this;
}
/**
* @deprecated Please use {@link FabricBlockSettings#luminance(ToIntFunction)}.
*/
@Deprecated
public FabricBlockSettings lightLevel(ToIntFunction<BlockState> levelFunction) {
return this.luminance(levelFunction);
}
@Deprecated
@Override
public FabricBlockSettings luminance(ToIntFunction<BlockState> luminanceFunction) {
super.luminance(luminanceFunction);
return this;
}
@Deprecated
@Override
public FabricBlockSettings strength(float hardness, float resistance) {
super.strength(hardness, resistance);
return this;
}
@Deprecated
@Override
public FabricBlockSettings breakInstantly() {
super.breakInstantly();
return this;
}
@Deprecated
@Override
public FabricBlockSettings strength(float strength) {
super.strength(strength);
return this;
}
@Deprecated
@Override
public FabricBlockSettings ticksRandomly() {
super.ticksRandomly();
return this;
}
@Deprecated
@Override
public FabricBlockSettings dynamicBounds() {
super.dynamicBounds();
return this;
}
@Deprecated
@Override
public FabricBlockSettings dropsNothing() {
super.dropsNothing();
return this;
}
@Deprecated
@Override
public FabricBlockSettings dropsLike(Block block) {
super.dropsLike(block);
return this;
}
@Deprecated
@Override
public FabricBlockSettings air() {
super.air();
return this;
}
@Deprecated
@Override
public FabricBlockSettings allowsSpawning(AbstractBlock.TypedContextPredicate<EntityType<?>> predicate) {
super.allowsSpawning(predicate);
return this;
}
@Deprecated
@Override
public FabricBlockSettings solidBlock(AbstractBlock.ContextPredicate predicate) {
super.solidBlock(predicate);
return this;
}
@Deprecated
@Override
public FabricBlockSettings suffocates(AbstractBlock.ContextPredicate predicate) {
super.suffocates(predicate);
return this;
}
@Deprecated
@Override
public FabricBlockSettings blockVision(AbstractBlock.ContextPredicate predicate) {
super.blockVision(predicate);
return this;
}
@Deprecated
@Override
public FabricBlockSettings postProcess(AbstractBlock.ContextPredicate predicate) {
super.postProcess(predicate);
return this;
}
@Deprecated
@Override
public FabricBlockSettings emissiveLighting(AbstractBlock.ContextPredicate predicate) {
super.emissiveLighting(predicate);
return this;
}
/**
* Make the block require tool to drop and slows down mining speed if the incorrect tool is used.
*/
@Deprecated
@Override
public FabricBlockSettings requiresTool() {
super.requiresTool();
return this;
}
@Deprecated
@Override
public FabricBlockSettings mapColor(MapColor color) {
super.mapColor(color);
return this;
}
@Deprecated
@Override
public FabricBlockSettings hardness(float hardness) {
super.hardness(hardness);
return this;
}
@Deprecated
@Override
public FabricBlockSettings resistance(float resistance) {
super.resistance(resistance);
return this;
}
@Deprecated
@Override
public FabricBlockSettings offset(AbstractBlock.OffsetType offsetType) {
super.offset(offsetType);
return this;
}
@Deprecated
@Override
public FabricBlockSettings noBlockBreakParticles() {
super.noBlockBreakParticles();
return this;
}
@Deprecated
@Override
public FabricBlockSettings requires(FeatureFlag... features) {
super.requires(features);
return this;
}
@Deprecated
@Override
public FabricBlockSettings mapColor(Function<BlockState, MapColor> mapColorProvider) {
super.mapColor(mapColorProvider);
return this;
}
@Deprecated
@Override
public FabricBlockSettings burnable() {
super.burnable();
return this;
}
@Deprecated
@Override
public FabricBlockSettings liquid() {
super.liquid();
return this;
}
@Deprecated
@Override
public FabricBlockSettings solid() {
super.solid();
return this;
}
@Deprecated
@Override
public FabricBlockSettings notSolid() {
super.notSolid();
return this;
}
@Deprecated
@Override
public FabricBlockSettings pistonBehavior(PistonBehavior pistonBehavior) {
super.pistonBehavior(pistonBehavior);
return this;
}
@Deprecated
@Override
public FabricBlockSettings instrument(NoteBlockInstrument instrument) {
super.instrument(instrument);
return this;
}
@Deprecated
@Override
public FabricBlockSettings replaceable() {
super.replaceable();
return this;
}
/* FABRIC ADDITIONS*/
/**
* @deprecated Please use {@link FabricBlockSettings#luminance(int)}.
*/
@Deprecated
public FabricBlockSettings lightLevel(int lightLevel) {
this.luminance(lightLevel);
return this;
}
/**
* @deprecated replace with {@link AbstractBlock.Settings#luminance(ToIntFunction)}
*/
@Deprecated
public FabricBlockSettings luminance(int luminance) {
this.luminance(ignored -> luminance);
return this;
}
@Deprecated
public FabricBlockSettings drops(RegistryKey<LootTable> dropTableId) {
((AbstractBlockSettingsAccessor) this).setLootTableKey(dropTableId);
return this;
}
/* FABRIC DELEGATE WRAPPERS */
/**
* @deprecated Please migrate to {@link AbstractBlock.Settings#mapColor(MapColor)}
*/
@Deprecated
public FabricBlockSettings materialColor(MapColor color) {
return this.mapColor(color);
}
/**
* @deprecated Please migrate to {@link AbstractBlock.Settings#mapColor(DyeColor)}
*/
@Deprecated
public FabricBlockSettings materialColor(DyeColor color) {
return this.mapColor(color);
}
/**
* @deprecated Please migrate to {@link AbstractBlock.Settings#mapColor(DyeColor)}
*/
@Deprecated
public FabricBlockSettings mapColor(DyeColor color) {
return this.mapColor(color.getMapColor());
}
@Deprecated
public FabricBlockSettings collidable(boolean collidable) {
((AbstractBlockSettingsAccessor) this).setCollidable(collidable);
return this;
}
}

View file

@ -51,15 +51,6 @@ public interface FabricEntityType {
throw new AssertionError("Implemented in Mixin"); throw new AssertionError("Implemented in Mixin");
} }
/**
* Build the entity type from the builder. Same as {@link EntityType.Builder#build(String)} but without an id.
*
* @return the entity type instance
*/
default EntityType<T> build() {
throw new AssertionError("Implemented in Mixin");
}
/** /**
* Creates an entity type builder for a living entity. * Creates an entity type builder for a living entity.
* *

View file

@ -33,6 +33,7 @@ import net.minecraft.entity.SpawnLocation;
import net.minecraft.entity.SpawnRestriction; import net.minecraft.entity.SpawnRestriction;
import net.minecraft.entity.attribute.DefaultAttributeContainer; import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.mob.MobEntity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.resource.featuretoggle.FeatureFlag; import net.minecraft.resource.featuretoggle.FeatureFlag;
import net.minecraft.world.Heightmap; import net.minecraft.world.Heightmap;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -306,10 +307,10 @@ public class FabricEntityTypeBuilder<T extends Entity> {
* Creates the entity type. * Creates the entity type.
* *
* @return a new {@link EntityType} * @return a new {@link EntityType}
* @deprecated use {@link EntityType.Builder#build()} * @deprecated use {@link EntityType.Builder#build(net.minecraft.registry.RegistryKey)}
*/ */
@Deprecated @Deprecated
public EntityType<T> build() { public EntityType<T> build(RegistryKey<EntityType<?>> key) {
EntityType.Builder<T> builder = EntityType.Builder.create(this.factory, this.spawnGroup) EntityType.Builder<T> builder = EntityType.Builder.create(this.factory, this.spawnGroup)
.allowSpawningInside(specificSpawnBlocks.toArray(Block[]::new)) .allowSpawningInside(specificSpawnBlocks.toArray(Block[]::new))
.maxTrackingRange(this.trackRange) .maxTrackingRange(this.trackRange)
@ -340,7 +341,7 @@ public class FabricEntityTypeBuilder<T extends Entity> {
builder = builder.alwaysUpdateVelocity(this.forceTrackedVelocityUpdates); builder = builder.alwaysUpdateVelocity(this.forceTrackedVelocityUpdates);
} }
return builder.build(null); return builder.build(key);
} }
/** /**
@ -476,8 +477,8 @@ public class FabricEntityTypeBuilder<T extends Entity> {
@Deprecated @Deprecated
@Override @Override
public EntityType<T> build() { public EntityType<T> build(RegistryKey<EntityType<?>> key) {
final EntityType<T> type = super.build(); final EntityType<T> type = super.build(key);
if (this.defaultAttributeBuilder != null) { if (this.defaultAttributeBuilder != null) {
FabricDefaultAttributeRegistry.register(type, this.defaultAttributeBuilder.get()); FabricDefaultAttributeRegistry.register(type, this.defaultAttributeBuilder.get());
@ -617,8 +618,8 @@ public class FabricEntityTypeBuilder<T extends Entity> {
} }
@Override @Override
public EntityType<T> build() { public EntityType<T> build(RegistryKey<EntityType<?>> key) {
EntityType<T> type = super.build(); EntityType<T> type = super.build(key);
if (this.spawnPredicate != null) { if (this.spawnPredicate != null) {
SpawnRestriction.register(type, this.spawnLocation, this.restrictionHeightmap, this.spawnPredicate); SpawnRestriction.register(type, this.spawnLocation, this.restrictionHeightmap, this.spawnPredicate);

View file

@ -1,180 +0,0 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.mixin.object.builder;
import java.util.function.Function;
import java.util.function.ToIntFunction;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.MapColor;
import net.minecraft.block.enums.NoteBlockInstrument;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.entity.EntityType;
import net.minecraft.loot.LootTable;
import net.minecraft.registry.RegistryKey;
import net.minecraft.resource.featuretoggle.FeatureSet;
import net.minecraft.sound.BlockSoundGroup;
@Mixin(AbstractBlock.Settings.class)
public interface AbstractBlockSettingsAccessor {
/* GETTERS */
@Accessor
float getHardness();
@Accessor
float getResistance();
@Accessor
boolean getCollidable();
@Accessor
boolean getRandomTicks();
@Accessor("luminance")
ToIntFunction<BlockState> getLuminance();
@Accessor
Function<BlockState, MapColor> getMapColorProvider();
@Accessor
BlockSoundGroup getSoundGroup();
@Accessor
float getSlipperiness();
@Accessor
float getVelocityMultiplier();
@Accessor
float getJumpVelocityMultiplier();
@Accessor
boolean getDynamicBounds();
@Accessor
boolean getOpaque();
@Accessor
boolean getIsAir();
@Accessor
boolean isToolRequired();
@Accessor
AbstractBlock.TypedContextPredicate<EntityType<?>> getAllowsSpawningPredicate();
@Accessor
AbstractBlock.ContextPredicate getSolidBlockPredicate();
@Accessor
AbstractBlock.ContextPredicate getSuffocationPredicate();
@Accessor
AbstractBlock.ContextPredicate getBlockVisionPredicate();
@Accessor
AbstractBlock.ContextPredicate getPostProcessPredicate();
@Accessor
AbstractBlock.ContextPredicate getEmissiveLightingPredicate();
@Accessor
AbstractBlock.Offsetter getOffsetter();
@Accessor
RegistryKey<LootTable> getLootTableKey();
@Accessor
boolean getBlockBreakParticles();
@Accessor
FeatureSet getRequiredFeatures();
@Accessor
boolean getBurnable();
@Accessor
boolean getLiquid();
@Accessor
boolean getForceNotSolid();
@Accessor
boolean getForceSolid();
@Accessor
PistonBehavior getPistonBehavior();
@Accessor
NoteBlockInstrument getInstrument();
@Accessor
boolean getReplaceable();
/* SETTERS */
@Accessor
void setCollidable(boolean collidable);
@Accessor
void setRandomTicks(boolean ticksRandomly);
@Accessor
void setMapColorProvider(Function<BlockState, MapColor> mapColorProvider);
@Accessor
void setDynamicBounds(boolean dynamicBounds);
@Accessor
void setOpaque(boolean opaque);
@Accessor
void setIsAir(boolean isAir);
@Accessor
void setLootTableKey(RegistryKey<LootTable> lootTableKey);
@Accessor
void setToolRequired(boolean toolRequired);
@Accessor
void setBlockBreakParticles(boolean blockBreakParticles);
@Accessor
void setRequiredFeatures(FeatureSet requiredFeatures);
@Accessor
void setOffsetter(AbstractBlock.Offsetter offsetter);
@Accessor
void setBurnable(boolean burnable);
@Accessor
void setLiquid(boolean liquid);
@Accessor
void setForceNotSolid(boolean forceNotSolid);
@Accessor
void setForceSolid(boolean forceSolid);
@Accessor
void setReplaceable(boolean replaceable);
}

View file

@ -34,6 +34,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.mob.MobEntity;
import net.minecraft.registry.RegistryKey;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityType; import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityType;
import net.fabricmc.fabric.impl.object.builder.FabricEntityTypeImpl; import net.fabricmc.fabric.impl.object.builder.FabricEntityTypeImpl;
@ -41,7 +42,7 @@ import net.fabricmc.fabric.impl.object.builder.FabricEntityTypeImpl;
@Mixin(EntityType.Builder.class) @Mixin(EntityType.Builder.class)
public abstract class EntityTypeBuilderMixin<T extends Entity> implements FabricEntityType.Builder<T>, FabricEntityTypeImpl.Builder { public abstract class EntityTypeBuilderMixin<T extends Entity> implements FabricEntityType.Builder<T>, FabricEntityTypeImpl.Builder {
@Shadow @Shadow
public abstract EntityType<T> build(String id); public abstract EntityType<T> build(RegistryKey<EntityType<?>> registryKey);
@Unique @Unique
private Boolean alwaysUpdateVelocity = null; private Boolean alwaysUpdateVelocity = null;
@ -57,13 +58,8 @@ public abstract class EntityTypeBuilderMixin<T extends Entity> implements Fabric
return (EntityType.Builder<T>) (Object) this; return (EntityType.Builder<T>) (Object) this;
} }
@Override
public EntityType<T> build() {
return build(null);
}
@Inject(method = "build", at = @At("RETURN")) @Inject(method = "build", at = @At("RETURN"))
private void applyChildBuilders(String id, CallbackInfoReturnable<EntityType<T>> cir) { private void applyChildBuilders(RegistryKey<EntityType<?>> registryKey, CallbackInfoReturnable<EntityType<T>> cir) {
if (!(cir.getReturnValue() instanceof FabricEntityTypeImpl entityType)) { if (!(cir.getReturnValue() instanceof FabricEntityTypeImpl entityType)) {
throw new IllegalStateException(); throw new IllegalStateException();
} }

View file

@ -4,7 +4,6 @@
"compatibilityLevel": "JAVA_21", "compatibilityLevel": "JAVA_21",
"mixins": [ "mixins": [
"AbstractBlockAccessor", "AbstractBlockAccessor",
"AbstractBlockSettingsAccessor",
"BlockEntityTypeMixin", "BlockEntityTypeMixin",
"DefaultAttributeRegistryAccessor", "DefaultAttributeRegistryAccessor",
"DefaultAttributeRegistryMixin", "DefaultAttributeRegistryMixin",

View file

@ -36,6 +36,9 @@ import net.minecraft.entity.attribute.DefaultAttributeRegistry;
import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.passive.PigEntity; import net.minecraft.entity.passive.PigEntity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import net.minecraft.world.Heightmap; import net.minecraft.world.Heightmap;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityType; import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityType;
@ -51,7 +54,7 @@ public class FabricEntityTypeTest {
void buildEntityType() { void buildEntityType() {
EntityType<Entity> type = EntityType.Builder.create(SpawnGroup.MISC) EntityType<Entity> type = EntityType.Builder.create(SpawnGroup.MISC)
.alwaysUpdateVelocity(true) .alwaysUpdateVelocity(true)
.build(); .build(RegistryKey.of(RegistryKeys.ENTITY_TYPE, Identifier.of("test", "test")));
assertNotNull(type); assertNotNull(type);
assertTrue(type.alwaysUpdateVelocity()); assertTrue(type.alwaysUpdateVelocity());
@ -61,7 +64,7 @@ public class FabricEntityTypeTest {
void buildLivingEntityType() { void buildLivingEntityType() {
EntityType<LivingEntity> type = FabricEntityType.Builder.createLiving((t, w) -> null, SpawnGroup.MISC, living -> living EntityType<LivingEntity> type = FabricEntityType.Builder.createLiving((t, w) -> null, SpawnGroup.MISC, living -> living
.defaultAttributes(FabricEntityTypeTest::createAttributes) .defaultAttributes(FabricEntityTypeTest::createAttributes)
).build(); ).build(RegistryKey.of(RegistryKeys.ENTITY_TYPE, Identifier.of("test", "test2")));
assertNotNull(type); assertNotNull(type);
assertNotNull(DefaultAttributeRegistry.get(type)); assertNotNull(DefaultAttributeRegistry.get(type));
@ -72,7 +75,7 @@ public class FabricEntityTypeTest {
EntityType<MobEntity> type = FabricEntityType.Builder.createMob((t, w) -> null, SpawnGroup.MISC, mob -> mob EntityType<MobEntity> type = FabricEntityType.Builder.createMob((t, w) -> null, SpawnGroup.MISC, mob -> mob
.spawnRestriction(SpawnLocationTypes.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, PigEntity::canMobSpawn) .spawnRestriction(SpawnLocationTypes.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, PigEntity::canMobSpawn)
.defaultAttributes(FabricEntityTypeTest::createAttributes) .defaultAttributes(FabricEntityTypeTest::createAttributes)
).build(); ).build(RegistryKey.of(RegistryKeys.ENTITY_TYPE, Identifier.of("test", "test3")));
assertNotNull(type); assertNotNull(type);
assertEquals(SpawnLocationTypes.ON_GROUND, SpawnRestriction.getLocation(type)); assertEquals(SpawnLocationTypes.ON_GROUND, SpawnRestriction.getLocation(type));

View file

@ -29,6 +29,7 @@ import net.minecraft.item.BlockItem;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@ -40,19 +41,19 @@ import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
public class BlockEntityTypeBuilderTest implements ModInitializer { public class BlockEntityTypeBuilderTest implements ModInitializer {
private static final Identifier INITIAL_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.id("initial_betrayal_block"); private static final RegistryKey<Block> INITIAL_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.block("initial_betrayal_block");
static final Block INITIAL_BETRAYAL_BLOCK = new BetrayalBlock(MapColor.BLUE); 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"); private static final RegistryKey<Block> ADDED_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.block("added_betrayal_block");
static final Block ADDED_BETRAYAL_BLOCK = new BetrayalBlock(MapColor.GREEN); 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"); private static final RegistryKey<Block> FIRST_MULTI_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.block("first_multi_betrayal_block");
static final Block FIRST_MULTI_BETRAYAL_BLOCK = new BetrayalBlock(MapColor.RED); 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"); private static final RegistryKey<Block> SECOND_MULTI_BETRAYAL_BLOCK_ID = ObjectBuilderTestConstants.block("second_multi_betrayal_block");
static final Block SECOND_MULTI_BETRAYAL_BLOCK = new BetrayalBlock(MapColor.YELLOW); 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> 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(); 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 @Override
@ -62,19 +63,23 @@ public class BlockEntityTypeBuilderTest implements ModInitializer {
register(FIRST_MULTI_BETRAYAL_BLOCK_ID, FIRST_MULTI_BETRAYAL_BLOCK); register(FIRST_MULTI_BETRAYAL_BLOCK_ID, FIRST_MULTI_BETRAYAL_BLOCK);
register(SECOND_MULTI_BETRAYAL_BLOCK_ID, SECOND_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<Block> key, MapColor color) {
return new BetrayalBlock(AbstractBlock.Settings.copy(Blocks.STONE).mapColor(color).registryKey(key));
}
private static void register(RegistryKey<Block> id, Block block) {
Registry.register(Registries.BLOCK, id, block); Registry.register(Registries.BLOCK, id, block);
Item item = new BlockItem(block, new Item.Settings()); 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 static class BetrayalBlock extends Block implements BlockEntityProvider {
private BetrayalBlock(MapColor color) { private BetrayalBlock(AbstractBlock.Settings settings) {
super(AbstractBlock.Settings.copy(Blocks.STONE).mapColor(color)); super(settings);
} }
@Override @Override

View file

@ -25,31 +25,35 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnGroup; import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.mob.MobEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Arm; import net.minecraft.util.Arm;
import net.minecraft.util.Identifier;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
// This test is intentionally not an entrypoint to verify the generics of the entity type builder propagate properly // This test is intentionally not an entrypoint to verify the generics of the entity type builder propagate properly
final class EntityTypeBuilderGenericsTest { final class EntityTypeBuilderGenericsTest {
static EntityType<Entity> ENTITY_1 = FabricEntityTypeBuilder.create().build(); static RegistryKey<EntityType<?>> DUMMY = RegistryKey.of(RegistryKeys.ENTITY_TYPE, Identifier.of("test", "dummy"));
static EntityType<LivingEntity> LIVING_ENTITY_1 = FabricEntityTypeBuilder.createLiving().build(); static EntityType<Entity> ENTITY_1 = FabricEntityTypeBuilder.create().build(DUMMY);
static EntityType<LivingEntity> LIVING_ENTITY_1 = FabricEntityTypeBuilder.createLiving().build(DUMMY);
static EntityType<TestEntity> TEST_ENTITY_1 = FabricEntityTypeBuilder.createLiving() static EntityType<TestEntity> TEST_ENTITY_1 = FabricEntityTypeBuilder.createLiving()
.entityFactory(TestEntity::new) .entityFactory(TestEntity::new)
.spawnGroup(SpawnGroup.CREATURE) .spawnGroup(SpawnGroup.CREATURE)
.build(); .build(DUMMY);
static EntityType<TestEntity> OLD_TEST = FabricEntityTypeBuilder.<TestEntity>createLiving() static EntityType<TestEntity> OLD_TEST = FabricEntityTypeBuilder.<TestEntity>createLiving()
.entityFactory(TestEntity::new) .entityFactory(TestEntity::new)
.spawnGroup(SpawnGroup.CREATURE) .spawnGroup(SpawnGroup.CREATURE)
.build(); .build(DUMMY);
static EntityType<TestMob> OLD_MOB = FabricEntityTypeBuilder.<TestMob>createMob() static EntityType<TestMob> OLD_MOB = FabricEntityTypeBuilder.<TestMob>createMob()
.disableSaving() .disableSaving()
.entityFactory(TestMob::new) .entityFactory(TestMob::new)
.build(); .build(DUMMY);
static EntityType<TestMob> MOB_TEST = FabricEntityTypeBuilder.createMob() static EntityType<TestMob> MOB_TEST = FabricEntityTypeBuilder.createMob()
.disableSaving() .disableSaving()
.entityFactory(TestMob::new) .entityFactory(TestMob::new)
.build(); .build(DUMMY);
private static class TestEntity extends LivingEntity { private static class TestEntity extends LivingEntity {
protected TestEntity(EntityType<? extends LivingEntity> entityType, World world) { protected TestEntity(EntityType<? extends LivingEntity> entityType, World world) {

View file

@ -1,57 +0,0 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.test.object.builder;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import org.objectweb.asm.Opcodes;
import net.minecraft.block.AbstractBlock;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
public class FabricBlockSettingsTest implements ModInitializer {
@Override
public void onInitialize() {
final List<String> missingMethods = new ArrayList<>();
for (Method method : FabricBlockSettings.class.getMethods()) {
if ((method.getModifiers() & Opcodes.ACC_SYNTHETIC) != 0) {
// Ignore synthetic bridge methods
continue;
}
if ((method.getModifiers() & Opcodes.ACC_STATIC) != 0) {
// Ignore static methods
continue;
}
if (method.getReturnType() == AbstractBlock.Settings.class) {
missingMethods.add(method.getName());
}
}
if (missingMethods.isEmpty()) {
return;
}
throw new IllegalStateException("Missing method overrides in FabricBlockSettings: " + String.join(", ", missingMethods));
}
}

View file

@ -19,6 +19,9 @@ package net.fabricmc.fabric.test.object.builder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import net.minecraft.block.Block;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
public final class ObjectBuilderTestConstants { public final class ObjectBuilderTestConstants {
@ -28,4 +31,8 @@ public final class ObjectBuilderTestConstants {
public static Identifier id(String name) { public static Identifier id(String name) {
return Identifier.of(MOD_ID, name); return Identifier.of(MOD_ID, name);
} }
public static RegistryKey<Block> block(String name) {
return RegistryKey.of(RegistryKeys.BLOCK, id(name));
}
} }

View file

@ -17,6 +17,7 @@
package net.fabricmc.fabric.test.object.builder; package net.fabricmc.fabric.test.object.builder;
import net.minecraft.block.AbstractBlock; import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSetType; import net.minecraft.block.BlockSetType;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.HangingSignBlock; import net.minecraft.block.HangingSignBlock;
@ -30,6 +31,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.SignItem; import net.minecraft.item.SignItem;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.fabricmc.api.ModInitializer; 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 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 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 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 RegistryKey<Block> TEAL_SIGN_KEY = ObjectBuilderTestConstants.block("teal_sign");
public static final WallSignBlock TEAL_WALL_SIGN = new WallSignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_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 HangingSignBlock TEAL_HANGING_SIGN = new HangingSignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_HANGING_SIGN)); public static final RegistryKey<Block> TEAL_WALL_SIGN_KEY = ObjectBuilderTestConstants.block("teal_wall_sign");
public static final WallHangingSignBlock TEAL_WALL_HANGING_SIGN = new WallHangingSignBlock(TEAL_WOOD_TYPE, AbstractBlock.Settings.copy(Blocks.OAK_HANGING_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<Block> 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<Block> 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 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()); 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() { public void onInitialize() {
WoodType.register(TEAL_WOOD_TYPE); WoodType.register(TEAL_WOOD_TYPE);
Registry.register(Registries.BLOCK, ObjectBuilderTestConstants.id("teal_sign"), TEAL_SIGN); Registry.register(Registries.BLOCK, TEAL_SIGN_KEY, TEAL_SIGN);
Registry.register(Registries.BLOCK, ObjectBuilderTestConstants.id("teal_wall_sign"), TEAL_WALL_SIGN); Registry.register(Registries.BLOCK, TEAL_WALL_SIGN_KEY, TEAL_WALL_SIGN);
Registry.register(Registries.BLOCK, ObjectBuilderTestConstants.id("teal_hanging_sign"), TEAL_HANGING_SIGN); Registry.register(Registries.BLOCK, TEAL_HANGING_SIGN_KEY, TEAL_HANGING_SIGN);
Registry.register(Registries.BLOCK, ObjectBuilderTestConstants.id("teal_wall_hanging_sign"), TEAL_WALL_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, TEAL_SIGN_KEY.getValue(), TEAL_SIGN_ITEM);
Registry.register(Registries.ITEM, ObjectBuilderTestConstants.id("teal_hanging_sign"), TEAL_HANGING_SIGN_ITEM); Registry.register(Registries.ITEM, TEAL_HANGING_SIGN_KEY.getValue(), TEAL_HANGING_SIGN_ITEM);
BlockEntityType.SIGN.addSupportedBlock(TEAL_SIGN); BlockEntityType.SIGN.addSupportedBlock(TEAL_SIGN);
BlockEntityType.HANGING_SIGN.addSupportedBlock(TEAL_HANGING_SIGN); BlockEntityType.HANGING_SIGN.addSupportedBlock(TEAL_HANGING_SIGN);

View file

@ -23,7 +23,6 @@
"entrypoints": { "entrypoints": {
"main": [ "main": [
"net.fabricmc.fabric.test.object.builder.BlockEntityTypeBuilderTest", "net.fabricmc.fabric.test.object.builder.BlockEntityTypeBuilderTest",
"net.fabricmc.fabric.test.object.builder.FabricBlockSettingsTest",
"net.fabricmc.fabric.test.object.builder.VillagerTypeTest1", "net.fabricmc.fabric.test.object.builder.VillagerTypeTest1",
"net.fabricmc.fabric.test.object.builder.VillagerTypeTest2", "net.fabricmc.fabric.test.object.builder.VillagerTypeTest2",
"net.fabricmc.fabric.test.object.builder.TealSignTest", "net.fabricmc.fabric.test.object.builder.TealSignTest",

View file

@ -26,6 +26,8 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.CommandManager;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@ -34,17 +36,20 @@ import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
public final class ParticleTestSetup implements ModInitializer { public final class ParticleTestSetup implements ModInitializer {
// The dust particles of this block are always tinted (default). // 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<Block> 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. // 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<Block> 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. // 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<Block> NEVER_TINTED_KEY = block("never_tinted");
public static final Block NEVER_TINTED = new ParticleTintTestBlock(AbstractBlock.Settings.create().breakInstantly().registryKey(NEVER_TINTED_KEY), 0x00FFFF);
@Override @Override
public void onInitialize() { public void onInitialize() {
registerBlock("always_tinted", ALWAYS_TINTED); registerBlock(ALWAYS_TINTED_KEY, ALWAYS_TINTED);
registerBlock("tinted_over_water", TINTED_OVER_WATER); registerBlock(TINTED_OVER_WATER_KEY, TINTED_OVER_WATER);
registerBlock("never_tinted", NEVER_TINTED); registerBlock(NEVER_TINTED_KEY, NEVER_TINTED);
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
dispatcher.register(CommandManager.literal("addparticletestblocks").executes(context -> { dispatcher.register(CommandManager.literal("addparticletestblocks").executes(context -> {
@ -57,9 +62,12 @@ public final class ParticleTestSetup implements ModInitializer {
}); });
} }
private static void registerBlock(String path, Block block) { private static RegistryKey<Block> block(String path) {
Identifier id = Identifier.of("fabric-particles-v1-testmod", path); return RegistryKey.of(RegistryKeys.BLOCK, 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 void registerBlock(RegistryKey<Block> key, Block block) {
Registry.register(Registries.BLOCK, key, block);
Registry.register(Registries.ITEM, key.getValue(), new BlockItem(block, new Item.Settings()));
} }
} }

View file

@ -209,7 +209,7 @@ public class FabricRegistryInit implements ModInitializer {
.addAttribute(RegistryAttribute.SYNCED); .addAttribute(RegistryAttribute.SYNCED);
// Synced via PacketCodecs.registry // Synced via PacketCodecs.registry
RegistryAttributeHolder.get(Registries.field_53967) RegistryAttributeHolder.get(Registries.CONSUME_EFFECT_TYPE)
.addAttribute(RegistryAttribute.SYNCED); .addAttribute(RegistryAttribute.SYNCED);
} }
} }

View file

@ -18,36 +18,13 @@ package net.fabricmc.fabric.impl.registry.sync.trackers.vanilla;
import java.util.List; import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback;
import net.fabricmc.fabric.mixin.registry.sync.DebugChunkGeneratorAccessor; import net.fabricmc.fabric.mixin.registry.sync.DebugChunkGeneratorAccessor;
public final class BlockInitTracker implements RegistryEntryAddedCallback<Block> { public final class BlockInitTracker {
private final Registry<Block> registry;
private BlockInitTracker(Registry<Block> registry) {
this.registry = registry;
}
public static void register(Registry<Block> 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 static void postFreeze() { public static void postFreeze() {
final List<BlockState> blockStateList = Registries.BLOCK.stream() final List<BlockState> blockStateList = Registries.BLOCK.stream()
.flatMap((block) -> block.getStateManager().getStates().stream()) .flatMap((block) -> block.getStateManager().getStates().stream())

View file

@ -32,7 +32,6 @@ import net.minecraft.registry.Registries;
import net.fabricmc.fabric.impl.registry.sync.RegistrySyncManager; import net.fabricmc.fabric.impl.registry.sync.RegistrySyncManager;
import net.fabricmc.fabric.impl.registry.sync.trackers.StateIdTracker; import net.fabricmc.fabric.impl.registry.sync.trackers.StateIdTracker;
import net.fabricmc.fabric.impl.registry.sync.trackers.vanilla.BlockInitTracker;
import net.fabricmc.fabric.impl.registry.sync.trackers.vanilla.BlockItemTracker; import net.fabricmc.fabric.impl.registry.sync.trackers.vanilla.BlockItemTracker;
@Mixin(Bootstrap.class) @Mixin(Bootstrap.class)
@ -54,9 +53,6 @@ public class BootstrapMixin {
// map tracking // map tracking
BlockItemTracker.register(Registries.ITEM); BlockItemTracker.register(Registries.ITEM);
// block initialization, like Blocks
BlockInitTracker.register(Registries.BLOCK);
RegistrySyncManager.bootstrapRegistries(); RegistrySyncManager.bootstrapRegistries();
} }

View file

@ -67,9 +67,8 @@ public final class CustomDynamicRegistryTest implements ModInitializer {
CommonLifecycleEvents.TAGS_LOADED.register((registries, client) -> { CommonLifecycleEvents.TAGS_LOADED.register((registries, client) -> {
// Check that the tag has applied // Check that the tag has applied
RegistryEntry.Reference<TestDynamicObject> entry = registries.get(TEST_SYNCED_1_DYNAMIC_REGISTRY_KEY) RegistryEntry.Reference<TestDynamicObject> entry = registries.getOrThrow(TEST_SYNCED_1_DYNAMIC_REGISTRY_KEY)
.getEntry(SYNCED_ENTRY_KEY) .getOrThrow(SYNCED_ENTRY_KEY);
.orElseThrow();
if (!entry.isIn(TEST_DYNAMIC_OBJECT_TAG)) { if (!entry.isIn(TEST_DYNAMIC_OBJECT_TAG)) {
LOGGER.error("Required dynamic registry entry is not in the expected tag! client: " + client); LOGGER.error("Required dynamic registry entry is not in the expected tag! client: " + client);

View file

@ -154,12 +154,13 @@ public class RegistrySyncTest implements ModInitializer {
private static void registerBlocks(String namespace, int amount, int startingId) { private static void registerBlocks(String namespace, int amount, int startingId) {
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
Block block = new Block(AbstractBlock.Settings.create()); Identifier id = Identifier.of(namespace, "block_" + (i + startingId));
Registry.register(Registries.BLOCK, Identifier.of(namespace, "block_" + (i + startingId)), block); Block block = new Block(AbstractBlock.Settings.create().registryKey(RegistryKey.of(RegistryKeys.BLOCK, id)));
Registry.register(Registries.BLOCK, id, block);
if (REGISTER_ITEMS) { if (REGISTER_ITEMS) {
BlockItem blockItem = new BlockItem(block, new Item.Settings()); BlockItem blockItem = new BlockItem(block, new Item.Settings());
Registry.register(Registries.ITEM, Identifier.of(namespace, "block_" + (i + startingId)), blockItem); Registry.register(Registries.ITEM, id, blockItem);
} }
} }
} }

View file

@ -43,13 +43,13 @@ public final class DynamicRegistryClientTest implements ClientModInitializer {
LOGGER.info("Starting dynamic registry sync tests..."); LOGGER.info("Starting dynamic registry sync tests...");
TestDynamicObject synced1 = handler.getRegistryManager() TestDynamicObject synced1 = handler.getRegistryManager()
.get(TEST_SYNCED_1_DYNAMIC_REGISTRY_KEY) .getOrThrow(TEST_SYNCED_1_DYNAMIC_REGISTRY_KEY)
.get(SYNCED_ID); .get(SYNCED_ID);
TestDynamicObject synced2 = handler.getRegistryManager() TestDynamicObject synced2 = handler.getRegistryManager()
.get(TEST_SYNCED_2_DYNAMIC_REGISTRY_KEY) .getOrThrow(TEST_SYNCED_2_DYNAMIC_REGISTRY_KEY)
.get(SYNCED_ID); .get(SYNCED_ID);
TestNestedDynamicObject simpleNested = handler.getRegistryManager() TestNestedDynamicObject simpleNested = handler.getRegistryManager()
.get(TEST_NESTED_DYNAMIC_REGISTRY_KEY) .getOrThrow(TEST_NESTED_DYNAMIC_REGISTRY_KEY)
.get(SYNCED_ID); .get(SYNCED_ID);
LOGGER.info("Synced - simple: {}", synced1); LOGGER.info("Synced - simple: {}", synced1);

View file

@ -16,6 +16,8 @@
package net.fabricmc.fabric.test.renderer; package net.fabricmc.fabric.test.renderer;
import java.util.function.Function;
import net.minecraft.block.AbstractBlock; import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
@ -24,16 +26,19 @@ import net.minecraft.item.BlockItem;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
public final class Registration { 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_BLOCK = register("frame", FrameBlock::new, 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_MULTIPART_BLOCK = register("frame_multipart", FrameBlock::new, 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 FrameBlock FRAME_VARIANT_BLOCK = register("frame_variant", FrameBlock::new, AbstractBlock.Settings.copy(Blocks.IRON_BLOCK).nonOpaque());
public static final Block PILLAR_BLOCK = register("pillar", new Block(AbstractBlock.Settings.create())); public static final Block PILLAR_BLOCK = register("pillar", Block::new, 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 OCTAGONAL_COLUMN_BLOCK = register("octagonal_column", OctagonalColumnBlock::new, 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 Block RIVERSTONE_BLOCK = register("riverstone", Block::new, AbstractBlock.Settings.copy(Blocks.STONE));
public static final FrameBlock[] FRAME_BLOCKS = new FrameBlock[] { public static final FrameBlock[] FRAME_BLOCKS = new FrameBlock[] {
FRAME_BLOCK, FRAME_BLOCK,
@ -50,8 +55,10 @@ public final class Registration {
public static final BlockEntityType<FrameBlockEntity> FRAME_BLOCK_ENTITY_TYPE = register("frame", FabricBlockEntityTypeBuilder.create(FrameBlockEntity::new, FRAME_BLOCKS).build()); public static final BlockEntityType<FrameBlockEntity> FRAME_BLOCK_ENTITY_TYPE = register("frame", FabricBlockEntityTypeBuilder.create(FrameBlockEntity::new, FRAME_BLOCKS).build());
private static <T extends Block> T register(String path, T block) { // see also Blocks#register, which is functionally the same
return Registry.register(Registries.BLOCK, RendererTest.id(path), block); private static <T extends Block> T register(String path, Function<AbstractBlock.Settings, T> 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 extends Item> T register(String path, T item) { private static <T extends Item> T register(String path, T item) {

View file

@ -17,33 +17,50 @@
package net.fabricmc.fabric.test.client.rendering.fluid; package net.fabricmc.fabric.test.client.rendering.fluid;
import net.minecraft.block.AbstractBlock; import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.FluidBlock; import net.minecraft.block.FluidBlock;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
public class TestFluids { 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 String MOD_ID = "fabric-rendering-fluids-v1-testmod";
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 RegistryKey<Block> 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 RegistryKey<Block> OVERLAY_KEY = block("overlay");
public static final OverlayFluid OVERLAY_FLOWING = Registry.register(Registries.FLUID, "fabric-rendering-fluids-v1-testmod:overlay_flowing", new OverlayFluid.Flowing()); 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 RegistryKey<Block> UNREGISTERED_KEY = block("unregistered");
public static final UnregisteredFluid UNREGISTERED_FLOWING = Registry.register(Registries.FLUID, "fabric-rendering-fluids-v1-testmod:unregistered_flowing", new UnregisteredFluid.Flowing()); 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 RegistryKey<Block> CUSTOM_KEY = block("custom");
public static final CustomFluid CUSTOM_FLOWING = Registry.register(Registries.FLUID, "fabric-rendering-fluids-v1-testmod:custom_flowing", new CustomFluid.Flowing()); 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> block(String path) {
return RegistryKey.of(RegistryKeys.BLOCK, id(path));
}
} }

View file

@ -171,7 +171,7 @@ public final class WorldRenderEvents {
* outline render for <em>all</em> blocks because all event subscribers will * outline render for <em>all</em> blocks because all event subscribers will
* always render - only the default outline render can be cancelled. That should * always render - only the default outline render can be cancelled. That should
* be accomplished by mixin to the block outline render routine itself, typically * be accomplished by mixin to the block outline render routine itself, typically
* by targeting {@link WorldRenderer#drawShapeOutline}. * by targeting {@link net.minecraft.client.render.VertexRendering#drawOutline}.
*/ */
public static final Event<BlockOutline> BLOCK_OUTLINE = EventFactory.createArrayBacked(BlockOutline.class, (worldRenderContext, blockOutlineContext) -> true, callbacks -> (worldRenderContext, blockOutlineContext) -> { public static final Event<BlockOutline> BLOCK_OUTLINE = EventFactory.createArrayBacked(BlockOutline.class, (worldRenderContext, blockOutlineContext) -> true, callbacks -> (worldRenderContext, blockOutlineContext) -> {
boolean shouldRender = true; boolean shouldRender = true;

View file

@ -50,7 +50,7 @@ public abstract class ArmorFeatureRendererMixin<S extends BipedEntityRenderState
} }
@Inject(method = "renderArmor", at = @At("HEAD"), cancellable = true) @Inject(method = "renderArmor", at = @At("HEAD"), cancellable = true)
private void renderArmor(MatrixStack matrices, VertexConsumerProvider vertexConsumers, ItemStack stack, EquipmentSlot armorSlot, int light, A model, CallbackInfo ci) { private void renderArmor(MatrixStack matrices, VertexConsumerProvider vertexConsumers, S state, ItemStack stack, EquipmentSlot armorSlot, int light, A armorModel, CallbackInfo ci) {
ArmorRenderer renderer = ArmorRendererRegistryImpl.get(stack.getItem()); ArmorRenderer renderer = ArmorRendererRegistryImpl.get(stack.getItem());
if (renderer != null) { if (renderer != null) {

View file

@ -22,17 +22,20 @@ import net.minecraft.item.BlockItem;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
public class CustomColorResolverTestInit implements ModInitializer { public class CustomColorResolverTestInit implements ModInitializer {
public static final Block CUSTOM_COLOR_BLOCK = new Block(AbstractBlock.Settings.create()); public static final RegistryKey<Block> 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()); public static final Item CUSTOM_COLOR_BLOCK_ITEM = new BlockItem(CUSTOM_COLOR_BLOCK, new Item.Settings());
@Override @Override
public void onInitialize() { public void onInitialize() {
Registry.register(Registries.BLOCK, Identifier.of("fabric-rendering-v1-testmod", "custom_color_block"), CUSTOM_COLOR_BLOCK); Registry.register(Registries.BLOCK, KEY, CUSTOM_COLOR_BLOCK);
Registry.register(Registries.ITEM, Identifier.of("fabric-rendering-v1-testmod", "custom_color_block"), CUSTOM_COLOR_BLOCK_ITEM); Registry.register(Registries.ITEM, KEY.getValue(), CUSTOM_COLOR_BLOCK_ITEM);
} }
} }

View file

@ -39,7 +39,7 @@ public class ArmorRenderingTests implements ClientModInitializer {
armorModel = new BipedEntityModel<>(MinecraftClient.getInstance().getEntityModelLoader().getModelPart(EntityModelLayers.PLAYER_OUTER_ARMOR)); armorModel = new BipedEntityModel<>(MinecraftClient.getInstance().getEntityModelLoader().getModelPart(EntityModelLayers.PLAYER_OUTER_ARMOR));
} }
model.copyBipedStateTo(armorModel); armorModel.setAngles(renderState);
armorModel.setVisible(false); armorModel.setVisible(false);
armorModel.body.visible = slot == EquipmentSlot.CHEST; armorModel.body.visible = slot == EquipmentSlot.CHEST;
armorModel.leftArm.visible = slot == EquipmentSlot.CHEST; armorModel.leftArm.visible = slot == EquipmentSlot.CHEST;

View file

@ -19,7 +19,7 @@ package net.fabricmc.fabric.test.rendering.client;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import net.minecraft.class_10142; import net.minecraft.client.gl.ShaderProgramKeys;
import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer; import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.DimensionEffects; import net.minecraft.client.render.DimensionEffects;
@ -41,7 +41,7 @@ public class DimensionalRenderingTest implements ClientModInitializer {
RenderSystem.enableBlend(); RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc(); RenderSystem.defaultBlendFunc();
RenderSystem.depthMask(false); RenderSystem.depthMask(false);
RenderSystem.setShader(class_10142.POSITION_TEX_COLOR); RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX_COLOR);
RenderSystem.setShaderTexture(0, END_SKY); RenderSystem.setShaderTexture(0, END_SKY);
Tessellator tessellator = Tessellator.getInstance(); Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR); BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);

View file

@ -19,15 +19,15 @@ package net.fabricmc.fabric.test.rendering.client;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.class_10142;
import net.minecraft.class_9974;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.ShaderProgramKeys;
import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer; import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.OverlayTexture; import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats; import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.VertexRendering;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -70,12 +70,12 @@ public class WorldRenderEventsTests implements ClientModInitializer {
matrices.push(); matrices.push();
matrices.translate(-camera.x, -camera.y, -camera.z); matrices.translate(-camera.x, -camera.y, -camera.z);
RenderSystem.setShader(class_10142.POSITION_COLOR); RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
RenderSystem.setShaderColor(1f, 1f, 1f, 1f); RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
RenderSystem.enableBlend(); RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc(); RenderSystem.defaultBlendFunc();
class_9974.method_62300(matrices, buffer, 0, 100, 0, 1, 101, 1, 0, 1, 0, 0.5f); VertexRendering.drawBox(matrices, buffer, 0, 100, 0, 1, 101, 1, 0, 1, 0, 0.5f);
BufferRenderer.drawWithGlobalProgram(buffer.end()); BufferRenderer.drawWithGlobalProgram(buffer.end());
matrices.pop(); matrices.pop();

View file

@ -108,8 +108,7 @@ public final class ResourceConditionsImpl implements ModInitializer {
} }
/** /**
* Stores the tags deserialized by {@link TagManagerLoader} before they are bound, to use them in the tags_populated conditions. * Stores the tags deserialized 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}.
* If the resource reload fails, the thread local is not cleared and: * If the resource reload fails, the thread local is not cleared and:
* - the map will remain in memory until the next reload; * - 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. * - any call to {@link #tagsPopulated} will check the tags from the failed reload instead of failing directly.

View file

@ -29,10 +29,10 @@ import net.minecraft.registry.RegistryWrapper;
public class RecipeManagerMixin extends SinglePreparationResourceReloaderMixin { public class RecipeManagerMixin extends SinglePreparationResourceReloaderMixin {
@Shadow @Shadow
@Final @Final
private RegistryWrapper.WrapperLookup registryLookup; private RegistryWrapper.WrapperLookup registries;
@Override @Override
protected @Nullable RegistryOps.RegistryInfoGetter fabric_getRegistryLookup() { protected @Nullable RegistryOps.RegistryInfoGetter fabric_getRegistryLookup() {
return new RegistryOps.CachedRegistryInfoGetter(registryLookup); return new RegistryOps.CachedRegistryInfoGetter(registries);
} }
} }

View file

@ -29,10 +29,10 @@ import net.minecraft.server.ServerAdvancementLoader;
public class ServerAdvancementLoaderMixin extends SinglePreparationResourceReloaderMixin { public class ServerAdvancementLoaderMixin extends SinglePreparationResourceReloaderMixin {
@Shadow @Shadow
@Final @Final
private RegistryWrapper.WrapperLookup registryLookup; private RegistryWrapper.WrapperLookup registries;
@Override @Override
protected @Nullable RegistryOps.RegistryInfoGetter fabric_getRegistryLookup() { protected @Nullable RegistryOps.RegistryInfoGetter fabric_getRegistryLookup() {
return new RegistryOps.CachedRegistryInfoGetter(this.registryLookup); return new RegistryOps.CachedRegistryInfoGetter(this.registries);
} }
} }

View file

@ -82,11 +82,11 @@ public class ConditionalResourcesTest {
RegistryEntryLookup.RegistryLookup registries = context.getWorld().getServer().getReloadableRegistries().createRegistryLookup(); 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."); 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."); throw new AssertionError("not_loaded predicate should not have been loaded.");
} }
@ -110,7 +110,7 @@ public class ConditionalResourcesTest {
@GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE) @GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE)
public void conditionalDynamicRegistry(TestContext context) { public void conditionalDynamicRegistry(TestContext context) {
Registry<BannerPattern> registry = context.getWorld().getRegistryManager().get(RegistryKeys.BANNER_PATTERN); Registry<BannerPattern> registry = context.getWorld().getRegistryManager().getOrThrow(RegistryKeys.BANNER_PATTERN);
if (registry.get(id("loaded")) == null) { if (registry.get(id("loaded")) == null) {
throw new AssertionError("loaded banner pattern should have been loaded."); throw new AssertionError("loaded banner pattern should have been loaded.");
@ -127,11 +127,11 @@ public class ConditionalResourcesTest {
public void conditionalOverlays(TestContext context) { public void conditionalOverlays(TestContext context) {
RegistryEntryLookup.RegistryLookup registries = context.getWorld().getServer().getReloadableRegistries().createRegistryLookup(); 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."); 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."); throw new AssertionError("dont_overlay predicate should not have been overlayed.");
} }

View file

@ -242,7 +242,7 @@ public class ResourceManagerHelperImpl implements ResourceManagerHelper {
for (ResourceReloader resourceReloader : listeners) { for (ResourceReloader resourceReloader : listeners) {
if (resourceReloader instanceof RecipeManager recipeManager) { if (resourceReloader instanceof RecipeManager recipeManager) {
return recipeManager.registryLookup; return recipeManager.registries;
} }
} }

View file

@ -4,4 +4,4 @@ accessible method net/minecraft/resource/NamespaceResourceManager getMetadataPat
accessible method net/minecraft/resource/NamespaceResourceManager loadMetadata (Lnet/minecraft/resource/InputSupplier;)Lnet/minecraft/resource/metadata/ResourceMetadata; accessible method net/minecraft/resource/NamespaceResourceManager loadMetadata (Lnet/minecraft/resource/InputSupplier;)Lnet/minecraft/resource/metadata/ResourceMetadata;
accessible field net/minecraft/resource/FileResourcePackProvider source Lnet/minecraft/resource/ResourcePackSource; accessible field net/minecraft/resource/FileResourcePackProvider source Lnet/minecraft/resource/ResourcePackSource;
accessible field net/minecraft/resource/ResourcePackManager providers Ljava/util/Set; accessible field net/minecraft/resource/ResourcePackManager providers Ljava/util/Set;
accessible field net/minecraft/recipe/RecipeManager registryLookup Lnet/minecraft/registry/RegistryWrapper$WrapperLookup; accessible field net/minecraft/recipe/RecipeManager registries Lnet/minecraft/registry/RegistryWrapper$WrapperLookup;

View file

@ -135,7 +135,7 @@ public class ResourceReloadListenerTestMod implements ModInitializer {
@Override @Override
public void reload(ResourceManager manager) { public void reload(ResourceManager manager) {
Objects.requireNonNull(wrapperLookup); Objects.requireNonNull(wrapperLookup);
wrapperLookup.getWrapperOrThrow(RegistryKeys.ENCHANTMENT).getOrThrow(Enchantments.FORTUNE); wrapperLookup.getOrThrow(RegistryKeys.ENCHANTMENT).getOrThrow(Enchantments.FORTUNE);
} }
} }
} }

View file

@ -23,20 +23,21 @@ import net.minecraft.item.BlockItem;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
public class VanillaBuiltinResourcePackInjectionTestMod implements ModInitializer { public class VanillaBuiltinResourcePackInjectionTestMod implements ModInitializer {
public static final String MODID = "fabric-resource-loader-v0-testmod"; public static final String MODID = "fabric-resource-loader-v0-testmod";
public static final RegistryKey<Block> KEY = RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(MODID, "testblock"));
public static final Block TEST_BLOCK = new Block(AbstractBlock.Settings.copy(Blocks.STONE)); public static final Block TEST_BLOCK = new Block(AbstractBlock.Settings.copy(Blocks.STONE).registryKey(KEY));
@Override @Override
public void onInitialize() { public void onInitialize() {
Identifier id = Identifier.of(MODID, "testblock"); Registry.register(Registries.BLOCK, KEY, TEST_BLOCK);
Registry.register(Registries.ITEM, KEY.getValue(), new BlockItem(TEST_BLOCK, new Item.Settings()));
Registry.register(Registries.BLOCK, id, TEST_BLOCK);
Registry.register(Registries.ITEM, id, new BlockItem(TEST_BLOCK, new Item.Settings()));
} }
} }

View file

@ -24,6 +24,8 @@ import net.minecraft.item.BlockItem;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.resource.featuretoggle.FeatureFlags; import net.minecraft.resource.featuretoggle.FeatureFlags;
import net.minecraft.screen.ScreenHandlerType; import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.util.Identifier; 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 BAG = new BagItem(new Item.Settings().maxCount(1));
public static final Item POSITIONED_BAG = new PositionedBagItem(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<Block> 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 Item BOX_ITEM = new BlockItem(BOX, new Item.Settings());
public static final BlockEntityType<BoxBlockEntity> BOX_ENTITY = FabricBlockEntityTypeBuilder.create(BoxBlockEntity::new, BOX).build(); public static final BlockEntityType<BoxBlockEntity> BOX_ENTITY = FabricBlockEntityTypeBuilder.create(BoxBlockEntity::new, BOX).build();
public static final ScreenHandlerType<BagScreenHandler> BAG_SCREEN_HANDLER = new ScreenHandlerType<>(BagScreenHandler::new, FeatureFlags.VANILLA_FEATURES); public static final ScreenHandlerType<BagScreenHandler> BAG_SCREEN_HANDLER = new ScreenHandlerType<>(BagScreenHandler::new, FeatureFlags.VANILLA_FEATURES);
@ -60,8 +63,8 @@ public class ScreenHandlerTest implements ModInitializer {
public void onInitialize() { public void onInitialize() {
Registry.register(Registries.ITEM, id("bag"), BAG); Registry.register(Registries.ITEM, id("bag"), BAG);
Registry.register(Registries.ITEM, id("positioned_bag"), POSITIONED_BAG); Registry.register(Registries.ITEM, id("positioned_bag"), POSITIONED_BAG);
Registry.register(Registries.BLOCK, id("box"), BOX); Registry.register(Registries.BLOCK, BOX_KEY, BOX);
Registry.register(Registries.ITEM, id("box"), BOX_ITEM); Registry.register(Registries.ITEM, BOX_KEY.getValue(), BOX_ITEM);
Registry.register(Registries.BLOCK_ENTITY_TYPE, id("box"), BOX_ENTITY); 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("bag"), BAG_SCREEN_HANDLER);
Registry.register(Registries.SCREEN_HANDLER, id("positioned_bag"), POSITIONED_BAG_SCREEN_HANDLER); Registry.register(Registries.SCREEN_HANDLER, id("positioned_bag"), POSITIONED_BAG_SCREEN_HANDLER);

View file

@ -41,8 +41,8 @@ import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorageUtil;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributes; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributes;
public class FluidChuteBlock extends Block implements BlockEntityProvider { public class FluidChuteBlock extends Block implements BlockEntityProvider {
public FluidChuteBlock() { public FluidChuteBlock(Settings settings) {
super(Settings.create()); super(settings);
} }
private static final VoxelShape SHAPE = VoxelShapes.cuboid( private static final VoxelShape SHAPE = VoxelShapes.cuboid(

View file

@ -24,6 +24,8 @@ import net.minecraft.item.BlockItem;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
@ -34,17 +36,20 @@ import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage;
public class TransferTestInitializer implements ModInitializer { public class TransferTestInitializer implements ModInitializer {
public static final String MOD_ID = "fabric-transfer-api-v1-testmod"; 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 RegistryKey<Block> INFINITE_WATER_SOURCE_KEY = block("infinite_water_source");
private static final Block INFINITE_LAVA_SOURCE = new Block(AbstractBlock.Settings.create()); private static final Block INFINITE_WATER_SOURCE = new Block(AbstractBlock.Settings.create().registryKey(INFINITE_WATER_SOURCE_KEY));
private static final Block FLUID_CHUTE = new FluidChuteBlock(); private static final RegistryKey<Block> 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<Block> 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(); private static final Item EXTRACT_STICK = new ExtractStickItem();
public static BlockEntityType<FluidChuteBlockEntity> FLUID_CHUTE_TYPE; public static BlockEntityType<FluidChuteBlockEntity> FLUID_CHUTE_TYPE;
@Override @Override
public void onInitialize() { public void onInitialize() {
registerBlock(INFINITE_WATER_SOURCE, "infinite_water_source"); registerBlock(INFINITE_WATER_SOURCE_KEY, INFINITE_WATER_SOURCE);
registerBlock(INFINITE_LAVA_SOURCE, "infinite_lava_source"); registerBlock(INFINITE_LAVA_SOURCE_KEY, INFINITE_LAVA_SOURCE);
registerBlock(FLUID_CHUTE, "fluid_chute"); registerBlock(FLUID_CHUTE_KEY, FLUID_CHUTE);
Registry.register(Registries.ITEM, Identifier.of(MOD_ID, "extract_stick"), EXTRACT_STICK); Registry.register(Registries.ITEM, Identifier.of(MOD_ID, "extract_stick"), EXTRACT_STICK);
FLUID_CHUTE_TYPE = FabricBlockEntityTypeBuilder.create(FluidChuteBlockEntity::new, FLUID_CHUTE).build(); FLUID_CHUTE_TYPE = FabricBlockEntityTypeBuilder.create(FluidChuteBlockEntity::new, FLUID_CHUTE).build();
@ -59,9 +64,12 @@ public class TransferTestInitializer implements ModInitializer {
ItemStorage.SIDED.registerForBlocks((world, pos, state, be, direction) -> CreativeStorage.DIAMONDS, Blocks.DIAMOND_ORE); ItemStorage.SIDED.registerForBlocks((world, pos, state, be, direction) -> CreativeStorage.DIAMONDS, Blocks.DIAMOND_ORE);
} }
private static void registerBlock(Block block, String name) { private static RegistryKey<Block> block(String name) {
Identifier id = Identifier.of(MOD_ID, name); return RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(MOD_ID, name));
Registry.register(Registries.BLOCK, id, block); }
Registry.register(Registries.ITEM, id, new BlockItem(block, new Item.Settings()));
private static void registerBlock(RegistryKey<Block> key, Block block) {
Registry.register(Registries.BLOCK, key, block);
Registry.register(Registries.ITEM, key.getValue(), new BlockItem(block, new Item.Settings()));
} }
} }

View file

@ -21,9 +21,9 @@ import java.util.List;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import net.minecraft.class_10142;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer; import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gl.ShaderProgramKeys;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer; import net.minecraft.client.render.BufferRenderer;
@ -93,7 +93,7 @@ public class FluidVariantRenderTest implements ClientModInitializer {
float b = (color & 255) / 255f; float b = (color & 255) / 255f;
RenderSystem.disableDepthTest(); RenderSystem.disableDepthTest();
RenderSystem.setShader(class_10142.POSITION_TEX_COLOR); RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX_COLOR);
BufferBuilder bufferBuilder = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR); BufferBuilder bufferBuilder = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
float x0 = (float) i; float x0 = (float) i;
float y0 = (float) j; float y0 = (float) j;

View file

@ -121,13 +121,11 @@ transitive-accessible method net/minecraft/entity/damage/DamageSources create (L
transitive-accessible field net/minecraft/client/MinecraftClient attackCooldown I transitive-accessible field net/minecraft/client/MinecraftClient attackCooldown I
# Creating certain types of blocks # 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 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 createLeavesBlock (Lnet/minecraft/sound/BlockSoundGroup;)Lnet/minecraft/block/Block; transitive-accessible method net/minecraft/block/Blocks createNetherStemSettings (Lnet/minecraft/block/MapColor;)Lnet/minecraft/block/AbstractBlock$Settings;
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 createLeavesSettings (Lnet/minecraft/sound/BlockSoundGroup;)Lnet/minecraft/block/AbstractBlock$Settings;
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 createButtonSettings ()Lnet/minecraft/block/AbstractBlock$Settings;
transitive-accessible method net/minecraft/block/Blocks createNetherStemBlock (Lnet/minecraft/block/MapColor;)Lnet/minecraft/block/Block; transitive-accessible method net/minecraft/block/Blocks createFlowerPotSettings ()Lnet/minecraft/block/AbstractBlock$Settings;
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;
# Methods used in block creation # 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 transitive-accessible method net/minecraft/block/Blocks always (Lnet/minecraft/block/BlockState;Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)Z
@ -137,6 +135,10 @@ 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;)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; 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 ### Generated access wideners below
# Constructors of non-abstract block classes # Constructors of non-abstract block classes
transitive-accessible method net/minecraft/block/AttachedStemBlock <init> (Lnet/minecraft/registry/RegistryKey;Lnet/minecraft/registry/RegistryKey;Lnet/minecraft/registry/RegistryKey;Lnet/minecraft/block/AbstractBlock$Settings;)V transitive-accessible method net/minecraft/block/AttachedStemBlock <init> (Lnet/minecraft/registry/RegistryKey;Lnet/minecraft/registry/RegistryKey;Lnet/minecraft/registry/RegistryKey;Lnet/minecraft/block/AbstractBlock$Settings;)V
@ -151,7 +153,7 @@ transitive-accessible method net/minecraft/block/CakeBlock <init> (Lnet/minecraf
transitive-accessible method net/minecraft/block/CandleCakeBlock <init> (Lnet/minecraft/block/Block;Lnet/minecraft/block/AbstractBlock$Settings;)V transitive-accessible method net/minecraft/block/CandleCakeBlock <init> (Lnet/minecraft/block/Block;Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/CartographyTableBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V transitive-accessible method net/minecraft/block/CartographyTableBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/CarvedPumpkinBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V transitive-accessible method net/minecraft/block/CarvedPumpkinBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/ChestBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;Ljava/util/function/Supplier;)V transitive-accessible method net/minecraft/block/ChestBlock <init> (Ljava/util/function/Supplier;Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/ChorusFlowerBlock <init> (Lnet/minecraft/block/Block;Lnet/minecraft/block/AbstractBlock$Settings;)V transitive-accessible method net/minecraft/block/ChorusFlowerBlock <init> (Lnet/minecraft/block/Block;Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/ChorusPlantBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V transitive-accessible method net/minecraft/block/ChorusPlantBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/CoralBlock <init> (Lnet/minecraft/block/Block;Lnet/minecraft/block/AbstractBlock$Settings;)V transitive-accessible method net/minecraft/block/CoralBlock <init> (Lnet/minecraft/block/Block;Lnet/minecraft/block/AbstractBlock$Settings;)V

View file

@ -17,6 +17,7 @@
package net.fabricmc.fabric.test.access; package net.fabricmc.fabric.test.access;
import net.minecraft.block.AbstractBlock; import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.SignBlock; import net.minecraft.block.SignBlock;
@ -29,6 +30,8 @@ import net.minecraft.item.Item;
import net.minecraft.item.SignItem; import net.minecraft.item.SignItem;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -37,13 +40,15 @@ import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityT
public final class SignBlockEntityTest implements ModInitializer { public final class SignBlockEntityTest implements ModInitializer {
public static final String MOD_ID = "fabric-transitive-access-wideners-v1-testmod"; 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<Block> 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 @Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new TestSign(pos, 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<Block> 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 @Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new TestSign(pos, state); return new TestSign(pos, state);
@ -52,11 +57,15 @@ public final class SignBlockEntityTest implements ModInitializer {
public static final SignItem TEST_SIGN_ITEM = new SignItem(new Item.Settings(), TEST_SIGN, TEST_WALL_SIGN); public static final SignItem TEST_SIGN_ITEM = new SignItem(new Item.Settings(), TEST_SIGN, TEST_WALL_SIGN);
public static final BlockEntityType<TestSign> TEST_SIGN_BLOCK_ENTITY = FabricBlockEntityTypeBuilder.create(TestSign::new, TEST_SIGN, TEST_WALL_SIGN).build(); public static final BlockEntityType<TestSign> TEST_SIGN_BLOCK_ENTITY = FabricBlockEntityTypeBuilder.create(TestSign::new, TEST_SIGN, TEST_WALL_SIGN).build();
private static RegistryKey<Block> keyOf(String id) {
return RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(MOD_ID, id));
}
@Override @Override
public void onInitialize() { public void onInitialize() {
Registry.register(Registries.BLOCK, Identifier.of(MOD_ID, "test_sign"), TEST_SIGN); Registry.register(Registries.BLOCK, TEST_SIGN_KEY, TEST_SIGN);
Registry.register(Registries.BLOCK, Identifier.of(MOD_ID, "test_wall_sign"), TEST_WALL_SIGN); Registry.register(Registries.BLOCK, TEST_WALL_SIGN_KEY, TEST_WALL_SIGN);
Registry.register(Registries.ITEM, Identifier.of(MOD_ID, "test_sign"), TEST_SIGN_ITEM); 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); Registry.register(Registries.BLOCK_ENTITY_TYPE, Identifier.of(MOD_ID, "test_sign"), TEST_SIGN_BLOCK_ENTITY);
} }

View file

@ -116,13 +116,11 @@ transitive-accessible method net/minecraft/entity/damage/DamageSources create (L
transitive-accessible field net/minecraft/client/MinecraftClient attackCooldown I transitive-accessible field net/minecraft/client/MinecraftClient attackCooldown I
# Creating certain types of blocks # 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 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 createLeavesBlock (Lnet/minecraft/sound/BlockSoundGroup;)Lnet/minecraft/block/Block; transitive-accessible method net/minecraft/block/Blocks createNetherStemSettings (Lnet/minecraft/block/MapColor;)Lnet/minecraft/block/AbstractBlock$Settings;
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 createLeavesSettings (Lnet/minecraft/sound/BlockSoundGroup;)Lnet/minecraft/block/AbstractBlock$Settings;
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 createButtonSettings ()Lnet/minecraft/block/AbstractBlock$Settings;
transitive-accessible method net/minecraft/block/Blocks createNetherStemBlock (Lnet/minecraft/block/MapColor;)Lnet/minecraft/block/Block; transitive-accessible method net/minecraft/block/Blocks createFlowerPotSettings ()Lnet/minecraft/block/AbstractBlock$Settings;
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;
# Methods used in block creation # 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 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;)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; 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 ### Generated access wideners below

View file

@ -3,8 +3,8 @@ org.gradle.parallel=true
fabric.loom.multiProjectOptimisation=true fabric.loom.multiProjectOptimisation=true
version=0.103.0 version=0.103.0
minecraft_version=24w34a minecraft_version=24w35a
yarn_version=+build.1 yarn_version=+build.4
loader_version=0.16.2 loader_version=0.16.2
installer_version=1.0.1 installer_version=1.0.1