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