Search in sources :

Example 1 with EquipmentSlotLensImpl

use of org.spongepowered.common.item.inventory.lens.impl.slots.EquipmentSlotLensImpl in project SpongeCommon by SpongePowered.

the class MixinInventoryPlayer method onConstructed.

@Inject(method = "<init>*", at = @At("RETURN"), remap = false)
private void onConstructed(EntityPlayer playerIn, CallbackInfo ci) {
    // Find offhand slot
    for (NonNullList<ItemStack> inventory : this.allInventories) {
        if (inventory == this.offHandInventory) {
            break;
        }
        this.offhandIndex += inventory.size();
    }
    // Set Carrier if we got a real Player
    if (playerIn instanceof EntityPlayerMP) {
        this.carrier = (Player) playerIn;
        this.inventory = new IInventoryFabric((IInventory) this);
        Class clazz = this.getClass();
        if (clazz == InventoryPlayer.class) {
            // Build Player Lens
            // We only care about Server inventories
            this.slots = new SlotCollection.Builder().add(this.mainInventory.size()).add(this.offHandInventory.size()).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.BOOTS)).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.LEGGINGS)).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.CHESTPLATE)).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.HEADWEAR)).add(this.armorInventory.size() - 4, EquipmentSlotAdapter.class).add(this.getSizeInventory() - this.mainInventory.size() - this.offHandInventory.size() - this.armorInventory.size()).build();
            this.lens = new PlayerInventoryLens(this, this.slots);
        } else if (this.getSizeInventory() != 0) {
            // Fallback OrderedLens when not 0 sized inventory
            this.slots = new SlotCollection.Builder().add(this.getSizeInventory()).build();
            this.lens = new OrderedInventoryLensImpl(0, this.getSizeInventory(), 1, slots);
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) Inventory(org.spongepowered.api.item.inventory.Inventory) PlayerInventory(org.spongepowered.api.item.inventory.entity.PlayerInventory) InventoryEventArgs(org.spongepowered.common.item.inventory.observer.InventoryEventArgs) Inject(org.spongepowered.asm.mixin.injection.Inject) EnumHand(net.minecraft.util.EnumHand) EquipmentInventory(org.spongepowered.api.item.inventory.equipment.EquipmentInventory) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) Overwrite(org.spongepowered.asm.mixin.Overwrite) MainPlayerInventoryAdapter(org.spongepowered.common.item.inventory.adapter.impl.comp.MainPlayerInventoryAdapter) ItemStackUtil(org.spongepowered.common.item.inventory.util.ItemStackUtil) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) IMixinInventoryPlayer(org.spongepowered.common.interfaces.entity.player.IMixinInventoryPlayer) Mixin(org.spongepowered.asm.mixin.Mixin) NonNullList(net.minecraft.util.NonNullList) At(org.spongepowered.asm.mixin.injection.At) Fabric(org.spongepowered.common.item.inventory.lens.Fabric) SlotProvider(org.spongepowered.common.item.inventory.lens.SlotProvider) IInventoryFabric(org.spongepowered.common.item.inventory.lens.impl.fabric.IInventoryFabric) Redirect(org.spongepowered.asm.mixin.injection.Redirect) EquipmentInventoryAdapter(org.spongepowered.common.item.inventory.adapter.impl.comp.EquipmentInventoryAdapter) EquipmentSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.EquipmentSlotLensImpl) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) Slot(org.spongepowered.api.item.inventory.Slot) Final(org.spongepowered.asm.mixin.Final) EquipmentSlotAdapter(org.spongepowered.common.item.inventory.adapter.impl.slots.EquipmentSlotAdapter) HotbarAdapter(org.spongepowered.common.item.inventory.adapter.impl.comp.HotbarAdapter) List(java.util.List) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IInventory(net.minecraft.inventory.IInventory) Lens(org.spongepowered.common.item.inventory.lens.Lens) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) Shadow(org.spongepowered.asm.mixin.Shadow) Optional(java.util.Optional) SlotCollection(org.spongepowered.common.item.inventory.lens.impl.collections.SlotCollection) Player(org.spongepowered.api.entity.living.player.Player) EquipmentTypes(org.spongepowered.api.item.inventory.equipment.EquipmentTypes) SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex) SlotAdapter(org.spongepowered.common.item.inventory.adapter.impl.slots.SlotAdapter) PlayerInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.PlayerInventoryLens) SPacketHeldItemChange(net.minecraft.network.play.server.SPacketHeldItemChange) MainPlayerInventory(org.spongepowered.api.item.inventory.entity.MainPlayerInventory) IInventoryFabric(org.spongepowered.common.item.inventory.lens.impl.fabric.IInventoryFabric) EquipmentSlotAdapter(org.spongepowered.common.item.inventory.adapter.impl.slots.EquipmentSlotAdapter) PlayerInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.PlayerInventoryLens) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) EquipmentSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.EquipmentSlotLensImpl) ItemStack(net.minecraft.item.ItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with EquipmentSlotLensImpl

use of org.spongepowered.common.item.inventory.lens.impl.slots.EquipmentSlotLensImpl in project SpongeCommon by SpongePowered.

the class MixinContainerPlayer method slotProvider.

@Override
public SlotProvider<IInventory, ItemStack> slotProvider(Fabric<IInventory> fabric, InventoryAdapter<IInventory, ItemStack> adapter) {
    SlotCollection.Builder builder = new SlotCollection.Builder().add(1, CraftingOutputAdapter.class, (i) -> new CraftingOutputSlotLensImpl(i, (t) -> false, (t) -> false)).add(4).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.HEADWEAR)).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.CHESTPLATE)).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.LEGGINGS)).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.BOOTS)).add(36).add(1);
    // Add additional slots (e.g. from mods)
    builder.add(this.inventorySlots.size() - 46);
    return builder.build();
}
Also used : Fabric(org.spongepowered.common.item.inventory.lens.Fabric) CraftingOutputSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.CraftingOutputSlotLensImpl) InventoryAdapter(org.spongepowered.common.item.inventory.adapter.InventoryAdapter) SlotProvider(org.spongepowered.common.item.inventory.lens.SlotProvider) ContainerPlayerInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.container.ContainerPlayerInventoryLens) EquipmentSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.EquipmentSlotLensImpl) EquipmentSlotAdapter(org.spongepowered.common.item.inventory.adapter.impl.slots.EquipmentSlotAdapter) ItemStack(net.minecraft.item.ItemStack) ContainerPlayer(net.minecraft.inventory.ContainerPlayer) Mixin(org.spongepowered.asm.mixin.Mixin) CraftingOutputAdapter(org.spongepowered.common.item.inventory.adapter.impl.slots.CraftingOutputAdapter) IInventory(net.minecraft.inventory.IInventory) Lens(org.spongepowered.common.item.inventory.lens.Lens) SlotCollection(org.spongepowered.common.item.inventory.lens.impl.collections.SlotCollection) EquipmentTypes(org.spongepowered.api.item.inventory.equipment.EquipmentTypes) LensProvider(org.spongepowered.common.item.inventory.lens.LensProvider) SlotCollection(org.spongepowered.common.item.inventory.lens.impl.collections.SlotCollection) CraftingOutputSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.CraftingOutputSlotLensImpl) EquipmentSlotAdapter(org.spongepowered.common.item.inventory.adapter.impl.slots.EquipmentSlotAdapter) CraftingOutputAdapter(org.spongepowered.common.item.inventory.adapter.impl.slots.CraftingOutputAdapter) EquipmentSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.EquipmentSlotLensImpl)

Aggregations

IInventory (net.minecraft.inventory.IInventory)2 ItemStack (net.minecraft.item.ItemStack)2 EquipmentTypes (org.spongepowered.api.item.inventory.equipment.EquipmentTypes)2 Mixin (org.spongepowered.asm.mixin.Mixin)2 EquipmentSlotAdapter (org.spongepowered.common.item.inventory.adapter.impl.slots.EquipmentSlotAdapter)2 Fabric (org.spongepowered.common.item.inventory.lens.Fabric)2 Lens (org.spongepowered.common.item.inventory.lens.Lens)2 SlotProvider (org.spongepowered.common.item.inventory.lens.SlotProvider)2 SlotCollection (org.spongepowered.common.item.inventory.lens.impl.collections.SlotCollection)2 EquipmentSlotLensImpl (org.spongepowered.common.item.inventory.lens.impl.slots.EquipmentSlotLensImpl)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)1 ContainerPlayer (net.minecraft.inventory.ContainerPlayer)1 SPacketHeldItemChange (net.minecraft.network.play.server.SPacketHeldItemChange)1 EnumHand (net.minecraft.util.EnumHand)1 NonNullList (net.minecraft.util.NonNullList)1