use of net.minecraft.entity.projectile.AbstractArrowEntity in project Spackenmobs by ACGaming.
the class AbstractApoRedEntity method performRangedAttack.
public void performRangedAttack(LivingEntity target, float distanceFactor) {
ItemStack itemstack = this.getProjectile(this.getItemInHand(ProjectileHelper.getWeaponHoldingHand(this, Items.BOW)));
AbstractArrowEntity abstractarrowentity = this.fireArrow(itemstack, distanceFactor);
if (this.getMainHandItem().getItem() instanceof net.minecraft.item.BowItem)
abstractarrowentity = ((net.minecraft.item.BowItem) this.getMainHandItem().getItem()).customArrow(abstractarrowentity);
double d0 = target.getX() - this.getX();
double d1 = target.getY(0.3333333333333333D) - abstractarrowentity.getY();
double d2 = target.getZ() - this.getZ();
double d3 = MathHelper.sqrt(d0 * d0 + d2 * d2);
abstractarrowentity.shoot(d0, d1 + d3 * (double) 0.2F, d2, 1.6F, (float) (14 - this.level.getDifficulty().getId() * 4));
this.playSound(SoundEvents.SKELETON_SHOOT, 1.0F, 1.0F / (this.getRandom().nextFloat() * 0.4F + 0.8F));
this.level.addFreshEntity(abstractarrowentity);
}
use of net.minecraft.entity.projectile.AbstractArrowEntity in project tetra by mickelus.
the class ModularBowItem method fireArrow.
protected void fireArrow(ItemStack itemStack, World world, LivingEntity entity, int timeLeft) {
if (entity instanceof PlayerEntity) {
PlayerEntity player = (PlayerEntity) entity;
boolean playerInfinite = player.abilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, itemStack) > 0;
ItemStack ammoStack = player.findAmmo(vanillaBow);
// multiply by 20 to align progress with vanilla bow (fully drawn at 1sec/20ticks)
int drawProgress = Math.round(getProgress(itemStack, entity) * 20);
drawProgress = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(itemStack, world, player, drawProgress, !ammoStack.isEmpty() || playerInfinite);
if (drawProgress < 0) {
return;
}
if (!ammoStack.isEmpty() || playerInfinite) {
if (ammoStack.isEmpty()) {
ammoStack = new ItemStack(Items.ARROW);
}
float projectileVelocity = getArrowVelocity(drawProgress, getOverbowCap(itemStack), (float) getOverbowRate(itemStack));
if (projectileVelocity > 0.1f) {
ArrowItem ammoItem = CastOptional.cast(ammoStack.getItem(), ArrowItem.class).orElse((ArrowItem) Items.ARROW);
boolean infiniteAmmo = player.abilities.isCreativeMode || ammoItem.isInfinite(ammoStack, itemStack, player);
if (!world.isRemote) {
AbstractArrowEntity projectile = ammoItem.createArrow(world, ammoStack, player);
projectile.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, projectileVelocity * 3.0F, 1.0F);
if (projectileVelocity == 1.0F) {
projectile.setIsCritical(true);
}
// the damage modifier is based on fully drawn damage, vanilla bows deal 5 times the base damage when fully drawn
projectile.setDamage(projectile.getDamage() + getDamageModifier(itemStack) / 5 - 2);
int powerLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, itemStack);
if (powerLevel > 0) {
projectile.setDamage(projectile.getDamage() + powerLevel * 0.5D + 0.5D);
}
int punchLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, itemStack);
if (punchLevel > 0) {
projectile.setKnockbackStrength(punchLevel);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, itemStack) > 0) {
projectile.setFire(100);
}
int piercingLevel = getEffectLevel(itemStack, ItemEffect.piercing);
if (piercingLevel > 0) {
projectile.setPierceLevel((byte) piercingLevel);
}
itemStack.damageItem(1, player, (p_220009_1_) -> {
p_220009_1_.sendBreakAnimation(player.getActiveHand());
});
if (infiniteAmmo || player.abilities.isCreativeMode && (ammoStack.getItem() == Items.SPECTRAL_ARROW || ammoStack.getItem() == Items.TIPPED_ARROW)) {
projectile.pickupStatus = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY;
}
world.addEntity(projectile);
applyUsageEffects(entity, itemStack, 1);
}
world.playSound(null, player.getPosX(), player.getPosY(), player.getPosZ(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (random.nextFloat() * 0.4F + 1.2F) + projectileVelocity * 0.5F);
if (!infiniteAmmo && !player.abilities.isCreativeMode) {
ammoStack.shrink(1);
if (ammoStack.isEmpty()) {
player.inventory.deleteStack(ammoStack);
}
}
player.addStat(Stats.ITEM_USED.get(this));
}
}
}
}
use of net.minecraft.entity.projectile.AbstractArrowEntity in project LoliServer by Loli-Server.
the class CraftBlockProjectileSource method launchProjectile.
@Override
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
Validate.isTrue(getBlock().getType() == Material.DISPENSER, "Block is no longer dispenser");
// Copied from DispenserBlock.dispense()
ProxyBlockSource isourceblock = new ProxyBlockSource((ServerWorld) dispenserBlock.getLevel(), dispenserBlock.getBlockPos());
// Copied from DispenseTaskProjectile
IPosition iposition = DispenserBlock.getDispensePosition(isourceblock);
Direction enumdirection = (Direction) isourceblock.getBlockState().getValue(DispenserBlock.FACING);
net.minecraft.world.World world = dispenserBlock.getLevel();
net.minecraft.entity.Entity launch = null;
if (Snowball.class.isAssignableFrom(projectile)) {
launch = new SnowballEntity(world, iposition.x(), iposition.y(), iposition.z());
} else if (Egg.class.isAssignableFrom(projectile)) {
launch = new EggEntity(world, iposition.x(), iposition.y(), iposition.z());
} else if (EnderPearl.class.isAssignableFrom(projectile)) {
launch = new EnderPearlEntity(world, null);
launch.setPos(iposition.x(), iposition.y(), iposition.z());
} else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
launch = new ExperienceBottleEntity(world, iposition.x(), iposition.y(), iposition.z());
} else if (ThrownPotion.class.isAssignableFrom(projectile)) {
if (LingeringPotion.class.isAssignableFrom(projectile)) {
launch = new PotionEntity(world, iposition.x(), iposition.y(), iposition.z());
((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
} else {
launch = new PotionEntity(world, iposition.x(), iposition.y(), iposition.z());
((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
}
} else if (AbstractArrow.class.isAssignableFrom(projectile)) {
if (TippedArrow.class.isAssignableFrom(projectile)) {
launch = new ArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
((ArrowEntity) launch).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
} else if (SpectralArrow.class.isAssignableFrom(projectile)) {
launch = new SpectralArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
} else {
launch = new ArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
}
((AbstractArrowEntity) launch).pickup = AbstractArrowEntity.PickupStatus.ALLOWED;
((AbstractArrowEntity) launch).projectileSource = this;
} else if (Fireball.class.isAssignableFrom(projectile)) {
double d0 = iposition.x() + (double) ((float) enumdirection.getStepX() * 0.3F);
double d1 = iposition.y() + (double) ((float) enumdirection.getStepY() * 0.3F);
double d2 = iposition.z() + (double) ((float) enumdirection.getStepZ() * 0.3F);
Random random = world.random;
double d3 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepX();
double d4 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepY();
double d5 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepZ();
if (SmallFireball.class.isAssignableFrom(projectile)) {
launch = new SmallFireballEntity(world, null, d0, d1, d2);
} else if (WitherSkull.class.isAssignableFrom(projectile)) {
launch = EntityType.WITHER_SKULL.create(world);
launch.setPos(d0, d1, d2);
double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
((DamagingProjectileEntity) launch).xPower = d3 / d6 * 0.1D;
((DamagingProjectileEntity) launch).yPower = d4 / d6 * 0.1D;
((DamagingProjectileEntity) launch).zPower = d5 / d6 * 0.1D;
} else {
launch = EntityType.FIREBALL.create(world);
launch.setPos(d0, d1, d2);
double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
((DamagingProjectileEntity) launch).xPower = d3 / d6 * 0.1D;
((DamagingProjectileEntity) launch).yPower = d4 / d6 * 0.1D;
((DamagingProjectileEntity) launch).zPower = d5 / d6 * 0.1D;
}
((DamagingProjectileEntity) launch).projectileSource = this;
}
Validate.notNull(launch, "Projectile not supported");
if (launch instanceof ProjectileEntity) {
if (launch instanceof ThrowableEntity) {
((ThrowableEntity) launch).projectileSource = this;
}
// Values from DispenseTaskProjectile
float a = 6.0F;
float b = 1.1F;
if (launch instanceof PotionEntity || launch instanceof ThrownExpBottle) {
// Values from respective DispenseTask classes
a *= 0.5F;
b *= 1.25F;
}
// Copied from DispenseTaskProjectile
((ProjectileEntity) launch).shoot((double) enumdirection.getStepX(), (double) ((float) enumdirection.getStepY() + 0.1F), (double) enumdirection.getStepZ(), b, a);
}
if (velocity != null) {
((T) launch.getBukkitEntity()).setVelocity(velocity);
}
world.addFreshEntity(launch);
return (T) launch.getBukkitEntity();
}
use of net.minecraft.entity.projectile.AbstractArrowEntity in project minecolonies by ldtteam.
the class CombatUtils method createArrowForShooter.
/**
* Get an arrow entity for the given shooter
*
* @param shooter entity
* @return arrow entity
*/
public static AbstractArrowEntity createArrowForShooter(final LivingEntity shooter) {
AbstractArrowEntity arrowEntity = ModEntities.MC_NORMAL_ARROW.create(shooter.level);
arrowEntity.setOwner(shooter);
final ItemStack rangedWeapon = shooter.getItemInHand(Hand.MAIN_HAND);
final Item rangedWeaponItem = rangedWeapon.getItem();
if (rangedWeaponItem instanceof BowItem) {
arrowEntity = ((BowItem) rangedWeaponItem).customArrow(arrowEntity);
} else if (rangedWeaponItem instanceof ItemSpear) {
arrowEntity = ModEntities.SPEAR.create(shooter.level);
} else if (rangedWeaponItem instanceof TridentItem) {
arrowEntity = EntityType.TRIDENT.create(shooter.level);
}
arrowEntity.setPos(shooter.getX(), shooter.getY() + 1, shooter.getZ());
return arrowEntity;
}
use of net.minecraft.entity.projectile.AbstractArrowEntity in project minecolonies by ldtteam.
the class ItemFireArrow method createArrow.
@NotNull
@Override
public AbstractArrowEntity createArrow(@NotNull final World worldIn, @NotNull final ItemStack stack, final LivingEntity shooter) {
AbstractArrowEntity entity = ModEntities.FIREARROW.create(worldIn);
entity.setOwner(shooter);
return entity;
}
Aggregations