3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-21 05:50:05 +01:00
Paper/nms-patches/EntityEgg.patch

67 Zeilen
2.6 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityEgg.java
+++ b/net/minecraft/server/EntityEgg.java
@@ -1,5 +1,12 @@
package net.minecraft.server;
+// CraftBukkit start
+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 EntityEgg extends EntityProjectile {
public EntityEgg(World world) {
2016-06-09 03:43:49 +02:00
@@ -23,21 +30,37 @@
movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.getShooter()), 0.0F);
}
2015-02-26 23:41:06 +01:00
- if (!this.world.isClientSide && this.random.nextInt(8) == 0) {
- byte b0 = 1;
+ // CraftBukkit start - Fire PlayerEggThrowEvent
2015-02-26 23:41:06 +01:00
+ boolean hatching = !this.world.isClientSide && this.random.nextInt(8) == 0;
+ int numHatching = (this.random.nextInt(32) == 0) ? 4 : 1;
+ if (!hatching) {
+ numHatching = 0;
+ }
2015-02-26 23:41:06 +01:00
+
+ EntityType hatchingType = EntityType.CHICKEN;
2015-02-26 23:41:06 +01:00
+
+ Entity shooter = this.getShooter();
+ if (shooter instanceof EntityPlayer) {
+ Player player = (shooter == null) ? null : (Player) shooter.getBukkitEntity();
+
+ PlayerEggThrowEvent event = new PlayerEggThrowEvent(player, (org.bukkit.entity.Egg) this.getBukkitEntity(), hatching, (byte) numHatching, hatchingType);
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ hatching = event.isHatching();
+ numHatching = event.getNumHatches();
+ hatchingType = event.getHatchingType();
+ }
- if (this.random.nextInt(32) == 0) {
- b0 = 4;
- }
-
- for (int i = 0; i < b0; ++i) {
- EntityChicken entitychicken = new EntityChicken(this.world);
-
- entitychicken.setAgeRaw(-24000);
- entitychicken.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, 0.0F);
- this.world.addEntity(entitychicken);
- }
+ if (hatching) {
+ for (int k = 0; k < numHatching; k++) {
+ Entity entity = world.getWorld().createEntity(new org.bukkit.Location(world.getWorld(), this.locX, this.locY, this.locZ, this.yaw, 0.0F), hatchingType.getEntityClass());
+ if (entity.getBukkitEntity() instanceof Ageable) {
+ ((Ageable) entity.getBukkitEntity()).setBaby();
+ }
+ world.getWorld().addEntity(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG);
+ }
}
+ // CraftBukkit end
double d0 = 0.08D;