Buckets:
| package com.example.examplemod; | |
| import net.fabricmc.api.ModInitializer; | |
| import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; | |
| import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; | |
| import net.minecraft.block.Block; | |
| import net.minecraft.block.AbstractBlock; | |
| import net.minecraft.item.Item; | |
| import net.minecraft.item.ItemGroups; | |
| import net.minecraft.item.ItemStack; | |
| import net.minecraft.registry.Registries; | |
| import net.minecraft.registry.Registry; | |
| import net.minecraft.registry.RegistryKey; | |
| import net.minecraft.registry.RegistryKeys; | |
| import net.minecraft.util.Identifier; | |
| /** | |
| * Entry point. Registered in fabric.mod.json under "entrypoints" -> "main". | |
| * Works unchanged across 1.21.7 - 1.21.11; registry/item APIs have been | |
| * stable through this range. | |
| */ | |
| public class ExampleMod implements ModInitializer { | |
| public static final String MOD_ID = "examplemod"; | |
| // --- Item registration (key-first pattern, current best practice) --- | |
| public static final Item EXAMPLE_GEM = registerItem( | |
| "example_gem", | |
| settings -> new Item(settings) | |
| ); | |
| // --- Block registration --- | |
| public static final Block EXAMPLE_BLOCK = registerBlock( | |
| "example_block", | |
| settings -> new Block(settings), | |
| AbstractBlock.Settings.create().strength(4.0f).requiresTool() | |
| ); | |
| public void onInitialize() { | |
| // Add our gem to the "ingredients" creative tab | |
| ItemGroupEvents.modifyEntriesEvent(ItemGroups.INGREDIENTS).register(entries -> | |
| entries.add(EXAMPLE_GEM) | |
| ); | |
| // Add a BlockItem for our block so it shows up in the building blocks tab | |
| ItemGroupEvents.modifyEntriesEvent(ItemGroups.BUILDING_BLOCKS).register(entries -> | |
| entries.add(new ItemStack(EXAMPLE_BLOCK)) | |
| ); | |
| } | |
| private static Item registerItem(String path, java.util.function.Function<Item.Settings, Item> factory) { | |
| RegistryKey<Item> key = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(MOD_ID, path)); | |
| Item item = factory.apply(new Item.Settings().registryKey(key)); | |
| return Registry.register(Registries.ITEM, key, item); | |
| } | |
| private static Block registerBlock(String path, | |
| java.util.function.Function<AbstractBlock.Settings, Block> factory, | |
| AbstractBlock.Settings settings) { | |
| RegistryKey<Block> key = RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(MOD_ID, path)); | |
| Block block = factory.apply(settings.registryKey(key)); | |
| return Registry.register(Registries.BLOCK, key, block); | |
| } | |
| } | |
Xet Storage Details
- Size:
- 2.67 kB
- Xet hash:
- 200c5b7a0f8c7503ee2dc6faa91f01e249d7b911cd2d68f58e574b15e584eb09
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.