Changes
From Forge Community Wiki
776 bytes added
, 16:37, 17 November 2021
Line 47:
Line 47:
class ExampleMod {
class ExampleMod {
BLOCKS.register(FMLJavaModLoadingContext.get.getModEventBus)
BLOCKS.register(FMLJavaModLoadingContext.get.getModEventBus)
+ }
+ |groovy=private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
+
+ public static final RegistryObject<Block> EXAMPLE_BLOCK = BLOCKS.register("example_block", () -> new Block(BlockBehaviour.Properties.of(Material.STONE)));
+
+ ExampleMod() {
+ BLOCKS.register(FMLJavaModLoadingContext.get().modEventBus);
}
}
|}}
|}}
Line 179:
Line 186:
|kotlin=val EXAMPLE_RECIPE: RecipeType<ExampleRecipe> = RecipeType.register("${MODID}:example_recipe")
|kotlin=val EXAMPLE_RECIPE: RecipeType<ExampleRecipe> = RecipeType.register("${MODID}:example_recipe")
|scala=final val EXAMPLE_RECIPE = RecipeType.register(s"${MODID}:example_recipe")
|scala=final val EXAMPLE_RECIPE = RecipeType.register(s"${MODID}:example_recipe")
+ |groovy=public static final RecipeType<ExampleRecipe> EXAMPLE_RECIPE = RecipeType.register("$MODID:example_recipe");
|}}
|}}
Line 403:
Line 411:
Here is an example: (the event handler is registered on the '''mod event bus''')
Here is an example: (the event handler is registered on the '''mod event bus''')
− <syntaxhighlight lang="Java">
+ {{Template:Tabs/Code_Snippets
− // This will ignore any missing test items from the specified world
+ |java =// This will ignore any missing test items from the specified world
@SubscribeEvent
@SubscribeEvent
− public void onMissingItems(RegistryEvent.MissingMappings<Item> event){
+ public void onMissingItems(final RegistryEvent.MissingMappings<Item> event) {
event.getMappings(MODID).stream()
event.getMappings(MODID).stream()
.filter(mapping -> mapping.key.getPath().contains("test"))
.filter(mapping -> mapping.key.getPath().contains("test"))
.forEach(Mapping::ignore);
.forEach(Mapping::ignore);
}
}
− </syntaxhighlight>
+ |groovy=// This will ignore any missing test items from the specified world
+ @SubscribeEvent
+ void onMissingItems(final RegistryEvent.MissingMappings <Item> event) {
+ event.getMappings(MODID).stream()
+ .filter(mapping - > mapping.key.path.contains("test"))
+ .forEach(Mapping::ignore);
+ }
+ |}}
[[Category:Common Concepts]]
[[Category:Common Concepts]]
Namespaces
Variants