Search in sources :

Example 1 with PotionEntity

use of net.minecraft.entity.projectile.thrown.PotionEntity in project bewitchment by MoriyaShiine.

the class LeonardEntity method spawnPotion.

private void spawnPotion(BlockPos target, Potion potionType) {
    PotionEntity potion = new PotionEntity(world, this);
    potion.setItem(PotionUtil.setPotion(new ItemStack(Items.SPLASH_POTION), potionType));
    potion.updatePosition(potion.getX(), getBodyY(0.5), potion.getZ());
    double targetX = target.getX() - getX();
    double targetY = target.getY() - 1 - getY();
    double targetZ = target.getZ() - getZ();
    potion.setVelocity(targetX, targetY + (MathHelper.sqrt((float) (targetX * targetX + targetZ * targetZ)) * 0.4), targetZ, 1, 0);
    world.playSound(null, getBlockPos(), SoundEvents.ENTITY_SPLASH_POTION_THROW, getSoundCategory(), getSoundVolume(), getSoundPitch());
    world.spawnEntity(potion);
    swingHand(Hand.MAIN_HAND);
}
Also used : ItemStack(net.minecraft.item.ItemStack) PotionEntity(net.minecraft.entity.projectile.thrown.PotionEntity)

Example 2 with PotionEntity

use of net.minecraft.entity.projectile.thrown.PotionEntity in project MCDoom by AzureDoom.

the class PossessedScientistEntity method attack.

@Override
public void attack(LivingEntity target, float pullProgress) {
    Vec3d vec3d = target.getVelocity();
    double d = target.getX() + vec3d.x - this.getX();
    double e = target.getEyeY() - (double) 1.1f - this.getY();
    double f = target.getZ() + vec3d.z - this.getZ();
    double g = Math.sqrt(d * d + f * f);
    Potion potion;
    if (target instanceof DemonEntity) {
        potion = target.getHealth() <= 4.0f ? Potions.HEALING : Potions.REGENERATION;
        this.setTarget(null);
    } else {
        potion = Potions.POISON;
    }
    PotionEntity potionEntity = new PotionEntity(this.world, this);
    potionEntity.setItem(PotionUtil.setPotion(new ItemStack(Items.SPLASH_POTION), potion));
    potionEntity.setPitch(potionEntity.getPitch() - -20.0f);
    potionEntity.setVelocity(d, e + g * 0.2, f, 0.75f, 8.0f);
    if (!this.isSilent()) {
        this.world.playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.ENTITY_WITCH_THROW, this.getSoundCategory(), 1.0f, 0.8f + this.random.nextFloat() * 0.4f);
    }
    this.world.spawnEntity(potionEntity);
}
Also used : DemonEntity(mod.azure.doom.entity.DemonEntity) Potion(net.minecraft.potion.Potion) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d) PotionEntity(net.minecraft.entity.projectile.thrown.PotionEntity)

Example 3 with PotionEntity

use of net.minecraft.entity.projectile.thrown.PotionEntity in project BleachHack by BleachDrinker420.

the class ProjectileSimulator method simulate.

public static Triple<List<Vec3d>, Entity, BlockPos> simulate(Entity e) {
    List<Vec3d> vecs = new ArrayList<>();
    SimulatedProjectile spoofE = new SimulatedProjectile(e);
    for (int i = 0; i < 100; i++) {
        Vec3d vel = spoofE.velocity;
        Vec3d newVec = spoofE.getPos().add(vel);
        // EntityHitResult entityHit = ProjectileUtil.raycast(mc.player, e.getPos(),
        // newVec, e.getBoundingBox(), null, 1f);
        List<LivingEntity> entities = mc.world.getEntitiesByClass(LivingEntity.class, spoofE.getBoundingBox().expand(0.15), EntityPredicates.VALID_LIVING_ENTITY.and(en -> en != mc.player && en != e));
        if (!entities.isEmpty()) {
            return Triple.of(vecs, entities.get(0), null);
        }
        BlockHitResult blockHit = mc.world.raycast(new RaycastContext(spoofE.getPos(), newVec, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, e));
        if (blockHit.getType() != HitResult.Type.MISS) {
            vecs.add(blockHit.getPos());
            return Triple.of(vecs, null, blockHit.getBlockPos());
        }
        float prevPitch = spoofE.pitch;
        spoofE.pitch = MathHelper.lerp(0.2F, spoofE.prevPitch, spoofE.pitch);
        spoofE.prevPitch = prevPitch;
        double gravity = e instanceof PotionEntity ? 0.05 : e instanceof ExperienceBottleEntity ? 0.07 : e instanceof ThrownEntity ? 0.03 : 0.05000000074505806;
        spoofE.velocity = new Vec3d(vel.x * 0.99, vel.y * 0.99 - gravity, vel.z * 0.99);
        spoofE.setPos(spoofE.getPos().x + spoofE.velocity.x, spoofE.getPos().y + spoofE.velocity.y, spoofE.getPos().z + spoofE.velocity.z);
        vecs.add(spoofE.getPos());
    }
    return Triple.of(vecs, null, null);
}
Also used : Entity(net.minecraft.entity.Entity) PotionEntity(net.minecraft.entity.projectile.thrown.PotionEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) Box(net.minecraft.util.math.Box) SnowballEntity(net.minecraft.entity.projectile.thrown.SnowballEntity) BlockHitResult(net.minecraft.util.hit.BlockHitResult) net.minecraft.item(net.minecraft.item) BlockPos(net.minecraft.util.math.BlockPos) TridentEntity(net.minecraft.entity.projectile.TridentEntity) ThrownEntity(net.minecraft.entity.projectile.thrown.ThrownEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) ArrayList(java.util.ArrayList) HitResult(net.minecraft.util.hit.HitResult) ExperienceBottleEntity(net.minecraft.entity.projectile.thrown.ExperienceBottleEntity) List(java.util.List) Vec3d(net.minecraft.util.math.Vec3d) MathHelper(net.minecraft.util.math.MathHelper) EntityPredicates(net.minecraft.predicate.entity.EntityPredicates) RaycastContext(net.minecraft.world.RaycastContext) MinecraftClient(net.minecraft.client.MinecraftClient) Triple(org.apache.commons.lang3.tuple.Triple) RaycastContext(net.minecraft.world.RaycastContext) ThrownEntity(net.minecraft.entity.projectile.thrown.ThrownEntity) ArrayList(java.util.ArrayList) Vec3d(net.minecraft.util.math.Vec3d) PotionEntity(net.minecraft.entity.projectile.thrown.PotionEntity) LivingEntity(net.minecraft.entity.LivingEntity) ExperienceBottleEntity(net.minecraft.entity.projectile.thrown.ExperienceBottleEntity) BlockHitResult(net.minecraft.util.hit.BlockHitResult)

