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)));
}
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());
}
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);
}
Aggregations