Search in sources :

Example 6 with InventoryBridge

use of org.spongepowered.common.bridge.world.inventory.InventoryBridge in project SpongeCommon by SpongePowered.

the class TraitMixin_ArmorEquipable_Inventory_API method equipped.

@Override
public Optional<ItemStack> equipped(final EquipmentType type) {
    final InventoryAdapter inv = ((InventoryBridge) this).bridge$getAdapter();
    final EquipmentInventoryLens lens = this.impl$equipmentInventory(inv);
    final Fabric fabric = inv.inventoryAdapter$getFabric();
    return Optional.of(ItemStackUtil.fromNative(lens.getSlotLens(type).getStack(fabric)));
}
Also used : InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) InventoryBridge(org.spongepowered.common.bridge.world.inventory.InventoryBridge) Fabric(org.spongepowered.common.inventory.fabric.Fabric) EquipmentInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens)

Example 7 with InventoryBridge

use of org.spongepowered.common.bridge.world.inventory.InventoryBridge in project SpongeCommon by SpongePowered.

the class LivingEntityMixin_Inventory method impl$getSpongeSlot.

@SuppressWarnings("ConstantConditions")
protected Slot impl$getSpongeSlot(final EquipmentSlot equipmentSlot) {
    final EquipmentType equipmentType = (EquipmentType) (Object) equipmentSlot;
    if (this instanceof InventoryBridge) {
        final InventoryAdapter adapter = ((InventoryBridge) this).bridge$getAdapter();
        final Lens lens = adapter.inventoryAdapter$getRootLens();
        if (lens instanceof EquipmentInventoryLens) {
            final SlotLens slotLens = ((EquipmentInventoryLens) lens).getSlotLens(equipmentType);
            return slotLens.getAdapter(adapter.inventoryAdapter$getFabric(), (Inventory) adapter);
        }
        throw new IllegalStateException("Expected EquipmentInventoryLens for " + this.getClass().getName() + " Inventory but found: " + lens.getClass().getName());
    }
    throw new IllegalStateException("Living Entity has no InventoryAdapter: " + this.getClass().getName());
}
Also used : InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) InventoryBridge(org.spongepowered.common.bridge.world.inventory.InventoryBridge) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens) Lens(org.spongepowered.common.inventory.lens.Lens) EquipmentInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens) EquipmentType(org.spongepowered.api.item.inventory.equipment.EquipmentType) EquipmentInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens)

Example 8 with InventoryBridge

use of org.spongepowered.common.bridge.world.inventory.InventoryBridge in project SpongeCommon by SpongePowered.

the class ReverseQuery method execute.

@Override
public Inventory execute(Inventory parent, InventoryAdapter inventory) {
    List<Slot> slots = new ArrayList<>(((Inventory) inventory).slots());
    Collections.reverse(slots);
    CompoundSlotLensProvider slotProvider = new CompoundSlotLensProvider();
    slots.forEach(s -> slotProvider.add((InventoryAdapter) s));
    InventoryAdapter adapter = ((InventoryBridge) inventory).bridge$getAdapter();
    CompoundLens lens = CompoundLens.builder().add(adapter.inventoryAdapter$getRootLens()).build(slotProvider);
    return lens.getAdapter(adapter.inventoryAdapter$getFabric(), (Inventory) inventory);
}
Also used : InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) InventoryBridge(org.spongepowered.common.bridge.world.inventory.InventoryBridge) ArrayList(java.util.ArrayList) Slot(org.spongepowered.api.item.inventory.Slot) CompoundSlotLensProvider(org.spongepowered.common.inventory.lens.CompoundSlotLensProvider) CompoundLens(org.spongepowered.common.inventory.lens.impl.CompoundLens)

Aggregations

InventoryBridge (org.spongepowered.common.bridge.world.inventory.InventoryBridge)8 InventoryAdapter (org.spongepowered.common.inventory.adapter.InventoryAdapter)5 EquipmentInventoryLens (org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens)4 CompoundSlotLensProvider (org.spongepowered.common.inventory.lens.CompoundSlotLensProvider)3 CompoundLens (org.spongepowered.common.inventory.lens.impl.CompoundLens)3 ArrayList (java.util.ArrayList)2 Slot (net.minecraft.world.inventory.Slot)2 Inventory (org.spongepowered.api.item.inventory.Inventory)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Random (java.util.Random)1 Collectors (java.util.stream.Collectors)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 CompoundContainer (net.minecraft.world.CompoundContainer)1 Containers (net.minecraft.world.Containers)1 ItemEntity (net.minecraft.world.entity.item.ItemEntity)1