Remove thrower and 'empty' overloads

This commit is contained in:
Strokkur24 2024-12-24 15:04:02 +01:00
parent 63a52404b0
commit 2d9e357a45
No known key found for this signature in database
2 changed files with 12 additions and 47 deletions

View file

@ -708,76 +708,42 @@ public interface HumanEntity extends LivingEntity, AnimalTamer, InventoryHolder
*/ */
public boolean dropItem(boolean dropAll); public boolean dropItem(boolean dropAll);
/**
* Makes the entity drop the first declared {@link ItemStack} occurrence in the inventory
*
* @param itemStack The ItemStack to drop
* @return The dropped item, or null if the action was unsuccessful
*/
public default @Nullable Item dropItem(final @NotNull ItemStack itemStack) {
return this.dropItem(itemStack, null, false);
}
/** /**
* Makes the entity drop an item from their inventory based on the specified ItemStack. * Makes the entity drop an item from their inventory based on the specified ItemStack.
* <br> * <br>
* This method calls {@link HumanEntity#dropItem(int slot, UUID thrower, boolean throwRandomly)} * This method calls {@link HumanEntity#dropItem(int slot, boolean throwRandomly)}
* with the first {@link ItemStack} occurrence in the inventory * with the first {@link ItemStack} occurrence in the inventory
* *
* @param itemStack The ItemStack to drop * @param itemStack The ItemStack to drop
* @param thrower The {@link UUID} to set the resulting {@link Item}'s thrower to
* @param throwRandomly Whether the item should disperse randomly. * @param throwRandomly Whether the item should disperse randomly.
* This means that instead of the item being dropped where the player is currently looking, * This means that instead of the item being dropped where the player is currently looking,
* it instead throws it in any direction, similar to how items drop after a player's death. * it instead throws it in any direction, similar to how items drop after a player's death.
* @return The dropped item, or null if the action was unsuccessful * @return The dropped item, or null if the action was unsuccessful
*/ */
public @Nullable Item dropItem(final @NotNull ItemStack itemStack, final @Nullable UUID thrower, final boolean throwRandomly); public @Nullable Item dropItem(final @NotNull ItemStack itemStack, final boolean throwRandomly);
/**
* Makes the entity drop an item from their inventory based on the slot.
*
* @param slot The slot to drop
* @return The dropped item, or null if the action was unsuccessful
* @throws IndexOutOfBoundsException If the slot is negative or bigger than the player's inventory
*/
public default @Nullable Item dropItem(final int slot) {
return this.dropItem(slot, null, false);
}
/** /**
* Makes the entity drop an item from their inventory based on the slot. * Makes the entity drop an item from their inventory based on the slot.
* *
* @param slot The slot to drop * @param slot The slot to drop
* @param thrower The {@link UUID} to set the resulting {@link Item}'s thrower to
* @param throwRandomly Whether the item should disperse randomly. * @param throwRandomly Whether the item should disperse randomly.
* This means that instead of the item being dropped where the player is currently looking, * This means that instead of the item being dropped where the player is currently looking,
* it instead throws it in any direction, similar to how items drop after a player's death. * it instead throws it in any direction, similar to how items drop after a player's death.
* @return The dropped item entity, or null if the action was unsuccessful * @return The dropped item entity, or null if the action was unsuccessful
* @throws IndexOutOfBoundsException If the slot is negative or bigger than the player's inventory * @throws IndexOutOfBoundsException If the slot is negative or bigger than the player's inventory
*/ */
public @Nullable Item dropItem(final int slot, final @Nullable UUID thrower, final boolean throwRandomly); public @Nullable Item dropItem(final int slot, final boolean throwRandomly);
/**
* Makes the entity drop an item from their inventory based on the {@link EquipmentSlot}
*
* @param slot The equipment slot to drop
* @return The dropped item entity, or null if the action was unsuccessful
*/
public default @Nullable Item dropItem(final @NotNull EquipmentSlot slot) {
return this.dropItem(slot, null, false);
}
/** /**
* Makes the player drop an item from their inventory based on the equipment slot. * Makes the player drop an item from their inventory based on the equipment slot.
* *
* @param slot The equipment slot to drop * @param slot The equipment slot to drop
* @param thrower The {@link UUID} to set the resulting {@link Item}'s thrower to
* @param throwRandomly Whether the item should disperse randomly. * @param throwRandomly Whether the item should disperse randomly.
* This means that instead of the item being dropped where the player is currently looking, * This means that instead of the item being dropped where the player is currently looking,
* it instead throws it in any direction, similar to how items drop after a player's death. * it instead throws it in any direction, similar to how items drop after a player's death.
* @return The dropped item entity, or null if the action was unsuccessful * @return The dropped item entity, or null if the action was unsuccessful
*/ */
public @Nullable Item dropItem(final @NotNull EquipmentSlot slot, final @Nullable UUID thrower, final boolean throwRandomly); public @Nullable Item dropItem(final @NotNull EquipmentSlot slot, final boolean throwRandomly);
/** /**

View file

@ -807,49 +807,48 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
} }
@Override @Override
public @Nullable Item dropItem(final @NotNull ItemStack itemStack, final @Nullable UUID thrower, final boolean throwRandomly) { public @Nullable Item dropItem(final @NotNull ItemStack itemStack, final boolean throwRandomly) {
final int slot = this.inventory.first(itemStack); final int slot = this.inventory.first(itemStack);
if (slot == -1) { if (slot == -1) {
return null; return null;
} }
return this.dropItem(slot, thrower, throwRandomly); return this.dropItem(slot, throwRandomly);
} }
@Override @Override
public @Nullable Item dropItem(final int slot, final @Nullable UUID thrower, final boolean throwRandomly) { public @Nullable Item dropItem(final int slot, final boolean throwRandomly) {
// Make sure the slot is in bounds // Make sure the slot is in bounds
if (slot < 0 || slot >= this.inventory.getSize()) { if (slot < 0 || slot >= this.inventory.getSize()) {
throw new IndexOutOfBoundsException("Slot " + slot + " out of range for inventory of size " + this.inventory.getSize()); throw new IndexOutOfBoundsException("Slot " + slot + " out of range for inventory of size " + this.inventory.getSize());
} }
final ItemStack stack = this.inventory.getItem(slot); final ItemStack stack = this.inventory.getItem(slot);
final Item itemEntity = dropItemRaw(stack, thrower, throwRandomly); final Item itemEntity = dropItemRaw(stack, throwRandomly);
this.inventory.setItem(slot, null); this.inventory.setItem(slot, null);
return itemEntity; return itemEntity;
} }
@Override @Override
public @Nullable Item dropItem(final @NotNull EquipmentSlot slot, final @Nullable UUID thrower, final boolean throwRandomly) { public @Nullable Item dropItem(final @NotNull EquipmentSlot slot, final boolean throwRandomly) {
final ItemStack stack = this.inventory.getItem(slot); final ItemStack stack = this.inventory.getItem(slot);
final Item itemEntity = dropItemRaw(stack, thrower, throwRandomly); final Item itemEntity = dropItemRaw(stack, throwRandomly);
this.inventory.setItem(slot, null); this.inventory.setItem(slot, null);
return itemEntity; return itemEntity;
} }
private Item dropItemRaw(final ItemStack itemStack, final @Nullable UUID thrower, final boolean throwRandomly) { private Item dropItemRaw(final ItemStack itemStack, final boolean throwRandomly) {
if (itemStack == null || itemStack.isEmpty()) { if (itemStack == null || itemStack.isEmpty()) {
return null; return null;
} }
final ItemEntity droppedEntity = this.getHandle().drop(CraftItemStack.asNMSCopy(itemStack), throwRandomly); final ItemEntity droppedEntity = this.getHandle().drop(CraftItemStack.asNMSCopy(itemStack), throwRandomly, true);
if (droppedEntity == null) { if (droppedEntity == null) {
return null; return null;
} }
droppedEntity.thrower = thrower;
return (Item) droppedEntity.getBukkitEntity(); return (Item) droppedEntity.getBukkitEntity();
} }