Search in sources :

Example 1 with PotionItem

use of net.minecraft.item.PotionItem 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 PotionItem

use of net.minecraft.item.PotionItem 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 PotionItem

use of net.minecraft.item.PotionItem in project minecolonies by Minecolonies.

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());
            }
        }
    }
}
Also used : AirBlock(net.minecraft.block.AirBlock) ItemScanTool(com.ldtteam.structurize.items.ItemScanTool) ContainerBlock(net.minecraft.block.ContainerBlock) PotionItem(net.minecraft.item.PotionItem) Permissions(com.minecolonies.coremod.colony.permissions.Permissions) AirBlock(net.minecraft.block.AirBlock) Block(net.minecraft.block.Block) ContainerBlock(net.minecraft.block.ContainerBlock) ItemStack(net.minecraft.item.ItemStack) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 4 with PotionItem

use of net.minecraft.item.PotionItem in project WK by witches-kitchen.

the class ItemUtil method consumeItem.

/**
 * <p>
 * <b>Consumes</b> the Item at the given hand of the player
 * with the {@link Item#getRecipeRemainder()} or air if it doesn't exist.
 * </p>
 *
 * @param player PlayerEntity
 * @param hand   Hand
 */
public static void consumeItem(PlayerEntity player, Hand hand) {
    final var stack = player.getStackInHand(hand);
    final var item = stack.getItem();
    final var hasRemainder = item.hasRecipeRemainder();
    var remainder = hasRemainder ? new ItemStack(item.getRecipeRemainder()) : ItemStack.EMPTY;
    if (item instanceof PotionItem && !hasRemainder) {
        remainder = new ItemStack(Items.GLASS_BOTTLE);
    }
    ItemUtil.replaceItem(player, hand, remainder);
}
Also used : PotionItem(net.minecraft.item.PotionItem) ItemStack(net.minecraft.item.ItemStack)

Example 5 with PotionItem

use of net.minecraft.item.PotionItem in project xercamods by ercanserteli.

the class RecipeFlaskFilling method matches.

/**
 * Used to check if a recipe matches current crafting inventory
 */
public boolean matches(CraftingInventory inv, World worldIn) {
    if (!Config.isEnderFlaskEnabled()) {
        return false;
    }
    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 false;
                }
                flaskStack = itemstack;
                currentFlaskPotion = PotionUtils.getPotionFromItem(flaskStack);
                if (potionType != Potions.EMPTY && !currentFlaskPotion.equals(Potions.EMPTY) && !currentFlaskPotion.equals(potionType)) {
                    return false;
                }
            } else {
                if (!(itemstack.getItem() instanceof PotionItem)) {
                    return false;
                }
                if (potionType.equals(Potions.EMPTY)) {
                    potionType = PotionUtils.getPotionFromItem(itemstack);
                } else if (!PotionUtils.getPotionFromItem(itemstack).equals(potionType)) {
                    return false;
                }
                if (!currentFlaskPotion.equals(Potions.EMPTY) && !currentFlaskPotion.equals(potionType)) {
                    return false;
                }
                ++i;
            }
        }
    }
    return !flaskStack.isEmpty() && i > 0 && !potionType.equals(Potions.EMPTY) && (ItemFlask.getCharges(flaskStack) + i) <= ItemFlask.maxCharges;
}
Also used : Potion(net.minecraft.potion.Potion) PotionItem(net.minecraft.item.PotionItem) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStack (net.minecraft.item.ItemStack)9 PotionItem (net.minecraft.item.PotionItem)9 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 Items (net.minecraft.item.Items)4 ImmutableList (com.google.common.collect.ImmutableList)2 ItemScanTool (com.ldtteam.structurize.items.ItemScanTool)2 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)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