use of org.spongepowered.common.inventory.lens.Lens 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.inventory.lens.Lens in project SpongeCommon by SpongePowered.
the class InventoryMixin_Inventory_API method armor.
@Override
public EquipmentInventory armor() {
if (this.api$armor == null && ((InventoryAdapter) this).inventoryAdapter$getRootLens() instanceof PlayerInventoryLens) {
final Lens lens = ((InventoryAdapter) this).inventoryAdapter$getRootLens();
final Fabric fabric = ((InventoryAdapter) this).inventoryAdapter$getFabric();
this.api$armor = (EquipmentInventoryAdapter) ((PlayerInventoryLens) lens).getArmorLens().getAdapter(fabric, this);
}
return this.api$armor;
}
use of org.spongepowered.common.inventory.lens.Lens in project SpongeCommon by SpongePowered.
the class InventoryMixin_Inventory_API method primary.
@Override
public PrimaryPlayerInventory primary() {
if (this.api$primary == null && ((InventoryAdapter) this).inventoryAdapter$getRootLens() instanceof PlayerInventoryLens) {
final Lens lens = ((InventoryAdapter) this).inventoryAdapter$getRootLens();
final Fabric fabric = ((InventoryAdapter) this).inventoryAdapter$getFabric();
this.api$primary = (PrimaryPlayerInventoryAdapter) ((PlayerInventoryLens) lens).getPrimaryInventoryLens().getAdapter(fabric, this);
}
return this.api$primary;
}
use of org.spongepowered.common.inventory.lens.Lens in project SpongeCommon by SpongePowered.
the class LensRegistrar method lensRepairContainer.
@SuppressWarnings("unchecked")
private static Lens lensRepairContainer(Object inventory, int size, SlotLensProvider slotLensProvider) {
final List<Lens> lenses = new ArrayList<>();
lenses.add(new DefaultIndexedLens(0, 3, slotLensProvider));
lenses.add(new PrimaryPlayerInventoryLens(3, slotLensProvider, true));
return new ContainerLens(size, (Class<? extends Inventory>) inventory.getClass(), slotLensProvider, lenses);
}
use of org.spongepowered.common.inventory.lens.Lens in project SpongeCommon by SpongePowered.
the class LensRegistrar method generateLens.
@SuppressWarnings("unchecked")
private static Lens generateLens(Object inventory, int size, SlotLensProvider slotLensProvider) {
if (size == 0) {
return new DefaultEmptyLens();
}
LensFactory lensFactory = LensRegistrar.lensFactories.get(inventory.getClass());
Lens lens = null;
if (lensFactory != null) {
lens = lensFactory.apply(inventory.getClass(), size, slotLensProvider);
if (lens != null) {
return lens;
}
}
if (inventory instanceof CraftingContainer) {
lens = LensRegistrar.lensCraftingInventory(size, ((CraftingContainer) inventory).getWidth(), ((CraftingContainer) inventory).getHeight(), slotLensProvider);
} else if (inventory instanceof AbstractContainerMenu) {
lens = ContainerUtil.generateLens(((AbstractContainerMenu) inventory), slotLensProvider);
} else if (size == 1) {
return slotLensProvider.getSlotLens(0);
}
if (lens != null) {
return lens;
}
return new SingleIndexedLens(0, size, (Class<? extends Inventory>) inventory.getClass(), slotLensProvider);
}
Aggregations