Search in sources :

Example 1 with SlotCrafting

use of net.minecraft.inventory.SlotCrafting in project SpongeCommon by SpongePowered.

the class ContainerUtil method generateAdapterLens.

@Nullable
private static Lens<IInventory, ItemStack> generateAdapterLens(SlotProvider<IInventory, ItemStack> slots, int index, CraftingInventoryData crafting, List<Slot> slotList, @Nullable IInventory subInventory) {
    if (!(subInventory instanceof InventoryAdapter)) {
        return null;
    }
    Lens<IInventory, ItemStack> adapterLens = ((InventoryAdapter) subInventory).getRootLens();
    if (adapterLens == null) {
        return null;
    }
    if (subInventory.getSizeInventory() == 0) {
        return new DefaultEmptyLens<>(((InventoryAdapter) subInventory));
    }
    if (adapterLens instanceof PlayerInventoryLens) {
        if (slotList.size() == 36) {
            return new DelegatingLens(index, new MainPlayerInventoryLensImpl(index, slots, true), slots);
        }
        return null;
    }
    // For Crafting Result we need the Slot to get Filter logic
    if (subInventory instanceof InventoryCraftResult) {
        Slot slot = slotList.get(0);
        adapterLens = new CraftingOutputSlotLensImpl(index, item -> slot.isItemValid(((ItemStack) item)), itemType -> (slot.isItemValid((ItemStack) org.spongepowered.api.item.inventory.ItemStack.of(itemType, 1))));
        crafting.out = index;
        if (slot instanceof SlotCrafting) {
            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 = ((SlotCrafting) slot).craftMatrix;
            }
        }
    }
    if (subInventory instanceof InventoryCrafting) {
        crafting.base = index;
        crafting.grid = ((InventoryCrafting) subInventory);
    }
    return new DelegatingLens(index, adapterLens, slots);
}
Also used : IInventory(net.minecraft.inventory.IInventory) MainPlayerInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.MainPlayerInventoryLensImpl) MinecraftFabric(org.spongepowered.common.item.inventory.lens.impl.MinecraftFabric) LargeChestInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.LargeChestInventoryLens) Random(java.util.Random) ContainerChest(net.minecraft.inventory.ContainerChest) ContainerWorkbench(net.minecraft.inventory.ContainerWorkbench) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) DelegatingLens(org.spongepowered.common.item.inventory.lens.impl.DelegatingLens) PhaseData(org.spongepowered.common.event.tracking.PhaseData) CustomContainer(org.spongepowered.common.item.inventory.custom.CustomContainer) BlockCarrier(org.spongepowered.api.item.inventory.BlockCarrier) Map(java.util.Map) InventoryArchetypes(org.spongepowered.api.item.inventory.InventoryArchetypes) AbstractChestHorse(net.minecraft.entity.passive.AbstractChestHorse) EntityItem(net.minecraft.entity.item.EntityItem) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) CraftingOutputSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.CraftingOutputSlotLensImpl) ContainerBeacon(net.minecraft.inventory.ContainerBeacon) Location(org.spongepowered.api.world.Location) InventoryAdapter(org.spongepowered.common.item.inventory.adapter.InventoryAdapter) InventoryHelper(net.minecraft.inventory.InventoryHelper) Collection(java.util.Collection) GridInventoryLens(org.spongepowered.common.item.inventory.lens.comp.GridInventoryLens) Carrier(org.spongepowered.api.item.inventory.Carrier) Collectors(java.util.stream.Collectors) SlotCrafting(net.minecraft.inventory.SlotCrafting) InventoryArchetype(org.spongepowered.api.item.inventory.InventoryArchetype) InventoryBasic(net.minecraft.inventory.InventoryBasic) BrewingStandInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.BrewingStandInventoryLens) List(java.util.List) ContainerLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.container.ContainerLens) PhaseContext(org.spongepowered.common.event.tracking.PhaseContext) CraftingOutputAdapter(org.spongepowered.common.item.inventory.adapter.impl.slots.CraftingOutputAdapter) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ContainerDispenser(net.minecraft.inventory.ContainerDispenser) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) Lens(org.spongepowered.common.item.inventory.lens.Lens) Optional(java.util.Optional) MixinInventoryHelper(org.spongepowered.common.mixin.core.inventory.MixinInventoryHelper) LensProvider(org.spongepowered.common.item.inventory.lens.LensProvider) ContainerRepair(net.minecraft.inventory.ContainerRepair) PlayerInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.PlayerInventoryLens) ContainerMerchant(net.minecraft.inventory.ContainerMerchant) SpongeImpl(org.spongepowered.common.SpongeImpl) GridInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.GridInventoryLensImpl) AbstractHorse(net.minecraft.entity.passive.AbstractHorse) VanillaAdapter(org.spongepowered.common.item.inventory.adapter.impl.VanillaAdapter) SpongeImplHooks(org.spongepowered.common.SpongeImplHooks) ContainerHopper(net.minecraft.inventory.ContainerHopper) InventoryCraftResult(net.minecraft.inventory.InventoryCraftResult) Multimap(com.google.common.collect.Multimap) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ItemStack(net.minecraft.item.ItemStack) InputSlot(org.spongepowered.api.item.inventory.slot.InputSlot) Inventory2DLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.Inventory2DLensImpl) ContainerEnchantment(net.minecraft.inventory.ContainerEnchantment) DefaultEmptyLens(org.spongepowered.common.item.inventory.lens.impl.DefaultEmptyLens) InventoryLargeChest(net.minecraft.inventory.InventoryLargeChest) ContainerFurnace(net.minecraft.inventory.ContainerFurnace) IMixinContainer(org.spongepowered.common.interfaces.IMixinContainer) ContainerBrewingStand(net.minecraft.inventory.ContainerBrewingStand) WorldServer(net.minecraft.world.WorldServer) Nullable(javax.annotation.Nullable) FurnaceInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.FurnaceInventoryLens) Fabric(org.spongepowered.common.item.inventory.lens.Fabric) Inventory2DLens(org.spongepowered.common.item.inventory.lens.comp.Inventory2DLens) SlotProvider(org.spongepowered.common.item.inventory.lens.SlotProvider) ContainerHorseInventory(net.minecraft.inventory.ContainerHorseInventory) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) IMixinSingleBlockCarrier(org.spongepowered.common.interfaces.IMixinSingleBlockCarrier) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) CraftingInventoryLens(org.spongepowered.common.item.inventory.lens.comp.CraftingInventoryLens) CraftingInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.CraftingInventoryLensImpl) ContainerPlayer(net.minecraft.inventory.ContainerPlayer) Container(org.spongepowered.api.item.inventory.Container) SlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.SlotLensImpl) IInventory(net.minecraft.inventory.IInventory) Slot(net.minecraft.inventory.Slot) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) VecHelper(org.spongepowered.common.util.VecHelper) ItemDropData(org.spongepowered.common.event.tracking.context.ItemDropData) TileEntity(net.minecraft.tileentity.TileEntity) SlotCollection(org.spongepowered.common.item.inventory.lens.impl.collections.SlotCollection) Collections(java.util.Collections) InventoryCrafting(net.minecraft.inventory.InventoryCrafting) MainPlayerInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.MainPlayerInventoryLensImpl) PlayerInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.PlayerInventoryLens) InventoryCraftResult(net.minecraft.inventory.InventoryCraftResult) InventoryCrafting(net.minecraft.inventory.InventoryCrafting) CraftingOutputSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.CraftingOutputSlotLensImpl) InventoryAdapter(org.spongepowered.common.item.inventory.adapter.InventoryAdapter) DefaultEmptyLens(org.spongepowered.common.item.inventory.lens.impl.DefaultEmptyLens) InputSlot(org.spongepowered.api.item.inventory.slot.InputSlot) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack) DelegatingLens(org.spongepowered.common.item.inventory.lens.impl.DelegatingLens) SlotCrafting(net.minecraft.inventory.SlotCrafting) Nullable(javax.annotation.Nullable)

