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