Search in sources :

Example 6 with OrderedInventoryLensImpl

use of org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl in project SpongeForge by SpongePowered.

the class MixinInvWrapper method init.

private void init() {
    if (!initalized) {
        initalized = true;
        this.fabric = new IItemHandlerFabric(((InvWrapper) (Object) this));
        this.slots = new SlotCollection.Builder().add(this.fabric.getSize()).build();
        this.lens = new OrderedInventoryLensImpl(0, this.fabric.getSize(), 1, slots);
    }
}
Also used : SlotCollection(org.spongepowered.common.item.inventory.lens.impl.collections.SlotCollection) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) IItemHandlerFabric(org.spongepowered.mod.item.inventory.fabric.IItemHandlerFabric)

Example 7 with OrderedInventoryLensImpl

use of org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl in project SpongeCommon by SpongePowered.

the class MixinEntityVillager method onConstructed.

@Inject(method = "<init>", at = @At("RETURN"))
public void onConstructed(CallbackInfo ci) {
    this.fabric = new IInventoryFabric(this.villagerInventory);
    this.slots = new SlotCollection.Builder().add(8).build();
    this.lens = new OrderedInventoryLensImpl(0, 8, 1, this.slots);
}
Also used : IInventoryFabric(org.spongepowered.common.item.inventory.lens.impl.fabric.IInventoryFabric) SlotCollection(org.spongepowered.common.item.inventory.lens.impl.collections.SlotCollection) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 8 with OrderedInventoryLensImpl

use of org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl 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 9 with OrderedInventoryLensImpl

use of org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl in project SpongeCommon by SpongePowered.

the class MixinTraitAdapter method getReusableLens.

@SuppressWarnings("unchecked")
private ReusableLens<?> getReusableLens() {
    if (this.reusableLens != null) {
        return this.reusableLens;
    }
    if (this instanceof ReusableLensProvider) {
        return ((ReusableLensProvider<IInventory, ItemStack>) this).generateLens(this.getFabric(), this);
    }
    if (this instanceof LensProvider) {
        this.slots = ((LensProvider) this).slotProvider(this.getFabric(), this);
        Lens lens = ((LensProvider) this).rootLens(this.getFabric(), this);
        return new ReusableLens<>(this.slots, lens);
    }
    SlotCollection slots = new SlotCollection.Builder().add(this.getFabric().getSize()).build();
    Lens<IInventory, ItemStack> lens;
    if (this.getFabric().getSize() == 0) {
        lens = new DefaultEmptyLens<>(this);
    } else {
        lens = new OrderedInventoryLensImpl(0, this.getFabric().getSize(), 1, slots);
    }
    return new ReusableLens<>(slots, lens);
}
Also used : IInventory(net.minecraft.inventory.IInventory) SlotCollection(org.spongepowered.common.item.inventory.lens.impl.collections.SlotCollection) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) ReusableLensProvider(org.spongepowered.common.item.inventory.lens.ReusableLensProvider) ReusableLens(org.spongepowered.common.item.inventory.lens.impl.ReusableLens) DefaultEmptyLens(org.spongepowered.common.item.inventory.lens.impl.DefaultEmptyLens) Lens(org.spongepowered.common.item.inventory.lens.Lens) ReusableLens(org.spongepowered.common.item.inventory.lens.impl.ReusableLens) ItemStack(net.minecraft.item.ItemStack) ReusableLensProvider(org.spongepowered.common.item.inventory.lens.ReusableLensProvider) LensProvider(org.spongepowered.common.item.inventory.lens.LensProvider)

Example 10 with OrderedInventoryLensImpl

use of org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl in project SpongeCommon by SpongePowered.

the class BrewingStandInventoryLens method init.

@Override
protected void init(SlotProvider<IInventory, ItemStack> slots) {
    this.potions = new OrderedInventoryLensImpl(0, 3, 1, OutputSlot.class, slots);
    // TODO filter PotionIngredients
    this.ingredient = new InputSlotLensImpl(3, (i) -> true, (i) -> true);
    this.fuel = new FuelSlotLensImpl(4, (i) -> BLAZE_POWDER.equals(i.getType()), BLAZE_POWDER::equals);
    this.addSpanningChild(this.potions);
    this.addSpanningChild(this.ingredient);
    this.addSpanningChild(this.fuel);
}
Also used : ItemStack(net.minecraft.item.ItemStack) InventoryAdapter(org.spongepowered.common.item.inventory.adapter.InventoryAdapter) SlotProvider(org.spongepowered.common.item.inventory.lens.SlotProvider) BLAZE_POWDER(org.spongepowered.api.item.ItemTypes.BLAZE_POWDER) InputSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.InputSlotLensImpl) IInventory(net.minecraft.inventory.IInventory) FuelSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.FuelSlotLensImpl) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) RealLens(org.spongepowered.common.item.inventory.lens.impl.RealLens) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) InputSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.InputSlotLensImpl) FuelSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.FuelSlotLensImpl) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot)

Aggregations

OrderedInventoryLensImpl (org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl)16 SlotCollection (org.spongepowered.common.item.inventory.lens.impl.collections.SlotCollection)9 IInventory (net.minecraft.inventory.IInventory)8 ItemStack (net.minecraft.item.ItemStack)7 SlotProvider (org.spongepowered.common.item.inventory.lens.SlotProvider)4 SlotIndex (org.spongepowered.api.item.inventory.property.SlotIndex)3 Inject (org.spongepowered.asm.mixin.injection.Inject)3 InventoryAdapter (org.spongepowered.common.item.inventory.adapter.InventoryAdapter)3 Lens (org.spongepowered.common.item.inventory.lens.Lens)3 MainPlayerInventoryLensImpl (org.spongepowered.common.item.inventory.lens.impl.comp.MainPlayerInventoryLensImpl)3 IInventoryFabric (org.spongepowered.common.item.inventory.lens.impl.fabric.IInventoryFabric)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Optional (java.util.Optional)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 Fabric (org.spongepowered.common.item.inventory.lens.Fabric)2 LensProvider (org.spongepowered.common.item.inventory.lens.LensProvider)2 DefaultEmptyLens (org.spongepowered.common.item.inventory.lens.impl.DefaultEmptyLens)2 ReusableLens (org.spongepowered.common.item.inventory.lens.impl.ReusableLens)2