Example 2 with SlotCrafting

use of net.minecraft.inventory.SlotCrafting in project SpongeCommon by SpongePowered.

the class MixinContainer method redirectTransferStackInSlot.

@Redirect(method = "slotClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/Container;transferStackInSlot(Lnet/minecraft/entity/player/EntityPlayer;I)Lnet/minecraft/item/ItemStack;"))
private ItemStack redirectTransferStackInSlot(Container thisContainer, EntityPlayer player, int slotId) {
    Slot slot = thisContainer.getSlot(slotId);
    if (!(slot instanceof SlotCrafting)) {
        return thisContainer.transferStackInSlot(player, slotId);
    }
    this.lastCraft = null;
    this.shiftCraft = true;
    ItemStack result = thisContainer.transferStackInSlot(player, slotId);
    if (this.lastCraft != null) {
        if (this.lastCraft.isCancelled()) {
            // Return empty to stop shift-crafting
            result = ItemStack.EMPTY;
        }
    }
    this.shiftCraft = false;
    return result;
}
Also used : SPacketSetSlot(net.minecraft.network.play.server.SPacketSetSlot) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack) SlotCrafting(net.minecraft.inventory.SlotCrafting) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 3 with SlotCrafting

use of net.minecraft.inventory.SlotCrafting in project ForestryMC by ForestryMC.

the class SlotUtil method transferStackInSlot.

