use of org.spongepowered.common.inventory.fabric.Fabric in project SpongeCommon by SpongePowered.
the class TraitMixin_ArmorEquipable_Inventory_API method equip.
@Override
public boolean equip(final EquipmentType type, @Nullable final ItemStack equipment) {
final InventoryAdapter inv = ((InventoryBridge) this).bridge$getAdapter();
final EquipmentInventoryLens lens = this.impl$equipmentInventory(inv);
final Fabric fabric = inv.inventoryAdapter$getFabric();
return lens.getSlotLens(type).setStack(fabric, ItemStackUtil.toNative(equipment));
}
use of org.spongepowered.common.inventory.fabric.Fabric in project SpongeCommon by SpongePowered.
the class InventoryMixin_Inventory_API method equipment.
@Override
public EquipmentInventory equipment() {
if (this.api$equipment == null && ((InventoryAdapter) this).inventoryAdapter$getRootLens() instanceof PlayerInventoryLens) {
final Lens lens = ((InventoryAdapter) this).inventoryAdapter$getRootLens();
final Fabric fabric = ((InventoryAdapter) this).inventoryAdapter$getFabric();
this.api$equipment = (EquipmentInventoryAdapter) ((PlayerInventoryLens) lens).getEquipmentLens().getAdapter(fabric, this);
}
return this.api$equipment;
}
use of org.spongepowered.common.inventory.fabric.Fabric in project SpongeCommon by SpongePowered.
the class ServerPlayerMixin_Inventory method impl$getSpongeSlot.
// -- small bridge-like methods
@SuppressWarnings("ConstantConditions")
@Override
protected Slot impl$getSpongeSlot(final EquipmentSlot equipmentSlot) {
final EquipmentType equipmentType = (EquipmentType) (Object) equipmentSlot;
final PlayerInventoryBridge inventory = (PlayerInventoryBridge) ((net.minecraft.server.level.ServerPlayer) (Object) this).inventory;
final Lens lens = ((InventoryAdapter) inventory).inventoryAdapter$getRootLens();
final Fabric fabric = ((InventoryAdapter) inventory).inventoryAdapter$getFabric();
if (lens instanceof PlayerInventoryLens) {
final SlotLens slotLens = ((PlayerInventoryLens) lens).getEquipmentLens().getSlotLens(equipmentType);
return slotLens.getAdapter(fabric, (Inventory) inventory);
}
throw new IllegalStateException("Unknown Lens for Player Inventory: " + lens.getClass().getName());
}
use of org.spongepowered.common.inventory.fabric.Fabric in project SpongeCommon by SpongePowered.
the class InventoryMixin_Inventory_API method offhand.
@Override
public Slot offhand() {
if (this.api$offhand == null && ((InventoryAdapter) this).inventoryAdapter$getRootLens() instanceof PlayerInventoryLens) {
final Lens lens = ((InventoryAdapter) this).inventoryAdapter$getRootLens();
final Fabric fabric = ((InventoryAdapter) this).inventoryAdapter$getFabric();
this.api$offhand = (SlotAdapter) ((PlayerInventoryLens) lens).getOffhandLens().getAdapter(fabric, this);
}
return this.api$offhand;
}
use of org.spongepowered.common.inventory.fabric.Fabric in project SpongeCommon by SpongePowered.
the class ItemStackQuery method matches.
@Override
public boolean matches(Lens lens, Lens parent, Inventory inventory) {
if (lens instanceof SlotLens) {
Fabric fabric = ((InventoryBridge) inventory).bridge$getAdapter().inventoryAdapter$getFabric();
ItemStack stack = ItemStackUtil.fromNative(((SlotLens) lens).getStack(fabric));
if (stack == null) {
return false;
}
return this.matches(stack, this.arg);
}
return false;
}
Aggregations