Search in sources :

Example 1 with EmptyInventory

use of org.spongepowered.api.item.inventory.EmptyInventory in project LanternServer by LanternPowered.

the class AbstractEquipable method equip.

@Override
default boolean equip(EquipmentType type, @Nullable ItemStack equipment) {
    checkNotNull(type, "type");
    final Inventory inventory = getInventory().query(Holder.EQUIPMENT_INVENTORY_OPERATION);
    if (inventory instanceof EmptyInventory) {
        return false;
    }
    final AbstractSlot slot = (AbstractSlot) inventory.<IEquipmentInventory>first().getSlot(type).orElse(null);
    if (slot == null) {
        return false;
    }
    final InventoryTransactionResult result = slot.set(equipment);
    return result.getType().equals(InventoryTransactionResult.Type.SUCCESS);
}
Also used : AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) EmptyInventory(org.spongepowered.api.item.inventory.EmptyInventory) Inventory(org.spongepowered.api.item.inventory.Inventory) IEquipmentInventory(org.lanternpowered.server.inventory.IEquipmentInventory) EmptyInventory(org.spongepowered.api.item.inventory.EmptyInventory) InventoryTransactionResult(org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult)

Example 2 with EmptyInventory

use of org.spongepowered.api.item.inventory.EmptyInventory in project LanternServer by LanternPowered.

the class AbstractEquipable method getEquipped.

@Override
default Optional<ItemStack> getEquipped(EquipmentType type) {
    checkNotNull(type, "type");
    final Inventory inventory = getInventory().query(Holder.EQUIPMENT_INVENTORY_OPERATION);
    if (inventory instanceof EmptyInventory) {
        return Optional.empty();
    }
    return inventory.peek();
}
Also used : EmptyInventory(org.spongepowered.api.item.inventory.EmptyInventory) Inventory(org.spongepowered.api.item.inventory.Inventory) IEquipmentInventory(org.lanternpowered.server.inventory.IEquipmentInventory) EmptyInventory(org.spongepowered.api.item.inventory.EmptyInventory)

Example 3 with EmptyInventory

use of org.spongepowered.api.item.inventory.EmptyInventory in project LanternServer by LanternPowered.

the class AbstractEquipable method canEquip.

@Override
default boolean canEquip(EquipmentType type, @Nullable ItemStack equipment) {
    checkNotNull(type, "type");
    final Inventory inventory = getInventory().query(Holder.EQUIPMENT_INVENTORY_OPERATION);
    if (inventory instanceof EmptyInventory) {
        return false;
    }
    final AbstractSlot slot = (AbstractSlot) inventory.<IEquipmentInventory>first().getSlot(type).orElse(null);
    return slot != null && (equipment == null || slot.isValidItem(equipment));
}
Also used : AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) EmptyInventory(org.spongepowered.api.item.inventory.EmptyInventory) Inventory(org.spongepowered.api.item.inventory.Inventory) IEquipmentInventory(org.lanternpowered.server.inventory.IEquipmentInventory) EmptyInventory(org.spongepowered.api.item.inventory.EmptyInventory)

Aggregations

IEquipmentInventory (org.lanternpowered.server.inventory.IEquipmentInventory)3 EmptyInventory (org.spongepowered.api.item.inventory.EmptyInventory)3 Inventory (org.spongepowered.api.item.inventory.Inventory)3 AbstractSlot (org.lanternpowered.server.inventory.AbstractSlot)2 InventoryTransactionResult (org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult)1