diff --git a/paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch b/paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch index 609198349..fde993169 100644 --- a/paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch @@ -114,11 +114,15 @@ @Nullable private Vec3 startingToFallPosition; @Nullable -@@ -258,7 +293,27 @@ +@@ -258,7 +293,31 @@ private final CommandSource commandSource; private int containerCounter; public boolean wonGame; + private int containerUpdateDelay; // Paper - Configurable container update tick rate ++ // Paper start - cancellable death event ++ public boolean queueHealthUpdatePacket; ++ public net.minecraft.network.protocol.game.ClientboundSetHealthPacket queuedHealthUpdatePacket; ++ // Paper end - cancellable death event + // CraftBukkit start + public CraftPlayer.TransferCookieConnection transferCookieConnection; @@ -142,7 +146,7 @@ public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ClientInformation clientOptions) { super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile); this.chatVisibility = ChatVisiblity.FULL; -@@ -266,7 +321,7 @@ +@@ -266,7 +325,7 @@ this.canChatColor = true; this.lastActionTime = Util.getMillis(); this.requestedViewDistance = 2; @@ -151,7 +155,7 @@ this.lastSectionPos = SectionPos.of(0, 0, 0); this.chunkTrackingView = ChunkTrackingView.EMPTY; this.respawnDimension = Level.OVERWORLD; -@@ -340,6 +395,13 @@ +@@ -340,6 +399,13 @@ public void sendSystemMessage(Component message) { ServerPlayer.this.sendSystemMessage(message); } @@ -165,7 +169,7 @@ }; this.textFilter = server.createTextFilterForPlayer(this); this.gameMode = server.createGameModeForPlayer(this); -@@ -352,14 +414,68 @@ +@@ -352,14 +418,68 @@ this.moveTo(this.adjustSpawnLocation(world, world.getSharedSpawnPos()).getBottomCenter(), 0.0F, 0.0F); this.updateOptions(clientOptions); this.object = null; @@ -235,7 +239,7 @@ int i = Math.max(0, this.server.getSpawnRadius(world)); int j = Mth.floor(world.getWorldBorder().getDistanceToBorder((double) basePos.getX(), (double) basePos.getZ())); -@@ -395,14 +511,20 @@ +@@ -395,14 +515,20 @@ Objects.requireNonNull(basePos); crashreportsystemdetails.setDetail("Origin", basePos::toString); @@ -258,7 +262,7 @@ }); throw new ReportedException(crashreport); } -@@ -440,7 +562,7 @@ +@@ -440,7 +566,7 @@ dataresult = WardenSpawnTracker.CODEC.parse(new Dynamic(NbtOps.INSTANCE, nbt.get("warden_spawn_tracker"))); logger = ServerPlayer.LOGGER; Objects.requireNonNull(logger); @@ -267,7 +271,7 @@ this.wardenSpawnTracker = wardenspawntracker; }); } -@@ -457,17 +579,26 @@ +@@ -457,17 +583,26 @@ return this.server.getRecipeManager().byKey(resourcekey).isPresent(); }); } @@ -295,7 +299,7 @@ Logger logger1 = ServerPlayer.LOGGER; Objects.requireNonNull(logger1); -@@ -482,7 +613,7 @@ +@@ -482,7 +617,7 @@ dataresult = BlockPos.CODEC.parse(NbtOps.INSTANCE, nbtbase); logger = ServerPlayer.LOGGER; Objects.requireNonNull(logger); @@ -304,7 +308,7 @@ this.raidOmenPosition = blockposition; }); } -@@ -492,7 +623,7 @@ +@@ -492,7 +627,7 @@ @Override public void addAdditionalSaveData(CompoundTag nbt) { super.addAdditionalSaveData(nbt); @@ -313,7 +317,7 @@ Logger logger = ServerPlayer.LOGGER; Objects.requireNonNull(logger); -@@ -526,6 +657,7 @@ +@@ -526,6 +661,7 @@ nbt.put("SpawnDimension", nbtbase); }); } @@ -321,7 +325,7 @@ nbt.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall); if (this.raidOmenPosition != null) { -@@ -544,7 +676,20 @@ +@@ -544,7 +680,20 @@ Entity entity = this.getRootVehicle(); Entity entity1 = this.getVehicle(); @@ -343,7 +347,7 @@ CompoundTag nbttagcompound1 = new CompoundTag(); CompoundTag nbttagcompound2 = new CompoundTag(); -@@ -598,12 +743,12 @@ +@@ -598,12 +747,12 @@ if (!this.isPassenger()) { ServerPlayer.LOGGER.warn("Couldn't reattach entity to player"); @@ -358,7 +362,7 @@ } } } -@@ -625,7 +770,7 @@ +@@ -625,7 +774,7 @@ CompoundTag nbttagcompound1 = new CompoundTag(); entityenderpearl.save(nbttagcompound1); @@ -367,7 +371,7 @@ Logger logger = ServerPlayer.LOGGER; Objects.requireNonNull(logger); -@@ -651,7 +796,7 @@ +@@ -651,7 +800,7 @@ nbttaglist.forEach((nbtbase1) -> { if (nbtbase1 instanceof CompoundTag nbttagcompound) { if (nbttagcompound.contains("ender_pearl_dimension")) { @@ -376,10 +380,12 @@ Logger logger = ServerPlayer.LOGGER; Objects.requireNonNull(logger); -@@ -686,6 +831,29 @@ - - } +@@ -684,7 +833,30 @@ + } + } ++ } ++ + // CraftBukkit start - World fallback code, either respawn location or global spawn + public void spawnIn(Level world) { + this.setLevel(world); @@ -400,13 +406,12 @@ + this.setPos(position); + } + this.gameMode.setLevel((ServerLevel) world); -+ } + } + // CraftBukkit end -+ + public void setExperiencePoints(int points) { float f = (float) this.getXpNeededForNextLevel(); - float f1 = (f - 1.0F) / f; -@@ -744,6 +912,11 @@ +@@ -744,6 +916,11 @@ @Override public void tick() { @@ -418,7 +423,7 @@ this.tickClientLoadTimeout(); this.gameMode.tick(); this.wardenSpawnTracker.tick(); -@@ -751,9 +924,13 @@ +@@ -751,9 +928,13 @@ --this.invulnerableTime; } @@ -434,7 +439,7 @@ this.containerMenu = this.inventoryMenu; } -@@ -820,7 +997,7 @@ +@@ -820,7 +1001,7 @@ } if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) { @@ -443,7 +448,7 @@ this.lastSentHealth = this.getHealth(); this.lastSentFood = this.foodData.getFoodLevel(); this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F; -@@ -851,6 +1028,12 @@ +@@ -851,6 +1032,12 @@ this.updateScoreForCriteria(ObjectiveCriteria.EXPERIENCE, Mth.ceil((float) this.lastRecordedExperience)); } @@ -456,7 +461,7 @@ if (this.experienceLevel != this.lastRecordedLevel) { this.lastRecordedLevel = this.experienceLevel; this.updateScoreForCriteria(ObjectiveCriteria.LEVEL, Mth.ceil((float) this.lastRecordedLevel)); -@@ -865,6 +1048,20 @@ +@@ -865,6 +1052,20 @@ CriteriaTriggers.LOCATION.trigger(this); } @@ -477,7 +482,7 @@ } catch (Throwable throwable) { CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player"); CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Player being ticked"); -@@ -893,7 +1090,7 @@ +@@ -893,7 +1094,7 @@ if (this.level().getDifficulty() == Difficulty.PEACEFUL && this.serverLevel().getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION)) { if (this.tickCount % 20 == 0) { if (this.getHealth() < this.getMaxHealth()) { @@ -486,7 +491,7 @@ } float f = this.foodData.getSaturationLevel(); -@@ -946,7 +1143,8 @@ +@@ -946,19 +1147,63 @@ } private void updateScoreForCriteria(ObjectiveCriteria criterion, int score) { @@ -496,9 +501,11 @@ scoreaccess.set(score); }); } -@@ -955,10 +1153,43 @@ + + @Override public void die(DamageSource damageSource) { - this.gameEvent(GameEvent.ENTITY_DIE); +- this.gameEvent(GameEvent.ENTITY_DIE); ++ // this.gameEvent(GameEvent.ENTITY_DIE); // Paper - move below event cancellation check boolean flag = this.serverLevel().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES); + // CraftBukkit start - fire PlayerDeathEvent + if (this.isRemoved()) { @@ -528,21 +535,31 @@ + String deathmessage = defaultMessage.getString(); + this.keepLevel = keepInventory; // SPIGOT-2222: pre-set keepLevel + org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, damageSource, loot, PaperAdventure.asAdventure(defaultMessage), keepInventory); // Paper - Adventure -+ ++ // Paper start - cancellable death event ++ if (event.isCancelled()) { ++ // make compatible with plugins that might have already set the health in an event listener ++ if (this.getHealth() <= 0) { ++ this.setHealth((float) event.getReviveHealth()); ++ } ++ return; ++ } ++ this.gameEvent(GameEvent.ENTITY_DIE); // moved from the top of this method ++ // Paper end + + // SPIGOT-943 - only call if they have an inventory open + if (this.containerMenu != this.inventoryMenu) { + this.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.DEATH); // Paper - Inventory close reason + } + + net.kyori.adventure.text.Component deathMessage = event.deathMessage() != null ? event.deathMessage() : net.kyori.adventure.text.Component.empty(); // Paper - Adventure - ++ + if (deathMessage != null && deathMessage != net.kyori.adventure.text.Component.empty() && flag) { // Paper - Adventure // TODO: allow plugins to override? + Component ichatbasecomponent = PaperAdventure.asVanilla(deathMessage); // Paper - Adventure + this.connection.send(new ClientboundPlayerCombatKillPacket(this.getId(), ichatbasecomponent), PacketSendListener.exceptionallySend(() -> { boolean flag1 = true; String s = ichatbasecomponent.getString(256); -@@ -988,12 +1219,18 @@ +@@ -988,12 +1233,18 @@ if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) { this.tellNeutralMobsThatIDied(); } @@ -565,7 +582,7 @@ LivingEntity entityliving = this.getKillCredit(); if (entityliving != null) { -@@ -1028,10 +1265,12 @@ +@@ -1028,10 +1279,12 @@ public void awardKillScore(Entity entityKilled, DamageSource damageSource) { if (entityKilled != this) { super.awardKillScore(entityKilled, damageSource); @@ -581,7 +598,7 @@ } else { this.awardStat(Stats.MOB_KILLS); } -@@ -1049,7 +1288,8 @@ +@@ -1049,7 +1302,8 @@ int i = scoreboardteam.getColor().getId(); if (i >= 0 && i < criterions.length) { @@ -591,7 +608,7 @@ } } -@@ -1062,8 +1302,8 @@ +@@ -1062,8 +1316,8 @@ } else { Entity entity = source.getEntity(); @@ -602,7 +619,7 @@ if (!this.canHarmPlayer(entityhuman)) { return false; -@@ -1074,8 +1314,8 @@ +@@ -1074,8 +1328,8 @@ AbstractArrow entityarrow = (AbstractArrow) entity; Entity entity1 = entityarrow.getOwner(); @@ -613,7 +630,23 @@ if (!this.canHarmPlayer(entityhuman1)) { return false; -@@ -1088,33 +1328,63 @@ +@@ -1083,38 +1337,78 @@ + } + } + +- return super.hurtServer(world, source, amount); ++ // Paper start - cancellable death events ++ // return super.hurtServer(world, source, amount); ++ this.queueHealthUpdatePacket = true; ++ boolean damaged = super.hurtServer(world, source, amount); ++ this.queueHealthUpdatePacket = false; ++ if (this.queuedHealthUpdatePacket != null) { ++ this.connection.send(this.queuedHealthUpdatePacket); ++ this.queuedHealthUpdatePacket = null; ++ } ++ return damaged; ++ // Paper end - cancellable death events + } } @Override @@ -684,7 +717,7 @@ } public static Optional findRespawnAndUseSpawnBlock(ServerLevel world, BlockPos pos, float spawnAngle, boolean spawnForced, boolean alive) { -@@ -1129,11 +1399,11 @@ +@@ -1129,11 +1423,11 @@ } return optional.map((vec3d) -> { @@ -698,7 +731,7 @@ }); } else if (!spawnForced) { return Optional.empty(); -@@ -1142,7 +1412,7 @@ +@@ -1142,7 +1436,7 @@ BlockState iblockdata1 = world.getBlockState(pos.above()); boolean flag3 = iblockdata1.getBlock().isPossibleToRespawnInThis(iblockdata1); @@ -707,7 +740,7 @@ } } -@@ -1160,6 +1430,7 @@ +@@ -1160,6 +1454,7 @@ @Nullable @Override public ServerPlayer teleport(TeleportTransition teleportTarget) { @@ -715,7 +748,7 @@ if (this.isRemoved()) { return null; } else { -@@ -1169,39 +1440,78 @@ +@@ -1169,39 +1464,78 @@ ServerLevel worldserver = teleportTarget.newLevel(); ServerLevel worldserver1 = this.serverLevel(); @@ -802,7 +835,7 @@ this.connection.resetPosition(); worldserver.addDuringTeleport(this); gameprofilerfiller.pop(); -@@ -1215,12 +1525,30 @@ +@@ -1215,12 +1549,30 @@ this.lastSentExp = -1; this.lastSentHealth = -1.0F; this.lastSentFood = -1; @@ -833,7 +866,7 @@ public void forceSetRotation(float yaw, float pitch) { this.connection.send(new ClientboundPlayerRotationPacket(yaw, pitch)); } -@@ -1228,13 +1556,21 @@ +@@ -1228,13 +1580,21 @@ public void triggerDimensionChangeTriggers(ServerLevel origin) { ResourceKey resourcekey = origin.dimension(); ResourceKey resourcekey1 = this.level().dimension(); @@ -858,7 +891,7 @@ this.enteredNetherPosition = null; } -@@ -1251,36 +1587,63 @@ +@@ -1251,36 +1611,63 @@ this.containerMenu.broadcastChanges(); } @@ -937,7 +970,7 @@ this.awardStat(Stats.SLEEP_IN_BED); CriteriaTriggers.SLEPT_IN_BED.trigger(this); }); -@@ -1293,9 +1656,8 @@ +@@ -1293,9 +1680,8 @@ return either; } } @@ -948,7 +981,7 @@ } @Override -@@ -1322,13 +1684,31 @@ +@@ -1322,13 +1708,31 @@ @Override public void stopSleepInBed(boolean skipSleepTimer, boolean updateSleepingPlayers) { @@ -981,7 +1014,7 @@ } } -@@ -1387,8 +1767,9 @@ +@@ -1387,8 +1791,9 @@ this.connection.send(new ClientboundOpenSignEditorPacket(sign.getBlockPos(), front)); } @@ -992,7 +1025,7 @@ } @Override -@@ -1396,13 +1777,35 @@ +@@ -1396,13 +1801,35 @@ if (factory == null) { return OptionalInt.empty(); } else { @@ -1028,7 +1061,7 @@ if (container == null) { if (this.isSpectator()) { this.displayClientMessage(Component.translatable("container.spectatorCantOpen").withStyle(ChatFormatting.RED), true); -@@ -1410,9 +1813,11 @@ +@@ -1410,9 +1837,11 @@ return OptionalInt.empty(); } else { @@ -1042,7 +1075,7 @@ return OptionalInt.of(this.containerCounter); } } -@@ -1425,15 +1830,26 @@ +@@ -1425,15 +1854,26 @@ @Override public void openHorseInventory(AbstractHorse horse, Container inventory) { @@ -1072,7 +1105,7 @@ this.initMenu(this.containerMenu); } -@@ -1456,6 +1872,13 @@ +@@ -1456,6 +1896,13 @@ @Override public void closeContainer() { @@ -1086,7 +1119,7 @@ this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId)); this.doCloseContainer(); } -@@ -1485,19 +1908,19 @@ +@@ -1485,19 +1932,19 @@ i = Math.round((float) Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) * 100.0F); if (i > 0) { this.awardStat(Stats.SWIM_ONE_CM, i); @@ -1109,7 +1142,7 @@ } } else if (this.onClimbable()) { if (deltaY > 0.0D) { -@@ -1508,13 +1931,13 @@ +@@ -1508,13 +1955,13 @@ if (i > 0) { if (this.isSprinting()) { this.awardStat(Stats.SPRINT_ONE_CM, i); @@ -1126,7 +1159,7 @@ } } } else if (this.isFallFlying()) { -@@ -1557,7 +1980,7 @@ +@@ -1557,7 +2004,7 @@ @Override public void awardStat(Stat stat, int amount) { this.stats.increment(this, stat, amount); @@ -1135,7 +1168,7 @@ scoreaccess.add(amount); }); } -@@ -1565,7 +1988,7 @@ +@@ -1565,7 +2012,7 @@ @Override public void resetStat(Stat stat) { this.stats.setValue(this, stat, 0); @@ -1144,7 +1177,7 @@ } @Override -@@ -1597,9 +2020,9 @@ +@@ -1597,9 +2044,9 @@ super.jumpFromGround(); this.awardStat(Stats.JUMP); if (this.isSprinting()) { @@ -1156,7 +1189,7 @@ } } -@@ -1625,6 +2048,7 @@ +@@ -1625,6 +2072,7 @@ public void resetSentInfo() { this.lastSentHealth = -1.0E8F; @@ -1164,7 +1197,7 @@ } @Override -@@ -1661,7 +2085,7 @@ +@@ -1661,7 +2109,7 @@ this.onUpdateAbilities(); if (alive) { this.getAttributes().assignBaseValues(oldPlayer.getAttributes()); @@ -1173,7 +1206,7 @@ this.setHealth(oldPlayer.getHealth()); this.foodData = oldPlayer.foodData; Iterator iterator = oldPlayer.getActiveEffects().iterator(); -@@ -1669,7 +2093,7 @@ +@@ -1669,7 +2117,7 @@ while (iterator.hasNext()) { MobEffectInstance mobeffect = (MobEffectInstance) iterator.next(); @@ -1182,7 +1215,7 @@ } this.getInventory().replaceWith(oldPlayer.getInventory()); -@@ -1680,7 +2104,7 @@ +@@ -1680,7 +2128,7 @@ this.portalProcess = oldPlayer.portalProcess; } else { this.getAttributes().assignBaseValues(oldPlayer.getAttributes()); @@ -1191,7 +1224,7 @@ if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || oldPlayer.isSpectator()) { this.getInventory().replaceWith(oldPlayer.getInventory()); this.experienceLevel = oldPlayer.experienceLevel; -@@ -1696,7 +2120,7 @@ +@@ -1696,7 +2144,7 @@ this.lastSentExp = -1; this.lastSentHealth = -1.0F; this.lastSentFood = -1; @@ -1200,7 +1233,7 @@ this.seenCredits = oldPlayer.seenCredits; this.enteredNetherPosition = oldPlayer.enteredNetherPosition; this.chunkTrackingView = oldPlayer.chunkTrackingView; -@@ -1752,19 +2176,19 @@ +@@ -1752,19 +2200,19 @@ } @Override @@ -1224,7 +1257,7 @@ } return flag1; -@@ -1861,8 +2285,13 @@ +@@ -1861,8 +2309,13 @@ } public void sendChatMessage(OutgoingChatMessage message, boolean filterMaskEnabled, ChatType.Bound params) { @@ -1239,7 +1272,7 @@ } } -@@ -1878,7 +2307,18 @@ +@@ -1878,7 +2331,18 @@ } public void updateOptions(ClientInformation clientOptions) { @@ -1258,7 +1291,7 @@ this.requestedViewDistance = clientOptions.viewDistance(); this.chatVisibility = clientOptions.chatVisibility(); this.canChatColor = clientOptions.chatColors(); -@@ -1962,7 +2402,7 @@ +@@ -1962,7 +2426,7 @@ if (world instanceof ServerLevel) { ServerLevel worldserver = (ServerLevel) world; @@ -1267,7 +1300,7 @@ } if (entity != null) { -@@ -1999,11 +2439,11 @@ +@@ -1999,11 +2463,11 @@ @Nullable public Component getTabListDisplayName() { @@ -1281,7 +1314,7 @@ } @Override -@@ -2046,17 +2486,43 @@ +@@ -2046,17 +2510,43 @@ } public void setRespawnPosition(ResourceKey dimension, @Nullable BlockPos pos, float angle, boolean forced, boolean sendMessage) { @@ -1332,7 +1365,7 @@ } else { this.respawnPosition = null; this.respawnDimension = Level.OVERWORLD; -@@ -2088,18 +2554,44 @@ +@@ -2088,18 +2578,44 @@ } @Override @@ -1381,7 +1414,7 @@ } this.awardStat(Stats.DROP); -@@ -2375,16 +2867,160 @@ +@@ -2375,16 +2891,160 @@ return TicketType.ENDER_PEARL.timeout(); } diff --git a/paper-server/patches/sources/net/minecraft/world/entity/LivingEntity.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/LivingEntity.java.patch index 82efda3bf..01b95860f 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/LivingEntity.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/LivingEntity.java.patch @@ -17,10 +17,11 @@ import net.minecraft.world.entity.projectile.AbstractArrow; import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.item.AxeItem; -@@ -136,6 +137,30 @@ +@@ -135,6 +136,30 @@ + import net.minecraft.world.scores.PlayerTeam; import net.minecraft.world.scores.Scoreboard; import org.slf4j.Logger; - ++ +// CraftBukkit start +import java.util.ArrayList; +import java.util.HashSet; @@ -44,10 +45,9 @@ +import org.bukkit.event.entity.EntityTeleportEvent; +import org.bukkit.event.player.PlayerItemConsumeEvent; +// CraftBukkit end -+ + public abstract class LivingEntity extends Entity implements Attackable { - private static final Logger LOGGER = LogUtils.getLogger(); @@ -174,7 +199,7 @@ public static final float DEFAULT_BABY_SCALE = 0.5F; public static final String ATTRIBUTES_FIELD = "attributes"; @@ -66,7 +66,7 @@ public int lastHurtByPlayerTime; protected boolean dead; protected int noActionTime; -@@ -260,7 +285,28 @@ +@@ -260,7 +285,29 @@ protected boolean skipDropExperience; private final EnumMap>> activeLocationDependentEnchantments; protected float appliedScale; @@ -78,6 +78,7 @@ + public Set collidableExemptions = new HashSet<>(); + public boolean bukkitPickUpLoot; + public org.bukkit.craftbukkit.entity.CraftLivingEntity getBukkitLivingEntity() { return (org.bukkit.craftbukkit.entity.CraftLivingEntity) super.getBukkitEntity(); } // Paper ++ public boolean silentDeath = false; // Paper - mark entity as dying silently for cancellable death event + @Override + public float getBukkitYaw() { @@ -95,7 +96,7 @@ protected LivingEntity(EntityType type, Level world) { super(type, world); this.lastHandItemStacks = NonNullList.withSize(2, ItemStack.EMPTY); -@@ -276,7 +322,9 @@ +@@ -276,7 +323,9 @@ this.activeLocationDependentEnchantments = new EnumMap(EquipmentSlot.class); this.appliedScale = 1.0F; this.attributes = new AttributeMap(DefaultAttributes.getSupplier(type)); @@ -106,7 +107,7 @@ this.blocksBuilding = true; this.rotA = (float) ((Math.random() + 1.0D) * 0.009999999776482582D); this.reapplyPosition(); -@@ -356,7 +404,13 @@ +@@ -356,7 +405,13 @@ double d8 = Math.min((double) (0.2F + f / 15.0F), 2.5D); int i = (int) (150.0D * d8); @@ -121,7 +122,7 @@ } } } -@@ -402,7 +456,7 @@ +@@ -402,7 +457,7 @@ } if (this.isAlive()) { @@ -130,7 +131,7 @@ Level world1 = this.level(); ServerLevel worldserver1; double d0; -@@ -424,7 +478,7 @@ +@@ -424,7 +479,7 @@ } if (this.isEyeInFluid(FluidTags.WATER) && !this.level().getBlockState(BlockPos.containing(this.getX(), this.getEyeY(), this.getZ())).is(Blocks.BUBBLE_COLUMN)) { @@ -139,7 +140,7 @@ if (flag1) { this.setAirSupply(this.decreaseAirSupply(this.getAirSupply())); -@@ -573,7 +627,7 @@ +@@ -573,7 +628,7 @@ ++this.deathTime; if (this.deathTime >= 20 && !this.level().isClientSide() && !this.isRemoved()) { this.level().broadcastEntityEvent(this, (byte) 60); @@ -148,7 +149,7 @@ } } -@@ -629,7 +683,7 @@ +@@ -629,7 +684,7 @@ return this.lastHurtByMobTimestamp; } @@ -157,7 +158,7 @@ this.lastHurtByPlayer = attacking; this.lastHurtByPlayerTime = this.tickCount; } -@@ -679,17 +733,23 @@ +@@ -679,17 +734,23 @@ } public void onEquipItem(EquipmentSlot slot, ItemStack oldStack, ItemStack newStack) { @@ -188,7 +189,7 @@ this.gameEvent(equippable != null ? GameEvent.EQUIP : GameEvent.UNEQUIP); } -@@ -699,17 +759,24 @@ +@@ -699,17 +760,24 @@ @Override public void remove(Entity.RemovalReason reason) { @@ -216,7 +217,7 @@ this.brain.clearMemories(); } -@@ -722,6 +789,7 @@ +@@ -722,6 +790,7 @@ mobeffect.onMobRemoved(world, this, reason); } @@ -224,7 +225,7 @@ this.activeEffects.clear(); } -@@ -763,7 +831,13 @@ +@@ -763,7 +832,13 @@ @Override public void readAdditionalSaveData(CompoundTag nbt) { @@ -239,7 +240,7 @@ if (nbt.contains("attributes", 9) && this.level() != null && !this.level().isClientSide) { this.getAttributes().load(nbt.getList("attributes", 10)); } -@@ -781,6 +855,17 @@ +@@ -781,6 +856,17 @@ } } @@ -257,7 +258,7 @@ if (nbt.contains("Health", 99)) { this.setHealth(nbt.getFloat("Health")); } -@@ -792,6 +877,7 @@ +@@ -792,6 +878,7 @@ String s = nbt.getString("Team"); Scoreboard scoreboard = this.level().getScoreboard(); PlayerTeam scoreboardteam = scoreboard.getPlayerTeam(s); @@ -265,7 +266,7 @@ boolean flag = scoreboardteam != null && scoreboard.addPlayerToTeam(this.getStringUUID(), scoreboardteam); if (!flag) { -@@ -819,9 +905,32 @@ +@@ -819,9 +906,32 @@ } @@ -298,7 +299,7 @@ try { while (iterator.hasNext()) { Holder holder = (Holder) iterator.next(); -@@ -831,6 +940,12 @@ +@@ -831,6 +941,12 @@ this.onEffectUpdated(mobeffect, true, (Entity) null); })) { if (!this.level().isClientSide) { @@ -311,7 +312,7 @@ iterator.remove(); this.onEffectsRemoved(List.of(mobeffect)); } -@@ -841,6 +956,17 @@ +@@ -841,6 +957,17 @@ } catch (ConcurrentModificationException concurrentmodificationexception) { ; } @@ -329,7 +330,7 @@ if (this.effectsDirty) { if (!this.level().isClientSide) { -@@ -921,7 +1047,7 @@ +@@ -921,7 +1048,7 @@ } public boolean canAttack(LivingEntity target) { @@ -338,7 +339,7 @@ } public boolean canBeSeenAsEnemy() { -@@ -952,17 +1078,36 @@ +@@ -952,17 +1079,36 @@ this.entityData.set(LivingEntity.DATA_EFFECT_PARTICLES, List.of()); } @@ -379,7 +380,7 @@ } } -@@ -987,24 +1132,55 @@ +@@ -987,24 +1133,55 @@ return this.addEffect(effect, (Entity) null); } @@ -408,9 +409,6 @@ + MobEffectInstance mobeffect1 = (MobEffectInstance) this.activeEffects.get(mobeffect.getEffect()); boolean flag = false; -- if (mobeffect1 == null) { -- this.activeEffects.put(effect.getEffect(), effect); -- this.onEffectAdded(effect, source); + // CraftBukkit start + boolean override = false; + if (mobeffect1 != null) { @@ -423,7 +421,9 @@ + } + // CraftBukkit end + -+ if (mobeffect1 == null) { + if (mobeffect1 == null) { +- this.activeEffects.put(effect.getEffect(), effect); +- this.onEffectAdded(effect, source); + this.activeEffects.put(mobeffect.getEffect(), mobeffect); + this.onEffectAdded(mobeffect, entity); flag = true; @@ -444,7 +444,7 @@ return flag; } } -@@ -1031,14 +1207,40 @@ +@@ -1031,14 +1208,40 @@ return this.getType().is(EntityTypeTags.INVERTED_HEALING_AND_HARM); } @@ -487,7 +487,7 @@ if (mobeffect != null) { this.onEffectsRemoved(List.of(mobeffect)); return true; -@@ -1142,20 +1344,65 @@ +@@ -1142,20 +1345,65 @@ } @@ -554,7 +554,7 @@ this.entityData.set(LivingEntity.DATA_HEALTH_ID, Mth.clamp(health, 0.0F, this.getMaxHealth())); } -@@ -1167,7 +1414,7 @@ +@@ -1167,7 +1415,7 @@ public boolean hurtServer(ServerLevel world, DamageSource source, float amount) { if (this.isInvulnerableTo(world, source)) { return false; @@ -563,7 +563,7 @@ return false; } else if (source.is(DamageTypeTags.IS_FIRE) && this.hasEffect(MobEffects.FIRE_RESISTANCE)) { return false; -@@ -1182,10 +1429,11 @@ +@@ -1182,10 +1430,11 @@ } float f1 = amount; @@ -577,7 +577,7 @@ this.hurtCurrentlyUsedShield(amount); f2 = amount; amount = 0.0F; -@@ -1202,15 +1450,26 @@ +@@ -1202,15 +1451,26 @@ flag = true; } @@ -606,7 +606,7 @@ this.walkAnimation.setSpeed(1.5F); if (Float.isNaN(amount) || Float.isInfinite(amount)) { amount = Float.MAX_VALUE; -@@ -1218,18 +1477,27 @@ +@@ -1218,18 +1478,27 @@ boolean flag1 = true; @@ -638,7 +638,7 @@ this.hurtDuration = 10; this.hurtTime = this.hurtDuration; } -@@ -1243,7 +1511,7 @@ +@@ -1243,7 +1512,7 @@ world.broadcastDamageEvent(this, source); } @@ -647,7 +647,7 @@ this.markHurt(); } -@@ -1263,7 +1531,7 @@ +@@ -1263,7 +1532,7 @@ d1 = source.getSourcePosition().z() - this.getZ(); } @@ -656,7 +656,21 @@ if (!flag) { this.indicateDamage(d0, d1); } -@@ -1282,7 +1550,7 @@ +@@ -1272,17 +1541,18 @@ + + if (this.isDeadOrDying()) { + if (!this.checkTotemDeathProtection(source)) { +- if (flag1) { +- this.makeSound(this.getDeathSound()); +- } ++ // Paper start - moved into CraftEventFactory event caller for cancellable death event ++ this.silentDeath = !flag1; // mark entity as dying silently ++ // Paper end + + this.die(source); ++ this.silentDeath = false; // Paper - cancellable death event - reset to default + } + } else if (flag1) { this.playHurtSound(source); } @@ -665,7 +679,7 @@ if (flag2) { this.lastDamageSource = source; -@@ -1329,10 +1597,10 @@ +@@ -1329,10 +1599,10 @@ } @Nullable @@ -678,7 +692,7 @@ this.lastHurtByPlayerTime = 100; this.lastHurtByPlayer = entityhuman; return entityhuman; -@@ -1342,8 +1610,8 @@ +@@ -1342,8 +1612,8 @@ this.lastHurtByPlayerTime = 100; LivingEntity entityliving = entitywolf.getOwner(); @@ -689,7 +703,7 @@ this.lastHurtByPlayer = entityhuman1; } else { -@@ -1363,7 +1631,7 @@ +@@ -1363,7 +1633,7 @@ } protected void blockedByShield(LivingEntity target) { @@ -698,7 +712,7 @@ } private boolean checkTotemDeathProtection(DamageSource source) { -@@ -1375,20 +1643,33 @@ +@@ -1375,20 +1645,33 @@ InteractionHand[] aenumhand = InteractionHand.values(); int i = aenumhand.length; @@ -736,16 +750,89 @@ ServerPlayer entityplayer = (ServerPlayer) this; entityplayer.awardStat(Stats.ITEM_USED.get(itemstack.getItem())); -@@ -1477,7 +1758,7 @@ +@@ -1468,6 +1751,7 @@ + Entity entity = damageSource.getEntity(); + LivingEntity entityliving = this.getKillCredit(); + ++ /* // Paper - move down to make death event cancellable - this is the awardKillScore below + if (entityliving != null) { + entityliving.awardKillScore(this, damageSource); + } +@@ -1477,26 +1761,61 @@ } if (!this.level().isClientSide && this.hasCustomName()) { - LivingEntity.LOGGER.info("Named entity {} died: {}", this, this.getCombatTracker().getDeathMessage().getString()); + if (org.spigotmc.SpigotConfig.logNamedDeaths) LivingEntity.LOGGER.info("Named entity {} died: {}", this, this.getCombatTracker().getDeathMessage().getString()); // Spigot } ++ */ // Paper - move down to make death event cancellable - this is the awardKillScore below this.dead = true; -@@ -1512,14 +1793,22 @@ +- this.getCombatTracker().recheckStatus(); ++ // Paper - moved into if below + Level world = this.level(); + + if (world instanceof ServerLevel) { + ServerLevel worldserver = (ServerLevel) world; ++ // Paper - move below into if for onKill + +- if (entity == null || entity.killedEntity(worldserver, this)) { ++ // Paper start ++ org.bukkit.event.entity.EntityDeathEvent deathEvent = this.dropAllDeathLoot(worldserver, damageSource); ++ if (deathEvent == null || !deathEvent.isCancelled()) { ++ if (entityliving != null) { ++ entityliving.awardKillScore(this, damageSource); ++ } ++ // Paper start - clear equipment if event is not cancelled ++ if (this instanceof Mob) { ++ for (EquipmentSlot slot : this.clearedEquipmentSlots) { ++ this.setItemSlot(slot, ItemStack.EMPTY); ++ } ++ this.clearedEquipmentSlots.clear(); ++ } ++ // Paper end ++ ++ if (this.isSleeping()) { ++ this.stopSleeping(); ++ } ++ ++ if (!this.level().isClientSide && this.hasCustomName()) { ++ if (org.spigotmc.SpigotConfig.logNamedDeaths) LivingEntity.LOGGER.info("Named entity {} died: {}", this, this.getCombatTracker().getDeathMessage().getString()); // Spigot ++ } ++ ++ this.getCombatTracker().recheckStatus(); ++ if (entity != null) { ++ entity.killedEntity((ServerLevel) this.level(), this); ++ } + this.gameEvent(GameEvent.ENTITY_DIE); +- this.dropAllDeathLoot(worldserver, damageSource); ++ } else { ++ this.dead = false; ++ this.setHealth((float) deathEvent.getReviveHealth()); ++ } ++ // Paper end + this.createWitherRose(entityliving); + } + ++ // Paper start ++ if (this.dead) { // Paper + this.level().broadcastEntityEvent(this, (byte) 3); +- } + + this.setPose(Pose.DYING); ++ } ++ // Paper end + } + } + +@@ -1506,20 +1825,28 @@ + if (world instanceof ServerLevel worldserver) { + boolean flag = false; + +- if (adversary instanceof WitherBoss) { ++ if (this.dead && adversary instanceof WitherBoss) { // Paper + if (worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { + BlockPos blockposition = this.blockPosition(); BlockState iblockdata = Blocks.WITHER_ROSE.defaultBlockState(); if (this.level().getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level(), blockposition)) { @@ -770,26 +857,43 @@ this.level().addFreshEntity(entityitem); } } -@@ -1530,24 +1819,39 @@ - protected void dropAllDeathLoot(ServerLevel world, DamageSource damageSource) { +@@ -1527,27 +1854,55 @@ + } + } + +- protected void dropAllDeathLoot(ServerLevel world, DamageSource damageSource) { ++ // Paper start ++ protected boolean clearEquipmentSlots = true; ++ protected Set clearedEquipmentSlots = new java.util.HashSet<>(); ++ protected org.bukkit.event.entity.EntityDeathEvent dropAllDeathLoot(ServerLevel world, DamageSource damageSource) { ++ // Paper end boolean flag = this.lastHurtByPlayerTime > 0; + this.dropEquipment(world); // CraftBukkit - from below if (this.shouldDropLoot() && world.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { this.dropFromLootTable(world, damageSource, flag); ++ // Paper start ++ final boolean prev = this.clearEquipmentSlots; ++ this.clearEquipmentSlots = false; ++ this.clearedEquipmentSlots.clear(); ++ // Paper end this.dropCustomDeathLoot(world, damageSource, flag); ++ this.clearEquipmentSlots = prev; // Paper } + // CraftBukkit start - Call death event -+ CraftEventFactory.callEntityDeathEvent(this, damageSource, this.drops); ++ org.bukkit.event.entity.EntityDeathEvent deathEvent = CraftEventFactory.callEntityDeathEvent(this, damageSource, this.drops); // Paper ++ this.postDeathDropItems(deathEvent); // Paper + this.drops = new ArrayList<>(); + // CraftBukkit end - this.dropEquipment(world); + // this.dropEquipment(worldserver);// CraftBukkit - moved up this.dropExperience(world, damageSource.getEntity()); ++ return deathEvent; // Paper } protected void dropEquipment(ServerLevel world) {} ++ protected void postDeathDropItems(org.bukkit.event.entity.EntityDeathEvent event) {} // Paper - method for post death logic that cannot be ran before the event is potentially cancelled - protected void dropExperience(ServerLevel world, @Nullable Entity attacker) { - if (!this.wasExperienceConsumed() && (this.isAlwaysExperienceDropper() || this.lastHurtByPlayerTime > 0 && this.shouldDropExperience() && world.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT))) { @@ -814,7 +918,7 @@ protected void dropCustomDeathLoot(ServerLevel world, DamageSource source, boolean causedByPlayer) {} public long getLootTableSeed() { -@@ -1612,19 +1916,35 @@ +@@ -1612,19 +1967,35 @@ } public void knockback(double strength, double x, double z) { @@ -857,7 +961,7 @@ } } -@@ -1683,6 +2003,20 @@ +@@ -1683,6 +2054,20 @@ return new LivingEntity.Fallsounds(SoundEvents.GENERIC_SMALL_FALL, SoundEvents.GENERIC_BIG_FALL); } @@ -878,7 +982,7 @@ public Optional getLastClimbablePos() { return this.lastClimbablePos; } -@@ -1757,9 +2091,14 @@ +@@ -1757,9 +2142,14 @@ int i = this.calculateFallDamage(fallDistance, damageMultiplier); if (i > 0) { @@ -894,7 +998,7 @@ return true; } else { return flag; -@@ -1830,7 +2169,7 @@ +@@ -1830,7 +2220,7 @@ protected float getDamageAfterArmorAbsorb(DamageSource source, float amount) { if (!source.is(DamageTypeTags.BYPASSES_ARMOR)) { @@ -903,7 +1007,7 @@ amount = CombatRules.getDamageAfterAbsorb(this, amount, source, (float) this.getArmorValue(), (float) this.getAttributeValue(Attributes.ARMOR_TOUGHNESS)); } -@@ -1841,7 +2180,8 @@ +@@ -1841,7 +2231,8 @@ if (source.is(DamageTypeTags.BYPASSES_EFFECTS)) { return amount; } else { @@ -913,7 +1017,7 @@ int i = (this.getEffect(MobEffects.DAMAGE_RESISTANCE).getAmplifier() + 1) * 5; int j = 25 - i; float f1 = amount * (float) j; -@@ -1884,18 +2224,144 @@ +@@ -1884,18 +2275,144 @@ } } @@ -1067,7 +1171,7 @@ if (entity instanceof ServerPlayer) { ServerPlayer entityplayer = (ServerPlayer) entity; -@@ -1904,13 +2370,48 @@ +@@ -1904,13 +2421,48 @@ } } @@ -1120,27 +1224,28 @@ } public CombatTracker getCombatTracker() { -@@ -1935,8 +2436,18 @@ +@@ -1935,9 +2487,19 @@ } public final void setArrowCount(int stuckArrowCount) { - this.entityData.set(LivingEntity.DATA_ARROW_COUNT_ID, stuckArrowCount); + // CraftBukkit start + this.setArrowCount(stuckArrowCount, false); -+ } -+ + } + + public final void setArrowCount(int i, boolean flag) { + ArrowBodyCountChangeEvent event = CraftEventFactory.callArrowBodyCountChangeEvent(this, this.getArrowCount(), i, flag); + if (event.isCancelled()) { + return; + } + this.entityData.set(LivingEntity.DATA_ARROW_COUNT_ID, event.getNewAmount()); - } ++ } + // CraftBukkit end - ++ public final int getStingerCount() { return (Integer) this.entityData.get(LivingEntity.DATA_STINGER_COUNT_ID); -@@ -1999,7 +2510,7 @@ + } +@@ -1999,7 +2561,7 @@ this.playSound(soundeffect, this.getSoundVolume(), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F); } @@ -1149,20 +1254,20 @@ this.setHealth(0.0F); this.die(this.damageSources().generic()); } -@@ -2181,6 +2692,12 @@ - public abstract Iterable getArmorSlots(); +@@ -2182,6 +2744,12 @@ public abstract ItemStack getItemBySlot(EquipmentSlot slot); -+ + + // CraftBukkit start + public void setItemSlot(EquipmentSlot enumitemslot, ItemStack itemstack, boolean silent) { + this.setItemSlot(enumitemslot, itemstack); + } + // CraftBukkit end - ++ public abstract void setItemSlot(EquipmentSlot slot, ItemStack stack); -@@ -2494,7 +3011,7 @@ + public Iterable getHandSlots() { +@@ -2494,7 +3062,7 @@ } @@ -1171,7 +1276,7 @@ Vec3 vec3d1 = this.getRiddenInput(controllingPlayer, movementInput); this.tickRidden(controllingPlayer, vec3d1); -@@ -2507,13 +3024,13 @@ +@@ -2507,13 +3075,13 @@ } @@ -1188,7 +1293,7 @@ return this.getSpeed(); } -@@ -2571,7 +3088,7 @@ +@@ -2571,7 +3139,7 @@ double d1 = Mth.clamp(motion.z, -0.15000000596046448D, 0.15000000596046448D); double d2 = Math.max(motion.y, -0.15000000596046448D); @@ -1197,7 +1302,7 @@ d2 = 0.0D; } -@@ -2586,7 +3103,7 @@ +@@ -2586,7 +3154,7 @@ } protected float getFlyingSpeed() { @@ -1206,7 +1311,7 @@ } public float getSpeed() { -@@ -2634,7 +3151,7 @@ +@@ -2634,7 +3202,7 @@ } } @@ -1215,7 +1320,7 @@ if (this.tickCount % 20 == 0) { this.getCombatTracker().recheckStatus(); } -@@ -2741,7 +3258,7 @@ +@@ -2741,7 +3309,7 @@ this.elytraAnimationState.tick(); } @@ -1224,7 +1329,7 @@ Map map = this.collectEquipmentChanges(); if (map != null) { -@@ -2778,10 +3295,17 @@ +@@ -2778,10 +3346,17 @@ throw new MatchException((String) null, (Throwable) null); } @@ -1244,7 +1349,7 @@ if (map == null) { map = Maps.newEnumMap(EquipmentSlot.class); } -@@ -3000,7 +3524,7 @@ +@@ -3000,7 +3575,7 @@ { LivingEntity entityliving = this.getControllingPassenger(); @@ -1253,7 +1358,7 @@ if (this.isAlive()) { this.travelRidden(entityhuman, vec3d1); break label112; -@@ -3063,6 +3587,7 @@ +@@ -3063,6 +3638,7 @@ this.checkSlowFallDistance(); if (!this.level().isClientSide) { if (!this.canGlide()) { @@ -1261,7 +1366,7 @@ this.setSharedFlag(7, false); return; } -@@ -3113,7 +3638,7 @@ +@@ -3113,7 +3689,7 @@ Level world = this.level(); if (!(world instanceof ServerLevel worldserver)) { @@ -1270,7 +1375,7 @@ } else { List list = this.level().getEntities((Entity) this, this.getBoundingBox(), EntitySelector.pushableBy(this)); -@@ -3138,10 +3663,12 @@ +@@ -3138,10 +3714,12 @@ } Iterator iterator1 = list.iterator(); @@ -1285,7 +1390,7 @@ this.doPush(entity1); } } -@@ -3305,15 +3832,22 @@ +@@ -3305,15 +3883,22 @@ @Override public boolean isPickable() { @@ -1310,7 +1415,7 @@ public float getYHeadRot() { return this.yHeadRot; } -@@ -3342,7 +3876,7 @@ +@@ -3342,7 +3927,7 @@ } public final void setAbsorptionAmount(float absorptionAmount) { @@ -1319,7 +1424,7 @@ } protected void internalSetAbsorptionAmount(float absorptionAmount) { -@@ -3483,13 +4017,48 @@ +@@ -3483,13 +4068,48 @@ this.releaseUsingItem(); } else { if (!this.useItem.isEmpty() && this.isUsingItem()) { @@ -1332,7 +1437,7 @@ + org.bukkit.inventory.EquipmentSlot hand = org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(enumhand); + event = new PlayerItemConsumeEvent((Player) this.getBukkitEntity(), craftItem, hand); // Paper + this.level().getCraftServer().getPluginManager().callEvent(event); -+ + + if (event.isCancelled()) { + // Update client + Consumable consumable = this.useItem.get(DataComponents.CONSUMABLE); @@ -1355,7 +1460,7 @@ + } + // Paper end + // CraftBukkit end - ++ if (itemstack != this.useItem) { this.setItemInHand(enumhand, itemstack); } @@ -1369,7 +1474,7 @@ } } -@@ -3544,12 +4113,37 @@ +@@ -3544,12 +4164,37 @@ if (this.isUsingItem() && !this.useItem.isEmpty()) { Item item = this.useItem.getItem(); @@ -1408,7 +1513,7 @@ public boolean isSuppressingSlidingDownLadder() { return this.isShiftKeyDown(); } -@@ -3568,12 +4162,18 @@ +@@ -3568,12 +4213,18 @@ } public boolean randomTeleport(double x, double y, double z, boolean particleEffects) { @@ -1429,7 +1534,7 @@ Level world = this.level(); if (world.hasChunkAt(blockposition)) { -@@ -3592,18 +4192,43 @@ +@@ -3592,18 +4243,43 @@ } if (flag2) { @@ -1477,7 +1582,7 @@ world.broadcastEntityEvent(this, (byte) 46); } -@@ -3613,7 +4238,7 @@ +@@ -3613,7 +4289,7 @@ entitycreature.getNavigation().stop(); } @@ -1486,7 +1591,7 @@ } } -@@ -3706,7 +4331,7 @@ +@@ -3706,7 +4382,7 @@ } public void stopSleeping() { @@ -1495,7 +1600,7 @@ Level world = this.level(); java.util.Objects.requireNonNull(world); -@@ -3718,9 +4343,9 @@ +@@ -3718,9 +4394,9 @@ this.level().setBlock(blockposition, (BlockState) iblockdata.setValue(BedBlock.OCCUPIED, false), 3); Vec3 vec3d = (Vec3) BedBlock.findStandUpPosition(this.getType(), this.level(), blockposition, enumdirection, this.getYRot()).orElseGet(() -> { @@ -1507,7 +1612,7 @@ }); Vec3 vec3d1 = Vec3.atBottomCenterOf(blockposition).subtract(vec3d).normalize(); float f = (float) Mth.wrapDegrees(Mth.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D); -@@ -3740,7 +4365,7 @@ +@@ -3740,7 +4416,7 @@ @Nullable public Direction getBedOrientation() { @@ -1516,7 +1621,7 @@ return blockposition != null ? BedBlock.getBedOrientation(this.level(), blockposition) : null; } -@@ -3905,7 +4530,7 @@ +@@ -3905,7 +4581,7 @@ public float maxUpStep() { float f = (float) this.getAttributeValue(Attributes.STEP_HEIGHT); diff --git a/paper-server/patches/sources/net/minecraft/world/entity/Mob.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/Mob.java.patch index 6695b8d4a..916c373d7 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/Mob.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/Mob.java.patch @@ -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 convertTo(EntityType entityType, ConversionParams context, ConversionParams.AfterConversion 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; diff --git a/paper-server/patches/sources/net/minecraft/world/entity/animal/Fox.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/animal/Fox.java.patch index aecbab30c..cd8c3724e 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/animal/Fox.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/animal/Fox.java.patch @@ -29,11 +29,53 @@ this.ticksSinceEaten = 0; } -@@ -852,7 +856,17 @@ +@@ -685,16 +689,38 @@ + return this.getTrustedUUIDs().contains(uuid); + } ++ // Paper start - handle the bitten item separately like vanilla + @Override +- protected void dropAllDeathLoot(ServerLevel world, DamageSource damageSource) { +- ItemStack itemstack = this.getItemBySlot(EquipmentSlot.MAINHAND); ++ protected boolean shouldSkipLoot(EquipmentSlot slot) { ++ return slot == EquipmentSlot.MAINHAND; ++ } ++ // Paper end + +- if (!itemstack.isEmpty()) { ++ @Override ++ // Paper start - Cancellable death event ++ protected org.bukkit.event.entity.EntityDeathEvent dropAllDeathLoot(ServerLevel world, DamageSource damageSource) { ++ ItemStack itemstack = this.getItemBySlot(EquipmentSlot.MAINHAND); ++ ++ boolean releaseMouth = false; ++ if (!itemstack.isEmpty() && world.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { // Fix MC-153010 + this.spawnAtLocation(world, itemstack); ++ releaseMouth = true; ++ } ++ ++ org.bukkit.event.entity.EntityDeathEvent deathEvent = super.dropAllDeathLoot(world, damageSource); ++ ++ // Below is code to drop ++ ++ if (deathEvent == null || deathEvent.isCancelled()) { ++ return deathEvent; ++ } ++ ++ if (releaseMouth) { ++ // Paper end - Cancellable death event + this.setItemSlot(EquipmentSlot.MAINHAND, ItemStack.EMPTY); + } + +- super.dropAllDeathLoot(world, damageSource); ++ return deathEvent; // Paper - Cancellable death event + } + + public static boolean isPathClear(Fox fox, LivingEntity chasedEntity) { +@@ -853,6 +879,16 @@ if (entityplayer1 != null && entityplayer != entityplayer1) { entityfox.addTrustedUUID(entityplayer1.getUUID()); -+ } + } + // CraftBukkit start - call EntityBreedEvent + entityfox.setAge(-24000); + entityfox.moveTo(this.animal.getX(), this.animal.getY(), this.animal.getZ(), 0.0F, 0.0F); @@ -41,13 +83,13 @@ + org.bukkit.event.entity.EntityBreedEvent entityBreedEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityBreedEvent(entityfox, this.animal, this.partner, entityplayer, this.animal.breedItem, experience); + if (entityBreedEvent.isCancelled()) { + return; - } ++ } + experience = entityBreedEvent.getExperience(); + // CraftBukkit end if (entityplayer2 != null) { entityplayer2.awardStat(Stats.ANIMALS_BRED); -@@ -863,12 +877,14 @@ +@@ -863,12 +899,14 @@ this.partner.setAge(6000); this.animal.resetLove(); this.partner.resetLove(); @@ -66,7 +108,7 @@ } } -@@ -1264,6 +1280,11 @@ +@@ -1264,6 +1302,11 @@ int i = (Integer) state.getValue(SweetBerryBushBlock.AGE); state.setValue(SweetBerryBushBlock.AGE, 1); @@ -78,7 +120,7 @@ int j = 1 + Fox.this.level().random.nextInt(2) + (i == 3 ? 1 : 0); ItemStack itemstack = Fox.this.getItemBySlot(EquipmentSlot.MAINHAND); -@@ -1494,7 +1515,7 @@ +@@ -1494,7 +1537,7 @@ } public static Fox.Variant byName(String name) { diff --git a/paper-server/patches/sources/net/minecraft/world/entity/animal/horse/AbstractChestedHorse.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/animal/horse/AbstractChestedHorse.java.patch new file mode 100644 index 000000000..78095235f --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/world/entity/animal/horse/AbstractChestedHorse.java.patch @@ -0,0 +1,19 @@ +--- a/net/minecraft/world/entity/animal/horse/AbstractChestedHorse.java ++++ b/net/minecraft/world/entity/animal/horse/AbstractChestedHorse.java +@@ -69,9 +69,16 @@ + super.dropEquipment(world); + if (this.hasChest()) { + this.spawnAtLocation(world, Blocks.CHEST); ++ //this.setChest(false); // Paper - moved to post death logic ++ } ++ } ++ // Paper start ++ protected void postDeathDropItems(org.bukkit.event.entity.EntityDeathEvent event) { ++ if (this.hasChest() && (event == null || !event.isCancelled())) { + this.setChest(false); + } + } ++ // Paper end + + @Override + public void addAdditionalSaveData(CompoundTag nbt) { diff --git a/paper-server/patches/sources/net/minecraft/world/entity/decoration/ArmorStand.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/decoration/ArmorStand.java.patch index 84c2f2641..e2ed55cf7 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/decoration/ArmorStand.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/decoration/ArmorStand.java.patch @@ -254,7 +254,7 @@ } @Override -@@ -436,12 +492,22 @@ +@@ -436,12 +492,24 @@ } else if (!world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) && source.getEntity() instanceof Mob) { return false; } else if (source.is(DamageTypeTags.BYPASSES_INVULNERABILITY)) { @@ -274,13 +274,16 @@ + } + // CraftBukkit end if (source.is(DamageTypeTags.IS_EXPLOSION)) { - this.brokenByAnything(world, source); +- this.brokenByAnything(world, source); - this.kill(world); -+ this.kill(world, source); // CraftBukkit ++ // Paper start - avoid duplicate event call ++ org.bukkit.event.entity.EntityDeathEvent event = this.brokenByAnything(world, source); ++ if (!event.isCancelled()) this.kill(source, false); // CraftBukkit ++ // Paper end return false; } else if (source.is(DamageTypeTags.IGNITES_ARMOR_STANDS)) { if (this.isOnFire()) { -@@ -463,8 +529,8 @@ +@@ -463,8 +531,8 @@ } else { Entity entity = source.getEntity(); @@ -291,7 +294,7 @@ if (!entityhuman.getAbilities().mayBuild) { return false; -@@ -474,7 +540,7 @@ +@@ -474,7 +542,7 @@ if (source.isCreativePlayer()) { this.playBrokenSound(); this.showBreakingParticles(); @@ -300,41 +303,54 @@ return true; } else { long i = world.getGameTime(); -@@ -486,7 +552,7 @@ +@@ -484,9 +552,9 @@ + this.gameEvent(GameEvent.ENTITY_DAMAGE, source.getEntity()); + this.lastHit = i; } else { - this.brokenByPlayer(world, source); +- this.brokenByPlayer(world, source); ++ org.bukkit.event.entity.EntityDeathEvent event = this.brokenByPlayer(world, source); // Paper this.showBreakingParticles(); - this.kill(world); -+ this.discard(EntityRemoveEvent.Cause.DEATH); // CraftBukkit - SPIGOT-4890: remain as this.discard() since above damagesource method will call death event ++ if (!event.isCancelled()) this.kill(source, false); // Paper - we still need to kill to follow vanilla logic (emit the game event etc...) } return true; -@@ -536,7 +602,7 @@ +@@ -536,7 +604,10 @@ f1 -= amount; if (f1 <= 0.5F) { this.brokenByAnything(world, damageSource); - this.kill(world); -+ this.kill(world, damageSource); // CraftBukkit ++ // Paper start - avoid duplicate event call ++ org.bukkit.event.entity.EntityDeathEvent event = this.brokenByAnything(world, damageSource); ++ if (!event.isCancelled()) this.kill(damageSource, false); // CraftBukkit ++ // Paper end } else { this.setHealth(f1); this.gameEvent(GameEvent.ENTITY_DAMAGE, damageSource.getEntity()); -@@ -548,13 +614,13 @@ +@@ -544,17 +615,17 @@ + + } + +- private void brokenByPlayer(ServerLevel world, DamageSource damageSource) { ++ private org.bukkit.event.entity.EntityDeathEvent brokenByPlayer(ServerLevel world, DamageSource damageSource) { // Paper ItemStack itemstack = new ItemStack(Items.ARMOR_STAND); itemstack.set(DataComponents.CUSTOM_NAME, this.getCustomName()); - Block.popResource(this.level(), this.blockPosition(), itemstack); +- this.brokenByAnything(world, damageSource); + this.drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack)); // CraftBukkit - add to drops - this.brokenByAnything(world, damageSource); ++ return this.brokenByAnything(world, damageSource); // Paper } - private void brokenByAnything(ServerLevel world, DamageSource damageSource) { +- private void brokenByAnything(ServerLevel world, DamageSource damageSource) { ++ private org.bukkit.event.entity.EntityDeathEvent brokenByAnything(ServerLevel world, DamageSource damageSource) { // Paper this.playBrokenSound(); - this.dropAllDeathLoot(world, damageSource); + // this.dropAllDeathLoot(worldserver, damagesource); // CraftBukkit - moved down ItemStack itemstack; int i; -@@ -562,7 +628,7 @@ +@@ -562,7 +633,7 @@ for (i = 0; i < this.handItems.size(); ++i) { itemstack = (ItemStack) this.handItems.get(i); if (!itemstack.isEmpty()) { @@ -343,7 +359,7 @@ this.handItems.set(i, ItemStack.EMPTY); } } -@@ -570,15 +636,16 @@ +@@ -570,15 +641,16 @@ for (i = 0; i < this.armorItems.size(); ++i) { itemstack = (ItemStack) this.armorItems.get(i); if (!itemstack.isEmpty()) { @@ -352,7 +368,7 @@ this.armorItems.set(i, ItemStack.EMPTY); } } -+ this.dropAllDeathLoot(world, damageSource); // CraftBukkit - moved from above ++ return this.dropAllDeathLoot(world, damageSource); // CraftBukkit - moved from above // Paper } @@ -362,7 +378,7 @@ } @Override -@@ -609,7 +676,29 @@ +@@ -609,7 +681,29 @@ @Override public void tick() { @@ -392,7 +408,7 @@ Rotations vector3f = (Rotations) this.entityData.get(ArmorStand.DATA_HEAD_POSE); if (!this.headPose.equals(vector3f)) { -@@ -664,9 +753,23 @@ +@@ -664,9 +758,31 @@ return this.isSmall(); } @@ -411,13 +427,21 @@ + } + + public void kill(ServerLevel worldserver, DamageSource damageSource) { -+ org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDeathEvent(this, (damageSource == null ? this.damageSources().genericKill() : damageSource), this.drops); // CraftBukkit - call event ++ // Paper start - make cancellable ++ this.kill(damageSource, true); ++ } ++ public void kill(DamageSource damageSource, boolean callEvent) { ++ if (callEvent) { ++ org.bukkit.event.entity.EntityDeathEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDeathEvent(this, (damageSource == null ? this.damageSources().genericKill() : damageSource), this.drops); // CraftBukkit - call event ++ if (event.isCancelled()) return; ++ } ++ // Paper end + this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause + // CraftBukkit end this.gameEvent(GameEvent.ENTITY_DIE); } -@@ -730,31 +833,37 @@ +@@ -730,31 +846,37 @@ public void setHeadPose(Rotations angle) { this.headPose = angle; this.entityData.set(ArmorStand.DATA_HEAD_POSE, angle); @@ -455,7 +479,7 @@ } public Rotations getHeadPose() { -@@ -788,7 +897,7 @@ +@@ -788,7 +910,7 @@ @Override public boolean skipAttackInteraction(Entity attacker) { @@ -464,7 +488,7 @@ } @Override -@@ -882,4 +991,13 @@ +@@ -882,4 +1004,13 @@ public boolean canBeSeenByAnyone() { return !this.isInvisible() && !this.isMarker(); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index c9c4696b1..63cc339b4 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -2517,7 +2517,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player { @Override public void sendHealthUpdate() { FoodData foodData = this.getHandle().getFoodData(); - this.sendHealthUpdate(this.getScaledHealth(), foodData.getFoodLevel(), foodData.getSaturationLevel()); + // Paper start - cancellable death event + ClientboundSetHealthPacket packet = new ClientboundSetHealthPacket(this.getScaledHealth(), foodData.getFoodLevel(), foodData.getSaturationLevel()); + if (this.getHandle().queueHealthUpdatePacket) { + this.getHandle().queuedHealthUpdatePacket = packet; + } else { + this.getHandle().connection.send(packet); + } + // Paper end } public void injectScaledMaxHealth(Collection collection, boolean force) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 474f330f3..b537b3ac2 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -902,8 +902,15 @@ public class CraftEventFactory { CraftDamageSource bukkitDamageSource = new CraftDamageSource(damageSource); CraftWorld world = (CraftWorld) entity.getWorld(); EntityDeathEvent event = new EntityDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(world.getHandle(), damageSource.getEntity())); + populateFields(victim, event); // Paper - make cancellable Bukkit.getServer().getPluginManager().callEvent(event); + // Paper start - make cancellable + if (event.isCancelled()) { + return event; + } + playDeathSound(victim, event); + // Paper end victim.expToDrop = event.getDroppedExp(); for (org.bukkit.inventory.ItemStack stack : event.getDrops()) { @@ -921,7 +928,14 @@ public class CraftEventFactory { PlayerDeathEvent event = new PlayerDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(victim.serverLevel(), damageSource.getEntity()), 0, deathMessage); event.setKeepInventory(keepInventory); event.setKeepLevel(victim.keepLevel); // SPIGOT-2222: pre-set keepLevel + populateFields(victim, event); // Paper - make cancellable Bukkit.getServer().getPluginManager().callEvent(event); + // Paper start - make cancellable + if (event.isCancelled()) { + return event; + } + playDeathSound(victim, event); + // Paper end victim.keepLevel = event.getKeepLevel(); victim.newLevel = event.getNewLevel(); @@ -944,6 +958,31 @@ public class CraftEventFactory { return event; } + // Paper start - helper methods for making death event cancellable + // Add information to death event + private static void populateFields(net.minecraft.world.entity.LivingEntity victim, EntityDeathEvent event) { + event.setReviveHealth(event.getEntity().getAttribute(org.bukkit.attribute.Attribute.MAX_HEALTH).getValue()); + event.setShouldPlayDeathSound(!victim.silentDeath && !victim.isSilent()); + net.minecraft.sounds.SoundEvent soundEffect = victim.getDeathSound(); + event.setDeathSound(soundEffect != null ? org.bukkit.craftbukkit.CraftSound.minecraftToBukkit(soundEffect) : null); + event.setDeathSoundCategory(org.bukkit.SoundCategory.valueOf(victim.getSoundSource().name())); + event.setDeathSoundVolume(victim.getSoundVolume()); + event.setDeathSoundPitch(victim.getVoicePitch()); + } + + // Play death sound manually + private static void playDeathSound(net.minecraft.world.entity.LivingEntity victim, EntityDeathEvent event) { + if (event.shouldPlayDeathSound() && event.getDeathSound() != null && event.getDeathSoundCategory() != null) { + net.minecraft.world.entity.player.Player source = victim instanceof net.minecraft.world.entity.player.Player ? (net.minecraft.world.entity.player.Player) victim : null; + double x = event.getEntity().getLocation().getX(); + double y = event.getEntity().getLocation().getY(); + double z = event.getEntity().getLocation().getZ(); + net.minecraft.sounds.SoundEvent soundEffect = org.bukkit.craftbukkit.CraftSound.bukkitToMinecraft(event.getDeathSound()); + net.minecraft.sounds.SoundSource soundCategory = net.minecraft.sounds.SoundSource.valueOf(event.getDeathSoundCategory().name()); + victim.level().playSound(source, x, y, z, soundEffect, soundCategory, event.getDeathSoundVolume(), event.getDeathSoundPitch()); + } + } + // Paper end /** * Server methods */