From 5982b79138edc29ca554173a50da7790afe7146e Mon Sep 17 00:00:00 2001 From: IThundxr Date: Sun, 22 Sep 2024 12:38:23 -0400 Subject: [PATCH] Merge fixes I --- build.gradle | 2 +- .../registrate/AbstractRegistrate.java | 430 ++---------------- .../com/tterrag/registrate/Registrate.java | 5 - .../registrate/builders/AbstractBuilder.java | 14 +- .../registrate/builders/BlockBuilder.java | 34 +- .../builders/BlockEntityBuilder.java | 5 +- .../tterrag/registrate/builders/Builder.java | 13 +- .../registrate/builders/BuilderCallback.java | 3 +- .../registrate/builders/EntityBuilder.java | 7 +- .../registrate/builders/FluidBuilder.java | 324 +------------ .../registrate/builders/ItemBuilder.java | 41 +- .../registrate/builders/MenuBuilder.java | 4 +- .../registrate/fabric/BaseLangProvider.java | 12 +- .../registrate/fabric/DeferredHolder.java | 288 ++++++++++++ .../fabric/FluidSpriteReloadListener.java | 2 +- .../registrate/fabric/RegistryObject.java | 136 ------ .../accessor/SpawnPlacementsAccessor.java | 3 +- .../registrate/providers/ProviderType.java | 4 +- .../RegistrateAdvancementProvider.java | 3 + .../RegistrateBlockstateProvider.java | 6 +- .../providers/RegistrateDataMapProvider.java | 31 -- .../providers/RegistrateDataProvider.java | 2 + .../providers/RegistrateGenericProvider.java | 4 +- .../RegistrateItemModelProvider.java | 6 +- .../providers/RegistrateLangProvider.java | 23 +- .../providers/RegistrateTagsProvider.java | 1 + .../loot/RegistrateBlockLootTables.java | 12 +- .../loot/RegistrateLootTableProvider.java | 2 + .../util/entry/BlockEntityEntry.java | 2 +- .../registrate/util/entry/BlockEntry.java | 3 +- .../registrate/util/entry/EntityEntry.java | 2 +- .../registrate/util/entry/FluidEntry.java | 31 +- .../registrate/util/entry/ItemEntry.java | 3 +- .../util/entry/ItemProviderEntry.java | 2 +- .../registrate/util/entry/MenuEntry.java | 3 +- .../registrate/util/entry/RegistryEntry.java | 79 +--- .../tterrag/registrate/test/mod/TestMod.java | 2 +- 37 files changed, 420 insertions(+), 1124 deletions(-) create mode 100644 src/main/java/com/tterrag/registrate/fabric/DeferredHolder.java delete mode 100644 src/main/java/com/tterrag/registrate/fabric/RegistryObject.java delete mode 100644 src/main/java/com/tterrag/registrate/providers/RegistrateDataMapProvider.java diff --git a/build.gradle b/build.gradle index 44574a0c..9c7432ee 100644 --- a/build.gradle +++ b/build.gradle @@ -35,7 +35,7 @@ dependencies { modImplementation("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}") modApi(include(fabricApi.module("fabric-data-generation-api-v1", project.fabric_version))) // include datagen api modApi(include("io.github.fabricators_of_create.Porting-Lib:tags:${project.porting_lib_version}")) { exclude(group: "io.vram") } - //modApi(include("io.github.fabricators_of_create.Porting-Lib:model_generators:${project.porting_lib_version}")) { exclude(group: "io.vram") } + modApi(include("io.github.fabricators_of_create.Porting-Lib:models:${project.porting_lib_version}")) { exclude(group: "io.vram") } modApi(include("io.github.fabricators_of_create.Porting-Lib:data:${project.porting_lib_version}")) { exclude(group: "io.vram") } compileOnly("org.projectlombok:lombok:1.18.22") diff --git a/src/main/java/com/tterrag/registrate/AbstractRegistrate.java b/src/main/java/com/tterrag/registrate/AbstractRegistrate.java index ce3d0053..6fde5420 100644 --- a/src/main/java/com/tterrag/registrate/AbstractRegistrate.java +++ b/src/main/java/com/tterrag/registrate/AbstractRegistrate.java @@ -1,23 +1,19 @@ package com.tterrag.registrate; -<<<<<<< HEAD import com.google.common.annotations.Beta; import com.google.common.base.Preconditions; -import com.google.common.collect.*; -import com.tterrag.registrate.builders.*; import com.tterrag.registrate.builders.BlockEntityBuilder.BlockEntityFactory; -import com.tterrag.registrate.builders.EnchantmentBuilder.EnchantmentFactory; import com.tterrag.registrate.builders.MenuBuilder.ForgeMenuFactory; import com.tterrag.registrate.builders.MenuBuilder.MenuFactory; import com.tterrag.registrate.builders.MenuBuilder.ScreenFactory; -import com.tterrag.registrate.fabric.RegistryObject; +import com.tterrag.registrate.fabric.DeferredHolder; import com.tterrag.registrate.fabric.RegistryUtil; import com.tterrag.registrate.fabric.SimpleFlowableFluid; import com.tterrag.registrate.providers.ProviderType; import com.tterrag.registrate.providers.RegistrateDataProvider; import com.tterrag.registrate.providers.RegistrateLangProvider; import com.tterrag.registrate.providers.RegistrateProvider; -======= + import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -32,18 +28,14 @@ import java.util.function.UnaryOperator; import java.util.stream.Collectors; -import javax.annotation.Nonnull; import javax.annotation.Nullable; import com.google.common.collect.Multimap; import com.google.common.collect.Table; -import com.mojang.serialization.Codec; import com.tterrag.registrate.providers.*; -import lombok.Setter; import net.minecraft.Util; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.MenuAccess; -import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.core.Registry; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; @@ -62,39 +54,23 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockBehaviour; -import net.neoforged.bus.api.EventPriority; -import net.neoforged.bus.api.IEventBus; -import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; -import net.neoforged.fml.loading.FMLLoader; -import net.neoforged.neoforge.data.event.GatherDataEvent; -import net.neoforged.neoforge.data.loading.DatagenModLoader; -import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; -import net.neoforged.neoforge.fluids.BaseFlowingFluid; -import net.neoforged.neoforge.fluids.FluidType; -import net.neoforged.neoforge.registries.*; import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.message.Message; -import com.google.common.base.Preconditions; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.HashBasedTable; import com.google.common.collect.HashMultimap; import com.google.common.collect.ListMultimap; import com.tterrag.registrate.builders.BlockBuilder; import com.tterrag.registrate.builders.BlockEntityBuilder; -import com.tterrag.registrate.builders.BlockEntityBuilder.BlockEntityFactory; import com.tterrag.registrate.builders.Builder; import com.tterrag.registrate.builders.BuilderCallback; import com.tterrag.registrate.builders.EntityBuilder; import com.tterrag.registrate.builders.FluidBuilder; import com.tterrag.registrate.builders.ItemBuilder; import com.tterrag.registrate.builders.MenuBuilder; -import com.tterrag.registrate.builders.MenuBuilder.ForgeMenuFactory; -import com.tterrag.registrate.builders.MenuBuilder.MenuFactory; -import com.tterrag.registrate.builders.MenuBuilder.ScreenFactory; import com.tterrag.registrate.builders.NoConfigBuilder; ->>>>>>> upstream/1.21/dev import com.tterrag.registrate.util.CreativeModeTabModifier; import com.tterrag.registrate.util.DebugMarkers; import com.tterrag.registrate.util.entry.ItemEntry; @@ -105,7 +81,6 @@ import lombok.Getter; import lombok.Value; import lombok.extern.log4j.Log4j2; -<<<<<<< HEAD import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder; @@ -113,48 +88,11 @@ import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.Util; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.inventory.MenuAccess; import net.minecraft.core.DefaultedMappedRegistry; -import net.minecraft.core.DefaultedRegistry; import net.minecraft.core.MappedRegistry; -import net.minecraft.core.Registry; -import net.minecraft.core.WritableRegistry; -import net.minecraft.core.registries.Registries; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType.EntityFactory; -import net.minecraft.world.entity.MobCategory; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.item.CreativeModeTab; -import net.minecraft.world.item.CreativeModeTabs; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.item.enchantment.Enchantment; -import net.minecraft.world.item.enchantment.EnchantmentCategory; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockBehaviour; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.message.Message; -import org.jetbrains.annotations.Nullable; import java.io.File; import java.nio.file.Path; -import java.util.*; -import java.util.Map.Entry; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.UnaryOperator; -import java.util.stream.Collectors; -======= ->>>>>>> upstream/1.21/dev /** * Manages all registrations and data generators for a mod. @@ -201,12 +139,7 @@ private class Registration { void register(Registry registry) { T entry = creator.get(); -<<<<<<< HEAD Registry.register(registry, name, entry); - delegate.updateReference(registry); -======= - event.register(type, rh -> rh.register(name, entry)); ->>>>>>> upstream/1.21/dev callbacks.forEach(c -> c.accept(entry)); callbacks.clear(); } @@ -220,17 +153,10 @@ void addRegisterCallback(NonNullConsumer callback) { /** * Checks if Minecraft is running from a dev environment. Enables certain debug logging. * -<<<<<<< HEAD * @return {@code true} when in a dev environment */ public static boolean isDevEnvironment() { return FabricLoader.getInstance().isDevelopmentEnvironment(); -======= - * @return {@code true} when in a dev environment (specifically, {@link FMLLoader#isProduction()} == false) - */ - public static boolean isDevEnvironment() { - return !FMLLoader.isProduction(); ->>>>>>> upstream/1.21/dev } private final Table>, String, Registration> registrations = HashBasedTable.create(); @@ -253,13 +179,6 @@ public static boolean isDevEnvironment() { @Getter private final String modid; - /** - * Get the mod event bus that event listeners will be registered to. Useful when Registrate is used in mods that use alternative language loaders, such as forgelin. - */ - @Getter @Setter - @Nullable - private IEventBus modEventBus; - @Nullable private String currentName; private boolean skipErrors; @@ -284,67 +203,24 @@ protected final S self() { return (S) this; } -<<<<<<< HEAD public void register() { RegistryUtil.forAllRegistries(registry -> { onRegister(registry); onRegisterLate(registry); -======= - /** - * Called during {@link Registrate#create(String) creation} to initialize event listeners. Custom implementations may add their own event listeners by overriding this. - *

- * Always call {@code super} in your override unless you know what you are doing! - * - * @param bus - * The event bus - * @return This {@link AbstractRegistrate} object - */ - public S registerEventListeners(IEventBus bus) { - if (this.modEventBus == null) { - this.modEventBus = bus; - } - - Consumer onRegister = this::onRegister; - Consumer onRegisterLate = this::onRegisterLate; - bus.addListener(onRegister); - bus.addListener(EventPriority.LOWEST, onRegisterLate); - bus.addListener(this::onBuildCreativeModeTabContents); // Fired multiple times when ever tabs need contents rebuilt (changing op tab perms for example) - - // Register events fire multiple times, so clean them up on common setup - OneTimeEventReceiver.addModListener(this, FMLCommonSetupEvent.class, $ -> { - OneTimeEventReceiver.unregister(this, onRegister, RegisterEvent.class); - OneTimeEventReceiver.unregister(this, onRegisterLate, RegisterEvent.class); ->>>>>>> upstream/1.21/dev }); creativeModeTabModifiers.forEach((key, consumer) -> ItemGroupEvents.modifyEntriesEvent(key).register(entries -> consumer.accept( new CreativeModeTabModifier( - entries::getEnabledFeatures, entries::shouldShowOpRestrictedItems, entries::accept + entries::getEnabledFeatures, entries::shouldShowOpRestrictedItems, entries::accept, entries::getContext ) ) ) ); } - -<<<<<<< HEAD + protected void onRegister(Registry registry) { ResourceKey> type = registry.key(); -======= - /** - * Called once per registry to gather collected registrations and add entries to the registry. May be overriden in custom implementations to perform additional actions upon entry registration, but - * must call {@code super}. - * - * @param event - * The {@link RegisterEvent} being fired, use {@link RegisterEvent#getRegistryKey()} to query the registry type - */ - protected void onRegister(RegisterEvent event) { - ResourceKey> type = event.getRegistryKey(); - if (type == null) { - log.debug(DebugMarkers.REGISTER, "Skipping invalid registry with no supertype: " + event.getRegistryKey().location()); - return; - } ->>>>>>> upstream/1.21/dev if (!registerCallbacks.isEmpty()) { registerCallbacks.asMap().forEach((k, v) -> log.warn("Found {} unused register callback(s) for entry {} [{}]. Was the entry ever registered?", v.size(), k.getLeft(), k.getRight().location())); registerCallbacks.clear(); @@ -357,17 +233,10 @@ protected void onRegister(RegisterEvent event) { log.trace(DebugMarkers.REGISTER, "({}) Registering {} known objects of type {}", getModid(), registrationsForType.size(), type.location()); for (Entry> e : registrationsForType.entrySet()) { try { -<<<<<<< HEAD e.getValue().register((Registry) registry); log.debug(DebugMarkers.REGISTER, "Registered {} to registry {}", e.getValue().getName(), type); } catch (Exception ex) { String err = "Unexpected error while registering entry " + e.getValue().getName() + " to registry " + type; -======= - e.getValue().register(event); - log.trace(DebugMarkers.REGISTER, "Registered {} to registry {}", e.getValue().getName(), event.getRegistryKey().location()); - } catch (Exception ex) { - String err = "Unexpected error while registering entry " + e.getValue().getName() + " to registry " + event.getRegistryKey().location(); ->>>>>>> upstream/1.21/dev if (skipErrors) { log.error(DebugMarkers.REGISTER, err); } else { @@ -389,24 +258,7 @@ protected void onRegisterLate(Registry registry) { callbacks.clear(); completedRegistrations.add(type); } - -<<<<<<< HEAD -======= - /** - * Called when a {@link CreativeModeTab} is being populated to fill in any entries that belong there. Can be overriden in custom implementations. - * - * @param event - * The event - */ - protected void onBuildCreativeModeTabContents(BuildCreativeModeTabContentsEvent event) { - var modifier = new CreativeModeTabModifier(event::getFlags, event::hasPermissions, event::accept, event::getParameters); - - creativeModeTabModifiers.forEach((key, value) -> { - if(event.getTabKey().equals(key)) value.accept(modifier); - }); - } - ->>>>>>> upstream/1.21/dev + @Nullable private RegistrateDataProvider provider; @@ -988,7 +840,6 @@ protected RegistryEntry accept(String name, ResourceKey ResourceKey> makeRegistry(FabricRegistryBuilder builder) { //noinspection unchecked @@ -998,7 +849,7 @@ public ResourceKey> makeRegistry(FabricRegistryBuilder bui @Beta public ResourceKey> makeRegistry(String name) { FabricRegistryBuilder> builder = FabricRegistryBuilder.createSimple( - ResourceKey.createRegistryKey(new ResourceLocation(getModid(), name)) + ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(getModid(), name)) ); return makeRegistry(builder); } @@ -1006,7 +857,7 @@ public ResourceKey> makeRegistry(String name) { @Beta public ResourceKey> makeRegistry(String name, RegistryAttribute... attributes) { FabricRegistryBuilder> builder = FabricRegistryBuilder - .createSimple(ResourceKey.createRegistryKey(new ResourceLocation(getModid(), name))); + .createSimple(ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(getModid(), name))); for (RegistryAttribute attribute : attributes) { builder.attribute(attribute); } @@ -1015,85 +866,64 @@ public ResourceKey> makeRegistry(String name, RegistryAttribute. @Beta public ResourceKey> makeRegistry(String name, String defaultName) { - return makeRegistry(name, new ResourceLocation(getModid(), defaultName)); + return makeRegistry(name, ResourceLocation.fromNamespaceAndPath(getModid(), defaultName)); } @Beta public ResourceKey> makeRegistry(String name, ResourceLocation defaultId) { - ResourceKey> key = ResourceKey.createRegistryKey(new ResourceLocation(getModid(), name)); + ResourceKey> key = ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(getModid(), name)); FabricRegistryBuilder> builder = FabricRegistryBuilder.createDefaulted(key, defaultId); return makeRegistry(builder); } @Beta public ResourceKey> makeRegistry(String name, ResourceLocation defaultId, RegistryAttribute... attributes) { - ResourceKey> key = ResourceKey.createRegistryKey(new ResourceLocation(getModid(), name)); + ResourceKey> key = ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(getModid(), name)); FabricRegistryBuilder> builder = FabricRegistryBuilder.createDefaulted(key, defaultId); for (RegistryAttribute attribute : attributes) { builder.attribute(attribute); } return makeRegistry(builder); -======= - /** - * Helper to create a new registry for custom objects. The returned {@link ResourceKey} can be used immediately in methods like {@link #simple(ResourceKey, NonNullSupplier) simple} or - * {@link #generic(ResourceKey, NonNullSupplier) generic}. - *

- * Alternatively, a custom {@link Builder builder} can be created. - *

- * This method will automatically subscribe to the {@link NewRegistryEvent} and create the registry at the proper time. Thus, the new registry will not exist immediately after this is called. - * - * @param - * The type of object the new registry will contain - * @param name - * The ID of this registry - * @param builder - * A function to create the {@link RegistryBuilder} that defines the other properties/behaviors of the created registry - * @return A {@link ResourceKey resource key} referencing the to-be-created registry. - */ - public ResourceKey> makeRegistry(String name, Function>, RegistryBuilder> builder) { - final ResourceKey> registryId = ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(getModid(), name)); - OneTimeEventReceiver.addModListener(this, NewRegistryEvent.class, e -> e.register(builder.apply(registryId).create())); - return registryId; } - /** - * Registers the given registry key as an unsynced datapack registry, which will cause data to be loaded from - * a datapack folder based on the registry's name. The datapack registry is not required to be present - * on clients when connecting to servers with the mod/registry. - *

- * Data JSONs will be loaded from {@code data//modid/registryname/}, where {@code modid} is the namespace of the registry key. - * - * @param name The ID of this registry - * @param codec The codec to be used for loading data from datapacks on servers - * @see #makeDatapackRegistry(String, Codec, Codec) - */ - public ResourceKey> makeDatapackRegistry(String name, Codec codec) { - return makeDatapackRegistry(name, codec, null); - } - - /** - * Registers the registry key as a datapack registry, which will cause data to be loaded from - * a datapack folder based on the registry's name. - *

- * Data JSONs will be loaded from {@code data//modid/registryname/}, where {@code modid} is the namespace of the registry key. - * - * @param name The ID of this registry - * @param codec The codec to be used for loading data from datapacks on servers - * @param networkCodec The codec to be used for syncing loaded data to clients. - * If {@code networkCodec} is null, data will not be synced, and clients are not required to have this - * datapack registry to join a server. - *

- * If {@code networkCodec} is not null, clients must have this datapack registry/mod - * when joining a server that has this datapack registry/mod. - * The data will be synced using the network codec and accessible via {@link ClientPacketListener#registryAccess()}. - * @see #makeDatapackRegistry(String, Codec) - */ - public ResourceKey> makeDatapackRegistry(String name, Codec codec, @Nullable Codec networkCodec) { - final ResourceKey> registryId = ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(getModid(), name)); - OneTimeEventReceiver.addModListener(this, DataPackRegistryEvent.NewRegistry.class, event -> event.dataPackRegistry(registryId, codec, networkCodec)); - return registryId; ->>>>>>> upstream/1.21/dev - } + //fixme +// /** +// * Registers the given registry key as an unsynced datapack registry, which will cause data to be loaded from +// * a datapack folder based on the registry's name. The datapack registry is not required to be present +// * on clients when connecting to servers with the mod/registry. +// *

