Search in sources :

Example 1 with DRUID_USE_POTIONS

use of com.minecolonies.api.research.util.ResearchConstants.DRUID_USE_POTIONS in project minecolonies by Minecolonies.

the class EntityAIDruid method atBuildingActions.

@Override
protected void atBuildingActions() {
    super.atBuildingActions();
    if (worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(DRUID_USE_POTIONS) > 0) {
        // Mistletoes and water bottles
        InventoryUtils.transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(getOwnBuilding(), item -> item.getItem() instanceof PotionItem, 32, worker.getInventoryCitizen());
        InventoryUtils.transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(getOwnBuilding(), item -> item.getItem() == ModItems.mistletoe, 32, worker.getInventoryCitizen());
        if (InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), item -> item.getItem() instanceof PotionItem) < 5) {
            checkIfRequestForItemExistOrCreateAsynch(PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER), 9, 1);
        }
        if (InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), item -> item.getItem() == ModItems.mistletoe) < 8) {
            checkIfRequestForItemExistOrCreateAsynch(new ItemStack(ModItems.mistletoe), 32, 8);
        }
    }
}
Also used : PotionItem(net.minecraft.item.PotionItem) AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) JobDruid(com.minecolonies.coremod.colony.jobs.JobDruid) MinecoloniesAdvancedPathNavigate(com.minecolonies.coremod.entity.pathfinding.MinecoloniesAdvancedPathNavigate) Potions(net.minecraft.potion.Potions) ArrowItem(net.minecraft.item.ArrowItem) ARCHER_USE_ARROWS(com.minecolonies.api.research.util.ResearchConstants.ARCHER_USE_ARROWS) Items(net.minecraft.item.Items) ItemStack(net.minecraft.item.ItemStack) PathJobWalkRandomEdge(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobWalkRandomEdge) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) InventoryUtils(com.minecolonies.api.util.InventoryUtils) ModItems(com.minecolonies.api.items.ModItems) NotNull(org.jetbrains.annotations.NotNull) DRUID_USE_POTIONS(com.minecolonies.api.research.util.ResearchConstants.DRUID_USE_POTIONS) PotionUtils(net.minecraft.potion.PotionUtils) PotionItem(net.minecraft.item.PotionItem) ItemStack(net.minecraft.item.ItemStack)

Example 2 with DRUID_USE_POTIONS

use of com.minecolonies.api.research.util.ResearchConstants.DRUID_USE_POTIONS in project minecolonies by Minecolonies.

the class DruidCombatAI method doAttack.

