mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 15:49:00 +01:00
Updated inventories to a has-a relationship.
Added PlayerInventory interface with playeronly methods. Add equals to ItemStack. By: Erik Broes <erikbroes@grum.nl>
This commit is contained in:
parent
f81c44fbba
commit
f95c139dd6
6 changed files with 237 additions and 50 deletions
|
@ -13,10 +13,34 @@ public interface HumanEntity extends LivingEntity {
|
||||||
public String getName();
|
public String getName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the item this entity has currently selected, which will be shown in
|
* Get the player's inventory.
|
||||||
* their hand
|
|
||||||
*
|
*
|
||||||
* @return ItemStack containing details on the item this entity has selected
|
* @return The inventory of the player, this also contains the armor slots.
|
||||||
|
*/
|
||||||
|
public PlayerInventory getInventory();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ItemStack currently in your hand, can be empty.
|
||||||
|
*
|
||||||
|
* @return The ItemStack of the item you are currently holding.
|
||||||
|
*/
|
||||||
|
public ItemStack getItemInHand();
|
||||||
|
|
||||||
|
|
||||||
|
/** TODO: This probably won't work ;(
|
||||||
|
* Sets the item to the given ItemStack, this will replace whatever the
|
||||||
|
* user was holding.
|
||||||
|
*
|
||||||
|
* @param item The ItemStack which will end up in the hand
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
public void setItemInHand( ItemStack item );
|
||||||
|
|
||||||
|
**
|
||||||
|
* Changes the item in hand to another of your 'action slots'.
|
||||||
|
*
|
||||||
|
* @param index The new index to use, only valid ones are 0-8.
|
||||||
|
*
|
||||||
|
public void selectItemInHand( int index );
|
||||||
*/
|
*/
|
||||||
public ItemStack getSelectedItem();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.bukkit;
|
package org.bukkit;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface to the various inventories
|
* Interface to the various inventories
|
||||||
|
@ -20,21 +20,6 @@ public interface Inventory {
|
||||||
*/
|
*/
|
||||||
public String getName();
|
public String getName();
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO Set the name of the inventory
|
|
||||||
*
|
|
||||||
* @param name The new name of the inventory
|
|
||||||
public void setName(String name);
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** TODO: Appears minecraft has different ideas for slots!
|
|
||||||
* Get the slot at a specific index of an inventory
|
|
||||||
*
|
|
||||||
* @param index The index of the slot to get
|
|
||||||
* @return The Slot found at the index
|
|
||||||
public Slot getSlot(int index);
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the ItemStack found in the slot at the given index
|
* Get the ItemStack found in the slot at the given index
|
||||||
*
|
*
|
||||||
|
@ -43,23 +28,108 @@ public interface Inventory {
|
||||||
*/
|
*/
|
||||||
public ItemStack getItem(int index);
|
public ItemStack getItem(int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the ItemStack at the given index
|
||||||
|
*
|
||||||
|
* @param index The index where to put the ItemStack
|
||||||
|
* @param item The ItemStack to set
|
||||||
|
*/
|
||||||
|
public void setItem(int index, ItemStack item);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the given ItemStacks in the inventory
|
||||||
|
*
|
||||||
|
* @param items The ItemStacks to add
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public HashMap<Integer, ItemStack> addItem(ItemStack... items);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all ItemStacks from the inventory
|
* Get all ItemStacks from the inventory
|
||||||
*
|
*
|
||||||
* @return All the ItemStacks from all slots
|
* @return All the ItemStacks from all slots
|
||||||
*/
|
*/
|
||||||
public Collection<ItemStack> getContents();
|
public ItemStack[] getContents();
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* TODO public boolean contains(int materialId); public boolean
|
* Check if the inventory contains any ItemStacks with the given materialId
|
||||||
* contains(Material material); public boolean contains(ItemStack item);
|
|
||||||
*
|
*
|
||||||
* public Collection<Slot> all(int materialId); public Collection<Slot>
|
* @param materialId The materialId to check for
|
||||||
* all(Material material); public Collection<Slot> all(ItemStack item);
|
* @return If any ItemStacks were found
|
||||||
*
|
|
||||||
* public Slot first(int materialId); public Slot first(Material material);
|
|
||||||
* public Slot first(ItemStack item);
|
|
||||||
*
|
|
||||||
* public int firstEmptyIndex();
|
|
||||||
*/
|
*/
|
||||||
|
public boolean contains(int materialId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the inventory contains any ItemStacks with the given material
|
||||||
|
*
|
||||||
|
* @param material The material to check for
|
||||||
|
* @return If any ItemStacks were found
|
||||||
|
*/
|
||||||
|
public boolean contains(Material material);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the inventory contains any ItemStacks matching the given ItemStack
|
||||||
|
* This will only match if both the type and the amount of the stack match
|
||||||
|
*
|
||||||
|
* @param item The ItemStack to match against
|
||||||
|
* @return If any matching ItemStacks were found
|
||||||
|
*/
|
||||||
|
public boolean contains(ItemStack item);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find all slots in the inventory containing any ItemStacks with the given materialId
|
||||||
|
*
|
||||||
|
* @param materialId The materialId to look for
|
||||||
|
* @return The Slots found.
|
||||||
|
*/
|
||||||
|
public HashMap<Integer,ItemStack> all(int materialId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find all slots in the inventory containing any ItemStacks with the given material
|
||||||
|
*
|
||||||
|
* @param materialId The material to look for
|
||||||
|
* @return The Slots found.
|
||||||
|
*/
|
||||||
|
public HashMap<Integer,ItemStack> all(Material material);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find all slots in the inventory containing any ItemStacks with the given ItemStack
|
||||||
|
* This will only match slots if both the type and the amount of the stack match
|
||||||
|
*
|
||||||
|
* @param item The ItemStack to match against
|
||||||
|
* @return The Slots found.
|
||||||
|
*/
|
||||||
|
public HashMap<Integer,ItemStack> all(ItemStack item);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the first slot in the inventory containing an ItemStack with the given materialId
|
||||||
|
*
|
||||||
|
* @param materialId The materialId to look for
|
||||||
|
* @return The Slot found.
|
||||||
|
*/
|
||||||
|
public int first(int materialId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the first slot in the inventory containing an ItemStack with the given material
|
||||||
|
*
|
||||||
|
* @param materialId The material to look for
|
||||||
|
* @return The Slot found.
|
||||||
|
*/
|
||||||
|
public int first(Material material);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the first slot in the inventory containing an ItemStack with the given stack
|
||||||
|
* This will only match a slot if both the type and the amount of the stack match
|
||||||
|
*
|
||||||
|
* @param item The ItemStack to match against
|
||||||
|
* @return The Slot found.
|
||||||
|
*/
|
||||||
|
public int first(ItemStack item);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the first empty Slot.
|
||||||
|
*
|
||||||
|
* @return The first empty Slot found.
|
||||||
|
*/
|
||||||
|
public int firstEmpty();
|
||||||
}
|
}
|
|
@ -115,4 +115,23 @@ public class ItemStack {
|
||||||
public byte getDamage() {
|
public byte getDamage() {
|
||||||
return damage;
|
return damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the maximum stacksize for the material hold in this ItemStack
|
||||||
|
* Returns -1 if it has no idea.
|
||||||
|
*
|
||||||
|
* @return The maximum you can stack this material to.
|
||||||
|
*/
|
||||||
|
public int getMaxStackSize() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object object) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(ItemStack item) {
|
||||||
|
return item.getAmount() == getAmount() && item.getTypeID() == getTypeID();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
82
paper-api/src/main/java/org/bukkit/PlayerInventory.java
Normal file
82
paper-api/src/main/java/org/bukkit/PlayerInventory.java
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
package org.bukkit;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Includes interface to the 4 armor slots
|
||||||
|
*/
|
||||||
|
public interface PlayerInventory extends Inventory {
|
||||||
|
/**
|
||||||
|
* Get all ItemStacks from the armor slots
|
||||||
|
*
|
||||||
|
* @return All the ItemStacks from the armor slots
|
||||||
|
*/
|
||||||
|
public ArrayList<ItemStack> getArmorContents();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the ItemStack from the helmet slot
|
||||||
|
*
|
||||||
|
* @return The ItemStack in the helmet slot
|
||||||
|
*/
|
||||||
|
public ItemStack getHelmet();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the ItemStack from the chestplate slot
|
||||||
|
*
|
||||||
|
* @return The ItemStack in the chestplate slot
|
||||||
|
*/
|
||||||
|
public ItemStack getChestplate();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the ItemStack from the leg slot
|
||||||
|
*
|
||||||
|
* @return The ItemStack in the leg slot
|
||||||
|
*/
|
||||||
|
public ItemStack getLeggings();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the ItemStack from the boots slot
|
||||||
|
*
|
||||||
|
* @return The ItemStack in the boots slot
|
||||||
|
*/
|
||||||
|
public ItemStack getBoots();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put the given ItemStack into the helmet slot
|
||||||
|
* This does not check if the ItemStack is a helmet
|
||||||
|
*
|
||||||
|
* @param helmet The ItemStack to use as helmet
|
||||||
|
*/
|
||||||
|
public void setHelmet(ItemStack helmet);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put the given ItemStack into the chestplate slot
|
||||||
|
* This does not check if the ItemStack is a chestplate
|
||||||
|
*
|
||||||
|
* @param chestplate The ItemStack to use as chestplate
|
||||||
|
*/
|
||||||
|
public void setChestplate(ItemStack chestplate);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put the given ItemStack into the leg slot
|
||||||
|
* This does not check if the ItemStack is a pair of leggings
|
||||||
|
*
|
||||||
|
* @param leggings The ItemStack to use as leggings
|
||||||
|
*/
|
||||||
|
public void setLeggings(ItemStack leggings);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put the given ItemStack into the boots slot
|
||||||
|
* This does not check if the ItemStack is a boots
|
||||||
|
*
|
||||||
|
* @param boots The ItemStack to use as boots
|
||||||
|
*/
|
||||||
|
public void setBoots(ItemStack boots);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ItemStack currently hold
|
||||||
|
*
|
||||||
|
* @return The currently holded ItemStack
|
||||||
|
*/
|
||||||
|
public ItemStack getItemInHand();
|
||||||
|
}
|
|
@ -3,39 +3,25 @@ package org.bukkit;
|
||||||
/**
|
/**
|
||||||
* Represents a slot in an inventory
|
* Represents a slot in an inventory
|
||||||
*/
|
*/
|
||||||
public class Slot {
|
public interface Slot {
|
||||||
private Inventory inventory;
|
|
||||||
private int index;
|
|
||||||
|
|
||||||
public Slot(Inventory inventory, int index) {
|
|
||||||
this.inventory = inventory;
|
|
||||||
this.index = index;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the inventory this slot belongs to
|
* Gets the inventory this slot belongs to
|
||||||
*
|
*
|
||||||
* @return The inventory
|
* @return The inventory
|
||||||
*/
|
*/
|
||||||
public Inventory getInventory() {
|
public Inventory getInventory();
|
||||||
return inventory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the index this slot belongs to
|
* Get the index this slot belongs to
|
||||||
*
|
*
|
||||||
* @return Index of the slot
|
* @return Index of the slot
|
||||||
*/
|
*/
|
||||||
public int getIndex() {
|
public int getIndex();
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the item from the slot.
|
* Get the item from the slot.
|
||||||
*
|
*
|
||||||
* @return ItemStack in the slot.
|
* @return ItemStack in the slot.
|
||||||
*/
|
*/
|
||||||
public ItemStack getItem() {
|
public ItemStack getItem();
|
||||||
return inventory.getItem(index);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,5 +5,11 @@ package org.bukkit;
|
||||||
*
|
*
|
||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public interface StorageMinecart extends Minecart, Inventory {
|
public interface StorageMinecart extends Minecart {
|
||||||
|
/**
|
||||||
|
* Return the inventory object for this StorageMinecart.
|
||||||
|
*
|
||||||
|
* @return The inventory for this Minecart
|
||||||
|
*/
|
||||||
|
public Inventory getInventory();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue