Search in sources :

Example 1 with Slot

use of net.minecraft.screen.slot.Slot in project Rug by RubixDev.

the class PeekCommand method showInventory.

public static void showInventory(ServerPlayerEntity executingPlayer, ServerPlayerEntity targetPlayer) {
    PlayerDataGui invScreen = new PlayerDataGui(ScreenHandlerType.GENERIC_9X5, executingPlayer, targetPlayer);
    invScreen.setTitle(Text.of("Inventory of " + targetPlayer.getDisplayName().asString()));
    for (int slot = 0; slot < executingPlayer.getInventory().size(); slot++) {
        invScreen.setSlotRedirect(slot, new Slot(targetPlayer.getInventory(), slot, 0, 0));
    }
    invScreen.open();
}
Also used : PlayerDataGui(de.rubixdev.rug.gui.PlayerDataGui) Slot(net.minecraft.screen.slot.Slot)

Example 2 with Slot

use of net.minecraft.screen.slot.Slot in project WK by witches-kitchen.

the class WKScreenHandler method transferStack.

protected boolean transferStack(final ItemStack stackToShift, final int start, final int end) {
    if (stackToShift.isEmpty()) {
        return false;
    }
    int inCount = stackToShift.getCount();
    // First lets see if we have the same item in a slot to merge with
    for (int slotIndex = start; stackToShift.getCount() > 0 && slotIndex < end; slotIndex++) {
        final Slot slot = this.slots.get(slotIndex);
        final ItemStack stackInSlot = slot.getStack();
        int maxCount = Math.min(stackToShift.getMaxCount(), slot.getMaxItemCount());
        if (!stackToShift.isEmpty() && slot.canInsert(stackToShift)) {
            if (ItemUtil.areItemsEqual(stackInSlot, stackToShift, true)) {
                // Got 2 stacks that need merging
                final int space = maxCount - stackInSlot.getCount();
                if (space > 0) {
                    int transferAmount = Math.min(space, stackToShift.getCount());
                    stackInSlot.increment(transferAmount);
                    stackToShift.decrement(transferAmount);
                }
            }
        }
    }
    // If not lets go find the next free slot to insert our remaining stack
    for (int slotIndex = start; stackToShift.getCount() > 0 && slotIndex < end; slotIndex++) {
        final Slot slot = this.slots.get(slotIndex);
        final ItemStack stackInSlot = slot.getStack();
        if (stackInSlot.isEmpty() && slot.canInsert(stackToShift)) {
            int maxCount = Math.min(stackToShift.getMaxCount(), slot.getMaxItemCount());
            int moveCount = Math.min(maxCount, stackToShift.getCount());
            ItemStack moveStack = stackToShift.copy();
            moveStack.setCount(moveCount);
            slot.setStack(moveStack);
            stackToShift.decrement(moveCount);
        }
    }
    // If we moved some, but still have more left over lets try again
    if (!stackToShift.isEmpty() && stackToShift.getCount() != inCount) {
        transferStack(stackToShift, start, end);
    }
    return stackToShift.getCount() != inCount;
}
Also used : Slot(net.minecraft.screen.slot.Slot) ItemStack(net.minecraft.item.ItemStack)

Example 3 with Slot

use of net.minecraft.screen.slot.Slot in project meteor-client by MeteorDevelopment.

the class InventorySorter method generateActions.

private void generateActions() {
    // Find all slots and sort them
    List<MySlot> slots = new ArrayList<>();
    for (Slot slot : screen.getScreenHandler().slots) {
        if (getInvPart(slot) == originInvPart)
            slots.add(new MySlot(((ISlot) slot).getId(), slot.getStack()));
    }
    slots.sort(Comparator.comparingInt(value -> value.id));
    // Generate actions
    generateStackingActions(slots);
    generateSortingActions(slots);
}
Also used : PlayerInventory(net.minecraft.entity.player.PlayerInventory) Pair(net.minecraft.util.Pair) ShulkerBoxScreen(net.minecraft.client.gui.screen.ingame.ShulkerBoxScreen) SimpleInventory(net.minecraft.inventory.SimpleInventory) Slot(net.minecraft.screen.slot.Slot) Registry(net.minecraft.util.registry.Registry) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) ISlot(meteordevelopment.meteorclient.mixininterface.ISlot) List(java.util.List) GenericContainerScreen(net.minecraft.client.gui.screen.ingame.GenericContainerScreen) PeekScreen(meteordevelopment.meteorclient.utils.render.PeekScreen) CreativeInventoryScreen(net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen) Comparator(java.util.Comparator) HandledScreen(net.minecraft.client.gui.screen.ingame.HandledScreen) ArrayList(java.util.ArrayList) Slot(net.minecraft.screen.slot.Slot) ISlot(meteordevelopment.meteorclient.mixininterface.ISlot)

