All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.nukkit.inventory.Inventory Maven / Gradle / Ivy

There is a newer version: 1.20.40-r1
Show newest version
package cn.nukkit.inventory;

import cn.nukkit.Player;
import cn.nukkit.api.DoNotModify;
import cn.nukkit.api.PowerNukkitOnly;
import cn.nukkit.api.PowerNukkitXOnly;
import cn.nukkit.api.Since;
import cn.nukkit.item.Item;
import cn.nukkit.network.protocol.InventorySlotPacket;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

/**
 * @author MagicDroidX (Nukkit Project)
 */
public interface Inventory {

    int MAX_STACK = 64;

    /**
     * 获取该库存大小
     */
    int getSize();

    /**
     * 获取最大库存大小
     */
    int getMaxStackSize();

    /**
     * 设置最大库存大小
     */
    void setMaxStackSize(int size);

    /**
     * 获取该库存的名字
     */
    String getName();

    /**
     * 获取该库存的标题
     */
    String getTitle();

    /**
     * 获取该库存指定索引处的物品
     *
     * @param index the index
     * @return the item
     */
    @NotNull
    Item getItem(int index);

    /**
     * 获取该库存指定索引处的未克隆的物品

* 若调用方保证不会修改此方法返回的Item对象,则使用此方法将降低特定场景下Item::clone()造成的性能开销 * * @param index the index * @return the item */ @PowerNukkitXOnly @Since("1.19.60-r1") @DoNotModify default Item getUnclonedItem(int index) { //你需要覆写它来实现 return getItem(index); } /** * 设置该库存指定索引处的物品 * * @param index the index * @param item the item * @return the item */ default boolean setItem(int index, Item item) { return setItem(index, item, true); } /** * 设置该库存指定索引处的物品 * * @param index the index * @param item the item * @param send 是否同时发送数据包 * @return the item */ boolean setItem(int index, Item item, boolean send); /** * Now it is only called by {@link cn.nukkit.inventory.transaction.action.SlotChangeAction} and {@link cn.nukkit.inventory.transaction.EnchantTransaction} * * @param player player that will receive the changes * @param index index of the item * @param item item to set * @return true if the item was set */ @Since("1.19.50-r3") @PowerNukkitXOnly default boolean setItemByPlayer(Player player, int index, Item item, boolean send) { return setItem(index, item, send); } Item[] addItem(Item... slots); boolean canAddItem(Item item); Item[] removeItem(Item... slots); Map getContents(); void setContents(Map items); void sendContents(Player player); void sendContents(Player... players); void sendContents(Collection players); void sendSlot(int index, Player player); void sendSlot(int index, Player... players); void sendSlot(int index, Collection players); boolean contains(Item item); Map all(Item item); default int first(Item item) { return first(item, false); } int first(Item item, boolean exact); int firstEmpty(Item item); void decreaseCount(int slot); void remove(Item item); default boolean clear(int index) { return clear(index, true); } boolean clear(int index, boolean send); void clearAll(); boolean isFull(); boolean isEmpty(); Set getViewers(); InventoryType getType(); InventoryHolder getHolder(); void onOpen(Player who); boolean open(Player who); void close(Player who); void onClose(Player who); /** * 当执行{@link #setItem(int, Item)}时该方法会被调用,此时物品已经put进slots *

* This method is called when {@link #setItem(int, Item)} is executed, and the item has been put into slots * * @param index 物品变动的格子索引
The grid index of the item's changes * @param before 变动前的物品
Items before the change * @param send 是否发送{@link InventorySlotPacket}到客户端
Whether to send {@link InventorySlotPacket} to the client */ void onSlotChange(int index, Item before, boolean send); @PowerNukkitOnly void addListener(InventoryListener listener); @PowerNukkitOnly void removeListener(InventoryListener listener); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy