Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 266 lines 9.6 kB view raw
1package net.minecraft.server; 2 3import org.bukkit.craftbukkit.entity.CraftEntity; 4import org.bukkit.craftbukkit.entity.CraftLivingEntity; 5import org.bukkit.entity.Explosive; 6import org.bukkit.entity.Projectile; 7import org.bukkit.event.entity.EntityDamageByEntityEvent; 8import org.bukkit.event.entity.EntityDamageEvent; 9import org.bukkit.event.entity.ExplosionPrimeEvent; 10import org.bukkit.event.entity.ProjectileHitEvent; 11 12import java.util.List; 13 14// CraftBukkit start 15// CraftBukkit end 16 17public class EntityFireball extends Entity { 18 19 private int f = -1; 20 private int g = -1; 21 private int h = -1; 22 private int i = 0; 23 private boolean j = false; 24 public int a = 0; 25 public EntityLiving shooter; 26 private int k; 27 private int l = 0; 28 public double c; 29 public double d; 30 public double e; 31 32 public float yield = 1; // CraftBukkit 33 public boolean isIncendiary = true; // CraftBukkit 34 35 public EntityFireball(World world) { 36 super(world); 37 this.b(1.0F, 1.0F); 38 } 39 40 protected void b() { 41 } 42 43 public EntityFireball(World world, EntityLiving entityliving, double d0, double d1, double d2) { 44 super(world); 45 this.shooter = entityliving; 46 this.b(1.0F, 1.0F); 47 this.setPositionRotation(entityliving.locX, entityliving.locY, entityliving.locZ, entityliving.yaw, entityliving.pitch); 48 this.setPosition(this.locX, this.locY, this.locZ); 49 this.height = 0.0F; 50 this.motX = this.motY = this.motZ = 0.0D; 51 // CraftBukkit start (added setDirection method) 52 this.setDirection(d0, d1, d2); 53 } 54 55 public void setDirection(double d0, double d1, double d2) { 56 d0 += this.random.nextGaussian() * 0.4D; 57 d1 += this.random.nextGaussian() * 0.4D; 58 d2 += this.random.nextGaussian() * 0.4D; 59 double d3 = (double) MathHelper.a(d0 * d0 + d1 * d1 + d2 * d2); 60 61 this.c = d0 / d3 * 0.1D; 62 this.d = d1 / d3 * 0.1D; 63 this.e = d2 / d3 * 0.1D; 64 } 65 66 public void m_() { 67 super.m_(); 68 this.fireTicks = 10; 69 if (this.a > 0) { 70 --this.a; 71 } 72 73 if (this.j) { 74 int i = this.world.getTypeId(this.f, this.g, this.h); 75 76 if (i == this.i) { 77 ++this.k; 78 if (this.k == 1200) { 79 this.die(); 80 } 81 82 return; 83 } 84 85 this.j = false; 86 this.motX *= (double) (this.random.nextFloat() * 0.2F); 87 this.motY *= (double) (this.random.nextFloat() * 0.2F); 88 this.motZ *= (double) (this.random.nextFloat() * 0.2F); 89 this.k = 0; 90 this.l = 0; 91 } else { 92 ++this.l; 93 } 94 95 Vec3D vec3d = Vec3D.create(this.locX, this.locY, this.locZ); 96 Vec3D vec3d1 = Vec3D.create(this.locX + this.motX, this.locY + this.motY, this.locZ + this.motZ); 97 MovingObjectPosition movingobjectposition = this.world.a(vec3d, vec3d1); 98 99 vec3d = Vec3D.create(this.locX, this.locY, this.locZ); 100 vec3d1 = Vec3D.create(this.locX + this.motX, this.locY + this.motY, this.locZ + this.motZ); 101 if (movingobjectposition != null) { 102 vec3d1 = Vec3D.create(movingobjectposition.f.a, movingobjectposition.f.b, movingobjectposition.f.c); 103 } 104 105 Entity entity = null; 106 List list = this.world.b((Entity) this, this.boundingBox.a(this.motX, this.motY, this.motZ).b(1.0D, 1.0D, 1.0D)); 107 double d0 = 0.0D; 108 109 for (int j = 0; j < list.size(); ++j) { 110 Entity entity1 = (Entity) list.get(j); 111 112 if (entity1.l_() && (entity1 != this.shooter || this.l >= 25)) { 113 float f = 0.3F; 114 AxisAlignedBB axisalignedbb = entity1.boundingBox.b((double) f, (double) f, (double) f); 115 MovingObjectPosition movingobjectposition1 = axisalignedbb.a(vec3d, vec3d1); 116 117 if (movingobjectposition1 != null) { 118 double d1 = vec3d.a(movingobjectposition1.f); 119 120 if (d1 < d0 || d0 == 0.0D) { 121 entity = entity1; 122 d0 = d1; 123 } 124 } 125 } 126 } 127 128 if (entity != null) { 129 movingobjectposition = new MovingObjectPosition(entity); 130 } 131 132 if (movingobjectposition != null) { 133 // CraftBukkit start 134 ProjectileHitEvent phe = new ProjectileHitEvent((Projectile) this.getBukkitEntity()); 135 this.world.getServer().getPluginManager().callEvent(phe); 136 // CraftBukkit end 137 if (!this.world.isStatic) { 138 // CraftBukkit start 139 if (movingobjectposition.entity != null) { 140 boolean stick; 141 if (movingobjectposition.entity instanceof EntityLiving) { 142 org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity(); 143 Projectile projectile = (Projectile) this.getBukkitEntity(); 144 145 // TODO @see EntityArrow#162 146 EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, 0); 147 this.world.getServer().getPluginManager().callEvent(event); 148 149 this.shooter = (projectile.getShooter() == null) ? null : ((CraftLivingEntity) projectile.getShooter()).getHandle(); 150 151 if (event.isCancelled()) { 152 stick = !projectile.doesBounce(); 153 } else { 154 // this function returns if the fireball should stick in or not, i.e. !bounce 155 stick = movingobjectposition.entity.damageEntity(this, event.getDamage()); 156 } 157 } else { 158 stick = movingobjectposition.entity.damageEntity(this.shooter, 0); 159 } 160 if (stick) { 161 ; 162 } 163 } 164 165 ExplosionPrimeEvent event = new ExplosionPrimeEvent((Explosive) CraftEntity.getEntity(this.world.getServer(), this)); 166 this.world.getServer().getPluginManager().callEvent(event); 167 168 if (!event.isCancelled()) { 169 // give 'this' instead of (Entity) null so we know what causes the damage 170 this.world.createExplosion(this, this.locX, this.locY, this.locZ, event.getRadius(), event.getFire()); 171 } 172 // CraftBukkit end 173 } 174 175 this.die(); 176 } 177 178 this.locX += this.motX; 179 this.locY += this.motY; 180 this.locZ += this.motZ; 181 float f1 = MathHelper.a(this.motX * this.motX + this.motZ * this.motZ); 182 183 this.yaw = (float) (Math.atan2(this.motX, this.motZ) * 180.0D / 3.1415927410125732D); 184 185 for (this.pitch = (float) (Math.atan2(this.motY, (double) f1) * 180.0D / 3.1415927410125732D); this.pitch - this.lastPitch < -180.0F; this.lastPitch -= 360.0F) { 186 ; 187 } 188 189 while (this.pitch - this.lastPitch >= 180.0F) { 190 this.lastPitch += 360.0F; 191 } 192 193 while (this.yaw - this.lastYaw < -180.0F) { 194 this.lastYaw -= 360.0F; 195 } 196 197 while (this.yaw - this.lastYaw >= 180.0F) { 198 this.lastYaw += 360.0F; 199 } 200 201 this.pitch = this.lastPitch + (this.pitch - this.lastPitch) * 0.2F; 202 this.yaw = this.lastYaw + (this.yaw - this.lastYaw) * 0.2F; 203 float f2 = 0.95F; 204 205 if (this.ad()) { 206 for (int k = 0; k < 4; ++k) { 207 float f3 = 0.25F; 208 209 this.world.a("bubble", this.locX - this.motX * (double) f3, this.locY - this.motY * (double) f3, this.locZ - this.motZ * (double) f3, this.motX, this.motY, this.motZ); 210 } 211 212 f2 = 0.8F; 213 } 214 215 this.motX += this.c; 216 this.motY += this.d; 217 this.motZ += this.e; 218 this.motX *= (double) f2; 219 this.motY *= (double) f2; 220 this.motZ *= (double) f2; 221 this.world.a("smoke", this.locX, this.locY + 0.5D, this.locZ, 0.0D, 0.0D, 0.0D); 222 this.setPosition(this.locX, this.locY, this.locZ); 223 } 224 225 public void b(NBTTagCompound nbttagcompound) { 226 nbttagcompound.a("xTile", (short) this.f); 227 nbttagcompound.a("yTile", (short) this.g); 228 nbttagcompound.a("zTile", (short) this.h); 229 nbttagcompound.a("inTile", (byte) this.i); 230 nbttagcompound.a("shake", (byte) this.a); 231 nbttagcompound.a("inGround", (byte) (this.j ? 1 : 0)); 232 } 233 234 public void a(NBTTagCompound nbttagcompound) { 235 this.f = nbttagcompound.d("xTile"); 236 this.g = nbttagcompound.d("yTile"); 237 this.h = nbttagcompound.d("zTile"); 238 this.i = nbttagcompound.c("inTile") & 255; 239 this.a = nbttagcompound.c("shake") & 255; 240 this.j = nbttagcompound.c("inGround") == 1; 241 } 242 243 public boolean l_() { 244 return true; 245 } 246 247 public boolean damageEntity(Entity entity, int i) { 248 this.af(); 249 if (entity != null) { 250 Vec3D vec3d = entity.Z(); 251 252 if (vec3d != null) { 253 this.motX = vec3d.a; 254 this.motY = vec3d.b; 255 this.motZ = vec3d.c; 256 this.c = this.motX * 0.1D; 257 this.d = this.motY * 0.1D; 258 this.e = this.motZ * 0.1D; 259 } 260 261 return true; 262 } else { 263 return false; 264 } 265 } 266}