diff --git a/patches/minecraft/net/minecraft/server/level/ServerPlayer.java.patch b/patches/minecraft/net/minecraft/server/level/ServerPlayer.java.patch index ad6872bd09..a50f6f7b15 100644 --- a/patches/minecraft/net/minecraft/server/level/ServerPlayer.java.patch +++ b/patches/minecraft/net/minecraft/server/level/ServerPlayer.java.patch @@ -149,15 +149,6 @@ ItemStack removed = inventory.removeFromSelected(all); this.containerMenu .findSlot(inventory, inventory.getSelectedSlot()) -@@ -2127,7 +_,7 @@ - this.stopUsingItem(); - } - -- this.drop(removed, true, Prediction.PREDICTED); -+ net.minecraftforge.common.ForgeHooks.onPlayerTossEvent(this, removed, true, Prediction.PREDICTED); - this.resetAttackStrengthTicker(); - } - @@ -2229,6 +_,75 @@ public @Nullable BlockPos getRaidOmenPosition() { diff --git a/patches/minecraft/net/minecraft/world/entity/player/Player.java.patch b/patches/minecraft/net/minecraft/world/entity/player/Player.java.patch index 1e6f250054..aee45e4873 100644 --- a/patches/minecraft/net/minecraft/world/entity/player/Player.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/player/Player.java.patch @@ -92,13 +92,16 @@ super.die(source); this.reapplyPosition(); if (!this.isSpectator() && this.level() instanceof ServerLevel level) { -@@ -580,7 +_,17 @@ +@@ -580,7 +_,20 @@ public void handleCreativeModeItemDrop(final ItemStack stack) { } + @Override + public net.minecraft.world.entity.item.@Nullable ItemEntity drop(final ItemStack itemStack, final boolean thrownFromHand, final net.minecraft.util.Prediction prediction) { -+ return net.minecraftforge.common.ForgeHooks.onPlayerTossEvent(this, itemStack, thrownFromHand, prediction); ++ captureDrops(new ArrayList<>()); ++ var ret = super.drop(itemStack, thrownFromHand, prediction); ++ captureDrops(null); ++ return net.minecraftforge.common.ForgeHooks.onPlayerTossEvent(this, ret); + } + + /** @deprecated Use {@link #getDestroySpeed(BlockState,BlockPos) */ diff --git a/src/main/java/net/minecraftforge/common/ForgeHooks.java b/src/main/java/net/minecraftforge/common/ForgeHooks.java index 3be6643690..6d3180583e 100644 --- a/src/main/java/net/minecraftforge/common/ForgeHooks.java +++ b/src/main/java/net/minecraftforge/common/ForgeHooks.java @@ -306,23 +306,17 @@ public final class ForgeHooks { @SuppressWarnings("resource") @Nullable - public static ItemEntity onPlayerTossEvent(@NotNull Player player, @NotNull ItemStack item, boolean thrownFromHand, Prediction prediction) { - if (item.isEmpty()) + public static ItemEntity onPlayerTossEvent(@NotNull Player player, @Nullable ItemEntity entity) { + if (entity == null) return null; - player.captureDrops(new ArrayList<>()); - ItemEntity ret = player.drop(item, thrownFromHand, prediction); - player.captureDrops(null); - - if (ret == null) - return null; - - var event = new ItemTossEvent(ret, player); + var event = new ItemTossEvent(entity, player); if (ItemTossEvent.BUS.post(event)) return null; if (!player.level().isClientSide()) player.level().addFreshEntity(event.getEntity()); + return event.getEntity(); } @@ -1012,12 +1006,12 @@ public final class ForgeHooks { * @param refillAirAmount The amount of air to refill when the entity is able to breathe * @implNote This method needs to closely replicate the logic found right after the call site in {@link LivingEntity#baseTick()} as it overrides it. */ - @SuppressWarnings("deprecation") public static void onLivingBreathe(LivingEntity entity, int consumeAirAmount, int refillAirAmount) { // Check things that vanilla considers to be air - these will cause the air supply to be increased. // This is only called when the server level is already checked var level = (ServerLevel)entity.level(); var eyeFluid = entity.getEyeInFluidType(); + boolean isAir = eyeFluid.isAir() || level.getBlockState(BlockPos.containing(entity.getX(), entity.getEyeY(), entity.getZ())).is(Blocks.BUBBLE_COLUMN); // The following effects cause the entity to not drown, but do not cause the air supply to be increased. boolean canBreathe = !entity.canDrownInFluidType(eyeFluid) || MobEffectUtil.hasWaterBreathing(entity) || (entity instanceof Player player && player.getAbilities().invulnerable);