use of net.minecraft.entity.projectile.EntityArrow in project Pearcel-Mod by MiningMark48.
the class ItemPearcelBow method onPlayerStoppedUsing.
@Override
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase entityLiving, int timeLeft) {
if (entityLiving instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entityLiving;
int i = getInventorySlotContainItem(ModItems.pearcel_arrow, player);
ItemStack itemstack = new ItemStack(ModItems.pearcel_arrow);
int j = this.getMaxItemUseDuration(stack);
ArrowLooseEvent event = new ArrowLooseEvent(player, stack, world, j, true);
MinecraftForge.EVENT_BUS.post(event);
if (event.isCanceled()) {
return;
}
j = event.getCharge();
boolean flag = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
if (flag || (i != -1)) {
float f = (float) j / 20.0F;
f = (f * f + f * 2.0F) / 3.0F;
if ((double) f < 0.1D) {
return;
}
if (f > 1.0F) {
f = 1.0F;
}
if (!world.isRemote) {
ItemPearcelArrow itemarrow = (ItemPearcelArrow) ((ItemPearcelArrow) (itemstack.getItem() instanceof ItemPearcelArrow ? itemstack.getItem() : ModItems.pearcel_arrow));
EntityArrow entityarrow = itemarrow.createArrow(world, itemstack, player);
entityarrow.setAim(player, player.rotationPitch, player.rotationYaw, 0.0F, f * 3.0F, 1.0F);
if (f == 1.0F) {
entityarrow.setIsCritical(true);
}
int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
if (k > 0) {
entityarrow.setDamage(entityarrow.getDamage() + (double) k * 0.5D + 0.5D);
}
int l = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
if (l > 0) {
entityarrow.setKnockbackStrength(l);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
entityarrow.setFire(100);
}
stack.damageItem(1, player);
world.playSound(player, player.getPosition(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
if (flag) {
entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
} else {
if (player.inventory.hasItemStack(new ItemStack(ModItems.pearcel_arrow))) {
if (player.inventory.getStackInSlot(i).hasTagCompound()) {
if (!player.inventory.getStackInSlot(i).getTagCompound().getBoolean("inf")) {
player.inventory.getStackInSlot(i).damageItem(1, player);
if (player.inventory.getStackInSlot(i).getItemDamage() == 0) {
player.inventory.removeStackFromSlot(i);
}
}
if (player.inventory.getStackInSlot(i).getTagCompound().getBoolean("pow")) {
entityarrow.setDamage(entityarrow.getDamage() + 2.0D);
}
if (player.inventory.getStackInSlot(i).getTagCompound().getBoolean("knock")) {
entityarrow.setKnockbackStrength(2);
}
} else {
player.inventory.getStackInSlot(i).damageItem(1, player);
if (player.inventory.getStackInSlot(i).getItemDamage() == 0) {
player.inventory.removeStackFromSlot(i);
}
}
entityarrow.pickupStatus = EntityArrow.PickupStatus.DISALLOWED;
}
}
world.spawnEntity(entityarrow);
zoomOut();
entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
}
}
}
return;
}
use of net.minecraft.entity.projectile.EntityArrow in project PneumaticCraft by MineMaarten.
the class TileEntityAirCannon method getPayloadEntity.
// warning: no null-check for inventory slot 0
private Entity getPayloadEntity() {
if (getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE, getUpgradeSlots()) > 0) {
Item item = inventory[0].getItem();
if (item == Item.getItemFromBlock(Blocks.tnt)) {
EntityTNTPrimed tnt = new EntityTNTPrimed(worldObj);
tnt.fuse = 80;
return tnt;
} else if (item == Items.experience_bottle)
return new EntityExpBottle(worldObj);
else if (item == Items.potionitem) {
EntityPotion potion = new EntityPotion(worldObj);
potion.setPotionDamage(inventory[0].getItemDamage());
return potion;
} else if (item == Items.arrow)
return new EntityArrow(worldObj);
else if (item == Items.egg)
return new EntityEgg(worldObj);
else // EntitySmallFireball(worldObj);
if (item == Items.snowball)
return new EntitySnowball(worldObj);
else if (item == Items.spawn_egg)
return ItemMonsterPlacer.spawnCreature(worldObj, inventory[0].getItemDamage(), 0, 0, 0);
else if (item == Items.minecart)
return new EntityMinecartEmpty(worldObj);
else if (item == Items.chest_minecart)
return new EntityMinecartChest(worldObj);
else if (item == Items.furnace_minecart)
return new EntityMinecartFurnace(worldObj);
else if (item == Items.hopper_minecart)
return new EntityMinecartHopper(worldObj);
else if (item == Items.tnt_minecart)
return new EntityMinecartTNT(worldObj);
else if (item == Items.boat)
return new EntityBoat(worldObj);
}
EntityItem item = new EntityItem(worldObj);
item.setEntityItemStack(inventory[0].copy());
// 1200 ticks left to live, = 60s.
item.age = 4800;
// add
item.lifespan += Math.min(getUpgrades(ItemMachineUpgrade.UPGRADE_ITEM_LIFE, getUpgradeSlots()) * 600, 4800);
// min.
return item;
}
use of net.minecraft.entity.projectile.EntityArrow in project TechReborn by TechReborn.
the class BlockNuke method onEntityCollidedWithBlock.
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
if (!worldIn.isRemote && entityIn instanceof EntityArrow) {
EntityArrow entityarrow = (EntityArrow) entityIn;
if (entityarrow.isBurning()) {
this.explode(worldIn, pos, state, entityarrow.shootingEntity instanceof EntityLivingBase ? (EntityLivingBase) entityarrow.shootingEntity : null);
worldIn.setBlockToAir(pos);
}
}
}
Aggregations