+// * Data JSONs will be loaded from {@code data//modid/registryname/}, where {@code modid} is the namespace of the registry key. +// * +// * @param name The ID of this registry +// * @param codec The codec to be used for loading data from datapacks on servers +// * @see #makeDatapackRegistry(String, Codec, Codec) +// */ +// public ResourceKey> makeDatapackRegistry(String name, Codec codec) { +// return makeDatapackRegistry(name, codec, null); +// } +// +// /** +// * Registers the registry key as a datapack registry, which will cause data to be loaded from +// * a datapack folder based on the registry's name. +// *

+// * Data JSONs will be loaded from {@code data//modid/registryname/}, where {@code modid} is the namespace of the registry key. +// * +// * @param name The ID of this registry +// * @param codec The codec to be used for loading data from datapacks on servers +// * @param networkCodec The codec to be used for syncing loaded data to clients. +// * If {@code networkCodec} is null, data will not be synced, and clients are not required to have this +// * datapack registry to join a server. +// *

+// * If {@code networkCodec} is not null, clients must have this datapack registry/mod +// * when joining a server that has this datapack registry/mod. +// * The data will be synced using the network codec and accessible via {@link ClientPacketListener#registryAccess()}. +// * @see #makeDatapackRegistry(String, Codec) +// */ +// public ResourceKey> makeDatapackRegistry(String name, Codec codec, @Nullable Codec networkCodec) { +// final ResourceKey> registryId = ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(getModid(), name)); +// OneTimeEventReceiver.addModListener(this, DataPackRegistryEvent.NewRegistry.class, event -> event.dataPackRegistry(registryId, codec, networkCodec)); +// return registryId; +// } /* === Builder helpers === */ @@ -1205,8 +1035,6 @@ public BlockEntityBuilder blockEntity(P parent, } // Fluids - -<<<<<<< HEAD public FluidBuilder fluid() { return fluid(self()); } @@ -1247,7 +1075,7 @@ public FluidBuilder fluid(P parent, Res } public

FluidBuilder fluid(P parent, String name) { - return fluid(parent, name, new ResourceLocation(getModid(), "block/" + currentName() + "_still"), new ResourceLocation(getModid(), "block/" + currentName() + "_flow")); + return fluid(parent, name, ResourceLocation.fromNamespaceAndPath(getModid(), "block/" + currentName() + "_still"), ResourceLocation.fromNamespaceAndPath(getModid(), "block/" + currentName() + "_flow")); } public

