PaperMC/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySlime.patch
CraftBukkit/Spigot 25f3b50f6b Update to Minecraft 1.19
By: md_5 <git@md-5.net>
2022-06-08 02:00:00 +10:00

66 lines
2.7 KiB
Diff

--- a/net/minecraft/world/entity/monster/EntitySlime.java
+++ b/net/minecraft/world/entity/monster/EntitySlime.java
@@ -42,6 +42,14 @@
import net.minecraft.world.level.levelgen.SeededRandom;
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.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);
@@ -184,7 +192,7 @@
@Override
public EntityTypes<? extends EntitySlime> getType() {
- return super.getType();
+ return (EntityTypes<? extends EntitySlime>) super.getType(); // CraftBukkit - decompile error
}
@Override
@@ -198,6 +206,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);
+ return;
+ }
+ List<EntityLiving> slimes = new ArrayList<>(j);
+ // CraftBukkit end
+
for (int l = 0; l < k; ++l) {
float f1 = ((float) (l % 2) - 0.5F) * f;
float f2 = ((float) (l / 2) - 0.5F) * f;
@@ -212,8 +233,18 @@
entityslime.setInvulnerable(this.isInvulnerable());
entityslime.setSize(j, true);
entityslime.moveTo(this.getX() + (double) f1, this.getY() + 0.5D, this.getZ() + (double) f2, 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);
+ 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);