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