Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (โ‹ฎ) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I have figured out how to make a custom villagers, but I don't understand how trades work? I know how to make an ITradeList class but I don't understand how to continue.

ย 

What I have so far:

package orangeVillager61.MoDrops.villager;

import net.minecraft.entity.passive.EntityVillager.EmeraldForItems;
import net.minecraft.entity.passive.EntityVillager.ITradeList;
import net.minecraft.entity.passive.EntityVillager.ListItemForEmeralds;
import net.minecraft.entity.passive.EntityVillager.PriceInfo;
import net.minecraft.init.Items;
import orangeVillager61.MoDrops.items.MoDropsItems;

public class SaltTrader_trades {

 public static final ITradeList[] trades =

	 {

	 };
}

You need to create and register a

VillagerProfession

using

GameRegistry.register

. You can then create one or more

VillagerCareer

s for the

VillagerProfession

and use

VillagerCareer#addTrade

to add trades to each

VillagerCareer

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

As stated I know how to make custom villagers, I don't know how to put the trades in the ITradeList file. I have added my custom villager file below.

ย 

package orangeVillager61.MoDrops.villager;

import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.VillagerRegistry;
import net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerCareer;
import net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession;
import orangeVillager61.MoDrops.Config;


public class SaltTrader{

public static boolean enableSaltTrader = Config.enableSaltTrader;

protected static final VillagerRegistry.VillagerProfession PROFESSION = new VillagerRegistry.VillagerProfession("Salt Trader", "minecraft:textures/entity/villager/villager.png", "minecraft:textures/entity/villager/zombie_villager.png");
ย  ย  protected static final VillagerRegistry.VillagerCareer CAREER = new VillagerRegistry.VillagerCareer(PROFESSION, "Salt Trader").addTrade(1, SaltTrader_trades.trades[1]);
ย  ย  
ย  ย  public static void onInit(FMLInitializationEvent event){
ย  ย  ย  ย  VillagerRegistry.instance().register(PROFESSION);
ย  ย  ย  ย  

ย  ย  }
}



ย 

Your IDE can almost certainly tell you which classes implement

ITradeList

.

ย 

In IDEA, there's a small green circle with a down arrow in the side bar between the line numbers and code, clicking this brings up the implementations of that interface/method. Eclipse probably has something similar.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

This has nothing to do with arrays or anything.

Just call addTrade as much as you want with every trade.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team onย Patreon

  • Author

This has nothing to do with arrays or anything.

Just call addTrade as much as you want with every trade.

ย 

Ehm, how does one do that? Doesn't it want just one list?

This has nothing to do with arrays or anything.

Just call addTrade as much as you want with every trade.

ย 

Ehm, how does one do that? Doesn't it want one list?

ย 

VillagerRegistry.VillagerCareer#addTrade

is a vararg method, you can pass any number of

ITradeList

objects to it and Java will automatically wrap them in an array.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

new EmeraldForItems(MoDropsItems.salted_chicken_cooked, new PriceInfo(7, 10)),
			 new ListItemForEmeralds(MoDropsItems.raw_horse_meat, new PriceInfo(-6, -2))

ย 

This is my attempt for the trades. The EmeraldForItems trade doesn't appear at all ingame.

  • Author

package orangeVillager61.MoDrops.villager;

import net.minecraft.entity.passive.EntityVillager.EmeraldForItems;
import net.minecraft.entity.passive.EntityVillager.ITradeList;
import net.minecraft.entity.passive.EntityVillager.ListItemForEmeralds;
import net.minecraft.entity.passive.EntityVillager.PriceInfo;
import net.minecraft.init.Items;
import orangeVillager61.MoDrops.items.MoDropsItems;

public class SaltTrader_trades {

 public static final ITradeList[] trades =

	 {
			 new EmeraldForItems(MoDropsItems.salted_chicken_cooked, new PriceInfo(7, 10)),
			 new ListItemForEmeralds(MoDropsItems.raw_horse_meat, new PriceInfo(-6, -2))
	 };
}

ย 

ย 

You only call

VillagerCareer#addTrade

with

SaltTrader_trades.trades[1]

, the second value in the array. You need to add both trades, not just one of them.

ย 

There's no real need to store the trades in an array, you can simply create them inline when you call

VillagerCareer#addTrade

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

you can call add trade multiple times stop trying to be 'smart' and making this complicated

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team onย Patreon

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions โ†’ Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.