Class TradeOfferHelper

java.lang.Object
net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper

public final class TradeOfferHelper extends Object
Utilities to help with registration of trade offers.
  • Method Details Link icon

    • registerVillagerOffers Link icon

      public static void registerVillagerOffers(RegistryKey<VillagerProfession> profession, int level, Consumer<List<TradeOffers.Factory>> factories)
      Registers trade offer factories for use by villagers. This adds the same trade offers to current and rebalanced trades. To add separate offers for the rebalanced trade experiment, use
      invalid reference
      #registerVillagerOffers(VillagerProfession, int, VillagerOffersAdder)
      .

      Below is an example, of registering a trade offer factory to be added a blacksmith with a profession level of 3:

       TradeOfferHelper.registerVillagerOffers(VillagerProfession.BLACKSMITH, 3, factories -> {
              factories.add(new CustomTradeFactory(...);
       });
       
      Parameters:
      profession - the villager profession to assign the trades to
      level - the profession level the villager must be to offer the trades
      factories - a consumer to provide the factories
    • registerVillagerOffers Link icon

      @Experimental public static void registerVillagerOffers(RegistryKey<VillagerProfession> profession, int level, TradeOfferHelper.VillagerOffersAdder factories)
      Registers trade offer factories for use by villagers. This method allows separate offers to be added depending on whether the rebalanced trade experiment is enabled. If a particular profession's rebalanced trade offers are not added at all, it falls back to the regular trade offers.

      Below is an example, of registering a trade offer factory to be added a blacksmith with a profession level of 3:

       TradeOfferHelper.registerVillagerOffers(VillagerProfession.BLACKSMITH, 3, (factories, rebalanced) -> {
              factories.add(new CustomTradeFactory(...);
       });
       

      Experimental feature. This API may receive changes as necessary to adapt to further experiment changes.

      Parameters:
      profession - the villager profession to assign the trades to
      level - the profession level the villager must be to offer the trades
      factories - a consumer to provide the factories
    • registerWanderingTraderOffers Link icon

      public static void registerWanderingTraderOffers(int level, Consumer<List<TradeOffers.Factory>> factory)
      Registers trade offer factories for use by wandering trades. This does not add offers for the rebalanced trade experiment. To add rebalanced trades, use registerRebalancedWanderingTraderOffers(java.util.function.Consumer<net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper.WanderingTraderOffersBuilder>).
      Parameters:
      level - the level the trades
      factory - a consumer to provide the factories
    • registerRebalancedWanderingTraderOffers Link icon

      @Experimental public static void registerRebalancedWanderingTraderOffers(Consumer<TradeOfferHelper.WanderingTraderOffersBuilder> factory)
      Registers trade offer factories for use by wandering trades. This only adds offers for the rebalanced trade experiment. To add regular trades, use registerWanderingTraderOffers(int, Consumer).

      Experimental feature. This API may receive changes as necessary to adapt to further experiment changes.

      Parameters:
      factory - a consumer to add trade offers