From e9e8ed7530a443a6e1b4ecbd8e37eb1d5f47fd02 Mon Sep 17 00:00:00 2001 From: md_5 Date: Tue, 19 Nov 2024 20:16:47 +1100 Subject: [PATCH] SPIGOT-7960: Improve natural item drop methods --- src/main/java/org/bukkit/craftbukkit/CraftWorld.java | 7 ++++--- .../craftbukkit/inventory/CraftAbstractInventoryView.java | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 0cffbfaac..9fa525246 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -49,6 +49,7 @@ import net.minecraft.sounds.SoundCategory; import net.minecraft.sounds.SoundEffect; import net.minecraft.sounds.SoundEffects; import net.minecraft.util.ArraySetSorted; +import net.minecraft.util.MathHelper; import net.minecraft.util.Unit; import net.minecraft.world.EnumDifficulty; import net.minecraft.world.entity.EntityLightning; @@ -568,9 +569,9 @@ public class CraftWorld extends CraftRegionAccessor implements World { Preconditions.checkArgument(loc != null, "Location cannot be null"); Preconditions.checkArgument(item != null, "ItemStack cannot be null"); - double xs = (world.random.nextFloat() * 0.5F) + 0.25D; - double ys = (world.random.nextFloat() * 0.5F) + 0.25D; - double zs = (world.random.nextFloat() * 0.5F) + 0.25D; + double xs = 0.5D + MathHelper.nextDouble(world.random, -0.25D, 0.25D); + double ys = 0.5D + MathHelper.nextDouble(world.random, -0.25D, 0.25D) - ((double) EntityTypes.ITEM.getHeight() / 2.0D); + double zs = MathHelper.nextDouble(world.random, -0.25D, 0.25D); loc = loc.clone().add(xs, ys, zs); return dropItem(loc, item, function); } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftAbstractInventoryView.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftAbstractInventoryView.java index 58d2dfe81..bc49532e5 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftAbstractInventoryView.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftAbstractInventoryView.java @@ -1,6 +1,9 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.base.Preconditions; +import net.minecraft.world.InventoryUtils; +import net.minecraft.world.entity.player.EntityHuman; +import org.bukkit.craftbukkit.entity.CraftHumanEntity; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; @@ -16,7 +19,8 @@ public abstract class CraftAbstractInventoryView implements InventoryView { if (inventory != null) { inventory.setItem(convertSlot(slot), item); } else if (item != null) { - getPlayer().getWorld().dropItemNaturally(getPlayer().getLocation(), item); + EntityHuman handle = ((CraftHumanEntity) getPlayer()).getHandle(); + InventoryUtils.dropItemStack(handle.level(), handle.getX(), handle.getY(), handle.getZ(), CraftItemStack.asNMSCopy(item)); } }