Example 4 with PotionEntity

use of net.minecraft.entity.projectile.thrown.PotionEntity in project BleachHack by BleachDrinker420.

the class ProjectileSimulator method summonProjectile.

public static Entity summonProjectile(PlayerEntity thrower, boolean allowThrowables, boolean allowXp, boolean allowPotions) {
    ItemStack hand = (isThrowable(thrower.getInventory().getMainHandStack().getItem(), allowThrowables, allowXp, allowPotions) ? thrower.getInventory().getMainHandStack() : isThrowable(thrower.getInventory().offHand.get(0).getItem(), allowThrowables, allowXp, allowPotions) ? thrower.getInventory().offHand.get(0) : null);
    if (hand == null) {
        return null;
    }
    if (hand.getItem() instanceof RangedWeaponItem) {
        float charged = hand.getItem() == Items.CROSSBOW && CrossbowItem.isCharged(hand) ? 1f : hand.getItem() == Items.CROSSBOW ? 0f : BowItem.getPullProgress(thrower.getItemUseTime());
        if (charged > 0f) {
            Entity e = new ArrowEntity(mc.world, mc.player);
            initProjectile(e, thrower, 0f, charged * 3);
            return e;
        }
    } else if (hand.getItem() instanceof SnowballItem || hand.getItem() instanceof EggItem || hand.getItem() instanceof EnderPearlItem) {
        Entity e = new SnowballEntity(mc.world, mc.player);
        initProjectile(e, thrower, 0f, 1.5f);
        return e;
    } else if (hand.getItem() instanceof ExperienceBottleItem) {
        Entity e = new ExperienceBottleEntity(mc.world, mc.player);
        initProjectile(e, thrower, -20f, 0.7f);
        return e;
    } else if (hand.getItem() instanceof ThrowablePotionItem) {
        Entity e = new PotionEntity(mc.world, mc.player);
        initProjectile(e, thrower, -20f, 0.5f);
        return e;
    } else if (hand.getItem() instanceof TridentItem) {
        Entity e = new TridentEntity(mc.world, mc.player, hand);
        initProjectile(e, thrower, 0f, 2.5f);
        return e;
    }
    return null;
}
Also used : Entity(net.minecraft.entity.Entity) PotionEntity(net.minecraft.entity.projectile.thrown.PotionEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) SnowballEntity(net.minecraft.entity.projectile.thrown.SnowballEntity) TridentEntity(net.minecraft.entity.projectile.TridentEntity) ThrownEntity(net.minecraft.entity.projectile.thrown.ThrownEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) ExperienceBottleEntity(net.minecraft.entity.projectile.thrown.ExperienceBottleEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) PotionEntity(net.minecraft.entity.projectile.thrown.PotionEntity) ExperienceBottleEntity(net.minecraft.entity.projectile.thrown.ExperienceBottleEntity) TridentEntity(net.minecraft.entity.projectile.TridentEntity) SnowballEntity(net.minecraft.entity.projectile.thrown.SnowballEntity)

Aggregations

PotionEntity (net.minecraft.entity.projectile.thrown.PotionEntity)4 Entity (net.minecraft.entity.Entity)2 LivingEntity (net.minecraft.entity.LivingEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ArrowEntity (net.minecraft.entity.projectile.ArrowEntity)2 TridentEntity (net.minecraft.entity.projectile.TridentEntity)2 ExperienceBottleEntity (net.minecraft.entity.projectile.thrown.ExperienceBottleEntity)2 SnowballEntity (net.minecraft.entity.projectile.thrown.SnowballEntity)2 ThrownEntity (net.minecraft.entity.projectile.thrown.ThrownEntity)2 ItemStack (net.minecraft.item.ItemStack)2 Vec3d (net.minecraft.util.math.Vec3d)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DemonEntity (mod.azure.doom.entity.DemonEntity)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 net.minecraft.item (net.minecraft.item)1 Potion (net.minecraft.potion.Potion)1 EntityPredicates (net.minecraft.predicate.entity.EntityPredicates)1 BlockHitResult (net.minecraft.util.hit.BlockHitResult)1 HitResult (net.minecraft.util.hit.HitResult)1