Search in sources :

Example 1 with PotionEntity

use of net.minecraft.entity.projectile.PotionEntity in project endergetic by team-abnormals.

the class EntityEvents method onThrowableImpact.

@SubscribeEvent
public static void onThrowableImpact(final ProjectileImpactEvent.Throwable event) {
    ThrowableEntity projectileEntity = event.getThrowable();
    if (projectileEntity instanceof PotionEntity) {
        PotionEntity potionEntity = ((PotionEntity) projectileEntity);
        ItemStack itemstack = potionEntity.getItem();
        Potion potion = PotionUtils.getPotion(itemstack);
        List<EffectInstance> list = PotionUtils.getMobEffects(itemstack);
        if (potion == Potions.WATER && list.isEmpty() && event.getRayTraceResult() instanceof BlockRayTraceResult) {
            World world = potionEntity.level;
            BlockRayTraceResult blockraytraceresult = (BlockRayTraceResult) event.getRayTraceResult();
            Direction direction = blockraytraceresult.getDirection();
            BlockPos blockpos = blockraytraceresult.getBlockPos().relative(Direction.DOWN).relative(direction);
            tryToConvertCorrockBlock(world, blockpos);
            tryToConvertCorrockBlock(world, blockpos.relative(direction.getOpposite()));
            for (Direction horizontals : Direction.Plane.HORIZONTAL) {
                tryToConvertCorrockBlock(world, blockpos.relative(horizontals));
            }
        }
    }
}
Also used : ThrowableEntity(net.minecraft.entity.projectile.ThrowableEntity) BlockPos(net.minecraft.util.math.BlockPos) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) ItemStack(net.minecraft.item.ItemStack) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World) Direction(net.minecraft.util.Direction) PotionEntity(net.minecraft.entity.projectile.PotionEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with PotionEntity

use of net.minecraft.entity.projectile.PotionEntity in project Enigmatic-Legacy by Aizistral-Studios.

the class AngelBlessing method onCurioTick.

@Override
public void onCurioTick(String identifier, LivingEntity living) {
    List<DamagingProjectileEntity> projectileEntities = living.world.getEntitiesWithinAABB(DamagingProjectileEntity.class, new AxisAlignedBB(living.posX - range, living.posY - range, living.posZ - range, living.posX + range, living.posY + range, living.posZ + range));
    List<AbstractArrowEntity> arrowEntities = living.world.getEntitiesWithinAABB(AbstractArrowEntity.class, new AxisAlignedBB(living.posX - range, living.posY - range, living.posZ - range, living.posX + range, living.posY + range, living.posZ + range));
    List<PotionEntity> potionEntities = living.world.getEntitiesWithinAABB(PotionEntity.class, new AxisAlignedBB(living.posX - range, living.posY - range, living.posZ - range, living.posX + range, living.posY + range, living.posZ + range));
    for (DamagingProjectileEntity entity : projectileEntities) this.redirect(living, entity);
    for (AbstractArrowEntity entity : arrowEntities) this.redirect(living, entity);
    for (PotionEntity entity : potionEntities) this.redirect(living, entity);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Example 3 with PotionEntity

use of net.minecraft.entity.projectile.PotionEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class BossAIPirateParrotThrowPotions method throwPotion.

private void throwPotion(EntityCQRPirateParrot thrower, LivingEntity target) {
    double d0 = target.getY() + target.getEyeHeight() - 1.100000023841858D;
    double d1 = target.getX() + target.getDeltaMovement().x() - thrower.getX();
    double d2 = d0 - thrower.getY();
    double d3 = target.getZ() + target.getDeltaMovement().z() - thrower.getZ();
    float f = MathHelper.sqrt(d1 * d1 + d3 * d3);
    ItemStack potionItem = thrower.getMainHandItem();
    PotionEntity potion = new PotionEntity(thrower.level, thrower);
    potion.setItem(potionItem);
    potion.xRot += 20F;
    potion.shoot(d1, d2 + f * 0.2F, d3, 0.75F, 8.0F);
    thrower.level.playSound((PlayerEntity) null, thrower.getX(), thrower.getY(), thrower.getZ(), SoundEvents.WITCH_THROW, thrower.getSoundSource(), 1.0F, 0.8F + thrower.getRandom().nextFloat() * 0.4F);
    thrower.level.addFreshEntity(potion);
    this.entity.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
}
Also used : ItemStack(net.minecraft.item.ItemStack) PotionEntity(net.minecraft.entity.projectile.PotionEntity)

Example 4 with PotionEntity

use of net.minecraft.entity.projectile.PotionEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class EntityAIPotionThrower method checkAndPerformAttack.

@Override
protected void checkAndPerformAttack(LivingEntity attackTarget) {
    if (this.entity.tickCount > this.prevTimeAttacked + this.getAttackCooldown()) {
        ItemStack stack = this.getEquippedWeapon();
        Item item = stack.getItem();
        final double x = attackTarget.getX() - this.entity.getX();
        double y = attackTarget.getY() + attackTarget.getBbHeight() * 0.5D;
        final double z = attackTarget.getZ() - this.entity.getZ();
        final double distance = Math.sqrt(x * x + z * z);
        // Throwable potions
        if (item instanceof SplashPotionItem || item instanceof LingeringPotionItem) {
            PotionEntity proj = new PotionEntity(this.world, this.entity);
            proj.setItem(stack.copy());
            y -= proj.getY();
            proj.shoot(x, y + distance * 0.06D, z, 1.F, this.entity.getRandom().nextFloat() * 0.25F);
            /*proj.motionX += this.entity.motionX;
				proj.motionZ += this.entity.motionZ;
				if (!this.entity.onGround) {
					proj.motionY += this.entity.motionY;
				}*/
            proj.setDeltaMovement(proj.getDeltaMovement().add(this.entity.getDeltaMovement()));
            proj.hasImpulse = true;
            this.entity.level.addFreshEntity(proj);
            this.entity.swing(Hand.OFF_HAND);
            this.entity.playSound(SoundEvents.SPLASH_POTION_THROW, 1.0F, 0.8F + this.random.nextFloat() * 0.4F);
            if (CQRConfig.mobs.offhandPotionsAreSingleUse) {
                stack.shrink(1);
            }
            this.prevTimeAttacked = this.entity.tickCount;
        } else if (item instanceof ItemAlchemyBag) {
            IItemHandler inventory = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).resolve().get();
            int indx = this.entity.getRandom().nextInt(inventory.getSlots());
            ItemStack st = inventory.getStackInSlot(indx);
            Set<Integer> usedIDs = new HashSet<>();
            int counter = 0;
            while (st.isEmpty() && !usedIDs.contains(indx) && counter > inventory.getSlots()) {
                indx = this.entity.getRandom().nextInt(inventory.getSlots());
                usedIDs.add(indx);
                st = inventory.getStackInSlot(indx);
                counter++;
            }
            if (!st.isEmpty()) {
                ItemStack potion = st.copy();
                // Now throw it
                if (potion.getItem() instanceof SplashPotionItem || potion.getItem() instanceof LingeringPotionItem) {
                    PotionEntity proj = new PotionEntity(this.world, this.entity);
                    proj.setItem(potion);
                    y -= proj.getY();
                    proj.shoot(x, y + distance * 0.08D, z, 1.F, this.entity.getRandom().nextFloat() * 0.25F);
                    /*proj.motionX += this.entity.motionX;
						proj.motionZ += this.entity.motionZ;
						if (!this.entity.onGround) {
							proj.motionY += this.entity.motionY;
						}*/
                    proj.setDeltaMovement(proj.getDeltaMovement().add(this.entity.getDeltaMovement()));
                    proj.hasImpulse = true;
                    this.entity.level.addFreshEntity(proj);
                    this.entity.swing(Hand.OFF_HAND);
                    this.entity.playSound(SoundEvents.SPLASH_POTION_THROW, 1.0F, 0.8F + this.random.nextFloat() * 0.4F);
                }
            }
            this.prevTimeAttacked = this.entity.tickCount;
        }
    }
}
Also used : SplashPotionItem(net.minecraft.item.SplashPotionItem) Item(net.minecraft.item.Item) LingeringPotionItem(net.minecraft.item.LingeringPotionItem) LingeringPotionItem(net.minecraft.item.LingeringPotionItem) Set(java.util.Set) HashSet(java.util.HashSet) IItemHandler(net.minecraftforge.items.IItemHandler) SplashPotionItem(net.minecraft.item.SplashPotionItem) ItemStack(net.minecraft.item.ItemStack) ItemAlchemyBag(team.cqr.cqrepoured.item.ItemAlchemyBag) PotionEntity(net.minecraft.entity.projectile.PotionEntity)

Example 5 with PotionEntity

use of net.minecraft.entity.projectile.PotionEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class ItemAlchemyBag method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity playerIn, Hand handIn) {
    if (!world.isClientSide) {
        if (playerIn.isCrouching()) {
            playerIn.openGui(CQRMain.INSTANCE, GuiHandler.ALCHEMY_BAG_GUI_ID, world, handIn.ordinal(), 0, 0);
            return new ActionResult<>(ActionResultType.SUCCESS, playerIn.getItemInHand(handIn));
        }
        ItemStack stack = playerIn.getItemInHand(handIn);
        Item item = stack.getItem();
        if (item == this) {
            IItemHandler inventory = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
            for (int i = 0; i < inventory.getSlots(); i++) {
                ItemStack potion = inventory.extractItem(i, 1, false);
                if (!potion.isEmpty()) {
                    if (potion.getItem() instanceof SplashPotionItem || potion.getItem() instanceof LingeringPotionItem) {
                        PotionEntity entitypotion = new PotionEntity(world, playerIn);
                        entitypotion.setItem(potion);
                        entitypotion.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, -20.0F, 0.5F, 1.0F);
                        world.addFreshEntity(entitypotion);
                        world.playSound((PlayerEntity) null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.SPLASH_POTION_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
                        return new ActionResult<>(ActionResultType.SUCCESS, playerIn.getItemInHand(handIn));
                    }
                }
            }
        }
    }
    return new ActionResult<>(ActionResultType.FAIL, playerIn.getItemInHand(handIn));
}
Also used : SplashPotionItem(net.minecraft.item.SplashPotionItem) Item(net.minecraft.item.Item) LingeringPotionItem(net.minecraft.item.LingeringPotionItem) LingeringPotionItem(net.minecraft.item.LingeringPotionItem) IItemHandler(net.minecraftforge.items.IItemHandler) SplashPotionItem(net.minecraft.item.SplashPotionItem) ItemStack(net.minecraft.item.ItemStack) PotionEntity(net.minecraft.entity.projectile.PotionEntity)

Aggregations

PotionEntity (net.minecraft.entity.projectile.PotionEntity)5 ItemStack (net.minecraft.item.ItemStack)4 Item (net.minecraft.item.Item)2 LingeringPotionItem (net.minecraft.item.LingeringPotionItem)2 SplashPotionItem (net.minecraft.item.SplashPotionItem)2 IItemHandler (net.minecraftforge.items.IItemHandler)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 AbstractArrowEntity (net.minecraft.entity.projectile.AbstractArrowEntity)1 DamagingProjectileEntity (net.minecraft.entity.projectile.DamagingProjectileEntity)1 ThrowableEntity (net.minecraft.entity.projectile.ThrowableEntity)1 Direction (net.minecraft.util.Direction)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)1 World (net.minecraft.world.World)1 ServerWorld (net.minecraft.world.server.ServerWorld)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1 ItemAlchemyBag (team.cqr.cqrepoured.item.ItemAlchemyBag)1