SPIGOT-7806: Handle both loot and inventory item drop behaviour in PlayerDeathEvent

This commit is contained in:
Doc 2024-07-06 17:25:39 +10:00 committed by md_5
parent a4ee40b749
commit 8fd64b0912
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
3 changed files with 89 additions and 62 deletions

View File

@ -1,16 +1,14 @@
--- a/net/minecraft/server/level/EntityPlayer.java --- a/net/minecraft/server/level/EntityPlayer.java
+++ b/net/minecraft/server/level/EntityPlayer.java +++ b/net/minecraft/server/level/EntityPlayer.java
@@ -166,6 +166,42 @@ @@ -166,6 +166,40 @@
import net.minecraft.world.scores.criteria.IScoreboardCriteria; import net.minecraft.world.scores.criteria.IScoreboardCriteria;
import org.slf4j.Logger; import org.slf4j.Logger;
+// CraftBukkit start +// CraftBukkit start
+import net.minecraft.nbt.NBTBase;
+import net.minecraft.world.damagesource.CombatTracker; +import net.minecraft.world.damagesource.CombatTracker;
+import net.minecraft.world.food.FoodMetaData; +import net.minecraft.world.food.FoodMetaData;
+import net.minecraft.world.inventory.ContainerPlayer; +import net.minecraft.world.inventory.ContainerPlayer;
+import net.minecraft.world.item.enchantment.EnchantmentEffectComponents; +import net.minecraft.world.item.enchantment.EnchantmentEffectComponents;
+import net.minecraft.world.item.enchantment.EnchantmentManager;
+import net.minecraft.world.level.block.BlockChest; +import net.minecraft.world.level.block.BlockChest;
+import net.minecraft.world.level.dimension.WorldDimension; +import net.minecraft.world.level.dimension.WorldDimension;
+import net.minecraft.world.scores.Scoreboard; +import net.minecraft.world.scores.Scoreboard;
@ -43,7 +41,7 @@
public class EntityPlayer extends EntityHuman { public class EntityPlayer extends EntityHuman {
private static final Logger LOGGER = LogUtils.getLogger(); private static final Logger LOGGER = LogUtils.getLogger();
@@ -204,7 +240,7 @@ @@ -204,7 +238,7 @@
private int levitationStartTime; private int levitationStartTime;
private boolean disconnected; private boolean disconnected;
private int requestedViewDistance; private int requestedViewDistance;
@ -52,7 +50,7 @@
@Nullable @Nullable
private Vec3D startingToFallPosition; private Vec3D startingToFallPosition;
@Nullable @Nullable
@@ -235,6 +271,21 @@ @@ -235,6 +269,21 @@
private int containerCounter; private int containerCounter;
public boolean wonGame; public boolean wonGame;
@ -74,7 +72,7 @@
public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, ClientInformation clientinformation) { public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, ClientInformation clientinformation) {
super(worldserver, worldserver.getSharedSpawnPos(), worldserver.getSharedSpawnAngle(), gameprofile); super(worldserver, worldserver.getSharedSpawnPos(), worldserver.getSharedSpawnAngle(), gameprofile);
this.chatVisibility = EnumChatVisibility.FULL; this.chatVisibility = EnumChatVisibility.FULL;
@@ -302,14 +353,67 @@ @@ -302,14 +351,67 @@
this.moveTo(this.adjustSpawnLocation(worldserver, worldserver.getSharedSpawnPos()).getBottomCenter(), 0.0F, 0.0F); this.moveTo(this.adjustSpawnLocation(worldserver, worldserver.getSharedSpawnPos()).getBottomCenter(), 0.0F, 0.0F);
this.updateOptions(clientinformation); this.updateOptions(clientinformation);
this.object = null; this.object = null;
@ -143,7 +141,7 @@
int i = Math.max(0, this.server.getSpawnRadius(worldserver)); int i = Math.max(0, this.server.getSpawnRadius(worldserver));
int j = MathHelper.floor(worldserver.getWorldBorder().getDistanceToBorder((double) blockposition.getX(), (double) blockposition.getZ())); int j = MathHelper.floor(worldserver.getWorldBorder().getDistanceToBorder((double) blockposition.getX(), (double) blockposition.getZ()));
@@ -366,7 +470,7 @@ @@ -366,7 +468,7 @@
dataresult = WardenSpawnTracker.CODEC.parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.get("warden_spawn_tracker"))); dataresult = WardenSpawnTracker.CODEC.parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.get("warden_spawn_tracker")));
logger = EntityPlayer.LOGGER; logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger); Objects.requireNonNull(logger);
@ -152,7 +150,7 @@
this.wardenSpawnTracker = wardenspawntracker; this.wardenSpawnTracker = wardenspawntracker;
}); });
} }
@@ -381,17 +485,26 @@ @@ -381,17 +483,26 @@
if (nbttagcompound.contains("recipeBook", 10)) { if (nbttagcompound.contains("recipeBook", 10)) {
this.recipeBook.fromNbt(nbttagcompound.getCompound("recipeBook"), this.server.getRecipeManager()); this.recipeBook.fromNbt(nbttagcompound.getCompound("recipeBook"), this.server.getRecipeManager());
} }
@ -180,7 +178,7 @@
Logger logger1 = EntityPlayer.LOGGER; Logger logger1 = EntityPlayer.LOGGER;
Objects.requireNonNull(logger1); Objects.requireNonNull(logger1);
@@ -406,7 +519,7 @@ @@ -406,7 +517,7 @@
dataresult = BlockPosition.CODEC.parse(DynamicOpsNBT.INSTANCE, nbtbase); dataresult = BlockPosition.CODEC.parse(DynamicOpsNBT.INSTANCE, nbtbase);
logger = EntityPlayer.LOGGER; logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger); Objects.requireNonNull(logger);
@ -189,7 +187,7 @@
this.raidOmenPosition = blockposition; this.raidOmenPosition = blockposition;
}); });
} }
@@ -416,7 +529,7 @@ @@ -416,7 +527,7 @@
@Override @Override
public void addAdditionalSaveData(NBTTagCompound nbttagcompound) { public void addAdditionalSaveData(NBTTagCompound nbttagcompound) {
super.addAdditionalSaveData(nbttagcompound); super.addAdditionalSaveData(nbttagcompound);
@ -198,7 +196,7 @@
Logger logger = EntityPlayer.LOGGER; Logger logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger); Objects.requireNonNull(logger);
@@ -437,7 +550,20 @@ @@ -437,7 +548,20 @@
Entity entity = this.getRootVehicle(); Entity entity = this.getRootVehicle();
Entity entity1 = this.getVehicle(); Entity entity1 = this.getVehicle();
@ -220,7 +218,7 @@
NBTTagCompound nbttagcompound2 = new NBTTagCompound(); NBTTagCompound nbttagcompound2 = new NBTTagCompound();
NBTTagCompound nbttagcompound3 = new NBTTagCompound(); NBTTagCompound nbttagcompound3 = new NBTTagCompound();
@@ -462,6 +588,7 @@ @@ -462,6 +586,7 @@
nbttagcompound.put("SpawnDimension", nbtbase); nbttagcompound.put("SpawnDimension", nbtbase);
}); });
} }
@ -228,7 +226,7 @@
nbttagcompound.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall); nbttagcompound.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall);
if (this.raidOmenPosition != null) { if (this.raidOmenPosition != null) {
@@ -475,6 +602,29 @@ @@ -475,6 +600,29 @@
} }
@ -258,7 +256,7 @@
public void setExperiencePoints(int i) { public void setExperiencePoints(int i) {
float f = (float) this.getXpNeededForNextLevel(); float f = (float) this.getXpNeededForNextLevel();
float f1 = (f - 1.0F) / f; float f1 = (f - 1.0F) / f;
@@ -533,6 +683,11 @@ @@ -533,6 +681,11 @@
@Override @Override
public void tick() { public void tick() {
@ -270,7 +268,7 @@
this.gameMode.tick(); this.gameMode.tick();
this.wardenSpawnTracker.tick(); this.wardenSpawnTracker.tick();
--this.spawnInvulnerableTime; --this.spawnInvulnerableTime;
@@ -613,7 +768,7 @@ @@ -613,7 +766,7 @@
} }
if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) { if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) {
@ -279,7 +277,7 @@
this.lastSentHealth = this.getHealth(); this.lastSentHealth = this.getHealth();
this.lastSentFood = this.foodData.getFoodLevel(); this.lastSentFood = this.foodData.getFoodLevel();
this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F; this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F;
@@ -644,6 +799,12 @@ @@ -644,6 +797,12 @@
this.updateScoreForCriteria(IScoreboardCriteria.EXPERIENCE, MathHelper.ceil((float) this.lastRecordedExperience)); this.updateScoreForCriteria(IScoreboardCriteria.EXPERIENCE, MathHelper.ceil((float) this.lastRecordedExperience));
} }
@ -292,7 +290,7 @@
if (this.experienceLevel != this.lastRecordedLevel) { if (this.experienceLevel != this.lastRecordedLevel) {
this.lastRecordedLevel = this.experienceLevel; this.lastRecordedLevel = this.experienceLevel;
this.updateScoreForCriteria(IScoreboardCriteria.LEVEL, MathHelper.ceil((float) this.lastRecordedLevel)); this.updateScoreForCriteria(IScoreboardCriteria.LEVEL, MathHelper.ceil((float) this.lastRecordedLevel));
@@ -658,6 +819,20 @@ @@ -658,6 +817,20 @@
CriterionTriggers.LOCATION.trigger(this); CriterionTriggers.LOCATION.trigger(this);
} }
@ -313,7 +311,7 @@
} catch (Throwable throwable) { } catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player"); CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player");
CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Player being ticked"); CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Player being ticked");
@@ -703,7 +878,8 @@ @@ -703,7 +876,8 @@
} }
private void updateScoreForCriteria(IScoreboardCriteria iscoreboardcriteria, int i) { private void updateScoreForCriteria(IScoreboardCriteria iscoreboardcriteria, int i) {
@ -323,7 +321,7 @@
scoreaccess.set(i); scoreaccess.set(i);
}); });
} }
@@ -712,9 +888,47 @@ @@ -712,9 +886,47 @@
public void die(DamageSource damagesource) { public void die(DamageSource damagesource) {
this.gameEvent(GameEvent.ENTITY_DIE); this.gameEvent(GameEvent.ENTITY_DIE);
boolean flag = this.level().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES); boolean flag = this.level().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
@ -339,7 +337,7 @@
+ if (!keepInventory) { + if (!keepInventory) {
+ for (ItemStack item : this.getInventory().getContents()) { + for (ItemStack item : this.getInventory().getContents()) {
+ if (!item.isEmpty() && !EnchantmentManager.has(item, EnchantmentEffectComponents.PREVENT_EQUIPMENT_DROP)) { + if (!item.isEmpty() && !EnchantmentManager.has(item, EnchantmentEffectComponents.PREVENT_EQUIPMENT_DROP)) {
+ loot.add(CraftItemStack.asCraftMirror(item)); + loot.add(CraftItemStack.asCraftMirror(item).markForInventoryDrop());
+ } + }
+ } + }
+ } + }
@ -373,7 +371,7 @@
this.connection.send(new ClientboundPlayerCombatKillPacket(this.getId(), ichatbasecomponent), PacketSendListener.exceptionallySend(() -> { this.connection.send(new ClientboundPlayerCombatKillPacket(this.getId(), ichatbasecomponent), PacketSendListener.exceptionallySend(() -> {
boolean flag1 = true; boolean flag1 = true;
@@ -745,12 +959,18 @@ @@ -745,12 +957,18 @@
if (this.level().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) { if (this.level().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) {
this.tellNeutralMobsThatIDied(); this.tellNeutralMobsThatIDied();
} }
@ -396,7 +394,7 @@
EntityLiving entityliving = this.getKillCredit(); EntityLiving entityliving = this.getKillCredit();
if (entityliving != null) { if (entityliving != null) {
@@ -785,10 +1005,12 @@ @@ -785,10 +1003,12 @@
if (entity != this) { if (entity != this) {
super.awardKillScore(entity, i, damagesource); super.awardKillScore(entity, i, damagesource);
this.increaseScore(i); this.increaseScore(i);
@ -411,7 +409,7 @@
} else { } else {
this.awardStat(StatisticList.MOB_KILLS); this.awardStat(StatisticList.MOB_KILLS);
} }
@@ -806,7 +1028,8 @@ @@ -806,7 +1026,8 @@
int i = scoreboardteam.getColor().getId(); int i = scoreboardteam.getColor().getId();
if (i >= 0 && i < aiscoreboardcriteria.length) { if (i >= 0 && i < aiscoreboardcriteria.length) {
@ -421,7 +419,7 @@
} }
} }
@@ -856,10 +1079,16 @@ @@ -856,10 +1077,16 @@
} }
private boolean isPvpAllowed() { private boolean isPvpAllowed() {
@ -440,7 +438,7 @@
BlockPosition blockposition = this.getRespawnPosition(); BlockPosition blockposition = this.getRespawnPosition();
float f = this.getRespawnAngle(); float f = this.getRespawnAngle();
boolean flag1 = this.isRespawnForced(); boolean flag1 = this.isRespawnForced();
@@ -871,13 +1100,32 @@ @@ -871,13 +1098,32 @@
if (optional.isPresent()) { if (optional.isPresent()) {
EntityPlayer.RespawnPosAngle entityplayer_respawnposangle = (EntityPlayer.RespawnPosAngle) optional.get(); EntityPlayer.RespawnPosAngle entityplayer_respawnposangle = (EntityPlayer.RespawnPosAngle) optional.get();
@ -457,11 +455,11 @@
} else { } else {
- return new DimensionTransition(this.server.overworld(), this, dimensiontransition_a); - return new DimensionTransition(this.server.overworld(), this, dimensiontransition_a);
+ dimensionTransition = new DimensionTransition(this.server.overworld(), this, dimensiontransition_a); // CraftBukkit + dimensionTransition = new DimensionTransition(this.server.overworld(), this, dimensiontransition_a); // CraftBukkit
+ } }
+ // CraftBukkit start + // CraftBukkit start
+ if (reason == null) { + if (reason == null) {
+ return dimensionTransition; + return dimensionTransition;
} + }
+ +
+ Player respawnPlayer = this.getBukkitEntity(); + Player respawnPlayer = this.getBukkitEntity();
+ Location location = CraftLocation.toBukkit(dimensionTransition.pos(), dimensionTransition.newLevel().getWorld(), dimensionTransition.yRot(), dimensionTransition.xRot()); + Location location = CraftLocation.toBukkit(dimensionTransition.pos(), dimensionTransition.newLevel().getWorld(), dimensionTransition.yRot(), dimensionTransition.xRot());
@ -476,7 +474,7 @@
} }
public static Optional<EntityPlayer.RespawnPosAngle> findRespawnAndUseSpawnBlock(WorldServer worldserver, BlockPosition blockposition, float f, boolean flag, boolean flag1) { public static Optional<EntityPlayer.RespawnPosAngle> findRespawnAndUseSpawnBlock(WorldServer worldserver, BlockPosition blockposition, float f, boolean flag, boolean flag1) {
@@ -892,11 +1140,11 @@ @@ -892,11 +1138,11 @@
} }
return optional.map((vec3d) -> { return optional.map((vec3d) -> {
@ -490,7 +488,7 @@
}); });
} else if (!flag) { } else if (!flag) {
return Optional.empty(); return Optional.empty();
@@ -905,7 +1153,7 @@ @@ -905,7 +1151,7 @@
IBlockData iblockdata1 = worldserver.getBlockState(blockposition.above()); IBlockData iblockdata1 = worldserver.getBlockState(blockposition.above());
boolean flag3 = iblockdata1.getBlock().isPossibleToRespawnInThis(iblockdata1); boolean flag3 = iblockdata1.getBlock().isPossibleToRespawnInThis(iblockdata1);
@ -499,7 +497,7 @@
} }
} }
@@ -923,6 +1171,7 @@ @@ -923,6 +1169,7 @@
@Nullable @Nullable
@Override @Override
public Entity changeDimension(DimensionTransition dimensiontransition) { public Entity changeDimension(DimensionTransition dimensiontransition) {
@ -507,7 +505,7 @@
if (this.isRemoved()) { if (this.isRemoved()) {
return null; return null;
} else { } else {
@@ -932,14 +1181,21 @@ @@ -932,14 +1179,21 @@
WorldServer worldserver = dimensiontransition.newLevel(); WorldServer worldserver = dimensiontransition.newLevel();
WorldServer worldserver1 = this.serverLevel(); WorldServer worldserver1 = this.serverLevel();
@ -532,7 +530,7 @@
this.isChangingDimension = true; this.isChangingDimension = true;
WorldData worlddata = worldserver.getLevelData(); WorldData worlddata = worldserver.getLevelData();
@@ -950,15 +1206,40 @@ @@ -950,15 +1204,40 @@
playerlist.sendPlayerPermissionLevel(this); playerlist.sendPlayerPermissionLevel(this);
worldserver1.removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION); worldserver1.removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION);
this.unsetRemoved(); this.unsetRemoved();
@ -575,7 +573,7 @@
this.connection.resetPosition(); this.connection.resetPosition();
worldserver.addDuringTeleport(this); worldserver.addDuringTeleport(this);
worldserver1.getProfiler().pop(); worldserver1.getProfiler().pop();
@@ -971,21 +1252,47 @@ @@ -971,21 +1250,47 @@
this.lastSentExp = -1; this.lastSentExp = -1;
this.lastSentHealth = -1.0F; this.lastSentHealth = -1.0F;
this.lastSentFood = -1; this.lastSentFood = -1;
@ -626,7 +624,7 @@
this.enteredNetherPosition = null; this.enteredNetherPosition = null;
} }
@@ -1002,19 +1309,17 @@ @@ -1002,19 +1307,17 @@
this.containerMenu.broadcastChanges(); this.containerMenu.broadcastChanges();
} }
@ -650,7 +648,7 @@
if (this.level().isDay()) { if (this.level().isDay()) {
return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_NOW); return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_NOW);
} else { } else {
@@ -1031,7 +1336,36 @@ @@ -1031,7 +1334,36 @@
} }
} }
@ -688,7 +686,7 @@
this.awardStat(StatisticList.SLEEP_IN_BED); this.awardStat(StatisticList.SLEEP_IN_BED);
CriterionTriggers.SLEPT_IN_BED.trigger(this); CriterionTriggers.SLEPT_IN_BED.trigger(this);
}); });
@@ -1044,9 +1378,8 @@ @@ -1044,9 +1376,8 @@
return either; return either;
} }
} }
@ -699,7 +697,7 @@
} }
@Override @Override
@@ -1073,13 +1406,31 @@ @@ -1073,13 +1404,31 @@
@Override @Override
public void stopSleepInBed(boolean flag, boolean flag1) { public void stopSleepInBed(boolean flag, boolean flag1) {
@ -732,7 +730,7 @@
} }
} }
@@ -1146,8 +1497,9 @@ @@ -1146,8 +1495,9 @@
this.connection.send(new PacketPlayOutOpenSignEditor(tileentitysign.getBlockPos(), flag)); this.connection.send(new PacketPlayOutOpenSignEditor(tileentitysign.getBlockPos(), flag));
} }
@ -743,7 +741,7 @@
} }
@Override @Override
@@ -1155,13 +1507,35 @@ @@ -1155,13 +1505,35 @@
if (itileinventory == null) { if (itileinventory == null) {
return OptionalInt.empty(); return OptionalInt.empty();
} else { } else {
@ -779,7 +777,7 @@
if (container == null) { if (container == null) {
if (this.isSpectator()) { if (this.isSpectator()) {
this.displayClientMessage(IChatBaseComponent.translatable("container.spectatorCantOpen").withStyle(EnumChatFormat.RED), true); this.displayClientMessage(IChatBaseComponent.translatable("container.spectatorCantOpen").withStyle(EnumChatFormat.RED), true);
@@ -1169,9 +1543,11 @@ @@ -1169,9 +1541,11 @@
return OptionalInt.empty(); return OptionalInt.empty();
} else { } else {
@ -793,7 +791,7 @@
return OptionalInt.of(this.containerCounter); return OptionalInt.of(this.containerCounter);
} }
} }
@@ -1184,15 +1560,26 @@ @@ -1184,15 +1558,26 @@
@Override @Override
public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) { public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) {
@ -822,7 +820,7 @@
this.initMenu(this.containerMenu); this.initMenu(this.containerMenu);
} }
@@ -1215,6 +1602,7 @@ @@ -1215,6 +1600,7 @@
@Override @Override
public void closeContainer() { public void closeContainer() {
@ -830,7 +828,7 @@
this.connection.send(new PacketPlayOutCloseWindow(this.containerMenu.containerId)); this.connection.send(new PacketPlayOutCloseWindow(this.containerMenu.containerId));
this.doCloseContainer(); this.doCloseContainer();
} }
@@ -1237,6 +1625,16 @@ @@ -1237,6 +1623,16 @@
} }
this.jumping = flag; this.jumping = flag;
@ -847,7 +845,7 @@
this.setShiftKeyDown(flag1); this.setShiftKeyDown(flag1);
} }
@@ -1270,19 +1668,19 @@ @@ -1270,19 +1666,19 @@
i = Math.round((float) Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F); i = Math.round((float) Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F);
if (i > 0) { if (i > 0) {
this.awardStat(StatisticList.SWIM_ONE_CM, i); this.awardStat(StatisticList.SWIM_ONE_CM, i);
@ -870,7 +868,7 @@
} }
} else if (this.onClimbable()) { } else if (this.onClimbable()) {
if (d1 > 0.0D) { if (d1 > 0.0D) {
@@ -1293,13 +1691,13 @@ @@ -1293,13 +1689,13 @@
if (i > 0) { if (i > 0) {
if (this.isSprinting()) { if (this.isSprinting()) {
this.awardStat(StatisticList.SPRINT_ONE_CM, i); this.awardStat(StatisticList.SPRINT_ONE_CM, i);
@ -887,7 +885,7 @@
} }
} }
} else if (this.isFallFlying()) { } else if (this.isFallFlying()) {
@@ -1342,7 +1740,7 @@ @@ -1342,7 +1738,7 @@
@Override @Override
public void awardStat(Statistic<?> statistic, int i) { public void awardStat(Statistic<?> statistic, int i) {
this.stats.increment(this, statistic, i); this.stats.increment(this, statistic, i);
@ -896,7 +894,7 @@
scoreaccess.add(i); scoreaccess.add(i);
}); });
} }
@@ -1350,7 +1748,7 @@ @@ -1350,7 +1746,7 @@
@Override @Override
public void resetStat(Statistic<?> statistic) { public void resetStat(Statistic<?> statistic) {
this.stats.setValue(this, statistic, 0); this.stats.setValue(this, statistic, 0);
@ -905,7 +903,7 @@
} }
@Override @Override
@@ -1398,6 +1796,7 @@ @@ -1398,6 +1794,7 @@
public void resetSentInfo() { public void resetSentInfo() {
this.lastSentHealth = -1.0E8F; this.lastSentHealth = -1.0E8F;
@ -913,7 +911,7 @@
} }
@Override @Override
@@ -1433,7 +1832,7 @@ @@ -1433,7 +1830,7 @@
this.gameMode.setGameModeForPlayer(entityplayer.gameMode.getGameModeForPlayer(), entityplayer.gameMode.getPreviousGameModeForPlayer()); this.gameMode.setGameModeForPlayer(entityplayer.gameMode.getGameModeForPlayer(), entityplayer.gameMode.getPreviousGameModeForPlayer());
this.onUpdateAbilities(); this.onUpdateAbilities();
this.getAttributes().assignBaseValues(entityplayer.getAttributes()); this.getAttributes().assignBaseValues(entityplayer.getAttributes());
@ -922,7 +920,7 @@
if (flag) { if (flag) {
this.getInventory().replaceWith(entityplayer.getInventory()); this.getInventory().replaceWith(entityplayer.getInventory());
this.setHealth(entityplayer.getHealth()); this.setHealth(entityplayer.getHealth());
@@ -1443,7 +1842,7 @@ @@ -1443,7 +1840,7 @@
while (iterator.hasNext()) { while (iterator.hasNext()) {
MobEffect mobeffect = (MobEffect) iterator.next(); MobEffect mobeffect = (MobEffect) iterator.next();
@ -931,7 +929,7 @@
} }
this.experienceLevel = entityplayer.experienceLevel; this.experienceLevel = entityplayer.experienceLevel;
@@ -1465,7 +1864,7 @@ @@ -1465,7 +1862,7 @@
this.lastSentExp = -1; this.lastSentExp = -1;
this.lastSentHealth = -1.0F; this.lastSentHealth = -1.0F;
this.lastSentFood = -1; this.lastSentFood = -1;
@ -940,7 +938,7 @@
this.seenCredits = entityplayer.seenCredits; this.seenCredits = entityplayer.seenCredits;
this.enteredNetherPosition = entityplayer.enteredNetherPosition; this.enteredNetherPosition = entityplayer.enteredNetherPosition;
this.chunkTrackingView = entityplayer.chunkTrackingView; this.chunkTrackingView = entityplayer.chunkTrackingView;
@@ -1516,6 +1915,12 @@ @@ -1516,6 +1913,12 @@
@Override @Override
public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set<RelativeMovement> set, float f, float f1) { public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set<RelativeMovement> set, float f, float f1) {
@ -953,7 +951,7 @@
ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(BlockPosition.containing(d0, d1, d2)); ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(BlockPosition.containing(d0, d1, d2));
worldserver.getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, chunkcoordintpair, 1, this.getId()); worldserver.getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, chunkcoordintpair, 1, this.getId());
@@ -1525,9 +1930,9 @@ @@ -1525,9 +1928,9 @@
} }
if (worldserver == this.level()) { if (worldserver == this.level()) {
@ -965,7 +963,7 @@
} }
this.setYHeadRot(f); this.setYHeadRot(f);
@@ -1635,6 +2040,16 @@ @@ -1635,6 +2038,16 @@
} }
public void updateOptions(ClientInformation clientinformation) { public void updateOptions(ClientInformation clientinformation) {
@ -982,7 +980,7 @@
this.language = clientinformation.language(); this.language = clientinformation.language();
this.requestedViewDistance = clientinformation.viewDistance(); this.requestedViewDistance = clientinformation.viewDistance();
this.chatVisibility = clientinformation.chatVisibility(); this.chatVisibility = clientinformation.chatVisibility();
@@ -1718,7 +2133,7 @@ @@ -1718,7 +2131,7 @@
if (world instanceof WorldServer) { if (world instanceof WorldServer) {
WorldServer worldserver = (WorldServer) world; WorldServer worldserver = (WorldServer) world;
@ -991,7 +989,7 @@
} }
if (entity != null) { if (entity != null) {
@@ -1755,7 +2170,7 @@ @@ -1755,7 +2168,7 @@
@Nullable @Nullable
public IChatBaseComponent getTabListDisplayName() { public IChatBaseComponent getTabListDisplayName() {
@ -1000,7 +998,7 @@
} }
@Override @Override
@@ -1776,14 +2191,24 @@ @@ -1776,14 +2189,24 @@
return this.advancements; return this.advancements;
} }
@ -1025,7 +1023,7 @@
} }
@@ -1809,6 +2234,32 @@ @@ -1809,6 +2232,32 @@
} }
public void setRespawnPosition(ResourceKey<World> resourcekey, @Nullable BlockPosition blockposition, float f, boolean flag, boolean flag1) { public void setRespawnPosition(ResourceKey<World> resourcekey, @Nullable BlockPosition blockposition, float f, boolean flag, boolean flag1) {
@ -1058,7 +1056,7 @@
if (blockposition != null) { if (blockposition != null) {
boolean flag2 = blockposition.equals(this.respawnPosition) && resourcekey.equals(this.respawnDimension); boolean flag2 = blockposition.equals(this.respawnPosition) && resourcekey.equals(this.respawnDimension);
@@ -1852,7 +2303,14 @@ @@ -1852,7 +2301,14 @@
@Override @Override
public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1) { public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1) {
@ -1074,7 +1072,7 @@
if (entityitem == null) { if (entityitem == null) {
return null; return null;
@@ -2049,10 +2507,12 @@ @@ -2049,10 +2505,12 @@
this.awardStat(StatisticList.ITEM_BROKEN.get(item)); this.awardStat(StatisticList.ITEM_BROKEN.get(item));
} }
@ -1090,7 +1088,7 @@
} }
private static float calculateLookAtYaw(Vec3D vec3d, BlockPosition blockposition) { private static float calculateLookAtYaw(Vec3D vec3d, BlockPosition blockposition) {
@@ -2061,4 +2521,147 @@ @@ -2061,4 +2519,147 @@
return (float) MathHelper.wrapDegrees(MathHelper.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D); return (float) MathHelper.wrapDegrees(MathHelper.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D);
} }
} }

