Search in sources :

Example 1 with VillagerProfession

use of net.minecraft.world.entity.npc.VillagerProfession in project MyPet by xXKeyleXx.

the class EntityMyVillager method updateVisuals.

@Override
public void updateVisuals() {
    this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby());
    String professionKey = MyVillager.Profession.values()[getMyPet().getProfession()].getKey();
    VillagerProfession profession = Registry.VILLAGER_PROFESSION.get(new ResourceLocation(professionKey));
    // TODO
    VillagerType type = Registry.VILLAGER_TYPE.get(new ResourceLocation(getMyPet().getType().getKey()));
    this.getEntityData().set(PROFESSION_WATCHER, new VillagerData(type, profession, getMyPet().getVillagerLevel()));
}
Also used : VillagerType(net.minecraft.world.entity.npc.VillagerType) VillagerProfession(net.minecraft.world.entity.npc.VillagerProfession) ResourceLocation(net.minecraft.resources.ResourceLocation) VillagerData(net.minecraft.world.entity.npc.VillagerData)

Example 2 with VillagerProfession

use of net.minecraft.world.entity.npc.VillagerProfession in project MyPet by xXKeyleXx.

the class EntityMyVillager method updateVisuals.

@Override
public void updateVisuals() {
    this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby());
    String professionKey = MyVillager.Profession.values()[getMyPet().getProfession()].getKey();
    VillagerProfession profession = Registry.VILLAGER_PROFESSION.get(new ResourceLocation(professionKey));
    // TODO
    VillagerType type = Registry.VILLAGER_TYPE.get(new ResourceLocation(getMyPet().getType().getKey()));
    this.getEntityData().set(PROFESSION_WATCHER, new VillagerData(type, profession, getMyPet().getVillagerLevel()));
}
Also used : VillagerType(net.minecraft.world.entity.npc.VillagerType) VillagerProfession(net.minecraft.world.entity.npc.VillagerProfession) ResourceLocation(net.minecraft.resources.ResourceLocation) VillagerData(net.minecraft.world.entity.npc.VillagerData)

Example 3 with VillagerProfession

use of net.minecraft.world.entity.npc.VillagerProfession in project MinecraftForge by MinecraftForge.

the class VillagerTradingManager method postVillagerEvents.

/**
 * Posts a VillagerTradesEvent for each registered profession.
 */
private static void postVillagerEvents() {
    for (VillagerProfession prof : ForgeRegistries.PROFESSIONS) {
        Int2ObjectMap<ItemListing[]> trades = VANILLA_TRADES.getOrDefault(prof, new Int2ObjectOpenHashMap<>());
        Int2ObjectMap<List<ItemListing>> mutableTrades = new Int2ObjectOpenHashMap<>();
        for (int i = 1; i < 6; i++) {
            mutableTrades.put(i, NonNullList.create());
        }
        trades.int2ObjectEntrySet().forEach(e -> {
            Arrays.stream(e.getValue()).forEach(mutableTrades.get(e.getIntKey())::add);
        });
        MinecraftForge.EVENT_BUS.post(new VillagerTradesEvent(mutableTrades, prof));
        Int2ObjectMap<ItemListing[]> newTrades = new Int2ObjectOpenHashMap<>();
        mutableTrades.int2ObjectEntrySet().forEach(e -> newTrades.put(e.getIntKey(), e.getValue().toArray(new ItemListing[0])));
        VillagerTrades.TRADES.put(prof, newTrades);
    }
}
Also used : Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) VillagerProfession(net.minecraft.world.entity.npc.VillagerProfession) List(java.util.List) NonNullList(net.minecraft.core.NonNullList) VillagerTradesEvent(net.minecraftforge.event.village.VillagerTradesEvent)

Example 4 with VillagerProfession

use of net.minecraft.world.entity.npc.VillagerProfession in project MyPet by xXKeyleXx.

the class EntityMyZombieVillager method updateVisuals.

@Override
public void updateVisuals() {
    getEntityData().set(BABY_WATCHER, getMyPet().isBaby());
    String professionKey = MyVillager.Profession.values()[getMyPet().getProfession()].getKey();
    VillagerProfession profession = Registry.VILLAGER_PROFESSION.get(new ResourceLocation(professionKey));
    // TODO
    VillagerType type = Registry.VILLAGER_TYPE.get(new ResourceLocation(getMyPet().getType().getKey()));
    getEntityData().set(PROFESSION_WATCHER, new VillagerData(type, profession, getMyPet().getTradingLevel()));
    Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> {
        if (getMyPet().getStatus() == MyPet.PetState.Here) {
            for (EquipmentSlot slot : EquipmentSlot.values()) {
                setPetEquipment(slot, CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)));
            }
        }
    }, 5L);
}
Also used : VillagerType(net.minecraft.world.entity.npc.VillagerType) VillagerProfession(net.minecraft.world.entity.npc.VillagerProfession) ResourceLocation(net.minecraft.resources.ResourceLocation) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) VillagerData(net.minecraft.world.entity.npc.VillagerData)

Example 5 with VillagerProfession

use of net.minecraft.world.entity.npc.VillagerProfession in project MyPet by xXKeyleXx.

the class EntityMyZombieVillager method updateVisuals.

@Override
public void updateVisuals() {
    getEntityData().set(BABY_WATCHER, getMyPet().isBaby());
    String professionKey = MyVillager.Profession.values()[getMyPet().getProfession()].getKey();
    VillagerProfession profession = Registry.VILLAGER_PROFESSION.get(new ResourceLocation(professionKey));
    // TODO
    VillagerType type = Registry.VILLAGER_TYPE.get(new ResourceLocation(getMyPet().getType().getKey()));
    getEntityData().set(PROFESSION_WATCHER, new VillagerData(type, profession, getMyPet().getTradingLevel()));
    Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> {
        if (getMyPet().getStatus() == MyPet.PetState.Here) {
            for (EquipmentSlot slot : EquipmentSlot.values()) {
                setPetEquipment(slot, CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)));
            }
        }
    }, 5L);
}
Also used : VillagerType(net.minecraft.world.entity.npc.VillagerType) VillagerProfession(net.minecraft.world.entity.npc.VillagerProfession) ResourceLocation(net.minecraft.resources.ResourceLocation) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) VillagerData(net.minecraft.world.entity.npc.VillagerData)

Aggregations

VillagerProfession (net.minecraft.world.entity.npc.VillagerProfession)5 ResourceLocation (net.minecraft.resources.ResourceLocation)4 VillagerData (net.minecraft.world.entity.npc.VillagerData)4 VillagerType (net.minecraft.world.entity.npc.VillagerType)4 EquipmentSlot (de.Keyle.MyPet.api.entity.EquipmentSlot)2 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)1 List (java.util.List)1 NonNullList (net.minecraft.core.NonNullList)1 VillagerTradesEvent (net.minecraftforge.event.village.VillagerTradesEvent)1