FluidBuilder fluid(P parent, String name, ResourceLocation stillTexture, ResourceLocation flowingTexture) { @@ -1258,165 +1086,7 @@ public FluidBuilder fluid(P parent, Str NonNullFunction fluidFactory) { return entry(name, callback -> FluidBuilder.create(this, parent, name, callback, stillTexture, flowingTexture, fluidFactory)); } - -======= - public FluidBuilder fluid() { - return fluid(self()); - } - - public FluidBuilder fluid(FluidBuilder.FluidTypeFactory typeFactory) { - return fluid(self(), typeFactory); - } - - public FluidBuilder fluid(NonNullSupplier fluidType) { - return fluid(self(), fluidType); - } - - public FluidBuilder fluid(ResourceLocation stillTexture, ResourceLocation flowingTexture) { - return fluid(self(), stillTexture, flowingTexture); - } - - public FluidBuilder fluid(ResourceLocation stillTexture, ResourceLocation flowingTexture, FluidBuilder.FluidTypeFactory typeFactory) { - return fluid(self(), stillTexture, flowingTexture, typeFactory); - } - - public FluidBuilder fluid(ResourceLocation stillTexture, ResourceLocation flowingTexture, NonNullSupplier fluidType) { - return fluid(self(), stillTexture, flowingTexture, fluidType); - } - - public FluidBuilder fluid(ResourceLocation stillTexture, ResourceLocation flowingTexture, - NonNullFunction fluidFactory) { - return fluid(self(), stillTexture, flowingTexture, fluidFactory); - } - - public FluidBuilder fluid(ResourceLocation stillTexture, ResourceLocation flowingTexture, - FluidBuilder.FluidTypeFactory typeFactory, NonNullFunction fluidFactory) { - return fluid(self(), stillTexture, flowingTexture, typeFactory, fluidFactory); - } - - public FluidBuilder fluid(ResourceLocation stillTexture, ResourceLocation flowingTexture, - NonNullSupplier fluidType, NonNullFunction fluidFactory) { - return fluid(self(), stillTexture, flowingTexture, fluidType, fluidFactory); - } - - public FluidBuilder fluid(String name) { - return fluid(self(), name); - } - - public FluidBuilder fluid(String name, FluidBuilder.FluidTypeFactory typeFactory) { - return fluid(self(), name, typeFactory); - } - - public FluidBuilder fluid(String name, NonNullSupplier fluidType) { - return fluid(self(), name, fluidType); - } - - public FluidBuilder fluid(String name, ResourceLocation stillTexture, ResourceLocation flowingTexture) { - return fluid(self(), name, stillTexture, flowingTexture); - } - - public FluidBuilder fluid(String name, ResourceLocation stillTexture, ResourceLocation flowingTexture, FluidBuilder.FluidTypeFactory typeFactory) { - return fluid(self(), name, stillTexture, flowingTexture, typeFactory); - } - - public FluidBuilder fluid(String name, ResourceLocation stillTexture, ResourceLocation flowingTexture, NonNullSupplier fluidType) { - return fluid(self(), name, stillTexture, flowingTexture, fluidType); - } - - public FluidBuilder fluid(String name, ResourceLocation stillTexture, ResourceLocation flowingTexture, - NonNullFunction fluidFactory) { - return fluid(self(), name, stillTexture, flowingTexture, fluidFactory); - } - - public FluidBuilder fluid(String name, ResourceLocation stillTexture, ResourceLocation flowingTexture, - FluidBuilder.FluidTypeFactory typeFactory, NonNullFunction fluidFactory) { - return fluid(self(), name, stillTexture, flowingTexture, typeFactory, fluidFactory); - } - - public FluidBuilder fluid(String name, ResourceLocation stillTexture, ResourceLocation flowingTexture, - NonNullSupplier fluidType, NonNullFunction fluidFactory) { - return fluid(self(), name, stillTexture, flowingTexture, fluidType, fluidFactory); - } - - public

FluidBuilder fluid(P parent) { - return fluid(parent, currentName()); - } - - public

FluidBuilder fluid(P parent, FluidBuilder.FluidTypeFactory typeFactory) { - return fluid(parent, currentName(), typeFactory); - } - - public

FluidBuilder fluid(P parent, NonNullSupplier fluidType) { - return fluid(parent, currentName(), fluidType); - } - - public

FluidBuilder fluid(P parent, ResourceLocation stillTexture, ResourceLocation flowingTexture) { - return fluid(parent, currentName(), stillTexture, flowingTexture); - } - - public

FluidBuilder fluid(P parent, ResourceLocation stillTexture, ResourceLocation flowingTexture, FluidBuilder.FluidTypeFactory typeFactory) { - return fluid(parent, currentName(), stillTexture, flowingTexture, typeFactory); - } - - public

FluidBuilder fluid(P parent, ResourceLocation stillTexture, ResourceLocation flowingTexture, NonNullSupplier fluidType) { - return fluid(parent, currentName(), stillTexture, flowingTexture, fluidType); - } - - public FluidBuilder fluid(P parent, ResourceLocation stillTexture, ResourceLocation flowingTexture, - NonNullFunction fluidFactory) { - return fluid(parent, currentName(), stillTexture, flowingTexture, fluidFactory); - } - - public FluidBuilder fluid(P parent, ResourceLocation stillTexture, ResourceLocation flowingTexture, - FluidBuilder.FluidTypeFactory typeFactory, NonNullFunction fluidFactory) { - return fluid(parent, currentName(), stillTexture, flowingTexture, typeFactory, fluidFactory); - } - - public FluidBuilder fluid(P parent, ResourceLocation stillTexture, ResourceLocation flowingTexture, - NonNullSupplier fluidType, NonNullFunction fluidFactory) { - return fluid(parent, currentName(), stillTexture, flowingTexture, fluidType, fluidFactory); - } - - public

FluidBuilder fluid(P parent, String name) { - return fluid(parent, name, ResourceLocation.fromNamespaceAndPath(getModid(), "block/" + currentName() + "_still"), ResourceLocation.fromNamespaceAndPath(getModid(), "block/" + currentName() + "_flow")); - } - - public

FluidBuilder fluid(P parent, String name, FluidBuilder.FluidTypeFactory typeFactory) { - return fluid(parent, name, ResourceLocation.fromNamespaceAndPath(getModid(), "block/" + currentName() + "_still"), ResourceLocation.fromNamespaceAndPath(getModid(), "block/" + currentName() + "_flow"), typeFactory); - } - - public

FluidBuilder fluid(P parent, String name, NonNullSupplier fluidType) { - return fluid(parent, name, ResourceLocation.fromNamespaceAndPath(getModid(), "block/" + currentName() + "_still"), ResourceLocation.fromNamespaceAndPath(getModid(), "block/" + currentName() + "_flow"), fluidType); - } - - public

FluidBuilder fluid(P parent, String name, ResourceLocation stillTexture, ResourceLocation flowingTexture) { - return entry(name, callback -> FluidBuilder.create(this, parent, name, callback, stillTexture, flowingTexture)); - } - - public

FluidBuilder fluid(P parent, String name, ResourceLocation stillTexture, ResourceLocation flowingTexture, FluidBuilder.FluidTypeFactory typeFactory) { - return entry(name, callback -> FluidBuilder.create(this, parent, name, callback, stillTexture, flowingTexture, typeFactory)); - } - - public

FluidBuilder fluid(P parent, String name, ResourceLocation stillTexture, ResourceLocation flowingTexture, NonNullSupplier fluidType) { - return entry(name, callback -> FluidBuilder.create(this, parent, name, callback, stillTexture, flowingTexture, fluidType)); - } - - public FluidBuilder fluid(P parent, String name, ResourceLocation stillTexture, ResourceLocation flowingTexture, - NonNullFunction fluidFactory) { - return entry(name, callback -> FluidBuilder.create(this, parent, name, callback, stillTexture, flowingTexture, fluidFactory)); - } - - public FluidBuilder fluid(P parent, String name, ResourceLocation stillTexture, ResourceLocation flowingTexture, - FluidBuilder.FluidTypeFactory typeFactory, NonNullFunction fluidFactory) { - return entry(name, callback -> FluidBuilder.create(this, parent, name, callback, stillTexture, flowingTexture, typeFactory, fluidFactory)); - } - - public FluidBuilder fluid(P parent, String name, ResourceLocation stillTexture, ResourceLocation flowingTexture, - NonNullSupplier fluidType, NonNullFunction fluidFactory) { - return entry(name, callback -> FluidBuilder.create(this, parent, name, callback, stillTexture, flowingTexture, fluidType, fluidFactory)); - } - ->>>>>>> upstream/1.21/dev + // Menu public > MenuBuilder menu(MenuFactory factory, NonNullSupplier> screenFactory) { diff --git a/src/main/java/com/tterrag/registrate/Registrate.java b/src/main/java/com/tterrag/registrate/Registrate.java index d791455f..31f76e27 100644 --- a/src/main/java/com/tterrag/registrate/Registrate.java +++ b/src/main/java/com/tterrag/registrate/Registrate.java @@ -1,11 +1,6 @@ package com.tterrag.registrate; import lombok.extern.log4j.Log4j2; -import net.neoforged.bus.api.IEventBus; -import net.neoforged.fml.ModContainer; -import net.neoforged.fml.ModList; - -import java.util.Optional; @Log4j2 public class Registrate extends AbstractRegistrate { diff --git a/src/main/java/com/tterrag/registrate/builders/AbstractBuilder.java b/src/main/java/com/tterrag/registrate/builders/AbstractBuilder.java index b023f12c..b1813d6a 100644 --- a/src/main/java/com/tterrag/registrate/builders/AbstractBuilder.java +++ b/src/main/java/com/tterrag/registrate/builders/AbstractBuilder.java @@ -3,8 +3,7 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.tterrag.registrate.AbstractRegistrate; -import com.tterrag.registrate.fabric.RegistryObject; -import com.tterrag.registrate.fabric.RegistryUtil; +import com.tterrag.registrate.fabric.DeferredHolder; import com.tterrag.registrate.providers.ProviderType; import com.tterrag.registrate.providers.RegistrateLangProvider; import com.tterrag.registrate.providers.RegistrateTagsProvider; @@ -22,13 +21,10 @@ import net.minecraft.data.tags.TagsProvider; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.TagEntry; import net.minecraft.tags.TagKey; import java.util.Arrays; -import java.util.Arrays; - /** * Base class which most builders should extend, instead of implementing [@link {@link Builder} directly. *

@@ -104,7 +100,7 @@ public final & RegistrateTagsProvider> S tag(Prov setData(type, (ctx, prov) -> tagsByType.get(type).stream() .map(t -> (TagKey) t) .map(prov::addTag) - .forEach(b -> b.add(asTag()))); + .forEach(b -> b.add(ResourceKey.create(getRegistryKey(), ResourceLocation.fromNamespaceAndPath(getOwner().getModid(), getName()))))); } tagsByType.putAll(type, Arrays.asList(tags)); return (S) this; @@ -119,12 +115,6 @@ public S asOptional(){ return (S) this; } - protected TagEntry asTag() { - ResourceLocation id = ResourceLocation.fromNamespaceAndPath(getOwner().getModid(), getName()); - if (isOptional) return TagEntry.optionalElement(id); - return TagEntry.element(id); - } - /** * Remove a tag (or tags) from this entry of a given type. Useful to remove default tags on fluids, for example. Multiple calls will remove additional tags. * diff --git a/src/main/java/com/tterrag/registrate/builders/BlockBuilder.java b/src/main/java/com/tterrag/registrate/builders/BlockBuilder.java index e1962f58..e847170b 100644 --- a/src/main/java/com/tterrag/registrate/builders/BlockBuilder.java +++ b/src/main/java/com/tterrag/registrate/builders/BlockBuilder.java @@ -3,23 +3,22 @@ import com.google.gson.JsonElement; import com.tterrag.registrate.AbstractRegistrate; import com.tterrag.registrate.builders.BlockEntityBuilder.BlockEntityFactory; +import com.tterrag.registrate.fabric.DeferredHolder; import com.tterrag.registrate.fabric.EnvExecutor; -import com.tterrag.registrate.fabric.RegistryObject; import com.tterrag.registrate.providers.*; import com.tterrag.registrate.providers.loot.RegistrateBlockLootTables; import com.tterrag.registrate.providers.loot.RegistrateLootTableProvider.LootType; +import com.tterrag.registrate.util.RegistrateDistExecutor; import com.tterrag.registrate.util.entry.BlockEntry; import com.tterrag.registrate.util.entry.RegistryEntry; import com.tterrag.registrate.util.nullness.*; -import io.github.fabricators_of_create.porting_lib.models.generators.block.BlockStateProvider; +import io.github.fabricators_of_create.porting_lib.models.generators.BlockStateProvider; import net.fabricmc.api.EnvType; import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; import net.minecraft.client.color.block.BlockColor; import net.minecraft.client.renderer.RenderType; -import net.minecraft.core.Registry; import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; @@ -315,33 +314,6 @@ public BlockBuilder recipe(NonNullBiConsumer, Reg return setData(ProviderType.RECIPE, cons); } - @Nullable - private NonNullSupplier> clientExtension; - - /** - * Register a client extension for this block. The {@link IClientBlockExtensions} instance can be shared across many items. - * - * @param clientExtension - * The client extension to register for this block - * @return this {@link BlockBuilder} - */ - public BlockBuilder clientExtension(NonNullSupplier> clientExtension) { - if (this.clientExtension == null) { - RegistrateDistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> this::registerClientExtension); - } - this.clientExtension = clientExtension; - return this; - } - - protected void registerClientExtension() { - OneTimeEventReceiver.addModListener(getOwner(), RegisterClientExtensionsEvent.class, e -> { - NonNullSupplier> clientExtension = this.clientExtension; - if (clientExtension != null) { - e.registerBlock(clientExtension.get().get(), getEntry()); - } - }); - } - /** * Assign {@link TagKey}{@code s} to this block. Multiple calls will add additional tags. * diff --git a/src/main/java/com/tterrag/registrate/builders/BlockEntityBuilder.java b/src/main/java/com/tterrag/registrate/builders/BlockEntityBuilder.java index b54d045d..759f824d 100644 --- a/src/main/java/com/tterrag/registrate/builders/BlockEntityBuilder.java +++ b/src/main/java/com/tterrag/registrate/builders/BlockEntityBuilder.java @@ -4,19 +4,16 @@ import java.util.HashSet; import java.util.Set; import java.util.function.Function; -import java.util.function.Supplier; import com.tterrag.registrate.AbstractRegistrate; +import com.tterrag.registrate.fabric.DeferredHolder; import com.tterrag.registrate.fabric.EnvExecutor; -import com.tterrag.registrate.fabric.RegistryObject; import com.tterrag.registrate.mixin.accessor.BlockEntityRenderersAccessor; -import com.tterrag.registrate.util.RegistrateDistExecutor; import com.tterrag.registrate.util.entry.BlockEntityEntry; import com.tterrag.registrate.util.entry.RegistryEntry; import com.tterrag.registrate.util.nullness.NonNullFunction; import com.tterrag.registrate.util.nullness.NonNullSupplier; import net.fabricmc.api.EnvType; -import net.minecraft.core.Registry; import org.jetbrains.annotations.Nullable; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; diff --git a/src/main/java/com/tterrag/registrate/builders/Builder.java b/src/main/java/com/tterrag/registrate/builders/Builder.java index 99ae02a4..9e53ba2c 100644 --- a/src/main/java/com/tterrag/registrate/builders/Builder.java +++ b/src/main/java/com/tterrag/registrate/builders/Builder.java @@ -3,8 +3,6 @@ import java.util.function.Function; import com.tterrag.registrate.AbstractRegistrate; -import com.tterrag.registrate.fabric.RegistryObject; -import com.tterrag.registrate.fabric.RegistryUtil; import com.tterrag.registrate.providers.DataGenContext; import com.tterrag.registrate.providers.ProviderType; import com.tterrag.registrate.providers.RegistrateProvider; @@ -137,15 +135,6 @@ default S addMiscData(ProviderType t return (S) this; } - /** - * Add data map associated with this builder - */ - default S dataMap(DataMapType type, D val) { - getOwner().addDataGenerator(ProviderType.DATA_MAP, e -> e.builder(type) - .add(DataGenContext.from(this).getId(), val, false)); - return (S) this; - } - /** * Add a callback to be invoked when this entry is registered. Can be called multiple times to add multiple callbacks. *

@@ -216,7 +205,7 @@ default > S2 transform } /** - * Register the entry and return the parent object. The {@link net.neoforged.neoforge.registries.DeferredHolder} will be created but not returned. It can be retrieved later with {@link AbstractRegistrate#get(ResourceKey)} or + * Register the entry and return the parent object. The {@link com.tterrag.registrate.fabric.DeferredHolder} will be created but not returned. It can be retrieved later with {@link AbstractRegistrate#get(ResourceKey)} or * {@link AbstractRegistrate#get(String, ResourceKey)}. * * @return the parent object diff --git a/src/main/java/com/tterrag/registrate/builders/BuilderCallback.java b/src/main/java/com/tterrag/registrate/builders/BuilderCallback.java index 3dfbd4d9..5517fd20 100644 --- a/src/main/java/com/tterrag/registrate/builders/BuilderCallback.java +++ b/src/main/java/com/tterrag/registrate/builders/BuilderCallback.java @@ -1,8 +1,7 @@ package com.tterrag.registrate.builders; import com.tterrag.registrate.AbstractRegistrate; -import com.tterrag.registrate.fabric.RegistryObject; -import com.tterrag.registrate.fabric.RegistryUtil; +import com.tterrag.registrate.fabric.DeferredHolder; import com.tterrag.registrate.util.entry.RegistryEntry; import com.tterrag.registrate.util.nullness.NonNullFunction; import com.tterrag.registrate.util.nullness.NonNullSupplier; diff --git a/src/main/java/com/tterrag/registrate/builders/EntityBuilder.java b/src/main/java/com/tterrag/registrate/builders/EntityBuilder.java index 92e8f904..178ee42d 100644 --- a/src/main/java/com/tterrag/registrate/builders/EntityBuilder.java +++ b/src/main/java/com/tterrag/registrate/builders/EntityBuilder.java @@ -3,8 +3,8 @@ import java.util.function.Supplier; import com.tterrag.registrate.AbstractRegistrate; +import com.tterrag.registrate.fabric.DeferredHolder; import com.tterrag.registrate.fabric.EnvExecutor; -import com.tterrag.registrate.fabric.RegistryObject; import com.tterrag.registrate.mixin.accessor.SpawnPlacementsAccessor; import com.tterrag.registrate.providers.DataGenContext; import com.tterrag.registrate.providers.ProviderType; @@ -169,7 +169,7 @@ public EntityBuilder attributes(Supplier attrib * When called more than once */ @SuppressWarnings("unchecked") - public EntityBuilder spawnPlacement(SpawnPlacementType type, Heightmap.Types heightmap, SpawnPredicate predicate, RegisterSpawnPlacementsEvent.Operation operation) { + public EntityBuilder spawnPlacement(SpawnPlacementType type, Heightmap.Types heightmap, SpawnPredicate predicate) { if (spawnConfigured) { throw new IllegalStateException("Cannot configure spawn placement more than once"); } @@ -223,8 +223,7 @@ public EntityBuilder defaultSpawnEgg(int primaryColor, int secondaryColor) @SuppressWarnings({"unchecked" }) @Deprecated public ItemBuilder> spawnEgg(int primaryColor, int secondaryColor) { - var sup = asSupplier(); - return getOwner().item(this, getName() + "_spawn_egg", p -> new DeferredSpawnEggItem((Supplier>) (Supplier) sup, primaryColor, secondaryColor, p)).tab(CreativeModeTabs.SPAWN_EGGS) + return getOwner().item(this, getName() + "_spawn_egg", p -> new SpawnEggItem((EntityType) get().get(), primaryColor, secondaryColor, p)).tab(CreativeModeTabs.SPAWN_EGGS) .model((ctx, prov) -> prov.withExistingParent(ctx.getName(), ResourceLocation.withDefaultNamespace("item/template_spawn_egg"))); } diff --git a/src/main/java/com/tterrag/registrate/builders/FluidBuilder.java b/src/main/java/com/tterrag/registrate/builders/FluidBuilder.java index 9c19f676..53adf95c 100644 --- a/src/main/java/com/tterrag/registrate/builders/FluidBuilder.java +++ b/src/main/java/com/tterrag/registrate/builders/FluidBuilder.java @@ -4,7 +4,6 @@ import java.util.Arrays; import java.util.List; import java.util.Optional; -import java.util.function.Consumer; import java.util.function.Supplier; import java.util.function.ToIntFunction; @@ -13,18 +12,14 @@ import com.google.common.annotations.Beta; import com.google.common.base.Preconditions; import com.tterrag.registrate.AbstractRegistrate; +import com.tterrag.registrate.fabric.DeferredHolder; import com.tterrag.registrate.fabric.EnvExecutor; import com.tterrag.registrate.fabric.FluidHelper; -import com.tterrag.registrate.fabric.RegistryObject; import com.tterrag.registrate.fabric.SimpleFlowableFluid; import com.tterrag.registrate.providers.ProviderType; import com.tterrag.registrate.providers.RegistrateLangProvider; import com.tterrag.registrate.providers.RegistrateTagsProvider; -<<<<<<< HEAD -======= -import com.tterrag.registrate.util.OneTimeEventReceiver; import com.tterrag.registrate.util.RegistrateDistExecutor; ->>>>>>> upstream/1.21/dev import com.tterrag.registrate.util.entry.FluidEntry; import com.tterrag.registrate.util.entry.RegistryEntry; import com.tterrag.registrate.util.nullness.NonNullBiConsumer; @@ -33,6 +28,7 @@ import com.tterrag.registrate.util.nullness.NonNullFunction; import com.tterrag.registrate.util.nullness.NonNullSupplier; +import io.github.fabricators_of_create.porting_lib.common.util.Lazy; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; @@ -40,6 +36,7 @@ import net.fabricmc.fabric.api.client.render.fluid.v1.SimpleFluidRenderHandler; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributeHandler; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributes; +import net.minecraft.Util; import net.minecraft.client.renderer.RenderType; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; @@ -54,7 +51,6 @@ import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Fluid; -<<<<<<< HEAD import javax.annotation.Nullable; import java.util.ArrayList; @@ -66,26 +62,6 @@ public class FluidBuilder extends AbstractBuil /** * Create a new {@link FluidBuilder} and configure data. The created builder will use a default fluid class ({@link SimpleFlowableFluid.Flowing}). -======= -import net.neoforged.api.distmarker.Dist; -import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; -import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions; -import net.neoforged.neoforge.common.util.Lazy; -import net.neoforged.neoforge.fluids.BaseFlowingFluid; -import net.neoforged.neoforge.fluids.FluidType; -import net.neoforged.neoforge.registries.DeferredHolder; -import net.neoforged.neoforge.registries.NeoForgeRegistries; - -public class FluidBuilder extends AbstractBuilder> { - - @FunctionalInterface - public interface FluidTypeFactory { - FluidType create(FluidType.Properties properties, ResourceLocation stillTexture, ResourceLocation flowingTexture); - } - - /** - * Create a new {@link FluidBuilder} and configure data. The created builder will use a default ({@link FluidType}) and fluid class ({@link BaseFlowingFluid.Flowing}). ->>>>>>> upstream/1.21/dev * * @param

* Parent object type @@ -104,93 +80,8 @@ public interface FluidTypeFactory { * @return A new {@link FluidBuilder} with reasonable default data generators. * @see #create(AbstractRegistrate, Object, String, BuilderCallback, ResourceLocation, ResourceLocation, NonNullFunction) */ -<<<<<<< HEAD public static

FluidBuilder create(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, ResourceLocation stillTexture, ResourceLocation flowingTexture) { return create(owner, parent, name, callback, stillTexture, flowingTexture, SimpleFlowableFluid.Flowing::new); -======= - public static

FluidBuilder create(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, ResourceLocation stillTexture, ResourceLocation flowingTexture) { - return create(owner, parent, name, callback, stillTexture, flowingTexture, FluidBuilder::defaultFluidType, BaseFlowingFluid.Flowing::new); - } - - /** - * Create a new {@link FluidBuilder} and configure data. The created builder will use a default fluid class ({@link BaseFlowingFluid.Flowing}). - * - * @param

- * Parent object type - * @param owner - * The owning {@link AbstractRegistrate} object - * @param parent - * The parent object - * @param name - * Name of the entry being built - * @param callback - * A callback used to actually register the built entry - * @param stillTexture - * The texture to use for still fluids - * @param typeFactory - * A factory that creates the fluid type - * @param flowingTexture - * The texture to use for flowing fluids - * @return A new {@link FluidBuilder} with reasonable default data generators. - * @see #create(AbstractRegistrate, Object, String, BuilderCallback, ResourceLocation, ResourceLocation, FluidTypeFactory, NonNullFunction) - */ - public static

FluidBuilder create(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, ResourceLocation stillTexture, ResourceLocation flowingTexture, FluidTypeFactory typeFactory) { - return create(owner, parent, name, callback, stillTexture, flowingTexture, typeFactory, BaseFlowingFluid.Flowing::new); - } - - /** - * Create a new {@link FluidBuilder} and configure data. The created builder will use a default fluid class ({@link BaseFlowingFluid.Flowing}). - * - * @param

- * Parent object type - * @param owner - * The owning {@link AbstractRegistrate} object - * @param parent - * The parent object - * @param name - * Name of the entry being built - * @param callback - * A callback used to actually register the built entry - * @param stillTexture - * The texture to use for still fluids - * @param fluidType - * An existing and registered fluid type. - * @param flowingTexture - * The texture to use for flowing fluids - * @return A new {@link FluidBuilder} with reasonable default data generators. - * @see #create(AbstractRegistrate, Object, String, BuilderCallback, ResourceLocation, ResourceLocation, FluidTypeFactory, NonNullFunction) - */ - public static

FluidBuilder create(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, ResourceLocation stillTexture, ResourceLocation flowingTexture, NonNullSupplier fluidType) { - return create(owner, parent, name, callback, stillTexture, flowingTexture, fluidType, BaseFlowingFluid.Flowing::new); - } - - /** - * Create a new {@link FluidBuilder} and configure data. The created builder will use a default ({@link FluidType}) and fluid class ({@link BaseFlowingFluid.Flowing}). - * - * @param - * The type of the builder - * @param

- * Parent object type - * @param owner - * The owning {@link AbstractRegistrate} object - * @param parent - * The parent object - * @param name - * Name of the entry being built - * @param callback - * A callback used to actually register the built entry - * @param stillTexture - * The texture to use for still fluids - * @param flowingTexture - * The texture to use for flowing fluids - * @param fluidFactory - * A factory that creates the flowing fluid - * @return A new {@link FluidBuilder} with reasonable default data generators. - */ - public static FluidBuilder create(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, ResourceLocation stillTexture, ResourceLocation flowingTexture, - NonNullFunction fluidFactory) { - return create(owner, parent, name, callback, stillTexture, flowingTexture, FluidBuilder::defaultFluidType, fluidFactory); ->>>>>>> upstream/1.21/dev } /** @@ -199,11 +90,7 @@ public static FluidBuilder create(Abstract * The fluid will be assigned the following data: *

    *
  • The default translation (via {@link #defaultLang()})
  • -<<<<<<< HEAD *
  • A default {@link SimpleFlowableFluid.Source source fluid} (via {@link #defaultSource})
  • -======= - *
  • A default {@link BaseFlowingFluid.Source source fluid} (via {@link #defaultSource})
  • ->>>>>>> upstream/1.21/dev *
  • A default block for the fluid, with its own default blockstate and model that configure the particle texture (via {@link #defaultBlock()})
  • *
  • A default bucket item, that uses a simple generated item model with a texture of the same name as this fluid (via {@link #defaultBucket()})
  • *
@@ -228,70 +115,17 @@ public static FluidBuilder create(Abstract * A factory that creates the flowing fluid * @return A new {@link FluidBuilder} with reasonable default data generators. */ -<<<<<<< HEAD public static FluidBuilder create(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, ResourceLocation stillTexture, ResourceLocation flowingTexture, NonNullFunction fluidFactory) { FluidBuilder ret = new FluidBuilder<>(owner, parent, name, callback, stillTexture, flowingTexture, fluidFactory) -======= - public static FluidBuilder create(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, ResourceLocation stillTexture, ResourceLocation flowingTexture, - FluidTypeFactory typeFactory, NonNullFunction fluidFactory) { - FluidBuilder ret = new FluidBuilder<>(owner, parent, name, callback, stillTexture, flowingTexture, typeFactory, fluidFactory) ->>>>>>> upstream/1.21/dev .defaultLang().defaultSource().defaultBlock().defaultBucket(); return ret; } -<<<<<<< HEAD private final String sourceName, bucketName; private final ResourceLocation stillTexture, flowingTexture; private final NonNullFunction fluidFactory; -======= - /** - * Create a new {@link FluidBuilder} and configure data. Used in lieu of adding side-effects to constructor, so that alternate initialization strategies can be done in subclasses. - *

- * The fluid will be assigned the following data: - *

    - *
  • The default translation (via {@link #defaultLang()})
  • - *
  • A default {@link BaseFlowingFluid.Source source fluid} (via {@link #defaultSource})
  • - *
  • A default block for the fluid, with its own default blockstate and model that configure the particle texture (via {@link #defaultBlock()})
  • - *
  • A default bucket item, that uses a simple generated item model with a texture of the same name as this fluid (via {@link #defaultBucket()})
  • - *
- * - * @param - * The type of the builder - * @param

- * Parent object type - * @param owner - * The owning {@link AbstractRegistrate} object - * @param parent - * The parent object - * @param name - * Name of the entry being built - * @param callback - * A callback used to actually register the built entry - * @param stillTexture - * The texture to use for still fluids - * @param flowingTexture - * The texture to use for flowing fluids - * @param fluidType - * An existing and registered fluid type - * @param fluidFactory - * A factory that creates the flowing fluid - * @return A new {@link FluidBuilder} with reasonable default data generators. - */ - public static FluidBuilder create(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, ResourceLocation stillTexture, ResourceLocation flowingTexture, - NonNullSupplier fluidType, NonNullFunction fluidFactory) { - FluidBuilder ret = new FluidBuilder<>(owner, parent, name, callback, stillTexture, flowingTexture, fluidType, fluidFactory) - .defaultLang().defaultSource().defaultBlock().defaultBucket(); - return ret; - } - - private final String sourceName, bucketName; - - private final ResourceLocation stillTexture, flowingTexture; - private final NonNullFunction fluidFactory; ->>>>>>> upstream/1.21/dev @Nullable // has sane defaults private NonNullSupplier attributeHandler = null; @@ -300,8 +134,7 @@ public static FluidBuilder create(Abstract private Boolean defaultSource, defaultBlock, defaultBucket; private NonNullConsumer fluidProperties; - -<<<<<<< HEAD + private @Nullable Supplier> layer = null; @Nullable @@ -309,46 +142,15 @@ public static FluidBuilder create(Abstract private final List> tags = new ArrayList<>(); public FluidBuilder(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, ResourceLocation stillTexture, ResourceLocation flowingTexture, NonNullFunction fluidFactory) { -======= - private NonNullConsumer fluidProperties; - - private @Nullable Supplier> layer = null; - - private boolean registerType; - - @Nullable - private NonNullSupplier source; - private final List> tags = new ArrayList<>(); - - public FluidBuilder(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, ResourceLocation stillTexture, ResourceLocation flowingTexture, FluidTypeFactory typeFactory, NonNullFunction fluidFactory) { ->>>>>>> upstream/1.21/dev - super(owner, parent, "flowing_" + name, callback, Registries.FLUID); - this.sourceName = name; - this.bucketName = name + "_bucket"; - this.stillTexture = stillTexture; - this.flowingTexture = flowingTexture; - this.fluidFactory = fluidFactory; - - String bucketName = this.bucketName; - this.fluidProperties = p -> p.bucket(() -> owner.get(bucketName, Registries.ITEM).get()) -<<<<<<< HEAD -======= - .block(() -> owner.get(name, Registries.BLOCK).get()); - } - - public FluidBuilder(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, ResourceLocation stillTexture, ResourceLocation flowingTexture, NonNullSupplier fluidType, NonNullFunction fluidFactory) { super(owner, parent, "flowing_" + name, callback, Registries.FLUID); this.sourceName = name; this.bucketName = name + "_bucket"; this.stillTexture = stillTexture; this.flowingTexture = flowingTexture; this.fluidFactory = fluidFactory; - this.fluidType = fluidType; - this.registerType = false; // Don't register if we have a fluid from outside. String bucketName = this.bucketName; this.fluidProperties = p -> p.bucket(() -> owner.get(bucketName, Registries.ITEM).get()) ->>>>>>> upstream/1.21/dev .block(() -> owner.get(name, Registries.BLOCK).get()); } @@ -373,11 +175,7 @@ public FluidBuilder fluidAttributes(NonNullSupplier fluidProperties(NonNullConsumer cons) { -======= - public FluidBuilder fluidProperties(NonNullConsumer cons) { ->>>>>>> upstream/1.21/dev fluidProperties = fluidProperties.andThen(cons); return this; } @@ -403,18 +201,7 @@ public FluidBuilder lang(String name) { return lang(flowing -> FluidHelper.getDescriptionId(flowing.getSource()), name); } -<<<<<<< HEAD public FluidBuilder renderType(Supplier> layer) { -======= - - - @SuppressWarnings("deprecation") - public FluidBuilder renderType(Supplier> layer) { - RegistrateDistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { - Preconditions.checkArgument(RenderType.chunkBufferLayers().contains(layer.get().get()), "Invalid render type: " + layer); - }); - ->>>>>>> upstream/1.21/dev if (this.layer == null) { onRegister(this::registerRenderType); } @@ -423,27 +210,11 @@ public FluidBuilder renderType(Supplier> layer) { } protected void registerRenderType(T entry) { -<<<<<<< HEAD EnvExecutor.runWhenOn(EnvType.CLIENT, () -> () -> BlockRenderLayerMap.INSTANCE.putFluids(layer.get().get(), entry, getSource())); } /** * Create a standard {@link SimpleFlowableFluid.Source} for this fluid which will be built and registered along with this fluid. -======= - RegistrateDistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { - OneTimeEventReceiver.addModListener(getOwner(), FMLClientSetupEvent.class, $ -> { - if (this.layer != null) { - RenderType layer = this.layer.get().get(); - ItemBlockRenderTypes.setRenderLayer(entry, layer); - ItemBlockRenderTypes.setRenderLayer(getSource(), layer); - } - }); - }); - } - - /** - * Create a standard {@link BaseFlowingFluid.Source} for this fluid which will be built and registered along with this fluid. ->>>>>>> upstream/1.21/dev * * @return this {@link FluidBuilder} * @see #source(NonNullFunction) @@ -459,21 +230,13 @@ public FluidBuilder defaultSource() { } /** -<<<<<<< HEAD * Create a {@link SimpleFlowableFluid} for this fluid, which is created by the given factory, and which will be built and registered along with this fluid. -======= - * Create a {@link BaseFlowingFluid} for this fluid, which is created by the given factory, and which will be built and registered along with this fluid. ->>>>>>> upstream/1.21/dev * * @param factory * A factory for the fluid, which accepts the properties and returns a new fluid * @return this {@link FluidBuilder} */ -<<<<<<< HEAD public FluidBuilder source(NonNullFunction factory) { -======= - public FluidBuilder source(NonNullFunction factory) { ->>>>>>> upstream/1.21/dev this.defaultSource = false; this.source = NonNullSupplier.lazy(() -> factory.apply(makeProperties())); return this; @@ -518,29 +281,20 @@ public BlockBuilder> block(NonNull throw new IllegalStateException("Only one call to block/noBlock per builder allowed"); } this.defaultBlock = false; -<<<<<<< HEAD NonNullSupplier supplier = asSupplier(); - return getOwner().>block(this, sourceName, p -> factory.apply(supplier, p)) - .properties(p -> BlockBehaviour.Properties.copy(Blocks.WATER).noLootTable()) + return getOwner().>block(this, sourceName, p -> factory.apply(supplier.get(), p)) + .properties(p -> BlockBehaviour.Properties.ofLegacyCopy(Blocks.WATER).noLootTable()) // fabric: luminance is fluid-sensitive, can't do this easily. // default impl will try to get it from the fluid's block, thus causing a loop. // if you want to do this, override getLuminance in FluidVariantAttributeHandler //.properties(p -> p.lightLevel(blockState -> fluidType.get().getLightLevel())) -======= - final NonNullSupplier supplier = asSupplier(); - final var lightLevel = Lazy.of(() -> fluidType.get().getLightLevel()); - final ToIntFunction lightLevelInt = $ -> lightLevel.get(); - return getOwner().>block(this, sourceName, p -> factory.apply(supplier.get(), p)) - .properties(p -> BlockBehaviour.Properties.ofFullCopy(Blocks.WATER).noLootTable()) - .properties(p -> p.lightLevel(lightLevelInt)) ->>>>>>> upstream/1.21/dev .blockstate((ctx, prov) -> prov.simpleBlock(ctx.getEntry(), prov.models().getBuilder(sourceName) .texture("particle", stillTexture))); } @SuppressWarnings("unchecked") public BlockBuilder> block1(NonNullBiFunction factory) { - return block((supplier, settings) -> ((NonNullBiFunction) factory).apply(supplier.get(), settings)); + return block((t, settings) -> ((NonNullBiFunction) factory).apply(t, settings)); } @Beta @@ -586,29 +340,17 @@ public ItemBuilder> bucket() { * A factory for the bucket item, which accepts the fluid object supplier and properties and returns a new item * @return the {@link ItemBuilder} for the {@link BucketItem} */ -<<<<<<< HEAD public ItemBuilder> bucket(NonNullBiFunction factory) { -======= - public ItemBuilder> bucket(NonNullBiFunction factory) { ->>>>>>> upstream/1.21/dev if (this.defaultBucket == Boolean.FALSE) { throw new IllegalStateException("Only one call to bucket/noBucket per builder allowed"); } this.defaultBucket = false; -<<<<<<< HEAD NonNullSupplier source = this.source; -======= - NonNullSupplier source = this.source; ->>>>>>> upstream/1.21/dev // TODO: Can we find a way to circumvent this limitation? if (source == null) { throw new IllegalStateException("Cannot create a bucket before creating a source block"); } -<<<<<<< HEAD return getOwner().>item(this, bucketName, p -> ((NonNullBiFunction) factory).apply(this.source.get(), p)) -======= - return getOwner().>item(this, bucketName, p -> factory.apply(get().get(), p)) ->>>>>>> upstream/1.21/dev .properties(p -> p.craftRemainder(Items.BUCKET).stacksTo(1)) .model((ctx, prov) -> prov.generated(ctx::getEntry, ResourceLocation.fromNamespaceAndPath(getOwner().getModid(), "item/" + bucketName))); } @@ -653,53 +395,19 @@ public final FluidBuilder removeTag(TagKey... tags) { return this.removeTag(ProviderType.FLUID_TAGS, tags); } -<<<<<<< HEAD private SimpleFlowableFluid getSource() { NonNullSupplier source = this.source; -======= - private BaseFlowingFluid getSource() { - NonNullSupplier source = this.source; ->>>>>>> upstream/1.21/dev Preconditions.checkNotNull(source, "Fluid has no source block: " + sourceName); return source.get(); } -<<<<<<< HEAD private SimpleFlowableFluid.Properties makeProperties() { NonNullSupplier source = this.source; SimpleFlowableFluid.Properties ret = new SimpleFlowableFluid.Properties(source == null ? null : source::get, asSupplier()); -======= - private BaseFlowingFluid.Properties makeProperties() { - NonNullSupplier source = this.source; - BaseFlowingFluid.Properties ret = new BaseFlowingFluid.Properties(fluidType, source == null ? null : source::get, asSupplier()); ->>>>>>> upstream/1.21/dev fluidProperties.accept(ret); return ret; } - -<<<<<<< HEAD -======= - private FluidType.Properties makeTypeProperties() { - FluidType.Properties properties = FluidType.Properties.create(); - Optional> block = getOwner().getOptional(sourceName, Registries.BLOCK); - this.typeProperties.accept(properties); - - // Force the translation key after the user callback runs - // This is done because we need to remove the lang data generator if using the block key, - // and if it was possible to undo this change, it might result in the user translation getting - // silently lost, as there's no good way to check whether the translation key was changed. - // TODO improve this? - if (block.isPresent() && block.get().isBound()) { - properties.descriptionId(block.get().get().getDescriptionId()); - setData(ProviderType.LANG, NonNullBiConsumer.noop()); - } else { - properties.descriptionId(Util.makeDescriptionId("fluid", ResourceLocation.fromNamespaceAndPath(getOwner().getModid(), sourceName))); - } - - return properties; - } - ->>>>>>> upstream/1.21/dev + @Override protected T createEntry() { return fluidFactory.apply(makeProperties()); @@ -721,29 +429,17 @@ public FluidEntry register() { // Check the fluid has a type. if (this.attributeHandler != null) { // Register the type. -<<<<<<< HEAD onRegister(entry -> { FluidVariantAttributeHandler handler = attributeHandler.get(); FluidVariantAttributes.register(entry, handler); FluidVariantAttributes.register(getSource(), handler); }); -======= - if (this.registerType) { - getOwner().simple(this, this.sourceName, NeoForgeRegistries.Keys.FLUID_TYPES, this.fluidType); - } - } else { - throw new IllegalStateException("Fluid must have a type: " + getName()); ->>>>>>> upstream/1.21/dev } EnvExecutor.runWhenOn(EnvType.CLIENT, () -> () -> onRegister(this::registerDefaultRenderer)); if (defaultSource == Boolean.TRUE) { -<<<<<<< HEAD source(SimpleFlowableFluid.Source::new); -======= - source(BaseFlowingFluid.Source::new); ->>>>>>> upstream/1.21/dev } if (defaultBlock == Boolean.TRUE) { block().register(); @@ -752,11 +448,7 @@ public FluidEntry register() { bucket().register(); } -<<<<<<< HEAD NonNullSupplier source = this.source; -======= - NonNullSupplier source = this.source; ->>>>>>> upstream/1.21/dev if (source != null) { getCallback().accept(sourceName, Registries.FLUID, (FluidBuilder) this, source::get); } else { diff --git a/src/main/java/com/tterrag/registrate/builders/ItemBuilder.java b/src/main/java/com/tterrag/registrate/builders/ItemBuilder.java index 78b4c2e1..f22c2e29 100644 --- a/src/main/java/com/tterrag/registrate/builders/ItemBuilder.java +++ b/src/main/java/com/tterrag/registrate/builders/ItemBuilder.java @@ -6,10 +6,11 @@ import com.google.common.collect.Maps; import com.tterrag.registrate.AbstractRegistrate; +import com.tterrag.registrate.fabric.DeferredHolder; import com.tterrag.registrate.fabric.EnvExecutor; -import com.tterrag.registrate.fabric.RegistryObject; import com.tterrag.registrate.providers.*; import com.tterrag.registrate.util.CreativeModeTabModifier; +import com.tterrag.registrate.util.RegistrateDistExecutor; import com.tterrag.registrate.util.entry.ItemEntry; import com.tterrag.registrate.util.entry.RegistryEntry; import com.tterrag.registrate.util.nullness.NonNullBiConsumer; @@ -18,9 +19,8 @@ import com.tterrag.registrate.util.nullness.NonNullUnaryOperator; import net.fabricmc.api.EnvType; import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; -import net.fabricmc.fabric.api.item.v1.FabricItemSettings; -import net.minecraft.core.Registry; -import net.minecraft.core.registries.Registries; +import net.fabricmc.fabric.api.registry.CompostingChanceRegistry; +import net.fabricmc.fabric.api.registry.FuelRegistry; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; import net.minecraft.tags.TagKey; @@ -72,7 +72,7 @@ public static ItemBuilder create(AbstractRegistrate private final NonNullFunction factory; - private NonNullSupplier initialProperties = FabricItemSettings::new; + private NonNullSupplier initialProperties = Item.Properties::new; private NonNullFunction propertiesCallback = NonNullUnaryOperator.identity(); @Nullable @@ -266,7 +266,8 @@ public ItemBuilder recipe(NonNullBiConsumer, Regis * @param tick time in ticks for this item to burn in furnace. */ public ItemBuilder burnTime(int tick) { - return dataMap(NeoForgeDataMaps.FURNACE_FUELS, new FurnaceFuel(tick)); + FuelRegistry.INSTANCE.add(get().get(), tick); + return this; } /** @@ -274,36 +275,10 @@ public ItemBuilder burnTime(int tick) { * @param chance chance for composter to increase one level when composting this item. */ public ItemBuilder compostable(float chance) { - return dataMap(NeoForgeDataMaps.COMPOSTABLES, new Compostable(chance)); - } - - @Nullable - private NonNullSupplier> clientExtension; - - /** - * Register a client extension for this item. The {@link IClientItemExtensions} instance can be shared across many items. - * - * @param clientExtension - * The client extension to register for this item - * @return this {@link ItemBuilder} - */ - public ItemBuilder clientExtension(NonNullSupplier> clientExtension) { - if (this.clientExtension == null) { - RegistrateDistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> this::registerClientExtension); - } - this.clientExtension = clientExtension; + CompostingChanceRegistry.INSTANCE.add(get().get(), chance); return this; } - protected void registerClientExtension() { - OneTimeEventReceiver.addModListener(getOwner(), RegisterClientExtensionsEvent.class, e -> { - NonNullSupplier> clientExtension = this.clientExtension; - if (clientExtension != null) { - e.registerItem(clientExtension.get().get(), getEntry()); - } - }); - } - /** * Assign {@link TagKey}{@code s} to this item. Multiple calls will add additional tags. * diff --git a/src/main/java/com/tterrag/registrate/builders/MenuBuilder.java b/src/main/java/com/tterrag/registrate/builders/MenuBuilder.java index 3ec32a36..81b6e991 100644 --- a/src/main/java/com/tterrag/registrate/builders/MenuBuilder.java +++ b/src/main/java/com/tterrag/registrate/builders/MenuBuilder.java @@ -1,8 +1,8 @@ package com.tterrag.registrate.builders; import com.tterrag.registrate.AbstractRegistrate; +import com.tterrag.registrate.fabric.DeferredHolder; import com.tterrag.registrate.fabric.EnvExecutor; -import com.tterrag.registrate.fabric.RegistryObject; import com.tterrag.registrate.util.entry.MenuEntry; import com.tterrag.registrate.util.entry.RegistryEntry; import com.tterrag.registrate.util.nullness.NonNullSupplier; @@ -12,9 +12,7 @@ import net.minecraft.client.gui.screens.MenuScreens; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.MenuAccess; -import net.minecraft.core.Registry; import net.minecraft.core.registries.Registries; -import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; diff --git a/src/main/java/com/tterrag/registrate/fabric/BaseLangProvider.java b/src/main/java/com/tterrag/registrate/fabric/BaseLangProvider.java index e712b7ab..b61fc5fe 100644 --- a/src/main/java/com/tterrag/registrate/fabric/BaseLangProvider.java +++ b/src/main/java/com/tterrag/registrate/fabric/BaseLangProvider.java @@ -2,23 +2,25 @@ import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider; +import net.minecraft.core.HolderLookup; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.CompletableFuture; public class BaseLangProvider extends FabricLanguageProvider { private final Map entries = new HashMap<>(); - protected BaseLangProvider(FabricDataOutput output) { - super(output); + protected BaseLangProvider(FabricDataOutput output, CompletableFuture registryLookup) { + super(output, registryLookup); } - protected BaseLangProvider(FabricDataOutput output, String languageCode) { - super(output, languageCode); + protected BaseLangProvider(FabricDataOutput output, String languageCode, CompletableFuture registryLookup) { + super(output, languageCode, registryLookup); } @Override - public void generateTranslations(TranslationBuilder translationBuilder) { + public void generateTranslations(HolderLookup.Provider registryLookup, TranslationBuilder translationBuilder) { entries.forEach(translationBuilder::add); } diff --git a/src/main/java/com/tterrag/registrate/fabric/DeferredHolder.java b/src/main/java/com/tterrag/registrate/fabric/DeferredHolder.java new file mode 100644 index 00000000..249e0d42 --- /dev/null +++ b/src/main/java/com/tterrag/registrate/fabric/DeferredHolder.java @@ -0,0 +1,288 @@ +/* + * Copyright (c) NeoForged and contributors + * SPDX-License-Identifier: LGPL-2.1-only + */ + +package com.tterrag.registrate.fabric; + +import com.mojang.datafixers.util.Either; +import java.util.Locale; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.stream.Stream; + +import lombok.Getter; +import net.minecraft.core.Holder; +import net.minecraft.core.HolderOwner; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import org.jetbrains.annotations.Nullable; + +/** + * A Deferred Holder is a {@link Holder} that is constructed with only a ResourceKey. + * + *

It will be populated with the underlying Holder from the registry when available. + * + * @param The type of object being held by this DeferredHolder. + */ +public class DeferredHolder implements Holder, Supplier { + /** + * Creates a new DeferredHolder targeting the value with the specified name in the specified registry. + * + * @param The type of the target value. + * @param The registry type. + * @param registryKey The name of the registry the target value is a member of. + * @param valueName The name of the target value. + */ + public static DeferredHolder create(ResourceKey> registryKey, ResourceLocation valueName) { + return create(ResourceKey.create(registryKey, valueName)); + } + + /** + * Creates a new DeferredHolder targeting the value with the specified name in the specified registry. + * + * @param The registry type. + * @param registryName The name of the registry the target value is a member of. + * @param valueName The name of the target value. + */ + public static DeferredHolder create(ResourceLocation registryName, ResourceLocation valueName) { + return create(ResourceKey.createRegistryKey(registryName), valueName); + } + + /** + * Creates a new DeferredHolder targeting the specified value. + * + * @param The type of the target value. + * @param key The resource key of the target value. + */ + public static DeferredHolder create(ResourceKey key) { + return new DeferredHolder<>(key); + } + + /** + * The resource key of the target object. + * -- GETTER -- + * + * @return The ResourceKey of the object pointed to by this DeferredHolder. + + */ + @Getter + protected final ResourceKey key; + + /** + * The currently cached value. + */ + @Nullable + private Holder holder = null; + + /** + * Creates a new DeferredHolder with a ResourceKey. + * + *

Attempts to bind immediately if possible. + * + * @param key The resource key of the target object. + * @see #create(ResourceKey, ResourceLocation) + * @see #create(ResourceLocation, ResourceLocation) + * @see #create(ResourceKey) + */ + protected DeferredHolder(ResourceKey key) { + this.key = Objects.requireNonNull(key); + this.bind(false); + } + + /** + * Gets the object stored by this DeferredHolder, if this holder {@linkplain #isBound() is bound}. + * + * @throws IllegalStateException If the backing registry is unavailable. + * @throws NullPointerException If the underlying Holder has not been populated (the target object is not registered). + */ + @SuppressWarnings("unchecked") + @Override + public T value() { + bind(true); + if (this.holder == null) { + throw new NullPointerException("Trying to access unbound value: " + this.key); + } + + return (T) this.holder.value(); + } + + /** + * Gets the object stored by this DeferredHolder, if this holder {@linkplain #isBound() is bound}. + * + * @throws IllegalStateException If the backing registry is unavailable. + * @throws NullPointerException If the underlying Holder has not been populated (the target object is not registered). + */ + @Override + public T get() { + return this.value(); + } + + /** + * Returns an optional containing the target object, if {@link #isBound() bound}; otherwise {@linkplain Optional#empty() an empty optional}. + * + * @return an optional containing the target object, if {@link #isBound() bound}; otherwise {@linkplain Optional#empty() an empty optional} + */ + public Optional asOptional() { + return isBound() ? Optional.of(value()) : Optional.empty(); + } + + /** + * Returns the registry that this DeferredHolder is pointing at, or {@code null} if it doesn't exist. + * + * @return the registry that this DeferredHolder is pointing at, or {@code null} if it doesn't exist + */ + @Nullable + @SuppressWarnings("unchecked") + protected Registry getRegistry() { + return (Registry) BuiltInRegistries.REGISTRY.get(this.key.registry()); + } + + /** + * Binds this DeferredHolder to the underlying registry and target object. + * + *

Has no effect if already bound. + * + * @param throwOnMissingRegistry If true, an exception will be thrown if the registry is absent. + * @throws IllegalStateException If throwOnMissingRegistry is true and the backing registry is unavailable. + */ + protected final void bind(boolean throwOnMissingRegistry) { + if (this.holder != null) return; + + Registry registry = getRegistry(); + if (registry != null) { + this.holder = registry.getHolder(this.key).orElse(null); + } else if (throwOnMissingRegistry) { + throw new IllegalStateException("Registry not present for " + this + ": " + this.key.registry()); + } + } + + /** + * @return The ID of the object pointed to by this DeferredHolder. + */ + public ResourceLocation getId() { + return this.key.location(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + return obj instanceof Holder h && h.kind() == Kind.REFERENCE && (h.unwrapKey().isPresent() && h.unwrapKey().get() == this.key); + } + + @Override + public int hashCode() { + return this.key.hashCode(); + } + + @Override + public String toString() { + return String.format(Locale.ENGLISH, "DeferredHolder{%s}", this.key); + } + + /** + * {@return true if the underlying object is available} + * + *

If {@code true}, the underlying object was added to the registry, + * and {@link #value()} or {@link #get()} can be called. + */ + @Override + public boolean isBound() { + bind(false); + return this.holder != null && this.holder.isBound(); + } + + /** + * {@return true if the passed ResourceLocation is the same as the ID of the target object} + */ + @Override + public boolean is(ResourceLocation id) { + return id.equals(this.key.location()); + } + + /** + * {@return true if the passed ResourceKey is the same as this holder's resource key} + */ + @Override + public boolean is(ResourceKey key) { + return key == this.key; + } + + /** + * Evaluates the passed predicate against this holder's resource key. + * + * @return {@code true} if the filter matches {@linkplain #getKey() this DH's resource key} + */ + @Override + public boolean is(Predicate> filter) { + return filter.test(this.key); + } + + /** + * {@return true if this holder is a member of the passed tag} + */ + @Override + public boolean is(TagKey tag) { + bind(false); + return this.holder != null && this.holder.is(tag); + } + + /** + * {@return {@code true} if the {@code holder} is the same as this holder} + */ + @Override + @Deprecated + public boolean is(Holder holder) { + bind(false); + return this.holder != null && this.holder.is(holder); + } + + /** + * {@return all tags present on the underlying object} + * + *

If the underlying object is not {@linkplain #isBound() bound} yet, and empty stream is returned. + */ + @Override + public Stream> tags() { + bind(false); + return this.holder != null ? this.holder.tags() : Stream.empty(); + } + + /** + * Returns an {@link Either#left()} containing {@linkplain #getKey() the resource key of this holder}. + * + * @apiNote This method is implemented for {@link Holder} compatibility, but {@link #getKey()} should be preferred. + */ + @Override + public Either, R> unwrap() { + // Holder.Reference always returns the key, do the same here. + return Either.left(this.key); + } + + /** + * Returns the resource key of this holder. + * + * @return a present optional containing {@linkplain #getKey() the resource key of this holder} + * @apiNote This method is implemented for {@link Holder} compatibility, but {@link #getKey()} should be preferred. + */ + @Override + public Optional> unwrapKey() { + return Optional.of(this.key); + } + + @Override + public Kind kind() { + return Kind.REFERENCE; + } + + @Override + public boolean canSerializeIn(HolderOwner owner) { + bind(false); + return this.holder != null && this.holder.canSerializeIn(owner); + } +} \ No newline at end of file diff --git a/src/main/java/com/tterrag/registrate/fabric/FluidSpriteReloadListener.java b/src/main/java/com/tterrag/registrate/fabric/FluidSpriteReloadListener.java index 5d3dd487..6aa54ee2 100644 --- a/src/main/java/com/tterrag/registrate/fabric/FluidSpriteReloadListener.java +++ b/src/main/java/com/tterrag/registrate/fabric/FluidSpriteReloadListener.java @@ -18,7 +18,7 @@ import net.minecraft.world.inventory.InventoryMenu; public class FluidSpriteReloadListener implements IdentifiableResourceReloadListener, ResourceManagerReloadListener { - public static final ResourceLocation ID = new ResourceLocation("registrate", "fluid_sprites"); + public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath("registrate", "fluid_sprites"); public static final FluidSpriteReloadListener INSTANCE = new FluidSpriteReloadListener(); private final Multimap> callbacks = HashMultimap.create(); diff --git a/src/main/java/com/tterrag/registrate/fabric/RegistryObject.java b/src/main/java/com/tterrag/registrate/fabric/RegistryObject.java deleted file mode 100644 index 9502f667..00000000 --- a/src/main/java/com/tterrag/registrate/fabric/RegistryObject.java +++ /dev/null @@ -1,136 +0,0 @@ -package com.tterrag.registrate.fabric; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.Objects; -import java.util.Optional; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.function.Supplier; -import java.util.stream.Stream; - -import net.minecraft.core.Registry; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; - -public class RegistryObject implements Supplier { - private static RegistryObject EMPTY = new RegistryObject<>(); - - private final ResourceLocation id; - @Nullable - private T object; - - private RegistryObject() { - id = null; - } - - @SuppressWarnings("unchecked") - private RegistryObject(ResourceLocation id, Registry registry) { - Objects.requireNonNull(registry); - this.id = id; - object = (T) registry.get(this.id); - } - - public static RegistryObject of(ResourceLocation id, Registry registry) { - return new RegistryObject<>(id, registry); - } - - public static RegistryObject create(final ResourceLocation name, final ResourceLocation registryName, String modid) { - //noinspection unchecked - return new RegistryObject<>(name, (Registry) BuiltInRegistries.REGISTRY.get(registryName)); - } - - @SuppressWarnings("unchecked") - public static RegistryObject empty() { - return (RegistryObject) EMPTY; - } - - @Override - @NotNull - public T get() { - Objects.requireNonNull(object); - return object; - } - - public ResourceLocation getId() { - return id; - } - - @SuppressWarnings("unchecked") - public void updateReference(Registry registry) { - object = (T) registry.get(getId()); - } - - public boolean isPresent() { - return object != null; - } - - public void ifPresent(Consumer consumer) { - if (isPresent()) { - consumer.accept(get()); - } - } - - public Stream stream() { - return isPresent() ? Stream.of(get()) : Stream.of(); - } - - public RegistryObject filter(Predicate predicate) { - Objects.requireNonNull(predicate); - if (isPresent() && !predicate.test(get())) { - return empty(); - } - return this; - } - - public Optional map(Function mapper) { - Objects.requireNonNull(mapper); - if (isPresent()) { - return Optional.ofNullable(mapper.apply(get())); - } - return Optional.empty(); - } - - public Optional flatMap(Function> mapper) { - Objects.requireNonNull(mapper); - if (isPresent()) { - return Objects.requireNonNull(mapper.apply(get())); - } - return Optional.empty(); - } - - public Supplier lazyMap(Function mapper) { - Objects.requireNonNull(mapper); - return () -> isPresent() ? mapper.apply(get()) : null; - } - - public T orElse(T other) { - return isPresent() ? get() : other; - } - - public T orElseGet(Supplier other) { - return isPresent() ? get() : other.get(); - } - - public T orElseThrow(Supplier exceptionSupplier) throws X { - if (isPresent()) { - return get(); - } - throw exceptionSupplier.get(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj instanceof RegistryObject) { - return Objects.equals(((RegistryObject) obj).id, id); - } - return false; - } - - @Override - public int hashCode() { - return Objects.hashCode(id); - } -} diff --git a/src/main/java/com/tterrag/registrate/mixin/accessor/SpawnPlacementsAccessor.java b/src/main/java/com/tterrag/registrate/mixin/accessor/SpawnPlacementsAccessor.java index e6e77e7d..acd54668 100644 --- a/src/main/java/com/tterrag/registrate/mixin/accessor/SpawnPlacementsAccessor.java +++ b/src/main/java/com/tterrag/registrate/mixin/accessor/SpawnPlacementsAccessor.java @@ -1,5 +1,6 @@ package com.tterrag.registrate.mixin.accessor; +import net.minecraft.world.entity.SpawnPlacementType; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; @@ -11,7 +12,7 @@ @Mixin(SpawnPlacements.class) public interface SpawnPlacementsAccessor { @Invoker - static void callRegister(EntityType entityType, SpawnPlacements.Type type, Heightmap.Types types, SpawnPlacements.SpawnPredicate spawnPredicate) { + static void callRegister(EntityType entityType, SpawnPlacementType spawnPlacementType, Heightmap.Types heightmapType, SpawnPlacements.SpawnPredicate predicate) { throw new UnsupportedOperationException(); } } diff --git a/src/main/java/com/tterrag/registrate/providers/ProviderType.java b/src/main/java/com/tterrag/registrate/providers/ProviderType.java index fede8af4..50651c04 100644 --- a/src/main/java/com/tterrag/registrate/providers/ProviderType.java +++ b/src/main/java/com/tterrag/registrate/providers/ProviderType.java @@ -8,6 +8,7 @@ import com.tterrag.registrate.util.nullness.NonNullBiFunction; import com.tterrag.registrate.util.nullness.NonNullFunction; import com.tterrag.registrate.util.nullness.NonNullUnaryOperator; +import io.github.fabricators_of_create.porting_lib.data.ExistingFileHelper; import net.minecraft.core.HolderLookup; import net.minecraft.core.Registry; import net.minecraft.core.registries.Registries; @@ -18,6 +19,8 @@ import net.minecraft.world.level.material.Fluid; import org.jetbrains.annotations.NotNull; + +import javax.annotation.Nonnull; import java.util.concurrent.CompletableFuture; import java.util.function.Function; @@ -38,7 +41,6 @@ public interface ProviderType { // SERVER DATA ProviderType DYNAMIC = registerServerData("dynamic", RegistrateDatapackProvider::new); - ProviderType DATA_MAP = registerServerData("data_map", RegistrateDataMapProvider::new); ProviderType RECIPE = registerServerData("recipe", RegistrateRecipeProvider::new); ProviderType ADVANCEMENT = registerServerData("advancement", RegistrateAdvancementProvider::new); ProviderType LOOT = registerServerData("loot", RegistrateLootTableProvider::new); diff --git a/src/main/java/com/tterrag/registrate/providers/RegistrateAdvancementProvider.java b/src/main/java/com/tterrag/registrate/providers/RegistrateAdvancementProvider.java index 790cd257..4f33e12c 100644 --- a/src/main/java/com/tterrag/registrate/providers/RegistrateAdvancementProvider.java +++ b/src/main/java/com/tterrag/registrate/providers/RegistrateAdvancementProvider.java @@ -4,6 +4,7 @@ import java.util.HashSet; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; @@ -12,6 +13,8 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.tterrag.registrate.AbstractRegistrate; +import io.github.fabricators_of_create.porting_lib.conditions.ICondition; +import io.github.fabricators_of_create.porting_lib.conditions.WithConditions; import lombok.Getter; import lombok.extern.log4j.Log4j2; import net.fabricmc.api.EnvType; diff --git a/src/main/java/com/tterrag/registrate/providers/RegistrateBlockstateProvider.java b/src/main/java/com/tterrag/registrate/providers/RegistrateBlockstateProvider.java index a7879d5d..544a2ab4 100644 --- a/src/main/java/com/tterrag/registrate/providers/RegistrateBlockstateProvider.java +++ b/src/main/java/com/tterrag/registrate/providers/RegistrateBlockstateProvider.java @@ -6,9 +6,9 @@ import net.minecraft.world.level.block.Block; import io.github.fabricators_of_create.porting_lib.data.ExistingFileHelper; -import io.github.fabricators_of_create.porting_lib.models.generators.block.BlockStateProvider; -import io.github.fabricators_of_create.porting_lib.models.generators.block.MultiPartBlockStateBuilder; -import io.github.fabricators_of_create.porting_lib.models.generators.block.VariantBlockStateBuilder; +import io.github.fabricators_of_create.porting_lib.models.generators.BlockStateProvider; +import io.github.fabricators_of_create.porting_lib.models.generators.MultiPartBlockStateBuilder; +import io.github.fabricators_of_create.porting_lib.models.generators.VariantBlockStateBuilder; import net.fabricmc.api.EnvType; import java.util.Optional; diff --git a/src/main/java/com/tterrag/registrate/providers/RegistrateDataMapProvider.java b/src/main/java/com/tterrag/registrate/providers/RegistrateDataMapProvider.java deleted file mode 100644 index ba88eb96..00000000 --- a/src/main/java/com/tterrag/registrate/providers/RegistrateDataMapProvider.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.tterrag.registrate.providers; - -import com.tterrag.registrate.AbstractRegistrate; -import net.minecraft.core.HolderLookup; -import net.minecraft.data.PackOutput; -import net.neoforged.fml.LogicalSide; -import net.neoforged.neoforge.common.data.DataMapProvider; -import net.neoforged.neoforge.registries.datamaps.DataMapType; - -import java.util.concurrent.CompletableFuture; - -public class RegistrateDataMapProvider extends DataMapProvider implements RegistrateProvider { - - private final AbstractRegistrate parent; - - protected RegistrateDataMapProvider(AbstractRegistrate parent, PackOutput output, CompletableFuture pvd) { - super(output, pvd); - this.parent = parent; - } - - @Override - public LogicalSide getSide() { - return LogicalSide.SERVER; - } - - @Override - protected void gather() { - parent.genData(ProviderType.DATA_MAP, this); - } - -} diff --git a/src/main/java/com/tterrag/registrate/providers/RegistrateDataProvider.java b/src/main/java/com/tterrag/registrate/providers/RegistrateDataProvider.java index 1d2df453..45da2d50 100644 --- a/src/main/java/com/tterrag/registrate/providers/RegistrateDataProvider.java +++ b/src/main/java/com/tterrag/registrate/providers/RegistrateDataProvider.java @@ -6,6 +6,7 @@ import java.util.Map; import java.util.Optional; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import com.google.common.collect.BiMap; @@ -25,6 +26,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; +import net.minecraft.resources.ResourceKey; import org.jetbrains.annotations.Nullable; @Log4j2 diff --git a/src/main/java/com/tterrag/registrate/providers/RegistrateGenericProvider.java b/src/main/java/com/tterrag/registrate/providers/RegistrateGenericProvider.java index cbfc43fa..cf1b422a 100644 --- a/src/main/java/com/tterrag/registrate/providers/RegistrateGenericProvider.java +++ b/src/main/java/com/tterrag/registrate/providers/RegistrateGenericProvider.java @@ -1,13 +1,11 @@ package com.tterrag.registrate.providers; import com.tterrag.registrate.AbstractRegistrate; +import io.github.fabricators_of_create.porting_lib.data.ExistingFileHelper; import net.minecraft.core.HolderLookup; import net.minecraft.data.CachedOutput; import net.minecraft.data.DataProvider; import net.minecraft.data.PackOutput; -import net.neoforged.fml.LogicalSide; -import net.neoforged.neoforge.common.data.ExistingFileHelper; -import net.neoforged.neoforge.data.event.GatherDataEvent; import org.apache.commons.compress.utils.Lists; import org.jetbrains.annotations.ApiStatus; diff --git a/src/main/java/com/tterrag/registrate/providers/RegistrateItemModelProvider.java b/src/main/java/com/tterrag/registrate/providers/RegistrateItemModelProvider.java index 5805f3cd..628410c8 100644 --- a/src/main/java/com/tterrag/registrate/providers/RegistrateItemModelProvider.java +++ b/src/main/java/com/tterrag/registrate/providers/RegistrateItemModelProvider.java @@ -3,15 +3,15 @@ import com.tterrag.registrate.AbstractRegistrate; import com.tterrag.registrate.util.nullness.NonNullSupplier; +import io.github.fabricators_of_create.porting_lib.models.generators.ModelFile; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.ItemLike; import io.github.fabricators_of_create.porting_lib.data.ExistingFileHelper; -import io.github.fabricators_of_create.porting_lib.models.generators.ModelFile.UncheckedModelFile; -import io.github.fabricators_of_create.porting_lib.models.generators.item.ItemModelBuilder; -import io.github.fabricators_of_create.porting_lib.models.generators.item.ItemModelProvider; +import io.github.fabricators_of_create.porting_lib.models.generators.ItemModelBuilder; +import io.github.fabricators_of_create.porting_lib.models.generators.ItemModelProvider; import net.fabricmc.api.EnvType; public class RegistrateItemModelProvider extends ItemModelProvider implements RegistrateProvider { diff --git a/src/main/java/com/tterrag/registrate/providers/RegistrateLangProvider.java b/src/main/java/com/tterrag/registrate/providers/RegistrateLangProvider.java index c1682356..2f1ba8b2 100644 --- a/src/main/java/com/tterrag/registrate/providers/RegistrateLangProvider.java +++ b/src/main/java/com/tterrag/registrate/providers/RegistrateLangProvider.java @@ -10,6 +10,7 @@ import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; import net.fabricmc.api.EnvType; +import net.minecraft.core.HolderLookup; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.data.CachedOutput; @@ -38,8 +39,8 @@ public class RegistrateLangProvider extends BaseLangProvider implements RegistrateProvider { private static class AccessibleLanguageProvider extends BaseLangProvider { - public AccessibleLanguageProvider(FabricDataOutput output, String locale) { - super(output, locale); + public AccessibleLanguageProvider(FabricDataOutput output, String locale, CompletableFuture registryLookup) { + super(output, locale, registryLookup); } } @@ -47,10 +48,10 @@ public AccessibleLanguageProvider(FabricDataOutput output, String locale) { private final AccessibleLanguageProvider upsideDown; - public RegistrateLangProvider(AbstractRegistrate owner, FabricDataOutput packOutput) { - super(packOutput, "en_us"); + public RegistrateLangProvider(AbstractRegistrate owner, FabricDataOutput packOutput, CompletableFuture registryLookup) { + super(packOutput, "en_us", registryLookup); this.owner = owner; - this.upsideDown = new AccessibleLanguageProvider(packOutput, "en_ud"); + this.upsideDown = new AccessibleLanguageProvider(packOutput, "en_ud", registryLookup); } @Override @@ -64,9 +65,9 @@ public String getName() { } @Override - public void generateTranslations(TranslationBuilder translationBuilder) { + public void generateTranslations(HolderLookup.Provider registryLookup, TranslationBuilder translationBuilder) { owner.genData(ProviderType.LANG, this); - super.generateTranslations(translationBuilder); + super.generateTranslations(registryLookup, translationBuilder); } public static final String toEnglishName(String internalName) { @@ -208,14 +209,6 @@ public void add(ItemStack key, String name) { add(key.getDescriptionId(), name); } - public void addEnchantment(Supplier key, String name) { - add(key.get(), name); - } - - public void add(Enchantment key, String name) { - add(key.getDescriptionId(), name); - } - public void addEffect(Supplier key, String name) { add(key.get(), name); } diff --git a/src/main/java/com/tterrag/registrate/providers/RegistrateTagsProvider.java b/src/main/java/com/tterrag/registrate/providers/RegistrateTagsProvider.java index d6a88215..77a37875 100644 --- a/src/main/java/com/tterrag/registrate/providers/RegistrateTagsProvider.java +++ b/src/main/java/com/tterrag/registrate/providers/RegistrateTagsProvider.java @@ -11,6 +11,7 @@ import net.minecraft.core.HolderLookup; import net.minecraft.core.HolderLookup.Provider; import net.minecraft.core.Registry; +import net.minecraft.data.tags.TagsProvider; import net.minecraft.resources.ResourceKey; import net.minecraft.tags.TagKey; diff --git a/src/main/java/com/tterrag/registrate/providers/loot/RegistrateBlockLootTables.java b/src/main/java/com/tterrag/registrate/providers/loot/RegistrateBlockLootTables.java index c1e7eb42..08784267 100644 --- a/src/main/java/com/tterrag/registrate/providers/loot/RegistrateBlockLootTables.java +++ b/src/main/java/com/tterrag/registrate/providers/loot/RegistrateBlockLootTables.java @@ -7,9 +7,9 @@ import com.tterrag.registrate.AbstractRegistrate; import net.minecraft.core.HolderLookup; -import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; -import net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider; +import net.minecraft.core.registries.Registries; import net.minecraft.data.loot.BlockLootSubProvider; +import net.minecraft.data.loot.packs.VanillaBlockLoot; import net.minecraft.world.item.Item; import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.block.Block; @@ -20,12 +20,9 @@ import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; import net.minecraft.world.level.storage.loot.providers.number.NumberProvider; -import java.util.function.Consumer; import java.util.function.Supplier; import java.util.stream.Collectors; -import javax.annotation.Generated; - public class RegistrateBlockLootTables extends VanillaBlockLoot implements RegistrateLootTables { private final AbstractRegistrate parent; private final Consumer callback; @@ -41,11 +38,6 @@ public void generate() { callback.accept(this); } - @Override - protected Iterable getKnownBlocks() { - return parent.getAll(Registries.BLOCK).stream().map(Supplier::get).collect(Collectors.toList()); - } - public HolderLookup.Provider getRegistries() { return this.registries; } diff --git a/src/main/java/com/tterrag/registrate/providers/loot/RegistrateLootTableProvider.java b/src/main/java/com/tterrag/registrate/providers/loot/RegistrateLootTableProvider.java index 38814b79..6cb52467 100644 --- a/src/main/java/com/tterrag/registrate/providers/loot/RegistrateLootTableProvider.java +++ b/src/main/java/com/tterrag/registrate/providers/loot/RegistrateLootTableProvider.java @@ -4,6 +4,7 @@ import com.tterrag.registrate.AbstractRegistrate; import com.tterrag.registrate.fabric.CustomValidationLootProvider; import com.tterrag.registrate.fabric.NonNullTriFunction; +import com.tterrag.registrate.fabric.TriFunction; import com.tterrag.registrate.mixin.accessor.LootContextParamSetsAccessor; import com.tterrag.registrate.mixin.accessor.LootTableProviderAccessor; import com.tterrag.registrate.providers.ProviderType; @@ -12,6 +13,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; +import net.minecraft.data.PackOutput; import org.jetbrains.annotations.NotNull; import lombok.Getter; diff --git a/src/main/java/com/tterrag/registrate/util/entry/BlockEntityEntry.java b/src/main/java/com/tterrag/registrate/util/entry/BlockEntityEntry.java index d61661f0..c5ff3db1 100644 --- a/src/main/java/com/tterrag/registrate/util/entry/BlockEntityEntry.java +++ b/src/main/java/com/tterrag/registrate/util/entry/BlockEntityEntry.java @@ -4,13 +4,13 @@ import com.tterrag.registrate.AbstractRegistrate; +import com.tterrag.registrate.fabric.DeferredHolder; import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import com.tterrag.registrate.fabric.RegistryObject; import org.jetbrains.annotations.Nullable; public class BlockEntityEntry extends RegistryEntry, BlockEntityType> { diff --git a/src/main/java/com/tterrag/registrate/util/entry/BlockEntry.java b/src/main/java/com/tterrag/registrate/util/entry/BlockEntry.java index 7c5e2897..67224396 100644 --- a/src/main/java/com/tterrag/registrate/util/entry/BlockEntry.java +++ b/src/main/java/com/tterrag/registrate/util/entry/BlockEntry.java @@ -2,11 +2,10 @@ import com.tterrag.registrate.AbstractRegistrate; +import com.tterrag.registrate.fabric.DeferredHolder; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; -import com.tterrag.registrate.fabric.RegistryObject; - public class BlockEntry extends ItemProviderEntry { public BlockEntry(AbstractRegistrate owner, DeferredHolder delegate) { diff --git a/src/main/java/com/tterrag/registrate/util/entry/EntityEntry.java b/src/main/java/com/tterrag/registrate/util/entry/EntityEntry.java index 66ab5c67..eaf3181f 100644 --- a/src/main/java/com/tterrag/registrate/util/entry/EntityEntry.java +++ b/src/main/java/com/tterrag/registrate/util/entry/EntityEntry.java @@ -1,11 +1,11 @@ package com.tterrag.registrate.util.entry; import com.tterrag.registrate.AbstractRegistrate; +import com.tterrag.registrate.fabric.DeferredHolder; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.level.Level; -import com.tterrag.registrate.fabric.RegistryObject; import org.jetbrains.annotations.Nullable; public class EntityEntry extends RegistryEntry, EntityType> { diff --git a/src/main/java/com/tterrag/registrate/util/entry/FluidEntry.java b/src/main/java/com/tterrag/registrate/util/entry/FluidEntry.java index 9e18a40f..da1270b8 100644 --- a/src/main/java/com/tterrag/registrate/util/entry/FluidEntry.java +++ b/src/main/java/com/tterrag/registrate/util/entry/FluidEntry.java @@ -4,31 +4,16 @@ import java.util.function.Predicate; import com.tterrag.registrate.AbstractRegistrate; - -<<<<<<< HEAD -import net.minecraft.core.Registry; -import net.minecraft.core.registries.Registries; +import com.tterrag.registrate.fabric.DeferredHolder; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.material.Fluid; -import com.tterrag.registrate.fabric.RegistryObject; import com.tterrag.registrate.fabric.SimpleFlowableFluid; import org.jetbrains.annotations.Nullable; -public class FluidEntry extends RegistryEntry { -======= -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceKey; -import net.minecraft.world.item.Item; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.material.Fluid; -import net.neoforged.neoforge.fluids.BaseFlowingFluid; -import net.neoforged.neoforge.fluids.FluidType; -import net.neoforged.neoforge.registries.DeferredHolder; - -public class FluidEntry extends RegistryEntry { ->>>>>>> upstream/1.21/dev +public class FluidEntry extends RegistryEntry { private final @Nullable BlockEntry block; @@ -36,11 +21,7 @@ public FluidEntry(AbstractRegistrate owner, DeferredHolder delegate super(owner, delegate); BlockEntry block = null; try { -<<<<<<< HEAD - block = BlockEntry.cast(getSibling(Registries.BLOCK)); -======= block = BlockEntry.cast(getSibling(BuiltInRegistries.BLOCK)); ->>>>>>> upstream/1.21/dev } catch (IllegalArgumentException e) {} // TODO add way to get entry optionally this.block = block; } @@ -51,11 +32,7 @@ public boolean is(R entry) { } @SuppressWarnings("unchecked") -<<<<<<< HEAD public S getSource() { -======= - public S getSource() { ->>>>>>> upstream/1.21/dev return (S) get().getSource(); } @@ -65,7 +42,7 @@ public Optional getBlock() { } @Override - public RegistryEntry filter(Predicate predicate) { + public Optional> filter(Predicate predicate) { return super.filter(predicate); } diff --git a/src/main/java/com/tterrag/registrate/util/entry/ItemEntry.java b/src/main/java/com/tterrag/registrate/util/entry/ItemEntry.java index dcad72a3..cc3a3636 100644 --- a/src/main/java/com/tterrag/registrate/util/entry/ItemEntry.java +++ b/src/main/java/com/tterrag/registrate/util/entry/ItemEntry.java @@ -2,10 +2,9 @@ import com.tterrag.registrate.AbstractRegistrate; +import com.tterrag.registrate.fabric.DeferredHolder; import net.minecraft.world.item.Item; -import com.tterrag.registrate.fabric.RegistryObject; - public class ItemEntry extends ItemProviderEntry { public ItemEntry(AbstractRegistrate owner, DeferredHolder delegate) { diff --git a/src/main/java/com/tterrag/registrate/util/entry/ItemProviderEntry.java b/src/main/java/com/tterrag/registrate/util/entry/ItemProviderEntry.java index 4ed05297..f52e36c8 100644 --- a/src/main/java/com/tterrag/registrate/util/entry/ItemProviderEntry.java +++ b/src/main/java/com/tterrag/registrate/util/entry/ItemProviderEntry.java @@ -1,7 +1,7 @@ package com.tterrag.registrate.util.entry; import com.tterrag.registrate.AbstractRegistrate; -import com.tterrag.registrate.fabric.RegistryObject; +import com.tterrag.registrate.fabric.DeferredHolder; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; diff --git a/src/main/java/com/tterrag/registrate/util/entry/MenuEntry.java b/src/main/java/com/tterrag/registrate/util/entry/MenuEntry.java index 2bb6b76d..5e521e03 100644 --- a/src/main/java/com/tterrag/registrate/util/entry/MenuEntry.java +++ b/src/main/java/com/tterrag/registrate/util/entry/MenuEntry.java @@ -4,10 +4,10 @@ import com.tterrag.registrate.AbstractRegistrate; +import com.tterrag.registrate.fabric.DeferredHolder; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.SimpleMenuProvider; import net.minecraft.world.entity.player.Inventory; @@ -16,7 +16,6 @@ import net.minecraft.world.inventory.MenuConstructor; import net.minecraft.world.inventory.MenuType; -import com.tterrag.registrate.fabric.RegistryObject; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/com/tterrag/registrate/util/entry/RegistryEntry.java b/src/main/java/com/tterrag/registrate/util/entry/RegistryEntry.java index 07abd4ba..73e375a1 100644 --- a/src/main/java/com/tterrag/registrate/util/entry/RegistryEntry.java +++ b/src/main/java/com/tterrag/registrate/util/entry/RegistryEntry.java @@ -5,47 +5,21 @@ import java.util.function.Predicate; import com.tterrag.registrate.AbstractRegistrate; -import com.tterrag.registrate.fabric.RegistryObject; +import com.tterrag.registrate.fabric.DeferredHolder; import com.tterrag.registrate.util.nullness.NonNullSupplier; +import lombok.experimental.Delegate; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; -<<<<<<< HEAD import org.jetbrains.annotations.Nullable; -======= -import net.neoforged.neoforge.registries.DeferredHolder; ->>>>>>> upstream/1.21/dev /** - * Wraps a {@link net.neoforged.neoforge.registries.DeferredHolder}, providing a cleaner API with null-safe access, and registrate-specific extensions such as {@link #getSibling(ResourceKey)}. + * Wraps a {@link DeferredHolder}, providing a cleaner API with null-safe access, and registrate-specific extensions such as {@link #getSibling(ResourceKey)}. * * @param * The type of the entry */ -<<<<<<< HEAD -@EqualsAndHashCode(of = "delegate") -public class RegistryEntry implements NonNullSupplier { - - private static RegistryEntry EMPTY = new RegistryEntry(null, RegistryObject.empty()); - - public static RegistryEntry empty() { - @SuppressWarnings("unchecked") - RegistryEntry t = (RegistryEntry) EMPTY; - return t; - } - - private interface Exclusions { - - T get(); - - RegistryObject filter(Predicate predicate); - - public void updateReference(Registry registry); - } - -======= public class RegistryEntry extends DeferredHolder implements NonNullSupplier { ->>>>>>> upstream/1.21/dev private final AbstractRegistrate owner; @SuppressWarnings("unused") @@ -56,51 +30,7 @@ public RegistryEntry(AbstractRegistrate owner, DeferredHolder key) { throw new NullPointerException("Owner must not be null"); this.owner = owner; } - -<<<<<<< HEAD - /** - * Update the underlying entry manually from the given registry. - * - * @param registry - * The registry to pull the entry from. - */ - public void updateReference(Registry registry) { - RegistryObject delegate = this.delegate; - Objects.requireNonNull(delegate, "Registry entry is empty").updateReference(registry); - } - - /** - * Get the entry, throwing an exception if it is not present for any reason. - * - * @return The (non-null) entry - */ - @Override - public @NonnullType T get() { - RegistryObject delegate = this.delegate; - return Objects.requireNonNull(getUnchecked(), () -> delegate == null ? "Registry entry is empty" : "Registry entry not present: " + delegate.getId()); - } - - /** - * Get the entry without performing any checks. - * - * @return The (nullable) entry - */ - public @Nullable T getUnchecked() { - RegistryObject delegate = this.delegate; - return delegate == null ? null : delegate.orElse(null); - } - - public RegistryEntry getSibling(ResourceKey> registryType) { - return this == EMPTY ? empty() : owner.get(getId().getPath(), registryType); - } - - public RegistryEntry getSibling(Registry registry) { - return getSibling(registry.key()); - } - - /** - * If an entry is present, and the entry matches the given predicate, return an {@link RegistryEntry} describing the value, otherwise return an empty {@link RegistryEntry}. -======= + public RegistryEntry getSibling(ResourceKey> registryType) { return owner.get(getId().getPath(), registryType); } @@ -111,7 +41,6 @@ public RegistryEntry getSibling(Registry registry) { /** * If an entry is present, and the entry matches the given predicate, return an {@link Optional} describing the value, otherwise return an empty {@link Optional}. ->>>>>>> upstream/1.21/dev * * @param predicate * a {@link Predicate predicate} to apply to the entry, if present diff --git a/src/testmod/java/com/tterrag/registrate/test/mod/TestMod.java b/src/testmod/java/com/tterrag/registrate/test/mod/TestMod.java index 374bc53a..c31f2d7d 100644 --- a/src/testmod/java/com/tterrag/registrate/test/mod/TestMod.java +++ b/src/testmod/java/com/tterrag/registrate/test/mod/TestMod.java @@ -242,7 +242,7 @@ private static class TestCustomRegistryEntry {} .entity(TestEntity::new, MobCategory.CREATURE) .attributes(Pig::createAttributes) .renderer(() -> PigRenderer::new) - .spawnPlacement(SpawnPlacementTypes.ON_GROUND, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, Animal::checkAnimalSpawnRules, RegisterSpawnPlacementsEvent.Operation.OR) + .spawnPlacement(SpawnPlacementTypes.ON_GROUND, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, Animal::checkAnimalSpawnRules) .defaultSpawnEgg(0xFF0000, 0x00FF00) .loot((prov, type) -> prov.add(type, LootTable.lootTable() .withPool(LootPool.lootPool()