Skip to content

Commit

Permalink
remove recommendation of separate DR and DH classes
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabeHunger54 committed Feb 23, 2024
1 parent 7a24414 commit 55873a1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 5 deletions.
4 changes: 0 additions & 4 deletions docs/concepts/registries.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ public static final DeferredHolder<Block, Block> EXAMPLE_BLOCK = BLOCKS.register

The class `DeferredHolder<R, T extends R>` holds our object. The type parameter `R` is the type of the registry we are registering to (in our case `Block`). The type parameter `T` is the type of our supplier. Since we directly register a `Block` in this example, we provide `Block` as the second parameter. If we were to register an object of a subclass of `Block`, for example `SlabBlock`, we would provide `SlabBlock` here instead.

:::note
Some modders prefer to keep their `DeferredRegister`s in the same class as their registered objects. Others prefer keeping all `DeferredRegister`s in a separate class for readability. This is mostly a design decision, however if you decide to do the latter, make sure to classload the classes the objects are in, for example through an empty static method.
:::

`DeferredHolder<R, T extends R>` is a subclass of `Supplier<T>`. To get our registered object when we need it, we can call `DeferredHolder#get()`. The fact that `DeferredHolder` extends `Supplier` also allows us to use `Supplier` as the type of our field. That way, the above code block becomes the following:

```java
Expand Down
2 changes: 1 addition & 1 deletion docs/items/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static final Supplier<BlockItem> EXAMPLE_BLOCK_ITEM = ITEMS.registerSimpl
```

:::note
If you keep your blocks in a separate class, you should classload your blocks class before your items class.
If you keep your registered blocks in a separate class, you should classload your blocks class before your items class.
:::

### Resources
Expand Down

1 comment on commit 55873a1

@neoforged-pages-deployments
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploying with Cloudflare Pages

Name Result
Last commit: 55873a11245fe70f12daa07fd9c4520100b57e29
Status: ✅ Deploy successful!
Preview URL: https://c29c27b7.neoforged-docs-previews.pages.dev
PR Preview URL: https://pr-48.neoforged-docs-previews.pages.dev

Please sign in to comment.