• Forums

Navigation

  • Home
  • Contributing to the Docs
  • Getting Started
    • Introduction
    • Structuring Your Mod
    • Versioning
  • Core Concepts
    • Registries
    • Sides
    • Events
    • Mod Lifecycle
    • Resources
    • Internationalization
  • Blocks
    • Introduction
    • Block States
  • Items
    • Introduction
      • Creating an Item
      • CreativeModeTabEvent
      • Registering an Item
    • BlockEntityWithoutLevelRenderer
  • Networking
    • Introduction
    • SimpleImpl
    • Synchronizing Entities
  • Block Entities
    • Introduction
    • BlockEntityRenderer
  • Game Effects
    • Particles
    • Sounds
  • Data Storage
    • Capabilities
    • Saved Data
    • Codecs
  • Graphical User Interfaces
    • Menus
    • Screens
  • Rendering
    • Model Loaders
      • Introduction
      • Baked Model
      • Transform
      • Item Overrides
  • Resources
    • Client Assets
      • Introduction
      • Models
        • Introduction
        • Texture Tinting
        • Item Properties
    • Server Data
      • Introduction
      • Recipes
        • Introduction
        • Custom Recipes
        • Ingredients
        • Non-Datapack Recipes
      • Loot Tables
      • Global Loot Modifiers
      • Tags
      • Advancements
      • Conditionally-Loaded Data
  • Data Generation
    • Introduction
    • Client Assets
      • Model Providers
      • Language Providers
      • Sound Providers
    • Server Data
      • Recipe Providers
      • Loot Table Providers
      • Tag Providers
      • Advancement Providers
      • Global Loot Modifier Providers
      • Datapack Registry Object Providers
  • Miscellaneous Features
    • Configuration
    • Key Mappings
    • Game Tests
    • Forge Update Checker
    • Debug Profiler
  • Advanced Topics
    • Access Transformers
  • Contributing to Forge
    • Introduction
    • Pull Request Guidelines
  • Legacy Versions
    • Introduction
    • Porting to This Version

Items

Along with blocks, items are a key component of most mods. While blocks make up the level around you, items exist within inventories.

Creating an Item

Basic Items

Basic items that need no special functionality (think sticks or sugar) do not need custom classes. You can create an item by instantiating the Item class with an Item$Properties object. This Item$Properties object can be made via the constructor and customized by calling its methods. For instance:

Method Description
requiredFeatures Sets the required FeatureFlags needed to see this item in the CreativeModeTab it is added to.
durability Sets the maximum damage value for this item. If it is over 0, two item properties “damaged” and “damage” are added.
stacksTo Sets the maximum stack size. You cannot have an item that is both damageable and stackable.
setNoRepair Makes this item impossible to repair, even if it is damageable.
craftRemainder Sets this item’s container item, the way that lava buckets give you back an empty bucket when they are used.

The above methods are chainable, meaning they return this to facilitate calling them in series.

Advanced Items

Setting the properties of an item as above only works for simple items. If you want more complicated items, you should subclass Item and override its methods.

CreativeModeTabEvent

An item can be added to a CreativeModeTab via CreativeModeTabEvent$BuildContents on the mod event bus. An item(s) can be added without any additional configurations via #accept.

// Registered on the MOD event bus
// Assume we have RegistryObject<Item> and RegistryObject<Block> called ITEM and BLOCK
@SubscribeEvent
public void buildContents(CreativeModeTabEvent.BuildContents event) {
  // Add to ingredients tab
  if (event.getTab() == CreativeModeTabs.INGREDIENTS) {
    event.accept(ITEM);
    event.accept(BLOCK); // Takes in an ItemLike, assumes block has registered item
  }
}

You can also enable or disable items being added through a FeatureFlag in the FeatureFlagSet or a boolean determining whether the player has permissions to see operator creative tabs.

Custom Creative Tabs

A custom CreativeModeTab can be created via CreativeModeTabEvent$Register#registerCreativeModeTab on the mod event bus. This takes in the name of the tab and a consumer of the builder. In addition, a list of ResourceLocations or CreativeModeTabs can be provided to determine where this tab should be located.

// Registered on the MOD event bus
// Assume we have RegistryObject<Item> and RegistryObject<Block> called ITEM and BLOCK
@SubscribeEvent
public void buildContents(CreativeModeTabEvent.Register event) {
  event.registerCreativeModeTab(new ResourceLocation(MOD_ID, "example"), builder ->
    // Set name of tab to display
    builder.title(Component.translatable("item_group." + MOD_ID + ".example"))
    // Set icon of creative tab
    .icon(() -> new ItemStack(ITEM.get()))
    // Add default items to tab
    .displayItems((enabledFlags, populator, hasPermissions) -> {
      populator.accept(ITEM.get());
      populator.accept(BLOCK.get());
    })
  );
}

Registering an Item

Items must be registered to function.

Built with MkDocs using a custom theme. Hosted by Read the Docs.
Enable Dark Theme