<commit_before>package com.raoulvdberge.refinedstorage.container;

import com.raoulvdberge.refinedstorage.container.slot.SlotCrafterManager;
import com.raoulvdberge.refinedstorage.gui.IResizableDisplay;
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
import com.raoulvdberge.refinedstorage.tile.TileCrafterManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.SlotItemHandler;

import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ContainerCrafterManager extends ContainerBase {
    public class Listener implements IContainerListener {
        private IContainerListener base;
        private boolean receivedContainerData;

        public Listener(IContainerListener base) {
            this.base = base;
        }

        public EntityPlayerMP getPlayer() {
            return (EntityPlayerMP) base;
        }

        @Override
        public void sendAllContents(Container containerToSend, NonNullList<ItemStack> itemsList) {
            if (receivedContainerData) {
                base.sendAllContents(containerToSend, itemsList);
            }
        }

        @Override
        public void sendSlotContents(Container containerToSend, int slotInd, ItemStack stack) {
            if (receivedContainerData) {
                base.sendSlotContents(containerToSend, slotInd, stack);
            }
        }

        public void setReceivedContainerData() {
            receivedContainerData = true;
        }

        @Override
        public void sendWindowProperty(Container containerIn, int varToUpdate, int newValue) {
            base.sendWindowProperty(containerIn, varToUpdate, newValue);
        }

        @Override
        public void sendAllWindowProperties(Container containerIn, IInventory inventory) {
            base.sendAllWindowProperties(containerIn, inventory);
        }
    }

    private IResizableDisplay display;
    private Map<String, Integer> containerData;
    private Map<String, IItemHandlerModifiable> dummyInventories = new HashMap<>();

    @Override
    public void addListener(IContainerListener listener) {
        super.addListener(new Listener(listener));
    }

    public List<IContainerListener> getListeners() {
        return listeners;
    }

    public ContainerCrafterManager(TileCrafterManager crafterManager, EntityPlayer player, IResizableDisplay display) {
        super(crafterManager, player);

        this.display = display;

        if (!player.world.isRemote) {
            addPlayerInventory(8, display.getYPlayerInventory());

            if (crafterManager.getNode().getNetwork() != null) {
                for (Map.Entry<String, List<IItemHandlerModifiable>> entry : crafterManager.getNode().getNetwork().getCraftingManager().getNamedContainers().entrySet()) {
                    for (IItemHandlerModifiable handler : entry.getValue()) {
                        for (int i = 0; i < handler.getSlots(); ++i) {
                            addSlotToContainer(new SlotItemHandler(handler, i, 0, 0));
                        }
                    }
                }
            }
        }
    }

    public void initSlots(@Nullable Map<String, Integer> newContainerData) {
        if (newContainerData == null) { // We resized
            if (containerData == null) { // No container data received yet, do nothing..
                return;
            }
        } else {
            containerData = newContainerData; // Received container data

            dummyInventories.clear();
        }

        this.inventorySlots.clear();
        this.inventoryItemStacks.clear();

        addPlayerInventory(8, display.getYPlayerInventory());

        int y = 19 + 18 - display.getCurrentOffset() * 18;
        int x = 8;

        for (Map.Entry<String, Integer> entry : containerData.entrySet()) {
            // @todo: Test on servers
            boolean visible = I18n.format(entry.getKey()).toLowerCase().contains(display.getSearchFieldText().toLowerCase());

            IItemHandlerModifiable dummy;

            if (newContainerData == null) { // We're only resizing, get the previous inventory...
                dummy = dummyInventories.get(entry.getKey());
            } else {
                dummyInventories.put(entry.getKey(), dummy = new ItemHandlerBase(entry.getValue()));
            }

            for (int slot = 0; slot < entry.getValue(); ++slot) {
                addSlotToContainer(new SlotCrafterManager(dummy, slot, x, y, visible, display));

                if (visible) {
                    x += 18;

                    // Don't increase y level if we are on our last slot row (otherwise we do y += 18 * 3)
                    if ((slot + 1) % 9 == 0 && slot + 1 < entry.getValue()) {
                        x = 8;
                        y += 18;
                    }
                }
            }<commit_msg>Assign slot limit to dummy crafter manager inventory<commit_after>package com.raoulvdberge.refinedstorage.container;

import com.raoulvdberge.refinedstorage.container.slot.SlotCrafterManager;
import com.raoulvdberge.refinedstorage.gui.IResizableDisplay;
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
import com.raoulvdberge.refinedstorage.tile.TileCrafterManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.SlotItemHandler;

import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ContainerCrafterManager extends ContainerBase {
    public class Listener implements IContainerListener {
        private IContainerListener base;
        private boolean receivedContainerData;

        public Listener(IContainerListener base) {
            this.base = base;
        }

        public EntityPlayerMP getPlayer() {
            return (EntityPlayerMP) base;
        }

        @Override
        public void sendAllContents(Container containerToSend, NonNullList<ItemStack> itemsList) {
            if (receivedContainerData) {
                base.sendAllContents(containerToSend, itemsList);
            }
        }

        @Override
        public void sendSlotContents(Container containerToSend, int slotInd, ItemStack stack) {
            if (receivedContainerData) {
                base.sendSlotContents(containerToSend, slotInd, stack);
            }
        }

        public void setReceivedContainerData() {
            receivedContainerData = true;
        }

        @Override
        public void sendWindowProperty(Container containerIn, int varToUpdate, int newValue) {
            base.sendWindowProperty(containerIn, varToUpdate, newValue);
        }

        @Override
        public void sendAllWindowProperties(Container containerIn, IInventory inventory) {
            base.sendAllWindowProperties(containerIn, inventory);
        }
    }

    private IResizableDisplay display;
    private Map<String, Integer> containerData;
    private Map<String, IItemHandlerModifiable> dummyInventories = new HashMap<>();

    @Override
    public void addListener(IContainerListener listener) {
        super.addListener(new Listener(listener));
    }

    public List<IContainerListener> getListeners() {
        return listeners;
    }

    public ContainerCrafterManager(TileCrafterManager crafterManager, EntityPlayer player, IResizableDisplay display) {
        super(crafterManager, player);

        this.display = display;

        if (!player.world.isRemote) {
            addPlayerInventory(8, display.getYPlayerInventory());

            if (crafterManager.getNode().getNetwork() != null) {
                for (Map.Entry<String, List<IItemHandlerModifiable>> entry : crafterManager.getNode().getNetwork().getCraftingManager().getNamedContainers().entrySet()) {
                    for (IItemHandlerModifiable handler : entry.getValue()) {
                        for (int i = 0; i < handler.getSlots(); ++i) {
                            addSlotToContainer(new SlotItemHandler(handler, i, 0, 0));
                        }
                    }
                }
            }
        }
    }

    public void initSlots(@Nullable Map<String, Integer> newContainerData) {
        if (newContainerData == null) { // We resized
            if (containerData == null) { // No container data received yet, do nothing..
                return;
            }
        } else {
            containerData = newContainerData; // Received container data

            dummyInventories.clear();
        }

        this.inventorySlots.clear();
        this.inventoryItemStacks.clear();

        addPlayerInventory(8, display.getYPlayerInventory());

        int y = 19 + 18 - display.getCurrentOffset() * 18;
        int x = 8;

        for (Map.Entry<String, Integer> entry : containerData.entrySet()) {
            // @todo: Test on servers
            boolean visible = I18n.format(entry.getKey()).toLowerCase().contains(display.getSearchFieldText().toLowerCase());

            IItemHandlerModifiable dummy;

            if (newContainerData == null) { // We're only resizing, get the previous inventory...
                dummy = dummyInventories.get(entry.getKey());
            } else {
                dummyInventories.put(entry.getKey(), dummy = new ItemHandlerBase(entry.getValue()) {
                    @Override
                    public int getSlotLimit(int slot) {
                        return 1;
                    }
                });
            }

            for (int slot = 0; slot < entry.getValue(); ++slot) {
                addSlotToContainer(new SlotCrafterManager(dummy, slot, x, y, visible, display));

                if (visible) {
                    x += 18;

                    // Don't increase y level if we are on our last slot row (otherwise we do y += 18 * 3)
                    if ((slot + 1) % 9 == 0 && slot + 1 < entry.getValue()) {
                        x = 8;
                        y += 18;
                    }
                }
            }
{'fraction_non_alphanumeric': 0.0916382409882917, 'fraction_numerical': 0.00543929197012999, 'mean_word_length': 2.320477502295684, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7154590', 'n_tokens_mistral': 2864, 'n_tokens_neox': 2739, 'n_words': 620}