use of net.minecraft.item.PotionItem 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 net.minecraft.item.PotionItem in project xercamods by ercanserteli.
the class RecipeFlaskFilling method getCraftingResult.
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(CraftingInventory inv) {
if (!Config.isEnderFlaskEnabled()) {
return ItemStack.EMPTY;
}
int i = 0;
Potion potionType = Potions.EMPTY;
ItemStack flaskStack = ItemStack.EMPTY;
Potion currentFlaskPotion = Potions.EMPTY;
for (int j = 0; j < inv.getSizeInventory(); ++j) {
ItemStack itemstack = inv.getStackInSlot(j);
if (!itemstack.isEmpty()) {
if (itemstack.getItem() == Items.FLASK) {
if (!flaskStack.isEmpty()) {
return ItemStack.EMPTY;
}
flaskStack = itemstack;
currentFlaskPotion = PotionUtils.getPotionFromItem(flaskStack);
if (potionType != Potions.EMPTY && !currentFlaskPotion.equals(Potions.EMPTY) && !currentFlaskPotion.equals(potionType)) {
return ItemStack.EMPTY;
}
} else {
if (!(itemstack.getItem() instanceof PotionItem)) {
return ItemStack.EMPTY;
}
if (potionType.equals(Potions.EMPTY)) {
potionType = PotionUtils.getPotionFromItem(itemstack);
} else if (!PotionUtils.getPotionFromItem(itemstack).equals(potionType)) {
return ItemStack.EMPTY;
}
if (!currentFlaskPotion.equals(Potions.EMPTY) && !currentFlaskPotion.equals(potionType)) {
return ItemStack.EMPTY;
}
++i;
}
}
}
int oldCharges = ItemFlask.getCharges(flaskStack);
if (!flaskStack.isEmpty() && i > 0 && !potionType.equals(Potions.EMPTY) && (oldCharges + i) <= ItemFlask.maxCharges) {
ItemStack resultStack = new ItemStack(Items.FLASK);
PotionUtils.addPotionToItemStack(resultStack, potionType);
ItemFlask.setCharges(resultStack, oldCharges + i);
return resultStack;
} else {
return ItemStack.EMPTY;
}
}
use of net.minecraft.item.PotionItem in project minecolonies by ldtteam.
the class ColonyPermissionEventHandler method on.
/**
* PlayerInteractEvent handler.
* <p>
* Check, if a player right clicked a block. Deny if: - If the block is in colony - block is AbstractBlockHut - player has not permission
*
* @param event PlayerInteractEvent
*/
@SubscribeEvent
public void on(final PlayerInteractEvent event) {
if (colony.isCoordInColony(event.getWorld(), event.getPos()) && !(event instanceof PlayerInteractEvent.EntityInteract || event instanceof PlayerInteractEvent.EntityInteractSpecific)) {
final Block block = event.getWorld().getBlockState(event.getPos()).getBlock();
// Huts
if (event instanceof PlayerInteractEvent.RightClickBlock && block instanceof AbstractBlockHut && !colony.getPermissions().hasPermission(event.getPlayer(), Action.ACCESS_HUTS)) {
cancelEvent(event, event.getPlayer(), colony, Action.ACCESS_HUTS, event.getPos());
return;
}
final Permissions perms = colony.getPermissions();
if (isFreeToInteractWith(block, event.getPos()) && perms.hasPermission(event.getPlayer(), Action.ACCESS_FREE_BLOCKS)) {
return;
}
if (MineColonies.getConfig().getServer().enableColonyProtection.get()) {
if (!perms.hasPermission(event.getPlayer(), Action.RIGHTCLICK_BLOCK) && !(block instanceof AirBlock)) {
checkEventCancelation(Action.RIGHTCLICK_BLOCK, event.getPlayer(), event.getWorld(), event, event.getPos());
return;
}
if (block instanceof ContainerBlock && !perms.hasPermission(event.getPlayer(), Action.OPEN_CONTAINER)) {
cancelEvent(event, event.getPlayer(), colony, Action.OPEN_CONTAINER, event.getPos());
return;
}
if (event.getWorld().getBlockEntity(event.getPos()) != null && !perms.hasPermission(event.getPlayer(), Action.RIGHTCLICK_ENTITY)) {
checkEventCancelation(Action.RIGHTCLICK_ENTITY, event.getPlayer(), event.getWorld(), event, event.getPos());
return;
}
final ItemStack stack = event.getItemStack();
if (ItemStackUtils.isEmpty(stack) || stack.getItem().isEdible()) {
return;
}
if (stack.getItem() instanceof PotionItem) {
checkEventCancelation(Action.THROW_POTION, event.getPlayer(), event.getWorld(), event, event.getPos());
return;
}
if (stack.getItem() instanceof ItemScanTool && !perms.hasPermission(event.getPlayer(), Action.USE_SCAN_TOOL)) {
cancelEvent(event, event.getPlayer(), colony, Action.USE_SCAN_TOOL, event.getPos());
}
}
}
}
use of net.minecraft.item.PotionItem 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