mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 06:50:12 +01:00
Remove thrower and 'empty' overloads
This commit is contained in:
parent
63a52404b0
commit
2d9e357a45
2 changed files with 12 additions and 47 deletions
|
@ -708,76 +708,42 @@ public interface HumanEntity extends LivingEntity, AnimalTamer, InventoryHolder
|
|||
*/
|
||||
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.
|
||||
* <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
|
||||
*
|
||||
* @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.
|
||||
* 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.
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
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
|
||||
* @param thrower The {@link UUID} to set the resulting {@link Item}'s thrower to
|
||||
* @param throwRandomly Whether the item should disperse randomly.
|
||||
* 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.
|
||||
* @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
|
||||
*/
|
||||
public @Nullable Item dropItem(final int slot, final @Nullable UUID thrower, 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);
|
||||
}
|
||||
public @Nullable Item dropItem(final int slot, final boolean throwRandomly);
|
||||
|
||||
/**
|
||||
* Makes the player drop an item from their inventory based on the equipment slot.
|
||||
*
|
||||
* @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.
|
||||
* 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.
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -807,49 +807,48 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
|||
}
|
||||
|
||||
@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);
|
||||
if (slot == -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.dropItem(slot, thrower, throwRandomly);
|
||||
return this.dropItem(slot, throwRandomly);
|
||||
}
|
||||
|
||||
@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
|
||||
if (slot < 0 || slot >= 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 Item itemEntity = dropItemRaw(stack, thrower, throwRandomly);
|
||||
final Item itemEntity = dropItemRaw(stack, throwRandomly);
|
||||
|
||||
this.inventory.setItem(slot, null);
|
||||
return itemEntity;
|
||||
}
|
||||
|
||||
@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 Item itemEntity = dropItemRaw(stack, thrower, throwRandomly);
|
||||
final Item itemEntity = dropItemRaw(stack, throwRandomly);
|
||||
|
||||
this.inventory.setItem(slot, null);
|
||||
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()) {
|
||||
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) {
|
||||
return null;
|
||||
}
|
||||
|
||||
droppedEntity.thrower = thrower;
|
||||
return (Item) droppedEntity.getBukkitEntity();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue