Package net.neoforged.neoforge.event
Class ModifyDefaultComponentsEvent
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.ModifyDefaultComponentsEvent
- All Implemented Interfaces:
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
}
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns 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
.
-
Constructor Details
-
ModifyDefaultComponentsEvent
@Internal public ModifyDefaultComponentsEvent()
-
-
Method Details
-
modify
Patches the default components of the givenitem
.- Parameters:
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.- Parameters:
predicate
- the item filterpatch
- the patch to apply
-
getAllItems
Returns all registered items.- Returns:
- all registered items
-