use of net.minecraft.entity.projectile.EntityArrow in project BuildCraft by BuildCraft.
the class StripesHandlerArrow method handle.
@Override
public boolean handle(World world, BlockPos pos, EnumFacing direction, ItemStack stack, EntityPlayer player, IStripesActivator activator) {
EntityArrow entityArrow = new EntityArrow(world, player, 0);
entityArrow.setPosition(pos.getX() + 0.5d, pos.getY() + 0.5d, pos.getZ() + 0.5d);
entityArrow.setDamage(3);
entityArrow.setKnockbackStrength(1);
entityArrow.motionX = direction.getFrontOffsetX() * 1.8d + world.rand.nextGaussian() * 0.007499999832361937D;
entityArrow.motionY = direction.getFrontOffsetY() * 1.8d + world.rand.nextGaussian() * 0.007499999832361937D;
entityArrow.motionZ = direction.getFrontOffsetZ() * 1.8d + world.rand.nextGaussian() * 0.007499999832361937D;
world.spawnEntityInWorld(entityArrow);
stack.stackSize--;
if (stack.stackSize > 0) {
activator.sendItem(stack, direction.getOpposite());
}
return true;
}
use of net.minecraft.entity.projectile.EntityArrow in project ImmersiveEngineering by BluSunrize.
the class TileEntityBalloon method onEntityCollision.
@Override
public void onEntityCollision(World world, Entity entity) {
if (entity instanceof EntityArrow || entity instanceof EntityRevolvershot) {
Vec3d pos = new Vec3d(getPos()).add(.5, .5, .5);
world.playSound(null, pos.x, pos.y, pos.z, SoundEvents.ENTITY_FIREWORK_BLAST, SoundCategory.BLOCKS, 1.5f, 0.7f);
world.setBlockToAir(getPos());
world.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, pos.x, pos.y, pos.z, 0, .05, 0);
Triple<ItemStack, ShaderRegistryEntry, ShaderCase> shader = ShaderRegistry.getStoredShaderAndCase(this.shader);
if (shader != null)
shader.getMiddle().getEffectFunction().execute(world, shader.getLeft(), null, shader.getRight().getShaderType(), pos, null, .375f);
}
}
use of net.minecraft.entity.projectile.EntityArrow in project GregTech by GregTechCE.
the class FieldProjectorEventHandler method isHostileProjectile.
private static Pair<Boolean, Entity> isHostileProjectile(Entity entity, Entity owner) {
if (entity instanceof EntityFireball) {
EntityLivingBase shooter = ((EntityFireball) entity).shootingEntity;
return Pair.of(!owner.isEntityEqual(shooter), shooter);
} else if (entity instanceof EntityArrow) {
Entity shooter = ((EntityArrow) entity).shootingEntity;
return Pair.of(!owner.isEntityEqual(shooter), shooter);
} else if (entity instanceof EntityPotion) {
EntityLivingBase shooter = ((EntityPotion) entity).getThrower();
ItemStack potionStack = ((EntityPotion) entity).getPotion();
List<PotionEffect> effectList = PotionUtils.getEffectsFromStack(potionStack);
boolean hasBadEffects = effectList.stream().anyMatch(it -> it.getPotion().isBadEffect());
// potions without bad effects are not hostile, so do not touch them
return Pair.of(!owner.isEntityEqual(shooter) && hasBadEffects, shooter);
} else if (entity instanceof EntityThrowable) {
EntityLivingBase shooter = ((EntityThrowable) entity).getThrower();
return Pair.of(!owner.isEntityEqual(shooter), shooter);
} else if (entity instanceof IThrowableEntity) {
Entity shooter = ((IThrowableEntity) entity).getThrower();
return Pair.of(!owner.isEntityEqual(shooter), shooter);
} else if (entity instanceof IProjectile) {
// unknown projectiles are always hostile
return Pair.of(true, null);
}
return Pair.of(false, null);
}
use of net.minecraft.entity.projectile.EntityArrow in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EntityDraggable method tickAddedVelocity.
//TODO: Finishme
public void tickAddedVelocity() {
if (worldBelowFeet != null && !ValkyrienWarfareMod.physicsManager.isEntityFixed(draggableAsEntity)) {
CoordTransformObject coordTransform = worldBelowFeet.wrapping.coordTransform;
float rotYaw = draggableAsEntity.rotationYaw;
float rotPitch = draggableAsEntity.rotationPitch;
float prevYaw = draggableAsEntity.prevRotationYaw;
float prevPitch = draggableAsEntity.prevRotationPitch;
Vector oldPos = new Vector(draggableAsEntity);
RotationMatrices.applyTransform(coordTransform.prevwToLTransform, coordTransform.prevWToLRotation, draggableAsEntity);
RotationMatrices.applyTransform(coordTransform.lToWTransform, coordTransform.lToWRotation, draggableAsEntity);
Vector newPos = new Vector(draggableAsEntity);
//Move the entity back to its old position, the added velocity will be used afterwards
draggableAsEntity.setPosition(oldPos.X, oldPos.Y, oldPos.Z);
Vector addedVel = oldPos.getSubtraction(newPos);
velocityAddedToPlayer = addedVel;
draggableAsEntity.rotationYaw = rotYaw;
draggableAsEntity.rotationPitch = rotPitch;
draggableAsEntity.prevRotationYaw = prevYaw;
draggableAsEntity.prevRotationPitch = prevPitch;
Vector oldLookingPos = new Vector(draggableAsEntity.getLook(1.0F));
RotationMatrices.applyTransform(coordTransform.prevWToLRotation, oldLookingPos);
RotationMatrices.applyTransform(coordTransform.lToWRotation, oldLookingPos);
double newPitch = Math.asin(oldLookingPos.Y) * -180D / Math.PI;
double f4 = -Math.cos(-newPitch * 0.017453292D);
double radianYaw = Math.atan2((oldLookingPos.X / f4), (oldLookingPos.Z / f4));
radianYaw += Math.PI;
radianYaw *= -180D / Math.PI;
if (!(Double.isNaN(radianYaw) || Math.abs(newPitch) > 85)) {
double wrappedYaw = MathHelper.wrapDegrees(radianYaw);
double wrappedRotYaw = MathHelper.wrapDegrees(draggableAsEntity.rotationYaw);
double yawDif = wrappedYaw - wrappedRotYaw;
if (Math.abs(yawDif) > 180D) {
if (yawDif < 0) {
yawDif += 360D;
} else {
yawDif -= 360D;
}
}
yawDif %= 360D;
final double threshold = .1D;
if (Math.abs(yawDif) < threshold) {
yawDif = 0D;
}
yawDifVelocity = yawDif;
}
}
boolean onGroundOrig = draggableAsEntity.onGround;
if (!ValkyrienWarfareMod.physicsManager.isEntityFixed(draggableAsEntity)) {
float originalWalked = draggableAsEntity.distanceWalkedModified;
float originalWalkedOnStep = draggableAsEntity.distanceWalkedOnStepModified;
boolean originallySneaking = draggableAsEntity.isSneaking();
draggableAsEntity.setSneaking(false);
if (draggableAsEntity.worldObj.isRemote && draggableAsEntity instanceof EntityPlayerSP) {
EntityPlayerSP playerSP = (EntityPlayerSP) draggableAsEntity;
MovementInput moveInput = playerSP.movementInput;
originallySneaking = moveInput.sneak;
moveInput.sneak = false;
}
draggableAsEntity.moveEntity(velocityAddedToPlayer.X, velocityAddedToPlayer.Y, velocityAddedToPlayer.Z);
if (!(draggableAsEntity instanceof EntityPlayer)) {
if (draggableAsEntity instanceof EntityArrow) {
draggableAsEntity.prevRotationYaw = draggableAsEntity.rotationYaw;
draggableAsEntity.rotationYaw -= yawDifVelocity;
} else {
draggableAsEntity.prevRotationYaw = draggableAsEntity.rotationYaw;
draggableAsEntity.rotationYaw += yawDifVelocity;
}
} else {
if (draggableAsEntity.worldObj.isRemote) {
draggableAsEntity.prevRotationYaw = draggableAsEntity.rotationYaw;
draggableAsEntity.rotationYaw += yawDifVelocity;
}
}
//Do not add this movement as if the entity were walking it
draggableAsEntity.distanceWalkedModified = originalWalked;
draggableAsEntity.distanceWalkedOnStepModified = originalWalkedOnStep;
draggableAsEntity.setSneaking(originallySneaking);
if (draggableAsEntity.worldObj.isRemote && draggableAsEntity instanceof EntityPlayerSP) {
EntityPlayerSP playerSP = (EntityPlayerSP) draggableAsEntity;
MovementInput moveInput = playerSP.movementInput;
moveInput.sneak = originallySneaking;
}
}
if (onGroundOrig) {
draggableAsEntity.onGround = onGroundOrig;
}
velocityAddedToPlayer.multiply(.99D);
yawDifVelocity *= .95D;
}
use of net.minecraft.entity.projectile.EntityArrow in project Totemic by TeamTotemic.
the class ItemBaykokBow method onPlayerStoppedUsing.
@Override
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase entity, int timeLeft) {
if (!(entity instanceof EntityPlayer))
return;
EntityPlayer player = (EntityPlayer) entity;
boolean infinity = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
ItemStack arrow = findAmmo0(player);
int chargeTicks = this.getMaxItemUseDuration(stack) - timeLeft;
chargeTicks = ForgeEventFactory.onArrowLoose(stack, world, player, chargeTicks, !arrow.isEmpty() || infinity);
if (chargeTicks < 0)
return;
if (!arrow.isEmpty() || infinity) {
if (arrow.isEmpty())
arrow = new ItemStack(Items.ARROW);
float charge = getArrowVelocity(chargeTicks);
if (charge >= 0.1) {
// Forge: Fix consuming custom arrows.
boolean flag1 = infinity && arrow.getItem() instanceof ItemArrow;
if (!world.isRemote) {
ItemArrow itemarrow = ((ItemArrow) (arrow.getItem() instanceof ItemArrow ? arrow.getItem() : Items.ARROW));
EntityArrow entityarrow;
if (// Mundane arrows will become invisible
itemarrow == Items.ARROW) {
entityarrow = new EntityInvisArrow(world, player);
} else {
entityarrow = itemarrow.createArrow(world, arrow, entity);
}
if (entityarrow.getDamage() < 2.5)
entityarrow.setDamage(2.5);
entityarrow.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, charge * 4.0F, 1.0F);
if (charge == 1.0F)
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 (flag1)
entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
world.spawnEntity(entityarrow);
}
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + charge * 0.5F);
if (!flag1) {
arrow.shrink(1);
if (arrow.isEmpty())
player.inventory.deleteStack(arrow);
}
player.addStat(StatList.getObjectUseStats(this));
}
}
}
Aggregations