Search in sources :

Example 1 with ZombieVillagerEntity

use of net.minecraft.entity.monster.ZombieVillagerEntity in project minecolonies by ldtteam.

the class EventHandler method onEntityConverted.

/**
 * Gets called when a Hoglin, Pig, Piglin, Villager, or ZombieVillager gets converted to something else.
 *
 * @param event the event to handle.
 */
@SubscribeEvent
public static void onEntityConverted(@NotNull final LivingConversionEvent.Pre event) {
    LivingEntity entity = event.getEntityLiving();
    if (entity instanceof ZombieVillagerEntity && event.getOutcome() == EntityType.VILLAGER) {
        final World world = entity.getCommandSenderWorld();
        final IColony colony = IColonyManager.getInstance().getIColony(world, entity.blockPosition());
        if (colony != null && colony.hasBuilding("tavern", 1, false)) {
            event.setCanceled(true);
            if (ForgeEventFactory.canLivingConvert(entity, ModEntities.VISITOR, null)) {
                IVisitorData visitorData = (IVisitorData) colony.getVisitorManager().createAndRegisterCivilianData();
                BlockPos tavernPos = colony.getBuildingManager().getRandomBuilding(b -> !b.getModules(TavernBuildingModule.class).isEmpty());
                IBuilding tavern = colony.getBuildingManager().getBuilding(tavernPos);
                visitorData.setHomeBuilding(tavern);
                visitorData.setBedPos(tavernPos);
                tavern.getModules(TavernBuildingModule.class).forEach(mod -> mod.getExternalCitizens().add(visitorData.getId()));
                int recruitLevel = world.random.nextInt(10 * tavern.getBuildingLevel()) + 15;
                List<com.minecolonies.api.util.Tuple<Item, Integer>> recruitCosts = IColonyManager.getInstance().getCompatibilityManager().getRecruitmentCostsWeights();
                visitorData.getCitizenSkillHandler().init(recruitLevel);
                colony.getVisitorManager().spawnOrCreateCivilian(visitorData, world, entity.blockPosition(), false);
                colony.getEventDescriptionManager().addEventDescription(new VisitorSpawnedEvent(entity.blockPosition(), visitorData.getName()));
                if (visitorData.getEntity().isPresent()) {
                    AbstractEntityCitizen visitorEntity = visitorData.getEntity().get();
                    for (EquipmentSlotType slotType : EquipmentSlotType.values()) {
                        ItemStack itemstack = entity.getItemBySlot(slotType);
                        if (slotType.getType() == EquipmentSlotType.Group.ARMOR && !itemstack.isEmpty()) {
                            visitorEntity.setItemSlot(slotType, itemstack);
                        }
                    }
                }
                if (!entity.isSilent()) {
                    world.levelEvent((PlayerEntity) null, 1027, entity.blockPosition(), 0);
                }
                entity.remove();
                Tuple<Item, Integer> cost = recruitCosts.get(world.random.nextInt(recruitCosts.size()));
                visitorData.setRecruitCosts(new ItemStack(cost.getA(), (int) (recruitLevel * 3.0 / cost.getB())));
                visitorData.triggerInteraction(new RecruitmentInteraction(new TranslationTextComponent("com.minecolonies.coremod.gui.chat.recruitstorycured", visitorData.getName().split(" ")[0]), ChatPriority.IMPORTANT));
            }
        }
    }
}
Also used : VisitorSpawnedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.VisitorSpawnedEvent) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) EquipmentSlotType(net.minecraft.inventory.EquipmentSlotType) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) World(net.minecraft.world.World) ClientWorld(net.minecraft.client.world.ClientWorld) ServerWorld(net.minecraft.world.server.ServerWorld) EntryPoint(com.minecolonies.coremod.commands.EntryPoint) LivingEntity(net.minecraft.entity.LivingEntity) Item(net.minecraft.item.Item) BlockItem(net.minecraft.item.BlockItem) RecruitmentInteraction(com.minecolonies.coremod.colony.interactionhandling.RecruitmentInteraction) ZombieVillagerEntity(net.minecraft.entity.monster.ZombieVillagerEntity) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) TavernBuildingModule(com.minecolonies.coremod.colony.buildings.modules.TavernBuildingModule) Tuple(com.minecolonies.api.util.Tuple) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with ZombieVillagerEntity

use of net.minecraft.entity.monster.ZombieVillagerEntity in project minecolonies by Minecolonies.

the class EventHandler method onEntityConverted.

/**
 * Gets called when a Hoglin, Pig, Piglin, Villager, or ZombieVillager gets converted to something else.
 *
 * @param event the event to handle.
 */
