mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 15:30:19 +01:00
Directly run logic on nms ItemStack
This commit is contained in:
parent
3fdd032529
commit
1cd52a97e7
2 changed files with 7 additions and 12 deletions
|
@ -716,7 +716,7 @@ public interface HumanEntity extends LivingEntity, AnimalTamer, InventoryHolder
|
||||||
* @param slot The slot to drop
|
* @param slot The slot to drop
|
||||||
* @param amount The number of items to drop from this slot. Values below 1 don't drop an Item
|
* @param amount The number of items to drop from this slot. Values below 1 don't drop an Item
|
||||||
* @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 IllegalArgumentException If the slot is negative or bigger than the player's inventory
|
||||||
*/
|
*/
|
||||||
public @Nullable Item dropItem(int slot, int amount);
|
public @Nullable Item dropItem(int slot, int amount);
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
@ -808,9 +807,8 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable Item dropItem(final int slot, final int amount) {
|
public @Nullable Item dropItem(final int slot, final int amount) {
|
||||||
// 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 IllegalArgumentException("Slot " + slot + " is not a valid inventory slot.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return dropItemRaw(this.inventory.getItem(slot), amount, false);
|
return dropItemRaw(this.inventory.getItem(slot), amount, false);
|
||||||
|
@ -823,9 +821,8 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable Item dropItemRandomly(final int slot, final int amount) {
|
public @Nullable Item dropItemRandomly(final int slot, final int amount) {
|
||||||
// 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 IllegalArgumentException("Slot " + slot + " is not a valid inventory slot.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return dropItemRaw(this.inventory.getItem(slot), amount, true);
|
return dropItemRaw(this.inventory.getItem(slot), amount, true);
|
||||||
|
@ -841,17 +838,15 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ItemStack clonedItemStack = originalItemStack.clone();
|
final net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.unwrap(originalItemStack);
|
||||||
final int droppedAmount = Math.min(clonedItemStack.getAmount(), amount);
|
final net.minecraft.world.item.ItemStack dropContent = nmsItemStack.split(Math.min(originalItemStack.getAmount(), amount));
|
||||||
clonedItemStack.setAmount(droppedAmount);
|
|
||||||
|
|
||||||
final ItemEntity droppedEntity = this.getHandle().drop(CraftItemStack.asNMSCopy(clonedItemStack), throwRandomly, true);
|
final ItemEntity droppedEntity = this.getHandle().drop(dropContent, throwRandomly, true);
|
||||||
if (droppedEntity == null) {
|
if (droppedEntity == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
originalItemStack.setAmount(originalItemStack.getAmount() - droppedAmount);
|
return (Item) droppedEntity.getBukkitEntity();
|
||||||
return new CraftItem(this.server, droppedEntity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue