-
Notifications
You must be signed in to change notification settings - Fork 0
Custom Villager Professions
This lib mod allows you to add new custom villager professions and also custom villager biome types.
To add a new villager profession you first needs to make a "Point Of Interest" also called POI. A POI iss
To make a custom POI you can do like this as an example:
public static PointOfInterestType TEST_POI = PointOfInterestRegistry.register("modid", new PointOfInterestTypeCustom("test_poi", PointOfInterestTypeCustom.getAllStatesOf(Blocks.BONE_BLOCK), 1, null, 1));
Then when you have created the new POI you can then make the main profession which could be like this as an example
public static VillagerProfession TEST_PROFESSION = VillagerProfessionRegistry.register(new Identifier("modid", "test"), TEST_POI , ImmutableSet.of(), ImmutableSet.of());
The different parameters for PointOfInterestRegistry is first a modid which would be used when registering it and then it would be a new instance of PointOfInterestTypeCustom which is a custom class we had to add because the vanilla one is private.
And the different parameters for VillagerProfessionRegistry is first an Identifier which would tell the modid the profession would be saved under and also the name for the profession, then it would take a PointOfInterestType which is where you can use the custom POI you made, then after that it takes an ImmutableSet of items that it can gather which in vanilla is mostly used for farmers, and lastly it takes an ImmutableSet of blocks which can be it's secondary job sites.
Example of how you can add custom trades for your new custom villager profession
TradeOffers.PROFESSION_TO_LEVELED_TRADE.put(ModVillagers.TEST_PROFESSION, TradeOfferFactories.TradingUtils.copyToFastUtilMap(
ImmutableMap.of(
1, new TradeOffers.Factory[]{
new TradeOfferFactories.BuyItemFactory(Items.RED_DYE, 18, 22, 2),
new TradeOfferFactories.BuyItemFactory(Items.GREEN_DYE, 18, 22, 2),
new TradeOfferFactories.BuyItemFactory(Items.PURPLE_DYE, 18, 22, 2),
new TradeOfferFactories.BuyItemFactory(Items.CYAN_DYE, 18, 22, 2),
new TradeOfferFactories.BuyItemFactory(Items.LIGHT_GRAY_DYE, 18, 22, 2),
new TradeOfferFactories.BuyItemFactory(Items.GRAY_DYE, 18, 22, 2)
},
2, new TradeOffers.Factory[]{
new TradeOfferFactories.SellItemFactory(Items.WHITE_BANNER, 3, 1, 15),
new TradeOfferFactories.SellItemFactory(Items.BLUE_BANNER, 3, 1, 15),
new TradeOfferFactories.SellItemFactory(Items.LIGHT_BLUE_BANNER, 3, 1, 15),
new TradeOfferFactories.SellItemFactory(Items.RED_BANNER, 3, 1, 15),
new TradeOfferFactories.SellItemFactory(Items.PINK_BANNER, 3, 1, 15),
new TradeOfferFactories.SellItemFactory(Items.GREEN_BANNER, 3, 1, 15)
}
)
));
In this demonstration I'll add a new profession called Baker. It will have some custom trades and also a custom profession block.
So, first we need to make the class that we will have everything in, I'll call it ModVillagers.java
public class ModVillagers {
public static void init() {
}
}
Now to add the custom POI for it, I have a null in the end since we don't have any custom sounds for it, so we just say play no sounds when working.
public class ModVillagers {
public static PointOfInterestType BAKER_POI;
public static void init() {
BAKER_POI = PointOfInterestRegistry.register("test_mod", new PointOfInterestTypeCustom("baker_poi", PointOfInterestTypeCustom.getAllStatesOf(Blocks.CRAFTING_TABLE), 1, null, 1));
}
}
Now we need to add a JSON for the POI which would go in data/"modid"/tags/blocks
and for us it would be called baker_poi.json
. It would look like
{
"replace": false,
"values": [
"minecraft:crafting_table"
]
}
Now that we have both the class and the POI we can actually add the profession since our bakes shouldn't be able to gather any items or have any secondary job sites we'll just return empty ImmutableSet's for them
public class ModVillagers {
public static PointOfInterestType BAKER_POI;
public static VillagerProfession BAKER;
public static void init() {
BAKER_POI = PointOfInterestRegistry.register("test_mod", new PointOfInterestTypeCustom("baker_poi", PointOfInterestTypeCustom.getAllStatesOf(Blocks.CRAFTING_TABLE), 1, null, 1));
BAKER = VillagerProfessionRegistry.register(new Identifier("test_mod", "baker"), BAKER_POI, ImmutableSet.of(), ImmutableSet.of());
}
}
Now that we have added both the POI and the profession we will give it some custom trades and for that we'll create a new class that we'll call CustomVillagerTrades.java
public class CustomVillagerTrades {
public static void init() {
}
}
Now to add the custom trades. We're making an ImmutableMap with a factory class for each of the trading levels, for this spesific one we're just having one level of new trades, they will cost 18 emeralds and you can trade them 22 times before the villager have to refill, you also get 2 experience for each trade.
public class CustomVillagerTrades {
public static void init() {
TradeOffers.PROFESSION_TO_LEVELED_TRADE.put(ModVillagers.BAKER, TradeOfferFactories.TradingUtils.copyToFastUtilMap(
ImmutableMap.of(
1, new TradeOffers.Factory[]{
new TradeOfferFactories.BuyItemFactory(Items.BREAD, 18, 22, 2),
new TradeOfferFactories.BuyItemFactory(Items.WHEAT, 18, 22, 2),
new TradeOfferFactories.BuyItemFactory(Items.PUMPKIN_PIE, 18, 22, 2),
new TradeOfferFactories.BuyItemFactory(Items.PUMPKIN_SEEDS, 18, 22, 2),
new TradeOfferFactories.BuyItemFactory(Items.RABBIT_STEW, 18, 22, 2)
}
)
));
}
}