| Line 23: |
Line 23: |
| | An example of a mod registering a custom block: | | An example of a mod registering a custom block: |
| | | | |
| − | <syntaxhighlight lang="java">
| + | {{Template:Tabs/Code_Snippets |
| − | private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID); | + | |java=private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID); |
| | | | |
| − | public static final RegistryObject<Block> EXAMPLE_BLOCK = BLOCKS.register("example_block", () -> new Block(Block.Properties.create(Material.ROCK))); | + | public static final RegistryObject<Block> EXAMPLE_BLOCK = BLOCKS.register("example_block", () -> new Block(AbstractBlock.Properties.create(Material.ROCK))); |
| | | | |
| | public ExampleMod() { | | public ExampleMod() { |
| | BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus()); | | BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus()); |
| | } | | } |
| − | </syntaxhighlight> | + | |kotlin=private val BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID) |
| | + | |
| | + | val EXAMPLE_BLOCK: RegistryObject<Block> = BLOCKS.register("example_block") { Block(AbstractBlock.Properties.create(Material.ROCK)) } |
| | + | |
| | + | internal class ExampleMod { |
| | + | init { |
| | + | BLOCKS.register(FMLJavaModLoadingContext.get().modEventBus) |
| | + | } |
| | + | } |
| | + | |scala=object ExampleMod { |
| | + | private final val BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID) |
| | + | |
| | + | final val EXAMPLE_BLOCK = registerBlock("example_block", () => new Block(AbstractBlock.Properties.create(Material.ROCK))) |
| | + | } |
| | + | class ExampleMod { |
| | + | BLOCKS.register(FMLJavaModLoadingContext.get.getModEventBus) |
| | + | } |
| | + | |}} |
| | | | |
| | {{Tip|When using a <code>DeferredRegister</code> to register any object, the name inputted will be automatically prefixed with the mod id passed in, giving the above object a "registry name" of <code>examplemod:example_block</code>.}} | | {{Tip|When using a <code>DeferredRegister</code> to register any object, the name inputted will be automatically prefixed with the mod id passed in, giving the above object a "registry name" of <code>examplemod:example_block</code>.}} |