@SubscribeEvent
public static void onEntityConverted(@NotNull final LivingConversionEvent.Pre event) {
    LivingEntity entity = event.getEntityLiving();
    if (entity instanceof ZombieVillagerEntity && event.getOutcome() == EntityType.VILLAGER) {
        final World world = entity.getCommandSenderWorld();
        final IColony colony = IColonyManager.getInstance().getIColony(world, entity.blockPosition());
        if (colony != null && colony.hasBuilding("tavern", 1, false)) {
            event.setCanceled(true);
            if (ForgeEventFactory.canLivingConvert(entity, ModEntities.VISITOR, null)) {
                IVisitorData visitorData = (IVisitorData) colony.getVisitorManager().createAndRegisterCivilianData();
                BlockPos tavernPos = colony.getBuildingManager().getRandomBuilding(b -> !b.getModules(TavernBuildingModule.class).isEmpty());
                IBuilding tavern = colony.getBuildingManager().getBuilding(tavernPos);
                visitorData.setHomeBuilding(tavern);
                visitorData.setBedPos(tavernPos);
                tavern.getModules(TavernBuildingModule.class).forEach(mod -> mod.getExternalCitizens().add(visitorData.getId()));
                int recruitLevel = world.random.nextInt(10 * tavern.getBuildingLevel()) + 15;
                List<com.minecolonies.api.util.Tuple<Item, Integer>> recruitCosts = IColonyManager.getInstance().getCompatibilityManager().getRecruitmentCostsWeights();
                visitorData.getCitizenSkillHandler().init(recruitLevel);
                colony.getVisitorManager().spawnOrCreateCivilian(visitorData, world, entity.blockPosition(), false);
                colony.getEventDescriptionManager().addEventDescription(new VisitorSpawnedEvent(entity.blockPosition(), visitorData.getName()));
                if (visitorData.getEntity().isPresent()) {
                    AbstractEntityCitizen visitorEntity = visitorData.getEntity().get();
                    for (EquipmentSlotType slotType : EquipmentSlotType.values()) {
                        ItemStack itemstack = entity.getItemBySlot(slotType);
                        if (slotType.getType() == EquipmentSlotType.Group.ARMOR && !itemstack.isEmpty()) {
                            visitorEntity.setItemSlot(slotType, itemstack);
                        }
                    }
                }
                if (!entity.isSilent()) {
                    world.levelEvent((PlayerEntity) null, 1027, entity.blockPosition(), 0);
                }
                entity.remove();
                Tuple<Item, Integer> cost = recruitCosts.get(world.random.nextInt(recruitCosts.size()));
                visitorData.setRecruitCosts(new ItemStack(cost.getA(), (int) (recruitLevel * 3.0 / cost.getB())));
                visitorData.triggerInteraction(new RecruitmentInteraction(new TranslationTextComponent("com.minecolonies.coremod.gui.chat.recruitstorycured", visitorData.getName().split(" ")[0]), ChatPriority.IMPORTANT));
            }
        }
    }
}
Also used : VisitorSpawnedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.VisitorSpawnedEvent) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) EquipmentSlotType(net.minecraft.inventory.EquipmentSlotType) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) World(net.minecraft.world.World) ClientWorld(net.minecraft.client.world.ClientWorld) ServerWorld(net.minecraft.world.server.ServerWorld) EntryPoint(com.minecolonies.coremod.commands.EntryPoint) LivingEntity(net.minecraft.entity.LivingEntity) Item(net.minecraft.item.Item) BlockItem(net.minecraft.item.BlockItem) RecruitmentInteraction(com.minecolonies.coremod.colony.interactionhandling.RecruitmentInteraction) ZombieVillagerEntity(net.minecraft.entity.monster.ZombieVillagerEntity) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) TavernBuildingModule(com.minecolonies.coremod.colony.buildings.modules.TavernBuildingModule) Tuple(com.minecolonies.api.util.Tuple) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)2 Tuple (com.minecolonies.api.util.Tuple)2 TavernBuildingModule (com.minecolonies.coremod.colony.buildings.modules.TavernBuildingModule)2 VisitorSpawnedEvent (com.minecolonies.coremod.colony.colonyEvents.citizenEvents.VisitorSpawnedEvent)2 RecruitmentInteraction (com.minecolonies.coremod.colony.interactionhandling.RecruitmentInteraction)2 EntryPoint (com.minecolonies.coremod.commands.EntryPoint)2 ClientWorld (net.minecraft.client.world.ClientWorld)2 LivingEntity (net.minecraft.entity.LivingEntity)2 ZombieVillagerEntity (net.minecraft.entity.monster.ZombieVillagerEntity)2 EquipmentSlotType (net.minecraft.inventory.EquipmentSlotType)2 BlockItem (net.minecraft.item.BlockItem)2 Item (net.minecraft.item.Item)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2 World (net.minecraft.world.World)2 ServerWorld (net.minecraft.world.server.ServerWorld)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2