use of net.minecraft.entity.projectile.EntityArrow in project Cavern2 by kegare.
the class ItemBowCavenic method onPlayerStoppedUsing.
@Override
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase entityLiving, int timeLeft) {
if (!(entityLiving instanceof EntityPlayer)) {
return;
}
EntityPlayer player = (EntityPlayer) entityLiving;
BowMode mode = BowMode.byItemStack(stack);
boolean infinity = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
ItemStack ammo = findAmmo(player);
ItemStack torch = mode == BowMode.TORCH ? findTorch(player) : ItemStack.EMPTY;
int i = getMaxItemUseDuration(stack) - timeLeft;
i = ForgeEventFactory.onArrowLoose(stack, world, player, i, !ammo.isEmpty() || infinity);
if (i < 0 || ammo.isEmpty() && !infinity || mode == BowMode.TORCH && torch.isEmpty() && !infinity) {
return;
}
if (ammo.isEmpty()) {
ammo = new ItemStack(Items.ARROW);
}
if (mode == BowMode.TORCH && torch.isEmpty()) {
torch = new ItemStack(Blocks.TORCH);
}
float f = getArrowVelocity(i);
if (f < 0.1D) {
return;
}
boolean flag = player.capabilities.isCreativeMode || ammo.getItem() instanceof ItemArrow && ((ItemArrow) ammo.getItem()).isInfinite(ammo, stack, player);
if (!world.isRemote) {
EntityArrow entityArrow = createCustomArrow(mode, world, player, torch);
if (entityArrow == null) {
ItemArrow arrow = (ItemArrow) (ammo.getItem() instanceof ItemArrow ? ammo.getItem() : Items.ARROW);
entityArrow = arrow.createArrow(world, ammo, player);
}
entityArrow.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, f * 3.0F, 1.0F);
if (f >= 1.0D || mode == BowMode.SNIPE && f >= 0.65D) {
entityArrow.setIsCritical(true);
}
int power = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
if (power > 0) {
entityArrow.setDamage(entityArrow.getDamage() + power * 0.5D + 0.5D);
}
int punch = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
if (punch > 0) {
entityArrow.setKnockbackStrength(punch);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
entityArrow.setFire(100);
}
stack.damageItem(1, player);
if (flag || player.capabilities.isCreativeMode && (ammo.getItem() == Items.SPECTRAL_ARROW || ammo.getItem() == Items.TIPPED_ARROW)) {
entityArrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
}
entityArrow.setDamage(entityArrow.getDamage() * mode.getAttackPower());
world.spawnEntity(entityArrow);
}
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
if (!flag && !player.capabilities.isCreativeMode) {
ammo.shrink(1);
if (ammo.isEmpty()) {
player.inventory.deleteStack(ammo);
}
}
player.addStat(StatList.getObjectUseStats(this));
}
use of net.minecraft.entity.projectile.EntityArrow in project Cavern2 by kegare.
the class EntityCavenicSkeleton method getArrow.
@Override
protected EntityArrow getArrow(float dist) {
ItemStack heldOff = getItemStackFromSlot(EntityEquipmentSlot.OFFHAND);
if (heldOff.getItem() == Items.SPECTRAL_ARROW) {
EntitySpectralArrow arrow = new EntitySpectralArrow(this.world, this);
arrow.setEnchantmentEffectsFromEntity(this, dist);
return arrow;
} else {
EntityArrow arrow = new EntityCavenicArrow(world, this);
arrow.setEnchantmentEffectsFromEntity(this, dist);
if (heldOff.getItem() == Items.TIPPED_ARROW && arrow instanceof EntityTippedArrow) {
((EntityTippedArrow) arrow).setPotionEffect(heldOff);
}
return arrow;
}
}
use of net.minecraft.entity.projectile.EntityArrow in project EnderIO by SleepyTrousers.
the class ItemDarkSteelBow method onPlayerStoppedUsing.
@Override
public void onPlayerStoppedUsing(@Nonnull ItemStack stack, @Nonnull World worldIn, @Nonnull EntityLivingBase entityLiving, int timeLeft) {
if (!(entityLiving instanceof EntityPlayer)) {
return;
}
EntityPlayer entityplayer = (EntityPlayer) entityLiving;
boolean hasInfinateArrows = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
ItemStack itemstack = getArrowsToShoot(entityplayer);
int draw = getMaxItemUseDuration(stack) - timeLeft;
draw = ForgeEventFactory.onArrowLoose(stack, worldIn, (EntityPlayer) entityLiving, draw, Prep.isValid(itemstack) || hasInfinateArrows);
if (draw < 0) {
return;
}
if (itemstack.isEmpty() && hasInfinateArrows) {
itemstack = new ItemStack(Items.ARROW);
}
if (itemstack.isEmpty()) {
return;
}
float drawRatio = getCustumArrowVelocity(stack, draw);
if (drawRatio >= 0.1) {
boolean arrowIsInfinite = hasInfinateArrows && itemstack.getItem() instanceof ItemArrow;
if (!worldIn.isRemote) {
EnergyUpgradeHolder upgrade = EnergyUpgradeManager.loadFromItem(stack);
ItemArrow itemarrow = ((ItemArrow) (itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW));
EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
// ATTENTION:
entityarrow.shoot(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, drawRatio * 3.0F * getForceMultiplier(upgrade), 0.25F);
if (drawRatio == 1.0F) {
entityarrow.setIsCritical(true);
}
int powerLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
if (powerLevel > 0) {
entityarrow.setDamage(entityarrow.getDamage() + powerLevel * 0.5D + 0.5D);
}
int knockBack = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
if (knockBack > 0) {
entityarrow.setKnockbackStrength(knockBack);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
entityarrow.setFire(100);
}
stack.damageItem(1, entityplayer);
if (arrowIsInfinite) {
entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
}
entityarrow.setDamage(entityarrow.getDamage() + damageBonus);
worldIn.spawnEntity(entityarrow);
int used = getRequiredPower(draw, upgrade);
if (used > 0) {
upgrade.setEnergy(upgrade.getEnergy() - used);
upgrade.writeToItem(stack, this);
}
}
worldIn.playSound((EntityPlayer) null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + drawRatio * 0.5F);
if (!arrowIsInfinite) {
itemstack.shrink(1);
}
supressed(entityplayer);
}
}
use of net.minecraft.entity.projectile.EntityArrow in project BloodMagic by WayofTime.
the class LivingArmourHandler method onArrowFire.
// Applies: Arrow Shot
// Tracks: Arrow Shot
@SubscribeEvent
public static void onArrowFire(ArrowLooseEvent event) {
World world = event.getEntityPlayer().getEntityWorld();
ItemStack stack = event.getBow();
EntityPlayer player = event.getEntityPlayer();
if (world.isRemote)
return;
if (LivingArmour.hasFullSet(player)) {
ItemStack chestStack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
LivingArmour armour = ItemLivingArmour.getLivingArmour(chestStack);
if (armour != null) {
StatTrackerArrowShot.incrementCounter(armour);
LivingArmourUpgrade upgrade = ItemLivingArmour.getUpgrade(BloodMagic.MODID + ".upgrade.arrowShot", chestStack);
if (upgrade instanceof LivingArmourUpgradeArrowShot) {
int charge = event.getCharge();
float velocity = (float) charge / 20.0F;
velocity = (velocity * velocity + velocity * 2.0F) / 3.0F;
if ((double) velocity < 0.1D)
return;
if (velocity > 1.0F)
velocity = 1.0F;
int extraArrows = ((LivingArmourUpgradeArrowShot) upgrade).getExtraArrows();
for (int n = 0; n < extraArrows; n++) {
ItemStack arrowStack = new ItemStack(Items.ARROW);
ItemArrow itemarrow = (ItemArrow) ((stack.getItem() instanceof ItemArrow ? arrowStack.getItem() : Items.ARROW));
EntityArrow entityarrow = itemarrow.createArrow(world, arrowStack, player);
entityarrow.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, velocity * 3.0F, 1.0F);
float velocityModifier = 0.6f * velocity;
entityarrow.motionX += (event.getWorld().rand.nextDouble() - 0.5) * velocityModifier;
entityarrow.motionY += (event.getWorld().rand.nextDouble() - 0.5) * velocityModifier;
entityarrow.motionZ += (event.getWorld().rand.nextDouble() - 0.5) * velocityModifier;
if (velocity == 1.0F)
entityarrow.setIsCritical(true);
int powerLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
if (powerLevel > 0)
entityarrow.setDamage(entityarrow.getDamage() + (double) powerLevel * 0.5D + 0.5D);
int punchLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
if (punchLevel > 0)
entityarrow.setKnockbackStrength(punchLevel);
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0)
entityarrow.setFire(100);
entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
world.spawnEntity(entityarrow);
}
}
}
}
}
use of net.minecraft.entity.projectile.EntityArrow in project MorePlanets by SteveKunG.
the class TileEntityJuicerEgg method update.
@Override
public void update() {
super.update();
if (!this.world.isRemote) {
double radius = 1.05D;
double radiusPlayer = 5.0D;
List<Entity> list = this.world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(this.pos.getX() - radius, this.pos.getY() - radius, this.pos.getZ() - radius, this.pos.getX() + radius, this.pos.getY() + radius, this.pos.getZ() + radius));
List<EntityPlayer> playerList = this.world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(this.pos.getX() - radiusPlayer, this.pos.getY() - radiusPlayer, this.pos.getZ() - radiusPlayer, this.pos.getX() + radiusPlayer, this.pos.getY() + radiusPlayer, this.pos.getZ() + radiusPlayer));
if (!list.isEmpty()) {
for (Entity entity : list) {
if (entity instanceof EntityArrow) {
EntityArrow arrow = (EntityArrow) entity;
if (arrow.inTile == MPBlocks.JUICER_EGG) {
arrow.setDead();
this.world.destroyBlock(this.pos, false);
if (this.world.rand.nextInt(5) == 0) {
EntityJuicer juicer = new EntityJuicer(this.world);
juicer.setLocationAndAngles(this.pos.getX() + 0.5D, this.pos.getY() + 1.0D, this.pos.getZ() + 0.5D, 0.0F, 0.0F);
this.world.spawnEntity(juicer);
}
}
}
}
}
if (!playerList.isEmpty()) {
for (EntityPlayer player : playerList) {
if (!player.isCreative() && !player.isSpectator()) {
if (this.needPlayerNearby && this.world.rand.nextInt(20) == 0) {
this.world.destroyBlock(this.pos, false);
EntityJuicer juicer = new EntityJuicer(this.world);
juicer.setLocationAndAngles(this.pos.getX() + 0.5D, this.pos.getY() + 1.0D, this.pos.getZ() + 0.5D, 0.0F, 0.0F);
this.world.spawnEntity(juicer);
}
}
}
}
}
}
Aggregations