Search in sources :

Example 1 with RecruitmentInteraction

use of com.minecolonies.coremod.colony.interactionhandling.RecruitmentInteraction in project minecolonies by ldtteam.

the class TavernBuildingModule method spawnVisitor.

/**
 * Spawns a recruitable visitor citizen.
 */
private void spawnVisitor() {
    IVisitorData newCitizen = (IVisitorData) building.getColony().getVisitorManager().createAndRegisterCivilianData();
    externalCitizens.add(newCitizen.getId());
    newCitizen.setBedPos(building.getPosition());
    newCitizen.setHomeBuilding(building);
    int recruitLevel = building.getColony().getWorld().random.nextInt(10 * building.getBuildingLevel()) + 15;
    List<com.minecolonies.api.util.Tuple<Item, Integer>> recruitCosts = IColonyManager.getInstance().getCompatibilityManager().getRecruitmentCostsWeights();
    if (newCitizen.getName().contains("Ray")) {
        newCitizen.setRecruitCosts(new ItemStack(Items.BAKED_POTATO, 64));
    }
    newCitizen.getCitizenSkillHandler().init(recruitLevel);
    BlockPos spawnPos = BlockPosUtil.findSpawnPosAround(building.getColony().getWorld(), building.getPosition());
    if (spawnPos == null) {
        spawnPos = building.getPosition();
    }
    Tuple<Item, Integer> cost = recruitCosts.get(building.getColony().getWorld().random.nextInt(recruitCosts.size()));
    ItemStack boots = ItemStack.EMPTY;
    if (recruitLevel > LEATHER_SKILL_LEVEL) {
        // Leather
        boots = new ItemStack(Items.LEATHER_BOOTS);
    }
    if (recruitLevel > GOLD_SKILL_LEVEL) {
        // Gold
        boots = new ItemStack(Items.GOLDEN_BOOTS);
    }
    if (recruitLevel > IRON_SKILL_LEVEL) {
        if (cost.getB() <= 2) {
            cost = recruitCosts.get(building.getColony().getWorld().random.nextInt(recruitCosts.size()));
        }
        // Iron
        boots = new ItemStack(Items.IRON_BOOTS);
    }
    if (recruitLevel > DIAMOND_SKILL_LEVEL) {
        if (cost.getB() <= 3) {
            cost = recruitCosts.get(building.getColony().getWorld().random.nextInt(recruitCosts.size()));
        }
        // Diamond
        boots = new ItemStack(Items.DIAMOND_BOOTS);
    }
    newCitizen.setRecruitCosts(new ItemStack(cost.getA(), (int) (recruitLevel * 3.0 / cost.getB())));
    if (!CustomVisitorListener.chanceCustomVisitors(newCitizen)) {
        newCitizen.triggerInteraction(new RecruitmentInteraction(new TranslationTextComponent("com.minecolonies.coremod.gui.chat.recruitstory" + (building.getColony().getWorld().random.nextInt(MAX_STORY) + 1), newCitizen.getName().split(" ")[0]), ChatPriority.IMPORTANT));
    }
    building.getColony().getVisitorManager().spawnOrCreateCivilian(newCitizen, building.getColony().getWorld(), spawnPos, true);
    if (newCitizen.getEntity().isPresent()) {
        newCitizen.getEntity().get().setItemSlot(EquipmentSlotType.FEET, boots);
    }
    building.getColony().getEventDescriptionManager().addEventDescription(new VisitorSpawnedEvent(spawnPos, newCitizen.getName()));
}
Also used : VisitorSpawnedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.VisitorSpawnedEvent) Item(net.minecraft.item.Item) RecruitmentInteraction(com.minecolonies.coremod.colony.interactionhandling.RecruitmentInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Tuple(com.minecolonies.api.util.Tuple)

Example 2 with RecruitmentInteraction

use of com.minecolonies.coremod.colony.interactionhandling.RecruitmentInteraction 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 3 with RecruitmentInteraction

use of com.minecolonies.coremod.colony.interactionhandling.RecruitmentInteraction 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)

Example 4 with RecruitmentInteraction

use of com.minecolonies.coremod.colony.interactionhandling.RecruitmentInteraction in project minecolonies by Minecolonies.

the class TavernBuildingModule method spawnVisitor.