public static ItemStack transferStackInSlot(List<Slot> inventorySlots, EntityPlayer player, int slotIndex) {
    Slot slot = inventorySlots.get(slotIndex);
    if (slot == null || !slot.getHasStack()) {
        return ItemStack.EMPTY;
    }
    boolean fromCraftingSlot = slot instanceof SlotCrafting || slot instanceof SlotCrafter;
    int numSlots = inventorySlots.size();
    ItemStack stackInSlot = slot.getStack();
    ItemStack originalStack = stackInSlot.copy();
    if (!shiftItemStack(inventorySlots, stackInSlot, slotIndex, numSlots, fromCraftingSlot)) {
        return ItemStack.EMPTY;
    }
    slot.onSlotChange(stackInSlot, originalStack);
    if (stackInSlot.isEmpty()) {
        slot.putStack(ItemStack.EMPTY);
    } else {
        slot.onSlotChanged();
    }
    if (stackInSlot.getCount() == originalStack.getCount()) {
        return ItemStack.EMPTY;
    }
    slot.onTake(player, stackInSlot);
    return originalStack;
}
Also used : SlotCrafter(forestry.core.gui.slots.SlotCrafter) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack) SlotCrafting(net.minecraft.inventory.SlotCrafting)

Example 4 with SlotCrafting

use of net.minecraft.inventory.SlotCrafting in project Galacticraft by micdoodle8.

the class NEIController method handleSlotClick.

@Override
public boolean handleSlotClick(GuiContainer gui, int slotIndex, int button, Slot slot, int modifier, boolean eventconsumed) {
    if (eventconsumed || !NEIClientConfig.isEnabled() || isSpreading(gui)) {
        return eventconsumed;
    }
    if (deleteMode && slotIndex >= 0 && slot != null) {
        if (NEIClientUtils.shiftKey() && button == 0) {
            ItemStack itemstack1 = slot.getStack();
            if (itemstack1 != null) {
                NEIClientUtils.deleteItemsOfType(itemstack1);
            }
        } else if (button == 1) {
            NEIClientUtils.decreaseSlotStack(slot.slotNumber);
        } else {
            NEIClientUtils.deleteSlotStack(slot.slotNumber);
        }
        return true;
    }
    if (// right click
    button == 1 && slot instanceof SlotCrafting) {
        for (// click this slot 64 times
        int i1 = 0; // click this slot 64 times
        i1 < 64; // click this slot 64 times
        i1++) {
            manager.handleSlotClick(slot.slotNumber, button, 0);
        }
        return true;
    }
    if (NEIClientUtils.controlKey() && slot != null && slot.getStack() != null && slot.isItemValid(slot.getStack())) {
        NEIClientUtils.cheatItem(slot.getStack(), button, 1);
        return true;
    }
    if (GuiInfo.hasCustomSlots(gui)) {
        return false;
    }
    if (slotIndex >= 0 && NEIClientUtils.shiftKey() && NEIClientUtils.getHeldItem() != null && !slot.getHasStack()) {
        ItemStack held = NEIClientUtils.getHeldItem();
        manager.handleSlotClick(slot.slotNumber, button, 0);
        if (slot.isItemValid(held) && !ItemInfo.fastTransferExemptions.contains(slot.getClass())) {
            fastTransferManager.performMassTransfer(gui, pickedUpFromSlot, slotIndex, held);
        }
        return true;
    }
    if (slotIndex == -999 && NEIClientUtils.shiftKey() && button == 0) {
        fastTransferManager.throwAll(gui, pickedUpFromSlot);
        return true;
    }
    return false;
}
Also used : ItemStack(net.minecraft.item.ItemStack) SlotCrafting(net.minecraft.inventory.SlotCrafting)

Example 5 with SlotCrafting

use of net.minecraft.inventory.SlotCrafting in project BuildCraft by BuildCraft.

the class TileAutoWorkbench method update.

@Override
public void update() {
    super.update();
    if (worldObj.isRemote) {
        return;
    }
    if (scheduledCacheRebuild) {
        craftMatrix.rebuildCache();
        scheduledCacheRebuild = false;
    }
    if (craftMatrix.isJammed || craftMatrix.currentRecipe == null) {
        progress = 0;
        return;
    }
    if (craftSlot == null) {
        craftSlot = new SlotCrafting(getInternalPlayer().get(), craftMatrix, craftResult, 0, 0, 0);
    }
    if (!hasWork) {
        return;
    }
    int updateNext = update + getBattery().getEnergyStored() + 1;
    int updateThreshold = (update & ~15) + 16;
    update = Math.min(updateThreshold, updateNext);
    if ((update % UPDATE_TIME) == 0) {
        updateCrafting();
    }
    getBattery().setEnergy(0);
}
Also used : SlotCrafting(net.minecraft.inventory.SlotCrafting)

Aggregations

SlotCrafting (net.minecraft.inventory.SlotCrafting)9 ItemStack (net.minecraft.item.ItemStack)7 IInventory (net.minecraft.inventory.IInventory)3 Slot (net.minecraft.inventory.Slot)3 Nonnull (javax.annotation.Nonnull)2 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)2 Multimap (com.google.common.collect.Multimap)1 SlotCrafter (forestry.core.gui.slots.SlotCrafter)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Random (java.util.Random)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 AutoCraftingInventory (logisticspipes.blocks.crafting.AutoCraftingInventory)1 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)1