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));
}
}
}
}
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));
}
}
}
}
Aggregations