@Override
protected void doAttack(final LivingEntity target) {
    if (user.distanceToSqr(target) < RANGED_FLEE_SQDIST) {
        if (user.getRandom().nextInt(FLEE_CHANCE) == 0 && !((AbstractBuildingGuards) user.getCitizenData().getWorkBuilding()).getTask().equals(GuardTaskSetting.GUARD)) {
            user.getNavigation().moveAwayFromLivingEntity(target, getAttackDistance() / 2.0, getCombatMovementSpeed());
        }
    } else {
        user.getNavigation().stop();
    }
    user.swing(Hand.MAIN_HAND);
    final int level = user.getCitizenData().getCitizenSkillHandler().getLevel(ModGuardTypes.druid.getSecondarySkill());
    final int time = user.getCitizenData().getCitizenSkillHandler().getLevel(ModGuardTypes.druid.getPrimarySkill()) * 20;
    final float inaccuracy = 99f / level;
    final Effect effect;
    final ItemStack stack = new ItemStack(Items.SPLASH_POTION);
    boolean gotMaterial = false;
    BiPredicate<LivingEntity, Effect> predicate;
    if (user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(DRUID_USE_POTIONS) > 0 && InventoryUtils.hasItemInItemHandler(user.getInventoryCitizen(), item -> item.getItem() instanceof PotionItem) && InventoryUtils.hasItemInItemHandler(user.getInventoryCitizen(), item -> item.getItem() == ModItems.mistletoe)) {
        gotMaterial = true;
    }
    if (AbstractEntityAIGuard.isAttackableTarget(user, target)) {
        effect = ADVERSE_EFFECTS.get(user.getRandom().nextInt(gotMaterial ? 2 : 1));
        predicate = (entity, eff) -> AbstractEntityAIGuard.isAttackableTarget(user, entity);
    } else {
        effect = SUPPORT_EFFECTS.get(user.getRandom().nextInt(gotMaterial ? 4 : 1));
        predicate = (entity, eff) -> !AbstractEntityAIGuard.isAttackableTarget(user, entity);
    }
    PotionUtils.setCustomEffects(stack, Collections.singleton(new EffectInstance(effect, time, gotMaterial ? 2 : 0)));
    DruidPotionEntity.throwPotionAt(stack, target, user, user.getCommandSenderWorld(), POTION_VELOCITY, inaccuracy, predicate);
    if (gotMaterial) {
        InventoryUtils.removeStackFromItemHandler(user.getCitizenData().getInventory(), PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER), 1);
        InventoryUtils.removeStackFromItemHandler(user.getCitizenData().getInventory(), new ItemStack(ModItems.mistletoe), 1);
    }
    this.instantEffect = effect.isInstantenous();
    user.setItemInHand(Hand.MAIN_HAND, stack);
    user.getThreatTable().removeCurrentTarget();
    user.decreaseSaturationForContinuousAction();
    user.getCitizenExperienceHandler().addExperience(PER_POTION_XP);
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) PotionItem(net.minecraft.item.PotionItem) JobDruid(com.minecolonies.coremod.colony.jobs.JobDruid) PathJobCanSee(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobCanSee) PathingOptions(com.minecolonies.api.entity.pathfinding.PathingOptions) GuardConstants(com.minecolonies.api.util.constant.GuardConstants) PathJobMoveAwayFromLocation(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobMoveAwayFromLocation) PathJobMoveToLocation(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobMoveToLocation) ItemStack(net.minecraft.item.ItemStack) BiPredicate(java.util.function.BiPredicate) net.minecraft.potion(net.minecraft.potion) ImmutableList(com.google.common.collect.ImmutableList) Attributes(net.minecraft.entity.ai.attributes.Attributes) ModItems(com.minecolonies.api.items.ModItems) Hand(net.minecraft.util.Hand) DruidPotionEntity(com.minecolonies.coremod.entity.DruidPotionEntity) AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) MinecoloniesAdvancedPathNavigate(com.minecolonies.coremod.entity.pathfinding.MinecoloniesAdvancedPathNavigate) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Skill(com.minecolonies.api.entity.citizen.Skill) IThreatTableEntity(com.minecolonies.api.entity.combat.threat.IThreatTableEntity) LivingEntity(net.minecraft.entity.LivingEntity) AttackMoveAI(com.minecolonies.coremod.entity.ai.combat.AttackMoveAI) ModGuardTypes(com.minecolonies.api.colony.guardtype.registry.ModGuardTypes) GuardTaskSetting(com.minecolonies.coremod.colony.buildings.modules.settings.GuardTaskSetting) Items(net.minecraft.item.Items) BlockPosUtil(com.minecolonies.api.util.BlockPosUtil) ITickRateStateMachine(com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.ITickRateStateMachine) List(java.util.List) PathResult(com.minecolonies.api.entity.pathfinding.PathResult) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) InventoryUtils(com.minecolonies.api.util.InventoryUtils) AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) AbstractPathJob(com.minecolonies.coremod.entity.pathfinding.pathjobs.AbstractPathJob) Collections(java.util.Collections) DRUID_USE_POTIONS(com.minecolonies.api.research.util.ResearchConstants.DRUID_USE_POTIONS) SPEED_LEVEL_BONUS(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIFight.SPEED_LEVEL_BONUS) PotionItem(net.minecraft.item.PotionItem) ItemStack(net.minecraft.item.ItemStack)

Example 3 with DRUID_USE_POTIONS

use of com.minecolonies.api.research.util.ResearchConstants.DRUID_USE_POTIONS in project minecolonies by ldtteam.

the class DruidCombatAI method doAttack.

