PaperMC/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySlime.patch

83 lines
3.4 KiB
Diff
Raw Normal View History

2021-03-15 23:00:00 +01:00
--- a/net/minecraft/world/entity/monster/EntitySlime.java
+++ b/net/minecraft/world/entity/monster/EntitySlime.java
@@ -43,6 +43,15 @@
import net.minecraft.world.level.levelgen.SeededRandom;
2021-03-15 23:00:00 +01:00
import net.minecraft.world.phys.Vec3D;
+// CraftBukkit start
+import java.util.ArrayList;
+import java.util.List;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityRemoveEvent;
+import org.bukkit.event.entity.EntityTransformEvent;
+import org.bukkit.event.entity.SlimeSplitEvent;
+// CraftBukkit end
+
public class EntitySlime extends EntityInsentient implements IMonster {
private static final DataWatcherObject<Integer> ID_SIZE = DataWatcher.defineId(EntitySlime.class, DataWatcherRegistry.INT);
@@ -193,11 +202,18 @@
@Override
public EntityTypes<? extends EntitySlime> getType() {
- return super.getType();
+ return (EntityTypes<? extends EntitySlime>) super.getType(); // CraftBukkit - decompile error
}
@Override
public void remove(Entity.RemovalReason entity_removalreason) {
+ // CraftBukkit start - add Bukkit remove cause
+ this.remove(entity_removalreason, null);
+ }
+
+ @Override
+ public void remove(Entity.RemovalReason entity_removalreason, EntityRemoveEvent.Cause cause) {
+ // CraftBukkit end
int i = this.getSize();
if (!this.level().isClientSide && i > 1 && this.isDeadOrDying()) {
@@ -208,6 +224,19 @@
int j = i / 2;
int k = 2 + this.random.nextInt(3);
+ // CraftBukkit start
+ SlimeSplitEvent event = new SlimeSplitEvent((org.bukkit.entity.Slime) this.getBukkitEntity(), k);
+ this.level().getCraftServer().getPluginManager().callEvent(event);
+
+ if (!event.isCancelled() && event.getCount() > 0) {
+ k = event.getCount();
+ } else {
+ super.remove(entity_removalreason, cause); // CraftBukkit - add Bukkit remove cause
+ return;
+ }
+ List<EntityLiving> slimes = new ArrayList<>(j);
+ // CraftBukkit end
+
for (int l = 0; l < k; ++l) {
float f2 = ((float) (l % 2) - 0.5F) * f1;
float f3 = ((float) (l / 2) - 0.5F) * f1;
@@ -223,12 +252,21 @@
entityslime.setInvulnerable(this.isInvulnerable());
entityslime.setSize(j, true);
entityslime.moveTo(this.getX() + (double) f2, this.getY() + 0.5D, this.getZ() + (double) f3, this.random.nextFloat() * 360.0F, 0.0F);
- this.level().addFreshEntity(entityslime);
+ slimes.add(entityslime); // CraftBukkit
}
}
+ // CraftBukkit start
+ if (CraftEventFactory.callEntityTransformEvent(this, slimes, EntityTransformEvent.TransformReason.SPLIT).isCancelled()) {
+ super.remove(entity_removalreason, cause); // CraftBukkit - add Bukkit remove cause
+ return;
+ }
+ for (EntityLiving living : slimes) {
+ this.level().addFreshEntity(living, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SLIME_SPLIT); // CraftBukkit - SpawnReason
+ }
+ // CraftBukkit end
}
- super.remove(entity_removalreason);
+ super.remove(entity_removalreason, cause); // CraftBukkit - add Bukkit remove cause
}
@Override