use of org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens in project SpongeCommon by SpongePowered.
the class ContainerUtil method generateAdapterLens.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static Lens generateAdapterLens(final SlotLensProvider slots, final int index, final org.spongepowered.common.inventory.util.ContainerUtil.CraftingInventoryData crafting, final List<Slot> slotList, final net.minecraft.world.@Nullable Container subInventory) {
Lens lens = ((InventoryBridge) subInventory).bridge$getAdapter().inventoryAdapter$getRootLens();
if (lens instanceof PlayerInventoryLens) {
if (slotList.size() == 36) {
return new DelegatingLens(index, new PrimaryPlayerInventoryLens(0, slots, true), slots);
}
return lens;
}
// For Crafting Result we need the Slot to get Filter logic
if (subInventory instanceof ResultContainer) {
final Slot slot = slotList.get(0);
if (slot instanceof ResultSlotAccessor) {
crafting.out = index;
if (crafting.base == null) {
// In case we do not find the InventoryCrafting later assume it is directly after the SlotCrafting
// e.g. for IC2 ContainerIndustrialWorkbench
crafting.base = index + 1;
crafting.grid = ((ResultSlotAccessor) slot).accessor$craftSlots();
}
}
}
if (subInventory instanceof CraftingContainer) {
crafting.base = index;
crafting.grid = ((CraftingContainer) subInventory);
}
return new DelegatingLens(index, slotList, lens, slots);
}
use of org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens 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.lens.impl.minecraft.PlayerInventoryLens 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.lens.impl.minecraft.PlayerInventoryLens 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.lens.impl.minecraft.PlayerInventoryLens in project SpongeCommon by SpongePowered.
the class ContainerPlayerInventoryLens method lenses.
private static List<Lens> lenses(int size, SlotLensProvider slots) {
// 1
int base = ContainerPlayerInventoryLens.CRAFTING_OUTPUT;
final CraftingInventoryLens crafting = new CraftingInventoryLens(0, base, ContainerPlayerInventoryLens.CRAFTING_GRID, ContainerPlayerInventoryLens.CRAFTING_GRID, slots);
// 4
base += ContainerPlayerInventoryLens.CRAFTING_GRID * ContainerPlayerInventoryLens.CRAFTING_GRID;
final PlayerInventoryLens player = new PlayerInventoryLens(base, size - base, slots);
return Arrays.asList(crafting, player);
}
Aggregations