/
EntityItemProjectile_v1_14_R1.java
185 lines (157 loc) · 6.81 KB
/
EntityItemProjectile_v1_14_R1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package net.aufdemrand.denizen.nms.impl.entities;
import net.aufdemrand.denizen.nms.Handler_v1_14_R1;
import net.aufdemrand.denizencore.utilities.debugging.dB;
import net.minecraft.server.v1_14_R1.*;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_14_R1.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
import java.util.Iterator;
import java.util.UUID;
public class EntityItemProjectile_v1_14_R1 extends EntityItem implements IProjectile {
public Entity shooter;
public UUID shooterId;
public Entity c;
private int aw;
public boolean inGround;
public int shake;
public EntityItemProjectile_v1_14_R1(CraftWorld craftWorld, Location location, org.bukkit.inventory.ItemStack itemStack) {
super(EntityTypes.ITEM, craftWorld.getHandle());
try {
Handler_v1_14_R1.ENTITY_BUKKITYENTITY.set(this, new CraftItemProjectile_v1_14_R1((CraftServer) Bukkit.getServer(), this));
}
catch (Exception ex) {
dB.echoError(ex);
}
this.pickupDelay = Integer.MAX_VALUE;
setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
//this.setSize(0.25F, 0.25F); as of 1.14, part of EntityTypes
this.setItemStack(CraftItemStack.asNMSCopy(itemStack));
world.addEntity(this);
}
@Override
public void tick() {
this.H = this.locX;
this.I = this.locY;
this.J = this.locZ;
super.tick();
if (this.shake > 0) {
--this.shake;
}
if (this.inGround) {
this.inGround = false;
this.setMot(this.getMot().d((double) (this.random.nextFloat() * 0.2F), (double) (this.random.nextFloat() * 0.2F), (double) (this.random.nextFloat() * 0.2F)));
}
AxisAlignedBB axisalignedbb = this.getBoundingBox().a(this.getMot()).g(1.0D);
Iterator iterator = this.world.getEntities(this, axisalignedbb, (entityx) -> {
return !entityx.isAlive() && entityx.isInteractable();
}).iterator();
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();
if (entity == this.c) {
++this.aw;
break;
}
if (this.shooter != null && this.ticksLived < 2 && this.c == null && this.shooter == entity) {
this.c = entity;
this.aw = 3;
break;
}
}
MovingObjectPosition movingobjectposition = ProjectileHelper.a(this, axisalignedbb, (entity1) -> {
return !entity1.isAlive() && entity1.isInteractable() && entity1 != this.c;
}, RayTrace.BlockCollisionOption.OUTLINE, true);
if (this.c != null && this.aw-- <= 0) {
this.c = null;
}
if (movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) {
if (movingobjectposition.getType() == MovingObjectPosition.EnumMovingObjectType.BLOCK && this.world.getType(((MovingObjectPositionBlock) movingobjectposition).getBlockPosition()).getBlock() == Blocks.NETHER_PORTAL) {
this.c(((MovingObjectPositionBlock) movingobjectposition).getBlockPosition());
}
else {
this.a(movingobjectposition);
if (this.dead) {
CraftEventFactory.callProjectileHitEvent(this, movingobjectposition);
}
}
}
Vec3D vec3d = this.getMot();
this.locX += vec3d.x;
this.locY += vec3d.y;
this.locZ += vec3d.z;
float f = MathHelper.sqrt(b(vec3d));
this.yaw = (float) (MathHelper.d(vec3d.x, vec3d.z) * 57.2957763671875D);
// TODO: what is this???
for (this.pitch = (float) (MathHelper.d(vec3d.y, (double) f) * 57.2957763671875D); this.pitch - this.lastPitch < -180.0F; this.lastPitch -= 360.0F) {
}
while (this.pitch - this.lastPitch >= 180.0F) {
this.lastPitch += 360.0F;
}
while (this.yaw - this.lastYaw < -180.0F) {
this.lastYaw -= 360.0F;
}
while (this.yaw - this.lastYaw >= 180.0F) {
this.lastYaw += 360.0F;
}
this.pitch = MathHelper.g(0.2F, this.lastPitch, this.pitch);
this.yaw = MathHelper.g(0.2F, this.lastYaw, this.yaw);
float f1;
if (this.isInWater()) {
for (int i = 0; i < 4; ++i) {
float f2 = 0.25F;
this.world.addParticle(Particles.BUBBLE, this.locX - vec3d.x * 0.25D, this.locY - vec3d.y * 0.25D, this.locZ - vec3d.z * 0.25D, vec3d.x, vec3d.y, vec3d.z);
}
f1 = 0.8F;
}
else {
f1 = 0.99F;
}
this.setMot(vec3d.a((double) f1));
if (!this.isNoGravity()) {
Vec3D vec3d1 = this.getMot();
this.setMot(vec3d1.x, vec3d1.y - 0.03, vec3d1.z);
}
this.setPosition(this.locX, this.locY, this.locZ);
}
@Override
public void shoot(double d0, double d1, double d2, float f, float f1) {
float f2 = MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
d0 /= f2;
d1 /= f2;
d2 /= f2;
d0 += random.nextGaussian() * 0.007499999832361937D * f1;
d1 += random.nextGaussian() * 0.007499999832361937D * f1;
d2 += random.nextGaussian() * 0.007499999832361937D * f1;
d0 *= f;
d1 *= f;
d2 *= f;
setMot(d0, d1, d2);
float f3 = MathHelper.sqrt(d0 * d0 + d2 * d2);
lastYaw = yaw = (float) (Math.atan2(d0, d2) * 180.0D / 3.1415927410125732D);
lastPitch = pitch = (float) (Math.atan2(d1, f3) * 180.0D / 3.1415927410125732D);
}
protected void a(MovingObjectPosition var1) {
if (var1 instanceof MovingObjectPositionEntity) {
((MovingObjectPositionEntity) var1).getEntity().damageEntity(DamageSource.projectile(this, this.getShooter()), 0);
}
this.die();
}
public Entity getShooter() {
if (this.shooter == null && this.shooterId != null && this.world instanceof WorldServer) {
Entity entity = ((WorldServer) this.world).getEntity(this.shooterId);
if (entity instanceof EntityLiving) {
this.shooter = entity;
}
else {
this.shooterId = null;
}
}
return this.shooter;
}
@Override
public CraftItemProjectile_v1_14_R1 getBukkitEntity() {
return (CraftItemProjectile_v1_14_R1) super.getBukkitEntity();
}
}