Class ModifyDefaultComponentsEvent
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.ModifyDefaultComponentsEvent
- All Implemented Interfaces:
IModBusEvent
public final class ModifyDefaultComponentsEvent
extends net.neoforged.bus.api.Event
implements 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
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<Item, Consumer<DataComponentMap.Builder>> private final List<com.mojang.datafixers.util.Pair<Predicate<? super Item>, Consumer<DataComponentMap.Builder>>> -
Constructor Summary
ConstructorsConstructorDescriptionModifyDefaultComponentsEvent(Map<Item, Consumer<DataComponentMap.Builder>> modifiersByItem, List<com.mojang.datafixers.util.Pair<Predicate<? super Item>, Consumer<DataComponentMap.Builder>>> modifiersByPredicate) -
Method Summary
Modifier and TypeMethodDescriptionvoidmodify(ItemLike item, Consumer<DataComponentMap.Builder> patch) Patches the default components of the givenitem.voidmodifyMatching(Predicate<? super Item> predicate, Consumer<DataComponentMap.Builder> patch) Patches the default components of all items matching the givenpredicate.
-
Field Details
-
modifiersByItem
-
modifiersByPredicate
private final List<com.mojang.datafixers.util.Pair<Predicate<? super Item>, Consumer<DataComponentMap.Builder>>> modifiersByPredicate
-
-
Constructor Details
-
ModifyDefaultComponentsEvent
@Internal public ModifyDefaultComponentsEvent(Map<Item, Consumer<DataComponentMap.Builder>> modifiersByItem, List<com.mojang.datafixers.util.Pair<Predicate<? super Item>, Consumer<DataComponentMap.Builder>>> modifiersByPredicate)
-
-
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<DataComponentMap.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 priorityso that other mods' modifications are already applied.- Parameters:
predicate- the item filterpatch- the patch to apply
-