View File

@ -924,7 +924,13 @@ public class CraftEventFactory {
for (org.bukkit.inventory.ItemStack stack : event.getDrops()) { for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
if (stack == null || stack.getType() == Material.AIR) continue; if (stack == null || stack.getType() == Material.AIR) continue;
victim.drop(CraftItemStack.asNMSCopy(stack), true, false, false); // SPIGOT-7800, SPIGOT-7801: Vanilla Behaviour for dropped items if (stack instanceof CraftItemStack craftItemStack && craftItemStack.isForInventoryDrop()) {
victim.drop(CraftItemStack.asNMSCopy(stack), true, false, false); // SPIGOT-7800, SPIGOT-7801: Vanilla Behaviour for Player Inventory dropped items
} else {
victim.forceDrops = true;
victim.spawnAtLocation(CraftItemStack.asNMSCopy(stack)); // SPIGOT-7806: Vanilla Behaviour for items not related to Player Inventory dropped items
victim.forceDrops = false;
}
} }
return event; return event;

View File

@ -18,6 +18,7 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
import org.jetbrains.annotations.ApiStatus;
@DelegateDeserialization(ItemStack.class) @DelegateDeserialization(ItemStack.class)
public final class CraftItemStack extends ItemStack { public final class CraftItemStack extends ItemStack {
@ -85,6 +86,7 @@ public final class CraftItemStack extends ItemStack {
} }
net.minecraft.world.item.ItemStack handle; net.minecraft.world.item.ItemStack handle;
private boolean isForInventoryDrop;
/** /**
* Mirror * Mirror
@ -104,6 +106,27 @@ public final class CraftItemStack extends ItemStack {
setItemMeta(itemMeta); setItemMeta(itemMeta);
} }
/**
* Gets if the item is marked as an inventory drop in death events.
*
* @return true if the item is marked as an inventory drop
*/
@ApiStatus.Internal
public boolean isForInventoryDrop() {
return this.isForInventoryDrop;
}
/**
* Marks this item as an inventory drop in death events.
*
* @return the ItemStack marked as an inventory drop
*/
@ApiStatus.Internal
public ItemStack markForInventoryDrop() {
this.isForInventoryDrop = true;
return this;
}
@Override @Override
public MaterialData getData() { public MaterialData getData() {
return handle != null ? CraftMagicNumbers.getMaterialData(handle.getItem()) : super.getData(); return handle != null ? CraftMagicNumbers.getMaterialData(handle.getItem()) : super.getData();