Search in sources :

Example 1 with Slot

use of net.minecraft.container.Slot in project tweakermore by Fallen-Breath.

the class ContainerFiller method process.

@Override
public boolean process(ClientPlayerEntity player, ContainerScreen<?> containerScreen, List<Slot> allSlots, List<Slot> playerInvSlots, List<Slot> containerInvSlots) {
    Slot bestSlot = null;
    long maxCount = TweakerMoreConfigs.AUTO_FILL_CONTAINER_THRESHOLD.getIntegerValue() - 1;
    for (Slot slot : playerInvSlots) if (slot.hasStack() && containerInvSlots.get(0).canInsert(slot.getStack())) {
        long cnt = playerInvSlots.stream().filter(slt -> InventoryUtils.areStacksEqual(slot.getStack(), slt.getStack())).count();
        if (cnt > maxCount) {
            maxCount = cnt;
            bestSlot = slot;
        } else if (cnt == maxCount && bestSlot != null && !InventoryUtils.areStacksEqual(slot.getStack(), bestSlot.getStack())) {
            bestSlot = null;
        }
    }
    if (bestSlot != null && !allSlots.isEmpty()) {
        Text stackName = bestSlot.getStack().getName();
        InventoryUtils.tryMoveStacks(bestSlot, containerScreen, true, true, false);
        long amount = containerInvSlots.stream().filter(Slot::hasStack).count(), total = containerInvSlots.size();
        boolean isFull = Container.calculateComparatorOutput(containerInvSlots.get(0).inventory) >= 15;
        String percentage = String.format("%s%d/%d%s", isFull ? Formatting.GREEN : Formatting.GOLD, amount, total, Formatting.RESET);
        InfoUtils.printActionbarMessage("tweakermore.config.tweakmAutoFillContainer.container_filled", containerScreen.getTitle(), stackName, percentage);
        return true;
    } else {
        InfoUtils.printActionbarMessage("tweakermore.config.tweakmAutoFillContainer.best_slot_not_found");
        return false;
    }
}
Also used : Slot(net.minecraft.container.Slot) Text(net.minecraft.text.Text)

Example 2 with Slot

use of net.minecraft.container.Slot in project tweakermore by Fallen-Breath.

the class ContainerProcessor method process.

public static void process(Container container) {
    if (hasTweakEnabled()) {
        Screen screen = MinecraftClient.getInstance().currentScreen;
        ClientPlayerEntity player = MinecraftClient.getInstance().player;
        // not inventory and not crafting table
        if (player != null && screen instanceof ContainerScreen<?> && !(screen instanceof AbstractInventoryScreen) && !(screen instanceof CraftingTableScreen)) {
            ContainerScreen<?> containerScreen = (ContainerScreen<?>) screen;
            if (containerScreen.getContainer() != container || !((AutoProcessableScreen) screen).shouldProcess()) {
                return;
            }
            ((AutoProcessableScreen) screen).setShouldProcess(false);
            List<Slot> allSlots = container.slots;
            List<Slot> playerInvSlots = allSlots.stream().filter(slot -> slot.inventory instanceof PlayerInventory).collect(Collectors.toList());
            if (allSlots.isEmpty() || playerInvSlots.isEmpty()) {
                return;
            }
            List<Slot> containerInvSlots = allSlots.stream().filter(slot -> ItemScrollerInventoryUtilsAccessor.areSlotsInSameInventory(slot, allSlots.get(0))).collect(Collectors.toList());
            if (containerInvSlots.isEmpty()) {
                return;
            }
            for (Processor processor : CONTAINER_PROCESSORS) {
                if (processor.isEnabled()) {
                    boolean success = processor.process(player, containerScreen, allSlots, playerInvSlots, containerInvSlots);
                    if (success) {
                        break;
                    }
                }
            }
            player.closeContainer();
        }
    }
}
Also used : PlayerInventory(net.minecraft.entity.player.PlayerInventory) AbstractInventoryScreen(net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen) ContainerScreen(net.minecraft.client.gui.screen.ingame.ContainerScreen) Slot(net.minecraft.container.Slot) Collectors(java.util.stream.Collectors) List(java.util.List) Screen(net.minecraft.client.gui.screen.Screen) ImmutableList(com.google.common.collect.ImmutableList) CraftingTableScreen(net.minecraft.client.gui.screen.ingame.CraftingTableScreen) MinecraftClient(net.minecraft.client.MinecraftClient) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) ItemScrollerInventoryUtilsAccessor(me.fallenbreath.tweakermore.mixins.tweaks.tweakmAutoContainerProcess.ItemScrollerInventoryUtilsAccessor) Container(net.minecraft.container.Container) AbstractInventoryScreen(net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen) ContainerScreen(net.minecraft.client.gui.screen.ingame.ContainerScreen) Screen(net.minecraft.client.gui.screen.Screen) CraftingTableScreen(net.minecraft.client.gui.screen.ingame.CraftingTableScreen) PlayerInventory(net.minecraft.entity.player.PlayerInventory) ContainerScreen(net.minecraft.client.gui.screen.ingame.ContainerScreen) Slot(net.minecraft.container.Slot) CraftingTableScreen(net.minecraft.client.gui.screen.ingame.CraftingTableScreen) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) AbstractInventoryScreen(net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen)

Example 3 with Slot

use of net.minecraft.container.Slot in project tweakermore by Fallen-Breath.

the class ContainerCleaner method process.

@Override
public boolean process(ClientPlayerEntity player, ContainerScreen<?> containerScreen, List<Slot> allSlots, List<Slot> playerInvSlots, List<Slot> containerInvSlots) {
    int counter = 0;
    for (Slot slot : containerInvSlots) {
        if (slot.hasStack()) {
            InventoryUtils.dropStack(containerScreen, slot.id);
            counter++;
        }
    }
    InfoUtils.printActionbarMessage("tweakermore.config.tweakmAutoCleanContainer.container_cleaned", counter, containerScreen.getTitle());
    return true;
}
Also used : Slot(net.minecraft.container.Slot)

Aggregations

Slot (net.minecraft.container.Slot)3 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ItemScrollerInventoryUtilsAccessor (me.fallenbreath.tweakermore.mixins.tweaks.tweakmAutoContainerProcess.ItemScrollerInventoryUtilsAccessor)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 Screen (net.minecraft.client.gui.screen.Screen)1 AbstractInventoryScreen (net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen)1 ContainerScreen (net.minecraft.client.gui.screen.ingame.ContainerScreen)1 CraftingTableScreen (net.minecraft.client.gui.screen.ingame.CraftingTableScreen)1 ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)1 Container (net.minecraft.container.Container)1 PlayerInventory (net.minecraft.entity.player.PlayerInventory)1 Text (net.minecraft.text.Text)1