Improve death events
This adds the ability to cancel the death events and to modify the sound an entity makes when dying. (In cases were no sound should it will be called with shouldPlaySound set to false allowing unsilencing of silent entities) It makes handling of entity deaths a lot nicer as you no longer need to listen on the damage event and calculate if the entity dies yourself to cancel the death which has the benefit of also receiving the dropped items and experience which is otherwise only properly possible by using internal code. == AT == public net.minecraft.world.entity.LivingEntity getDeathSound()Lnet/minecraft/sounds/SoundEvent; public net.minecraft.world.entity.LivingEntity getSoundVolume()F
This commit is contained in:
@ -279,7 +279,42 @@
|
||||
ProfilerFiller gameprofilerfiller = Profiler.get();
|
||||
|
||||
gameprofilerfiller.push("sensing");
|
||||
@@ -1338,7 +1444,7 @@
|
||||
@@ -1011,6 +1117,12 @@
|
||||
|
||||
}
|
||||
|
||||
+ // Paper start
|
||||
+ protected boolean shouldSkipLoot(EquipmentSlot slot) { // method to avoid to fallback into the global mob loot logic (i.e fox)
|
||||
+ return false;
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
@Override
|
||||
protected void dropCustomDeathLoot(ServerLevel world, DamageSource source, boolean causedByPlayer) {
|
||||
super.dropCustomDeathLoot(world, source, causedByPlayer);
|
||||
@@ -1018,6 +1130,7 @@
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
EquipmentSlot enumitemslot = (EquipmentSlot) iterator.next();
|
||||
+ if (this.shouldSkipLoot(enumitemslot)) continue; // Paper
|
||||
ItemStack itemstack = this.getItemBySlot(enumitemslot);
|
||||
float f = this.getEquipmentDropChance(enumitemslot);
|
||||
|
||||
@@ -1042,7 +1155,13 @@
|
||||
}
|
||||
|
||||
this.spawnAtLocation(world, itemstack);
|
||||
+ if (this.clearEquipmentSlots) { // Paper
|
||||
this.setItemSlot(enumitemslot, ItemStack.EMPTY);
|
||||
+ // Paper start
|
||||
+ } else {
|
||||
+ this.clearedEquipmentSlots.add(enumitemslot);
|
||||
+ }
|
||||
+ // Paper end
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1338,7 +1457,7 @@
|
||||
if (itemstack.getItem() instanceof SpawnEggItem) {
|
||||
if (this.level() instanceof ServerLevel) {
|
||||
SpawnEggItem itemmonsteregg = (SpawnEggItem) itemstack.getItem();
|
||||
@ -288,7 +323,7 @@
|
||||
|
||||
optional.ifPresent((entityinsentient) -> {
|
||||
this.onOffspringSpawnedFromEgg(player, entityinsentient);
|
||||
@@ -1389,28 +1495,51 @@
|
||||
@@ -1389,28 +1508,51 @@
|
||||
return this.restrictRadius != -1.0F;
|
||||
}
|
||||
|
||||
@ -321,13 +356,13 @@
|
||||
+ conversionparams.type().convert(this, t0, conversionparams);
|
||||
+ if (!conversionparams_a.finalizeConversionOrCancel(t0)) return null; // Paper - entity zap event - return null if conversion was cancelled
|
||||
Level world = this.level();
|
||||
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ if (transformReason == null) {
|
||||
+ // Special handling for slime split and pig lightning
|
||||
+ return t0;
|
||||
+ }
|
||||
+
|
||||
|
||||
+ if (CraftEventFactory.callEntityTransformEvent(this, t0, transformReason).isCancelled()) {
|
||||
+ return null;
|
||||
+ }
|
||||
@ -346,7 +381,7 @@
|
||||
}
|
||||
|
||||
return t0;
|
||||
@@ -1420,10 +1549,22 @@
|
||||
@@ -1420,10 +1562,22 @@
|
||||
|
||||
@Nullable
|
||||
public <T extends Mob> T convertTo(EntityType<T> entityType, ConversionParams context, ConversionParams.AfterConversion<T> finalizer) {
|
||||
@ -370,7 +405,7 @@
|
||||
@Override
|
||||
public Leashable.LeashData getLeashData() {
|
||||
return this.leashData;
|
||||
@@ -1458,6 +1599,7 @@
|
||||
@@ -1458,6 +1612,7 @@
|
||||
boolean flag1 = super.startRiding(entity, force);
|
||||
|
||||
if (flag1 && this.isLeashed()) {
|
||||
@ -378,7 +413,7 @@
|
||||
this.dropLeash();
|
||||
}
|
||||
|
||||
@@ -1542,7 +1684,7 @@
|
||||
@@ -1542,7 +1697,7 @@
|
||||
|
||||
if (f1 > 0.0F && target instanceof LivingEntity) {
|
||||
entityliving = (LivingEntity) target;
|
||||
|
||||
Reference in New Issue
Block a user