类 ModifyDefaultComponentsEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.ModifyDefaultComponentsEvent
所有已实现的接口:
net.neoforged.fml.event.IModBusEvent

public final class ModifyDefaultComponentsEvent extends net.neoforged.bus.api.Event implements net.neoforged.fml.event.IModBusEvent
The event used to modify the default components of an item.
This event is fired on the mod event bus.

Example usage:

import net.minecraft.core.component.DataComponents;
import net.minecraft.world.item.Items;

public void modifyComponents(ModifyDefaultComponentsEvent event) {
   event.modify(Items.MELON_SEEDS, builder -> builder
        .set(DataComponents.MAX_STACK_SIZE, 16)); // Stack melon seeds to at most 16 items

   event.modify(Items.APPLE, builder -> builder
        .remove(DataComponents.FOOD)); // Remove the ability of eating apples
}

// Lowest priority listener
public void modifyComponentsLow(ModifyDefaultComponentsEvent event) {
   event.modifyMatching(item -> item.components().has(DataComponents.FIRE_RESISTANT), builder -> builder
        .set(DataComponents.ENCHANTMENT_GLINT_OVERRIDE, true)); // Make all fire resistant items have a glint
}
  • 构造器详细资料

    • ModifyDefaultComponentsEvent

      @Internal public ModifyDefaultComponentsEvent()
  • 方法详细资料

    • modify

      public void modify(ItemLike item, Consumer<DataComponentPatch.Builder> patch)
      Patches the default components of the given item.
      参数:
      item - the item to modify the default components for
      patch - the patch to apply
    • modifyMatching

      public void modifyMatching(Predicate<? super Item> predicate, Consumer<DataComponentPatch.Builder> patch)
      Patches the default components of all items matching the given predicate.

      If this method is used to modify components based on the item's current default components, the event listener should use the lowest priority so that other mods' modifications are already applied.

      参数:
      predicate - the item filter
      patch - the patch to apply
    • getAllItems

      public Stream<Item> getAllItems()
      返回 all registered items。
      返回:
      all registered items