@Override
protected void doAttack(final LivingEntity target) {
    if (user.distanceToSqr(target) < RANGED_FLEE_SQDIST) {
        if (user.getRandom().nextInt(FLEE_CHANCE) == 0 && !((AbstractBuildingGuards) user.getCitizenData().getWorkBuilding()).getTask().equals(GuardTaskSetting.GUARD)) {
            user.getNavigation().moveAwayFromLivingEntity(target, getAttackDistance() / 2.0, getCombatMovementSpeed());
        }
    } else {
        user.getNavigation().stop();
    }
    user.swing(Hand.MAIN_HAND);
    final int level = user.getCitizenData().getCitizenSkillHandler().getLevel(ModGuardTypes.druid.getSecondarySkill());
    final int time = user.getCitizenData().getCitizenSkillHandler().getLevel(ModGuardTypes.druid.getPrimarySkill()) * 20;
    final float inaccuracy = 99f / level;
    final Effect effect;
    final ItemStack stack = new ItemStack(Items.SPLASH_POTION);
    boolean gotMaterial = false;
    BiPredicate<LivingEntity, Effect> predicate;
    if (user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(DRUID_USE_POTIONS) > 0 && InventoryUtils.hasItemInItemHandler(user.getInventoryCitizen(), item -> item.getItem() instanceof PotionItem) && InventoryUtils.hasItemInItemHandler(user.getInventoryCitizen(), item -> item.getItem() == ModItems.mistletoe)) {
        gotMaterial = true;
    }
    if (AbstractEntityAIGuard.isAttackableTarget(user, target)) {
        effect = ADVERSE_EFFECTS.get(user.getRandom().nextInt(gotMaterial ? 2 : 1));
        predicate = (entity, eff) -> AbstractEntityAIGuard.isAttackableTarget(user, entity);
    } else {
        effect = SUPPORT_EFFECTS.get(user.getRandom().nextInt(gotMaterial ? 4 : 1));
        predicate = (entity, eff) -> !AbstractEntityAIGuard.isAttackableTarget(user, entity);
    }
    PotionUtils.setCustomEffects(stack, Collections.singleton(new EffectInstance(effect, time, gotMaterial ? 2 : 0)));
    DruidPotionEntity.throwPotionAt(stack, target, user, user.getCommandSenderWorld(), POTION_VELOCITY, inaccuracy, predicate);
    if (gotMaterial) {
        InventoryUtils.removeStackFromItemHandler(user.getCitizenData().getInventory(), PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER), 1);
        InventoryUtils.removeStackFromItemHandler(user.getCitizenData().getInventory(), new ItemStack(ModItems.mistletoe), 1);
    }
    this.instantEffect = effect.isInstantenous();
    user.setItemInHand(Hand.MAIN_HAND, stack);
    user.getThreatTable().removeCurrentTarget();
    user.decreaseSaturationForContinuousAction();
    user.getCitizenExperienceHandler().addExperience(PER_POTION_XP);
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) PotionItem(net.minecraft.item.PotionItem) JobDruid(com.minecolonies.coremod.colony.jobs.JobDruid) PathJobCanSee(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobCanSee) PathingOptions(com.minecolonies.api.entity.pathfinding.PathingOptions) GuardConstants(com.minecolonies.api.util.constant.GuardConstants) PathJobMoveAwayFromLocation(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobMoveAwayFromLocation) PathJobMoveToLocation(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobMoveToLocation) ItemStack(net.minecraft.item.ItemStack) BiPredicate(java.util.function.BiPredicate) net.minecraft.potion(net.minecraft.potion) ImmutableList(com.google.common.collect.ImmutableList) Attributes(net.minecraft.entity.ai.attributes.Attributes) ModItems(com.minecolonies.api.items.ModItems) Hand(net.minecraft.util.Hand) DruidPotionEntity(com.minecolonies.coremod.entity.DruidPotionEntity) AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) MinecoloniesAdvancedPathNavigate(com.minecolonies.coremod.entity.pathfinding.MinecoloniesAdvancedPathNavigate) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Skill(com.minecolonies.api.entity.citizen.Skill) IThreatTableEntity(com.minecolonies.api.entity.combat.threat.IThreatTableEntity) LivingEntity(net.minecraft.entity.LivingEntity) AttackMoveAI(com.minecolonies.coremod.entity.ai.combat.AttackMoveAI) ModGuardTypes(com.minecolonies.api.colony.guardtype.registry.ModGuardTypes) GuardTaskSetting(com.minecolonies.coremod.colony.buildings.modules.settings.GuardTaskSetting) Items(net.minecraft.item.Items) BlockPosUtil(com.minecolonies.api.util.BlockPosUtil) ITickRateStateMachine(com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.ITickRateStateMachine) List(java.util.List) PathResult(com.minecolonies.api.entity.pathfinding.PathResult) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) InventoryUtils(com.minecolonies.api.util.InventoryUtils) AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) AbstractPathJob(com.minecolonies.coremod.entity.pathfinding.pathjobs.AbstractPathJob) Collections(java.util.Collections) DRUID_USE_POTIONS(com.minecolonies.api.research.util.ResearchConstants.DRUID_USE_POTIONS) SPEED_LEVEL_BONUS(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIFight.SPEED_LEVEL_BONUS) PotionItem(net.minecraft.item.PotionItem) ItemStack(net.minecraft.item.ItemStack)