Example 4 with Slot

use of net.minecraft.screen.slot.Slot in project SinoCate by EverlastSino.

the class SaucepanScreenHandler method transferSlot.

@Override
public ItemStack transferSlot(PlayerEntity player, int invSlot) {
    ItemStack newStack = ItemStack.EMPTY;
    Slot slot = this.slots.get(invSlot);
    if (slot.hasStack()) {
        ItemStack originalStack = slot.getStack();
        newStack = originalStack.copy();
        if (invSlot < this.inventory.size()) {
            if (!this.insertItem(originalStack, this.inventory.size(), this.slots.size(), true)) {
                return ItemStack.EMPTY;
            }
        } else if (!this.insertItem(originalStack, 0, this.inventory.size(), false)) {
            return ItemStack.EMPTY;
        }
        if (originalStack.isEmpty()) {
            slot.setStack(ItemStack.EMPTY);
        } else {
            slot.markDirty();
        }
    }
    return newStack;
}
Also used : WaterBucketSlot(com.everlastsino.cate.screen.screens.slots.WaterBucketSlot) Slot(net.minecraft.screen.slot.Slot) ItemStack(net.minecraft.item.ItemStack)

Example 5 with Slot

use of net.minecraft.screen.slot.Slot in project Biome-Makeover by Lemonszz.

the class AltarScreenHandler method transferSlot.

@Override
public ItemStack transferSlot(PlayerEntity player, int index) {
    ItemStack stackCopy = ItemStack.EMPTY;
    Slot slot = this.slots.get(index);
    if (slot != null && slot.hasStack()) {
        ItemStack moveStack = slot.getStack();
        stackCopy = moveStack.copy();
        if (index == 0) {
            if (!this.insertItem(moveStack, 2, 38, true))
                return ItemStack.EMPTY;
        } else if (index == 1) {
            if (!this.insertItem(moveStack, 2, 38, true))
                return ItemStack.EMPTY;
        } else if (moveStack.getItem().isIn(BMItems.CURSE_FUEL)) {
            if (!this.insertItem(moveStack, 1, 2, true))
                return ItemStack.EMPTY;
        } else {
            if (this.slots.get(0).hasStack() || !this.slots.get(0).canInsert(moveStack))
                return ItemStack.EMPTY;
            ItemStack finalStack = moveStack.copy();
            finalStack.setCount(1);
            moveStack.decrement(1);
            this.slots.get(0).setStack(finalStack);
        }
        if (moveStack.isEmpty())
            slot.setStack(ItemStack.EMPTY);
        else
            slot.markDirty();
        if (moveStack.getCount() == stackCopy.getCount()) {
            return ItemStack.EMPTY;
        }
        slot.onTakeItem(player, moveStack);
    }
    return stackCopy;
}
Also used : Slot(net.minecraft.screen.slot.Slot) ItemStack(net.minecraft.item.ItemStack)

Aggregations

Slot (net.minecraft.screen.slot.Slot)24 ItemStack (net.minecraft.item.ItemStack)14 EquipmentSlot (net.minecraft.entity.EquipmentSlot)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ArmorStandPreset (eu.pb4.armorstandeditor.config.ArmorStandPreset)2 ConfigManager (eu.pb4.armorstandeditor.config.ConfigManager)2 ArmorStandData (eu.pb4.armorstandeditor.helpers.ArmorStandData)2 ArmorStandInventory (eu.pb4.armorstandeditor.helpers.ArmorStandInventory)2 ItemFrameInventory (eu.pb4.armorstandeditor.helpers.ItemFrameInventory)2 SPEInterface (eu.pb4.armorstandeditor.helpers.SPEInterface)2 ArmorStandEntityAccessor (eu.pb4.armorstandeditor.mixin.ArmorStandEntityAccessor)2 ItemFrameEntityAccessor (eu.pb4.armorstandeditor.mixin.ItemFrameEntityAccessor)2 ClickType (eu.pb4.sgui.api.ClickType)2 GuiElement (eu.pb4.sgui.api.elements.GuiElement)2 GuiElementBuilder (eu.pb4.sgui.api.elements.GuiElementBuilder)2 GuiElementInterface (eu.pb4.sgui.api.elements.GuiElementInterface)2 AnvilInputGui (eu.pb4.sgui.api.gui.AnvilInputGui)2 SimpleGui (eu.pb4.sgui.api.gui.SimpleGui)2 Collection (java.util.Collection)2