Class VillagerTradesEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.village.VillagerTradesEvent

public class VillagerTradesEvent extends net.neoforged.bus.api.Event
VillagerTradesEvent is fired during reload by TagsUpdatedEvent. It is used to gather the trade lists for each profession. It is fired on the NeoForge.EVENT_BUS. It is fired once for each registered villager profession. Villagers pick two trades from their trade map, based on their level. Villager level is increased by successful trades. The map is populated for levels 1-5 (inclusive), so Map#get will never return null for those keys. Levels outside of this range do nothing, as specified by VillagerData.canLevelUp(int) which is called before attempting to level up. To add trades to the merchant, simply add new trades to the list. BasicItemListing provides a default implementation.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final net.minecraft.core.HolderLookup.Provider
     
    protected it.unimi.dsi.fastutil.ints.Int2ObjectMap<List<net.minecraft.world.entity.npc.VillagerTrades.ItemListing>>
     
    protected net.minecraft.resources.ResourceKey<net.minecraft.world.entity.npc.VillagerProfession>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    VillagerTradesEvent(it.unimi.dsi.fastutil.ints.Int2ObjectMap<List<net.minecraft.world.entity.npc.VillagerTrades.ItemListing>> trades, net.minecraft.resources.ResourceKey<net.minecraft.world.entity.npc.VillagerProfession> type, net.minecraft.core.HolderLookup.Provider registries)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    net.minecraft.core.HolderLookup.Provider
     
    it.unimi.dsi.fastutil.ints.Int2ObjectMap<List<net.minecraft.world.entity.npc.VillagerTrades.ItemListing>>
     
    net.minecraft.resources.ResourceKey<net.minecraft.world.entity.npc.VillagerProfession>
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • trades

      protected it.unimi.dsi.fastutil.ints.Int2ObjectMap<List<net.minecraft.world.entity.npc.VillagerTrades.ItemListing>> trades
    • type

      protected net.minecraft.resources.ResourceKey<net.minecraft.world.entity.npc.VillagerProfession> type
    • registries

      private final net.minecraft.core.HolderLookup.Provider registries
  • Constructor Details

    • VillagerTradesEvent

      @Internal public VillagerTradesEvent(it.unimi.dsi.fastutil.ints.Int2ObjectMap<List<net.minecraft.world.entity.npc.VillagerTrades.ItemListing>> trades, net.minecraft.resources.ResourceKey<net.minecraft.world.entity.npc.VillagerProfession> type, net.minecraft.core.HolderLookup.Provider registries)
  • Method Details

    • getTrades

      public it.unimi.dsi.fastutil.ints.Int2ObjectMap<List<net.minecraft.world.entity.npc.VillagerTrades.ItemListing>> getTrades()
    • getType

      public net.minecraft.resources.ResourceKey<net.minecraft.world.entity.npc.VillagerProfession> getType()
    • getRegistries

      public net.minecraft.core.HolderLookup.Provider getRegistries()