Jump to content

Recommended Posts

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 =

	 {

	 };
}

Posted

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.

Posted

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);
        

    }
}



 

Posted

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.

Posted

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

Posted

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.

Posted

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.

Posted

Post your full code, not just a snippet of it.

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.

Posted

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))
	 };
}

 

 

Posted

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.

Posted

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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