use of net.minecraft.network.play.server.SPacketChangeGameState in project MorePlanets by SteveKunG.
the class EntityArrowMP method onUpdate.
@Override
public void onUpdate() {
this.onEntityUpdate();
if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.prevRotationYaw = this.rotationYaw = (float) (MathHelper.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
this.prevRotationPitch = this.rotationPitch = (float) (MathHelper.atan2(this.motionY, f) * 180.0D / Math.PI);
}
BlockPos blockpos = new BlockPos(this.xTile, this.yTile, this.zTile);
IBlockState iblockstate = this.world.getBlockState(blockpos);
Block block = iblockstate.getBlock();
if (iblockstate.getMaterial() != Material.AIR) {
AxisAlignedBB axisalignedbb = iblockstate.getCollisionBoundingBox(this.world, blockpos);
if (axisalignedbb != null && axisalignedbb.offset(blockpos).contains(new Vec3d(this.posX, this.posY, this.posZ))) {
this.inGround = true;
}
}
if (this.arrowShake > 0) {
--this.arrowShake;
}
if (this.inGround) {
int meta = block.getMetaFromState(iblockstate);
if (block == this.inTile && meta == this.inData) {
++this.ticksInGround;
if (this.ticksInGround >= 1200) {
this.setDead();
}
} else {
this.inGround = false;
this.motionX *= this.rand.nextFloat() * 0.2F;
this.motionY *= this.rand.nextFloat() * 0.2F;
this.motionZ *= this.rand.nextFloat() * 0.2F;
this.ticksInGround = 0;
this.ticksInAir = 0;
}
} else {
++this.ticksInAir;
Vec3d vec31 = new Vec3d(this.posX, this.posY, this.posZ);
Vec3d vec3 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
RayTraceResult movingobjectposition = this.world.rayTraceBlocks(vec31, vec3, false, true, false);
vec31 = new Vec3d(this.posX, this.posY, this.posZ);
vec3 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
if (movingobjectposition != null) {
vec3 = new Vec3d(movingobjectposition.hitVec.x, movingobjectposition.hitVec.y, movingobjectposition.hitVec.z);
}
Entity entity = null;
List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D, 1.0D, 1.0D));
double d0 = 0.0D;
for (int i = 0; i < list.size(); ++i) {
Entity entity1 = list.get(i);
if (entity1.canBeCollidedWith() && (entity1 != this.shootingEntity || this.ticksInAir >= 5)) {
float f1 = 0.3F;
AxisAlignedBB axisalignedbb1 = entity1.getEntityBoundingBox().grow(f1, f1, f1);
RayTraceResult movingobjectposition1 = axisalignedbb1.calculateIntercept(vec31, vec3);
if (movingobjectposition1 != null) {
double d1 = vec31.squareDistanceTo(movingobjectposition1.hitVec);
if (d1 < d0 || d0 == 0.0D) {
entity = entity1;
d0 = d1;
}
}
}
}
if (entity != null) {
movingobjectposition = new RayTraceResult(entity);
}
if (movingobjectposition != null && movingobjectposition.entityHit != null && movingobjectposition.entityHit instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) movingobjectposition.entityHit;
if (entityplayer.capabilities.disableDamage || this.shootingEntity instanceof EntityPlayer && !((EntityPlayer) this.shootingEntity).canAttackPlayer(entityplayer)) {
movingobjectposition = null;
}
}
if (movingobjectposition != null) {
if (movingobjectposition.entityHit != null) {
float f2 = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
int l = MathHelper.ceil(f2 * this.damage);
if (this.getIsCritical()) {
l += this.rand.nextInt(l / 2 + 2);
}
DamageSource damagesource;
if (this.shootingEntity == null) {
damagesource = this.getDamageSource()[0];
} else {
damagesource = this.getDamageSource()[1];
}
if (this.isBurning() && !(movingobjectposition.entityHit instanceof EntityEnderman)) {
movingobjectposition.entityHit.setFire(5);
}
if (movingobjectposition.entityHit.attackEntityFrom(damagesource, l)) {
if (movingobjectposition.entityHit instanceof EntityLivingBase) {
EntityLivingBase entitylivingbase = (EntityLivingBase) movingobjectposition.entityHit;
this.addEffect(entitylivingbase);
if (!this.world.isRemote) {
entitylivingbase.setArrowCountInEntity(entitylivingbase.getArrowCountInEntity() + 1);
}
if (this.knockbackStrength > 0) {
float f7 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
if (f7 > 0.0F) {
movingobjectposition.entityHit.addVelocity(this.motionX * this.knockbackStrength * 0.6000000238418579D / f7, 0.1D, this.motionZ * this.knockbackStrength * 0.6000000238418579D / f7);
}
}
if (this.shootingEntity instanceof EntityLivingBase) {
EnchantmentHelper.applyThornEnchantments(entitylivingbase, this.shootingEntity);
EnchantmentHelper.applyArthropodEnchantments((EntityLivingBase) this.shootingEntity, entitylivingbase);
}
if (this.shootingEntity != null && movingobjectposition.entityHit != this.shootingEntity && movingobjectposition.entityHit instanceof EntityPlayer && this.shootingEntity instanceof EntityPlayerMP) {
((EntityPlayerMP) this.shootingEntity).connection.sendPacket(new SPacketChangeGameState(6, 0.0F));
}
}
this.playSound(SoundEvents.ENTITY_ARROW_HIT, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
if (!(movingobjectposition.entityHit instanceof EntityEnderman)) {
this.setDead();
}
} else {
this.motionX *= -0.10000000149011612D;
this.motionY *= -0.10000000149011612D;
this.motionZ *= -0.10000000149011612D;
this.rotationYaw += 180.0F;
this.prevRotationYaw += 180.0F;
this.ticksInAir = 0;
}
} else {
BlockPos blockpos1 = movingobjectposition.getBlockPos();
this.xTile = blockpos1.getX();
this.yTile = blockpos1.getY();
this.zTile = blockpos1.getZ();
IBlockState iblockstate1 = this.world.getBlockState(blockpos1);
this.inTile = iblockstate1.getBlock();
this.inData = this.inTile.getMetaFromState(iblockstate1);
this.motionX = (float) (movingobjectposition.hitVec.x - this.posX);
this.motionY = (float) (movingobjectposition.hitVec.y - this.posY);
this.motionZ = (float) (movingobjectposition.hitVec.z - this.posZ);
float f5 = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
this.posX -= this.motionX / f5 * 0.05000000074505806D;
this.posY -= this.motionY / f5 * 0.05000000074505806D;
this.posZ -= this.motionZ / f5 * 0.05000000074505806D;
this.playSound(SoundEvents.ENTITY_ARROW_HIT, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
this.inGround = true;
this.arrowShake = 7;
this.setIsCritical(false);
if (iblockstate1.getMaterial() != Material.AIR) {
this.inTile.onEntityCollidedWithBlock(this.world, blockpos1, iblockstate1, this);
}
}
}
if (this.getIsCritical()) {
for (int k = 0; k < 4; ++k) {
this.world.spawnParticle(EnumParticleTypes.CRIT, this.posX + this.motionX * k / 4.0D, this.posY + this.motionY * k / 4.0D, this.posZ + this.motionZ * k / 4.0D, -this.motionX, -this.motionY + 0.2D, -this.motionZ, new int[0]);
}
}
this.posX += this.motionX;
this.posY += this.motionY;
this.posZ += this.motionZ;
float f3 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotationYaw = (float) (MathHelper.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
for (this.rotationPitch = (float) (MathHelper.atan2(this.motionY, f3) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) {
}
while (this.rotationPitch - this.prevRotationPitch >= 180.0F) {
this.prevRotationPitch += 360.0F;
}
while (this.rotationYaw - this.prevRotationYaw < -180.0F) {
this.prevRotationYaw -= 360.0F;
}
while (this.rotationYaw - this.prevRotationYaw >= 180.0F) {
this.prevRotationYaw += 360.0F;
}
this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
float f4 = 0.99F;
float motionGravity = TransformerHooks.getArrowGravity(this);
if (this.isInWater()) {
for (int i1 = 0; i1 < 4; ++i1) {
float f8 = 0.25F;
this.world.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * f8, this.posY - this.motionY * f8, this.posZ - this.motionZ * f8, this.motionX, this.motionY, this.motionZ, new int[0]);
}
f4 = 0.6F;
}
if (this.isWet()) {
this.extinguish();
}
this.doMotion(f4, f3, motionGravity);
this.setPosition(this.posX, this.posY, this.posZ);
this.doBlockCollisions();
}
}
use of net.minecraft.network.play.server.SPacketChangeGameState in project MorePlanets by SteveKunG.
the class EntityLaserBullet method onUpdate.
@Override
public void onUpdate() {
super.onUpdate();
if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.prevRotationYaw = this.rotationYaw = (float) (MathHelper.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
this.prevRotationPitch = this.rotationPitch = (float) (MathHelper.atan2(this.motionY, f) * 180.0D / Math.PI);
}
++this.ticksInAir;
Vec3d vec31 = new Vec3d(this.posX, this.posY, this.posZ);
Vec3d vec3 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
RayTraceResult movingobjectposition = this.world.rayTraceBlocks(vec31, vec3, false, true, false);
vec31 = new Vec3d(this.posX, this.posY, this.posZ);
vec3 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
if (this.ticksInAir > 8) {
this.setDead();
}
if (this.isInWater()) {
for (int i = 0; i < 4; ++i) {
this.world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, this.posX - this.motionX, this.posY - this.motionY, this.posZ - this.motionZ, this.motionX, this.motionY, this.motionZ);
this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.HOSTILE, 0.25F, 0.9F);
}
this.setDead();
}
if (movingobjectposition != null) {
vec3 = new Vec3d(movingobjectposition.hitVec.x, movingobjectposition.hitVec.y, movingobjectposition.hitVec.z);
}
Entity entity = null;
List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D, 1.0D, 1.0D));
double d0 = 0.0D;
for (int i = 0; i < list.size(); ++i) {
Entity entity1 = list.get(i);
if (entity1.canBeCollidedWith() && (entity1 != this.shootingEntity || this.ticksInAir >= 5)) {
float f1 = 0.3F;
AxisAlignedBB axisalignedbb1 = entity1.getEntityBoundingBox().grow(f1, f1, f1);
RayTraceResult movingobjectposition1 = axisalignedbb1.calculateIntercept(vec31, vec3);
if (movingobjectposition1 != null) {
double d1 = vec31.squareDistanceTo(movingobjectposition1.hitVec);
if (d1 < d0 || d0 == 0.0D) {
entity = entity1;
d0 = d1;
}
}
}
}
if (entity != null) {
movingobjectposition = new RayTraceResult(entity);
}
if (movingobjectposition != null && movingobjectposition.entityHit != null && movingobjectposition.entityHit instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) movingobjectposition.entityHit;
if (entityplayer.capabilities.disableDamage || this.shootingEntity instanceof EntityPlayer && !((EntityPlayer) this.shootingEntity).canAttackPlayer(entityplayer)) {
movingobjectposition = null;
}
}
switch(this.getLaserType()) {
case 0:
this.damage = 2.0D;
break;
case 1:
this.damage = 4.5D;
break;
}
if (this.isInWater()) {
this.damage = 0.0D;
}
if (movingobjectposition != null) {
if (movingobjectposition.entityHit != null) {
float f2 = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
int l = MathHelper.ceil(f2 * this.damage);
DamageSource damagesource;
if (this.shootingEntity == null) {
damagesource = DamageSourceMP.causeLaserDamage(this, this);
} else {
damagesource = DamageSourceMP.causeLaserDamage(this, this.shootingEntity);
}
if (movingobjectposition.entityHit.attackEntityFrom(damagesource, l)) {
if (movingobjectposition.entityHit instanceof EntityLivingBase) {
EntityLivingBase entitylivingbase = (EntityLivingBase) movingobjectposition.entityHit;
if (this.shootingEntity instanceof EntityLivingBase) {
EnchantmentHelper.applyThornEnchantments(entitylivingbase, this.shootingEntity);
EnchantmentHelper.applyArthropodEnchantments((EntityLivingBase) this.shootingEntity, entitylivingbase);
}
if (this.shootingEntity != null && movingobjectposition.entityHit != this.shootingEntity && movingobjectposition.entityHit instanceof EntityPlayer && this.shootingEntity instanceof EntityPlayerMP) {
((EntityPlayerMP) this.shootingEntity).connection.sendPacket(new SPacketChangeGameState(6, 0.0F));
}
if (this.getLaserType() == 1) {
entitylivingbase.addPotionEffect(new PotionEffect(MPPotions.INFECTED_CRYSTALLIZE, 100));
}
}
if (!(movingobjectposition.entityHit instanceof EntityEnderman)) {
this.setDead();
}
}
} else {
this.motionX = (float) (movingobjectposition.hitVec.x - this.posX);
this.motionY = (float) (movingobjectposition.hitVec.y - this.posY);
this.motionZ = (float) (movingobjectposition.hitVec.z - this.posZ);
float f5 = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
this.posX -= this.motionX / f5 * 0.05000000074505806D;
this.posY -= this.motionY / f5 * 0.05000000074505806D;
this.posZ -= this.motionZ / f5 * 0.05000000074505806D;
this.setDead();
}
}
this.posX += this.motionX;
this.posY += this.motionY;
this.posZ += this.motionZ;
float f3 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotationYaw = (float) (MathHelper.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
for (this.rotationPitch = (float) (MathHelper.atan2(this.motionY, f3) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) {
}
while (this.rotationPitch - this.prevRotationPitch >= 180.0F) {
this.prevRotationPitch += 360.0F;
}
while (this.rotationYaw - this.prevRotationYaw < -180.0F) {
this.prevRotationYaw -= 360.0F;
}
while (this.rotationYaw - this.prevRotationYaw >= 180.0F) {
this.prevRotationYaw += 360.0F;
}
this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
float speed = 1.5F;
this.motionX *= speed;
this.motionY *= speed;
this.motionZ *= speed;
this.setPosition(this.posX, this.posY, this.posZ);
this.doBlockCollisions();
}
Aggregations