Java Code Examples for net.minecraft.init.Items#SPLASH_POTION

The following examples show how to use net.minecraft.init.Items#SPLASH_POTION . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityWitherWitch.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
@Override
public void attackEntityWithRangedAttack(EntityLivingBase entity, float rangeRatio) {   
  //the EntityPotion class validates if this potion is throwable, and if not it logs error "ThrownPotion entity {} has no item?!
  if(attackTimer <= 0 && getHeldItem(EnumHand.MAIN_HAND).getItem() == Items.SPLASH_POTION && !isHealing) {

    attackedWithPotion = entity;

    double x = entity.posX + entity.motionX - posX;
    double y = entity.posY + entity.getEyeHeight() - 1.100000023841858D - posY;
    double z = entity.posZ + entity.motionZ - posZ;
    float groundDistance = MathHelper.sqrt(x * x + z * z);

    ItemStack potion = getHeldItem(EnumHand.MAIN_HAND);
    attackTimer = getHeldItem(EnumHand.MAIN_HAND).getMaxItemUseDuration();

    EntityPotion entitypotion = new EntityPotion(world, this, potion);
    entitypotion.rotationPitch -= -20.0F;
    entitypotion.setThrowableHeading(x, y + groundDistance * 0.2F, z, 0.75F, 8.0F);
    world.spawnEntity(entitypotion);

    setItemStackToSlot(EntityEquipmentSlot.MAINHAND, ItemStack.EMPTY);
  }
}