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
|
--- a/net/minecraft/world/entity/projectile/ThrownEgg.java
+++ b/net/minecraft/world/entity/projectile/ThrownEgg.java
@@ -1,47 +1,45 @@
package net.minecraft.world.entity.projectile;
-import net.minecraft.core.particles.ItemParticleOption;
-import net.minecraft.core.particles.ParticleTypes;
-import net.minecraft.world.entity.EntityType;
-import net.minecraft.world.entity.LivingEntity;
-import net.minecraft.world.entity.animal.Chicken;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
+import net.minecraft.core.particles.ItemParticleOption;
+import net.minecraft.core.particles.ParticleTypes;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.LivingEntity;
+import org.bukkit.entity.Ageable;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.PlayerEggThrowEvent;
+// CraftBukkit end
public class ThrownEgg extends ThrowableItemProjectile {
- public ThrownEgg(EntityType<? extends ThrownEgg> entityType, Level level) {
+
+ public ThrownEgg(net.minecraft.world.entity.EntityType<? extends ThrownEgg> entityType, Level level) {
super(entityType, level);
}
public ThrownEgg(Level level, LivingEntity shooter) {
- super(EntityType.EGG, shooter, level);
+ super(net.minecraft.world.entity.EntityType.EGG, shooter, level);
}
- public ThrownEgg(Level level, double x, double y, double z) {
- super(EntityType.EGG, x, y, z, level);
+ public ThrownEgg(Level level, double x, double d1, double y) {
+ super(net.minecraft.world.entity.EntityType.EGG, x, d1, y, level);
}
@Override
public void handleEntityEvent(byte id) {
if (id == 3) {
- double d = 0.08;
+ double d0 = 0.08D;
- for (int i = 0; i < 8; i++) {
- this.level()
- .addParticle(
- new ItemParticleOption(ParticleTypes.ITEM, this.getItem()),
- this.getX(),
- this.getY(),
- this.getZ(),
- ((double)this.random.nextFloat() - 0.5) * 0.08,
- ((double)this.random.nextFloat() - 0.5) * 0.08,
- ((double)this.random.nextFloat() - 0.5) * 0.08
- );
+ for (int i = 0; i < 8; ++i) {
+ this.level().addParticle(new ItemParticleOption(ParticleTypes.ITEM, this.getItem()), this.getX(), this.getY(), this.getZ(), ((double) this.random.nextFloat() - 0.5D) * 0.08D, ((double) this.random.nextFloat() - 0.5D) * 0.08D, ((double) this.random.nextFloat() - 0.5D) * 0.08D);
}
}
+
}
@Override
@@ -54,25 +52,55 @@
protected void onHit(HitResult result) {
super.onHit(result);
if (!this.level().isClientSide) {
- if (this.random.nextInt(8) == 0) {
- int i = 1;
+ // CraftBukkit start
+ boolean hatching = this.random.nextInt(8) == 0;
+ if (true) {
+ // CraftBukkit end
+ byte b0 = 1;
+
if (this.random.nextInt(32) == 0) {
- i = 4;
+ b0 = 4;
}
- for (int i1 = 0; i1 < i; i1++) {
- Chicken chicken = EntityType.CHICKEN.create(this.level());
- if (chicken != null) {
- chicken.setAge(-24000);
- chicken.moveTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), 0.0F);
- this.level().addFreshEntity(chicken);
+ // CraftBukkit start
+ EntityType hatchingType = EntityType.CHICKEN;
+
+ Entity shooter = this.getOwner();
+ if (!hatching) {
+ b0 = 0;
+ }
+ if (shooter instanceof ServerPlayer) {
+ PlayerEggThrowEvent event = new PlayerEggThrowEvent((Player) shooter.getBukkitEntity(), (org.bukkit.entity.Egg) this.getBukkitEntity(), hatching, b0, hatchingType);
+ this.level().getCraftServer().getPluginManager().callEvent(event);
+
+ b0 = event.getNumHatches();
+ hatching = event.isHatching();
+ hatchingType = event.getHatchingType();
+ // If hatching is set to false, ensure child count is 0
+ if (!hatching) {
+ b0 = 0;
}
}
+ // CraftBukkit end
+
+ for (int i = 0; i < b0; ++i) {
+ Entity entitychicken = this.level().getWorld().makeEntity(new org.bukkit.Location(this.level().getWorld(), this.getX(), this.getY(), this.getZ(), this.getYRot(), 0.0F), hatchingType.getEntityClass()); // CraftBukkit
+
+ if (entitychicken != null) {
+ // CraftBukkit start
+ if (entitychicken.getBukkitEntity() instanceof Ageable) {
+ ((Ageable) entitychicken.getBukkitEntity()).setBaby();
+ }
+ this.level().addFreshEntity(entitychicken, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG);
+ // CraftBukkit end
+ }
+ }
}
- this.level().broadcastEntityEvent(this, (byte)3);
+ this.level().broadcastEntityEvent(this, (byte) 3);
this.discard();
}
+
}
@Override
|