- Версия(и) Minecraft
- 1.12.2
Для жителя понадобится:
2. Создаём класс VillagerRegister, отвечающий за регистрацию жителей
3. Вызываем метод регистрации жителей в Init
4. Кладём текстурки villager_example.png и villager_example_zombie.png в папку src/main/resources/assets/examplemod/textures/models/
Теперь в игре вызывая жителей яйцом мы имеем шанс наткнутся на свежесделанного жителя
- Текстурки обычного и зомби варианта
- Базовое понимание, как работать с forge, java и средой разработки
VillagerTrades.java:
public class VillagerTrades
{
public static class ItemstackForItemstack implements EntityVillager.ITradeList
{
public ItemStack buyingItem;
public ItemStack sellingItem;
public EntityVillager.PriceInfo buyAmounts;
public EntityVillager.PriceInfo sellAmounts;
// buyItem - покупаемое жителем, sellItem - продаваемое жителем, buyAmounts и sellAmounts - диапазоны количеств
public ItemstackForItemstack(@Nonnull ItemStack buyItem, @Nonnull ItemStack sellItem, @Nonnull EntityVillager.PriceInfo buyAmounts, @Nonnull EntityVillager.PriceInfo sellAmounts)
{
this.buyingItem = buyItem;
this.sellingItem = sellItem;
this.buyAmounts = buyAmounts;
this.sellAmounts = sellAmounts;
}
@Override
public void addMerchantRecipe(IMerchant merchant, MerchantRecipeList recipeList, Random random)
{
recipeList.add(new MerchantRecipe(addAmount(this.buyingItem, this.buyAmounts.getPrice(random)), addAmount(this.sellingItem, this.sellAmounts.getPrice(random))));
}
}
// Вспомогательный метод для добавления случайного количества к итему
public static ItemStack addAmount(ItemStack item, int amount)
{
ItemStack s2 = item.copy();
s2.setCount(amount);
return s2;
}
}
2. Создаём класс VillagerRegister, отвечающий за регистрацию жителей
VillagerRegister.java:
public class VillagerRegister {
public static VillagerRegistry.VillagerProfession PROF_EXAMPLE;
public static void registerVillagers() {
PROF_EXAMPLE = new VillagerRegistry.VillagerProfession(ExampleMod.MODID + ":example", ExampleMod.MODID + ":textures/models/villager_example.png", ExampleMod.MODID + ":textures/models/villager_example_zombie.png");
ForgeRegistries.VILLAGER_PROFESSIONS.register(PROF_EXAMPLE);
VillagerRegistry.VillagerCareer career_example = new VillagerRegistry.VillagerCareer(PROF_EXAMPLE, ExampleMod.MODID + ".example");
career_example.addTrade(1,
new VillagerTrades.ItemstackForItemstack(Items.DIAMOND, Items.EMERALD, new EntityVillager.PriceInfo(1, 2), new EntityVillager.PriceInfo(3, 4))
);
}
}
3. Вызываем метод регистрации жителей в Init
CommonProxy.java:
public void init(FMLInitializationEvent event)
{
VillagerRegister.registerVillagers();
}
4. Кладём текстурки villager_example.png и villager_example_zombie.png в папку src/main/resources/assets/examplemod/textures/models/
Теперь в игре вызывая жителей яйцом мы имеем шанс наткнутся на свежесделанного жителя