/**
 * Spawns a recruitable visitor citizen.
 */
private void spawnVisitor() {
    IVisitorData newCitizen = (IVisitorData) building.getColony().getVisitorManager().createAndRegisterCivilianData();
    externalCitizens.add(newCitizen.getId());
    newCitizen.setBedPos(building.getPosition());
    newCitizen.setHomeBuilding(building);
    int recruitLevel = building.getColony().getWorld().random.nextInt(10 * building.getBuildingLevel()) + 15;
    List<com.minecolonies.api.util.Tuple<Item, Integer>> recruitCosts = IColonyManager.getInstance().getCompatibilityManager().getRecruitmentCostsWeights();
    if (newCitizen.getName().contains("Ray")) {
        newCitizen.setRecruitCosts(new ItemStack(Items.BAKED_POTATO, 64));
    }
    newCitizen.getCitizenSkillHandler().init(recruitLevel);
    BlockPos spawnPos = BlockPosUtil.findSpawnPosAround(building.getColony().getWorld(), building.getPosition());
    if (spawnPos == null) {
        spawnPos = building.getPosition();
    }
    Tuple<Item, Integer> cost = recruitCosts.get(building.getColony().getWorld().random.nextInt(recruitCosts.size()));
    ItemStack boots = ItemStack.EMPTY;
    if (recruitLevel > LEATHER_SKILL_LEVEL) {
        // Leather
        boots = new ItemStack(Items.LEATHER_BOOTS);
    }
    if (recruitLevel > GOLD_SKILL_LEVEL) {
        // Gold
        boots = new ItemStack(Items.GOLDEN_BOOTS);
    }
    if (recruitLevel > IRON_SKILL_LEVEL) {
        if (cost.getB() <= 2) {
            cost = recruitCosts.get(building.getColony().getWorld().random.nextInt(recruitCosts.size()));
        }
        // Iron
        boots = new ItemStack(Items.IRON_BOOTS);
    }
    if (recruitLevel > DIAMOND_SKILL_LEVEL) {
        if (cost.getB() <= 3) {
            cost = recruitCosts.get(building.getColony().getWorld().random.nextInt(recruitCosts.size()));
        }
        // Diamond
        boots = new ItemStack(Items.DIAMOND_BOOTS);
    }
    newCitizen.setRecruitCosts(new ItemStack(cost.getA(), (int) (recruitLevel * 3.0 / cost.getB())));
    if (!CustomVisitorListener.chanceCustomVisitors(newCitizen)) {
        newCitizen.triggerInteraction(new RecruitmentInteraction(new TranslationTextComponent("com.minecolonies.coremod.gui.chat.recruitstory" + (building.getColony().getWorld().random.nextInt(MAX_STORY) + 1), newCitizen.getName().split(" ")[0]), ChatPriority.IMPORTANT));
    }
    building.getColony().getVisitorManager().spawnOrCreateCivilian(newCitizen, building.getColony().getWorld(), spawnPos, true);
    if (newCitizen.getEntity().isPresent()) {
        newCitizen.getEntity().get().setItemSlot(EquipmentSlotType.FEET, boots);
    }
    building.getColony().getEventDescriptionManager().addEventDescription(new VisitorSpawnedEvent(spawnPos, newCitizen.getName()));
}
Also used : VisitorSpawnedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.VisitorSpawnedEvent) Item(net.minecraft.item.Item) RecruitmentInteraction(com.minecolonies.coremod.colony.interactionhandling.RecruitmentInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Tuple(com.minecolonies.api.util.Tuple)

Aggregations

Tuple (com.minecolonies.api.util.Tuple)4 VisitorSpawnedEvent (com.minecolonies.coremod.colony.colonyEvents.citizenEvents.VisitorSpawnedEvent)4 RecruitmentInteraction (com.minecolonies.coremod.colony.interactionhandling.RecruitmentInteraction)4 Item (net.minecraft.item.Item)4 ItemStack (net.minecraft.item.ItemStack)4 BlockPos (net.minecraft.util.math.BlockPos)4 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)4 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)2 TavernBuildingModule (com.minecolonies.coremod.colony.buildings.modules.TavernBuildingModule)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 World (net.minecraft.world.World)2 ServerWorld (net.minecraft.world.server.ServerWorld)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2