5/30/2023 0 Comments Chrome blocks minecraft forge"example_block_entity", () -> (ExampleBlockEntity::new, EXAMPLE_BLOCK.get()).build(null) Public static final RegistryObject> EXAMPLE_BLOCK_ENTITY = REGISTER.register( An example: ( REGISTER refers to a DeferredRegister) These factories are created through the use of their *Type$Builder classes. These *Type classes are factories that simply create the containing type on demand. For example, BlockEntity has BlockEntityType, and Entity has EntityType. Instead, *Type classes are registered, and used in the formers’ constructors. Some classes cannot by themselves be registered. The registry method and attaching to the mod event bus is the same as other DeferredRegisters. DeferredRegister#create has an overload which allows modders to specify the registry key of which vanilla registry to create a RegistryObject for. There are also dynamic registries, like ConfiguredFeature and some other worldgen registries, which are typically represented in JSON. These can be static registries, like LootItemConditionType, which are safe to use. Here is an example: (the event handler is registered on the mod event bus) void register(RegisterEvent event) Registries that aren’t Forge Registries It is recommended to use this method to avoid unnecessary object creation. There is an additional #register overload which takes in a consumed helper to register an object with a given name. Objects are registered using #register by passing in the registry key, the name of the registry object, and the object itself. This event is fired for each registry after the mod constructors and before the loading of configs. RegisterEvent is the second way to register objects. Public static final RegistryObject ROCK_BLOCK = BLOCKS.register("rock", () -> new Block((Material.STONE))) īLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus()) It simply maintains a list of suppliers for entries and registers the objects from those suppliers during RegisterEvent.Īn example of a mod registering a custom block: private static final DeferredRegister BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID) It allows the use and convenience of static initializers while avoiding the issues associated with it. DeferredRegisterĭeferredRegister is the recommended way to register objects. There are two proper ways to register objects: the DeferredRegister class, and the RegisterEvent lifecycle event. A Block and an Item may be registered with the same name example:thing without colliding however, if two different Blocks or Items were registered with the same exact name, the second object will override the first. For example, there’s a Block registry, and an Item registry. However, names in different registries will not collide. All registry names within a registry must be unique. To see all registries wrapped by Forge, see the ForgeRegistries class. This allows the ResourceLocation to act as the “registry name” for objects.Įvery type of registrable object has its own registry. Forge uses registries with ResourceLocation keys to register objects. A registry is an object similar to a map that assigns values to keys. Most things that require registration in the game are handled by the Forge registries. Registering things is important, as without registration the game will simply not know about these objects, which will cause unexplainable behaviors and crashes. Registration is the process of taking the objects of a mod (such as items, blocks, sounds, etc.) and making them known to the game.
0 Comments
Leave a Reply. |