Example 4 with DRUID_USE_POTIONS

use of com.minecolonies.api.research.util.ResearchConstants.DRUID_USE_POTIONS in project minecolonies by ldtteam.

the class EntityAIDruid method atBuildingActions.

@Override
protected void atBuildingActions() {
    super.atBuildingActions();
    if (worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(DRUID_USE_POTIONS) > 0) {
        // Mistletoes and water bottles
        InventoryUtils.transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(getOwnBuilding(), item -> item.getItem() instanceof PotionItem, 32, worker.getInventoryCitizen());
        InventoryUtils.transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(getOwnBuilding(), item -> item.getItem() == ModItems.mistletoe, 32, worker.getInventoryCitizen());
        if (InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), item -> item.getItem() instanceof PotionItem) < 5) {
            checkIfRequestForItemExistOrCreateAsynch(PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER), 9, 1);
        }
        if (InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), item -> item.getItem() == ModItems.mistletoe) < 8) {
            checkIfRequestForItemExistOrCreateAsynch(new ItemStack(ModItems.mistletoe), 32, 8);
        }
    }
}
Also used : PotionItem(net.minecraft.item.PotionItem) AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) JobDruid(com.minecolonies.coremod.colony.jobs.JobDruid) MinecoloniesAdvancedPathNavigate(com.minecolonies.coremod.entity.pathfinding.MinecoloniesAdvancedPathNavigate) Potions(net.minecraft.potion.Potions) ArrowItem(net.minecraft.item.ArrowItem) ARCHER_USE_ARROWS(com.minecolonies.api.research.util.ResearchConstants.ARCHER_USE_ARROWS) Items(net.minecraft.item.Items) ItemStack(net.minecraft.item.ItemStack) PathJobWalkRandomEdge(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobWalkRandomEdge) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) InventoryUtils(com.minecolonies.api.util.InventoryUtils) ModItems(com.minecolonies.api.items.ModItems) NotNull(org.jetbrains.annotations.NotNull) DRUID_USE_POTIONS(com.minecolonies.api.research.util.ResearchConstants.DRUID_USE_POTIONS) PotionUtils(net.minecraft.potion.PotionUtils) PotionItem(net.minecraft.item.PotionItem) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ModItems (com.minecolonies.api.items.ModItems)4 DRUID_USE_POTIONS (com.minecolonies.api.research.util.ResearchConstants.DRUID_USE_POTIONS)4 InventoryUtils (com.minecolonies.api.util.InventoryUtils)4 AbstractBuildingGuards (com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards)4 JobDruid (com.minecolonies.coremod.colony.jobs.JobDruid)4 EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)4 MinecoloniesAdvancedPathNavigate (com.minecolonies.coremod.entity.pathfinding.MinecoloniesAdvancedPathNavigate)4 ItemStack (net.minecraft.item.ItemStack)4 Items (net.minecraft.item.Items)4 PotionItem (net.minecraft.item.PotionItem)4 ImmutableList (com.google.common.collect.ImmutableList)2 ModGuardTypes (com.minecolonies.api.colony.guardtype.registry.ModGuardTypes)2 ITickRateStateMachine (com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.ITickRateStateMachine)2 Skill (com.minecolonies.api.entity.citizen.Skill)2 IThreatTableEntity (com.minecolonies.api.entity.combat.threat.IThreatTableEntity)2 PathResult (com.minecolonies.api.entity.pathfinding.PathResult)2 PathingOptions (com.minecolonies.api.entity.pathfinding.PathingOptions)2 ARCHER_USE_ARROWS (com.minecolonies.api.research.util.ResearchConstants.ARCHER_USE_ARROWS)2 BlockPosUtil (com.minecolonies.api.util.BlockPosUtil)2 GuardConstants (com.minecolonies.api.util.constant.GuardConstants)2