类 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
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
}
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明返回 all registered items。void
modify
(ItemLike item, Consumer<DataComponentPatch.Builder> patch) Patches the default components of the givenitem
.void
modifyMatching
(Predicate<? super Item> predicate, Consumer<DataComponentPatch.Builder> patch) Patches the default components of all items matching the givenpredicate
.
-
构造器详细资料
-
ModifyDefaultComponentsEvent
@Internal public ModifyDefaultComponentsEvent()
-
-
方法详细资料
-
modify
Patches the default components of the givenitem
.- 参数:
item
- the item to modify the default components forpatch
- 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 givenpredicate
.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 filterpatch
- the patch to apply
-
getAllItems
返回 all registered items。- 返回:
- all registered items
-