GUI Слот выхода ресурсов

Версия Minecraft
1.12.2
81
3
В общем мучаюсь с инвентарем механизма. Просто так положить в слот ничего нельзя, однако если в слоте уже есть предмет, то при зажатии "Шифт" можно положить в слот недостающие ресурсы до стека. Я хочу что бы игрок мог только забирать из слота, а не скидывать в слот ресурсы. То есть, данный слот только для выхода производства в механизме. Можно только забирать. Вот кусок слота из гуи:
Java:
            this.addSlotToContainer(new Slot(inherited, 1, 80, 48) {

                public boolean isItemValid(ItemStack stack) {
                    return false;
                }
 
Последнее редактирование:
81
3
Нашел у себя, прикладываю, сейчас попробую поправить, но помощь не помешает, ибо могут все сломать:
Java:
        @Override
        public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
            ItemStack itemstack = null;
            Slot slot = (Slot) this.inventorySlots.get(index);
            if (slot != null && slot.getHasStack()) {
                ItemStack itemstack1 = slot.getStack();
                itemstack = itemstack1.copy();
                if (index < 9) {
                    if (!this.mergeItemStack(itemstack1, 9, (45 - 9), true))
                        return ItemStack.EMPTY;
                } else if (!this.mergeItemStack(itemstack1, 0, 9, false)) {
                    return ItemStack.EMPTY;
                }
                if (itemstack1.getCount() == 0) {
                    slot.putStack(ItemStack.EMPTY);
                } else {
                    slot.onSlotChanged();
                }
                if (itemstack1.getCount() == itemstack.getCount()) {
                    return ItemStack.EMPTY;
                }
                slot.onTake(playerIn, itemstack1);
            }
            return itemstack;
        }
 
Последнее редактирование:
81
3
Я еще не набил шишки, и не до конца понимаю как все работает. Пока у меня вышло не так как я планировал.
Так скину весь код гуи без импортов. Там всего пара слотов. Нулевой для загрузки предметов. Слот "1" уже вывод предмета, но на данный момент игрок может через шифт положить предметы туда, если там есть хотя бы 1 шт, доступ к гуи вместе с инвентарем игрока:

Java:
    public static int GUIID = 3;
    public static HashMap guiinventory = new HashMap();
    public static IInventory inherited;

    public campfirePrGUI(testmod instance) {
        super(instance);
    }

    public static class GuiContainerMod extends Container {

        World world;
        EntityPlayer entity;
        int x, y, z;

        public GuiContainerMod(World world, int x, int y, int z, EntityPlayer player) {
            this.world = world;
            this.entity = player;
            this.x = x;
            this.y = y;
            this.z = z;
            TileEntity ent = world.getTileEntity(new BlockPos(x, y, z));
            if (ent instanceof cFirePrLogic.TileEntityCustom)
                inherited = (IInventory) ent;
            else
                inherited = new InventoryBasic("", true, 9);
            this.addSlotToContainer(new Slot(inherited, 0, 26, 48) {
            });
            this.addSlotToContainer(new Slot(inherited, 1, 80, 48) {

                public boolean isItemValid(ItemStack stack) {
                    return false;
                }
            });
            int si;
            int sj;
            for (si = 0; si < 3; ++si)
                for (sj = 0; sj < 9; ++sj)
                    this.addSlotToContainer(new Slot(player.inventory, sj + (si + 1) * 9, 0 + 8 + sj * 18, 0 + 84 + si * 18));
            for (si = 0; si < 9; ++si)
                this.addSlotToContainer(new Slot(player.inventory, si, 0 + 8 + si * 18, 0 + 142));
        }

        @Override
        public boolean canInteractWith(EntityPlayer player) {
            return true;
        }

        @Override
        public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
            ItemStack itemstack = null;
            Slot slot = (Slot) this.inventorySlots.get(index);
            if (slot != null && slot.getHasStack()) {
                ItemStack itemstack1 = slot.getStack();
                itemstack = itemstack1.copy();
                if (index < 9) {
                    if (!this.mergeItemStack(itemstack1, 9, (45 - 9), true))
                        return ItemStack.EMPTY;
                } else if (!this.mergeItemStack(itemstack1, 0, 9, false)) {
                    return ItemStack.EMPTY;
                }
                if (itemstack1.getCount() == 0) {
                    slot.putStack(ItemStack.EMPTY);
                } else {
                    slot.onSlotChanged();
                }
                if (itemstack1.getCount() == itemstack.getCount()) {
                    return ItemStack.EMPTY;
                }
                slot.onTake(playerIn, itemstack1);
            }
            return itemstack;
        }

        public void onContainerClosed(EntityPlayer playerIn) {
            super.onContainerClosed(playerIn);
        }
    }

    public static class GuiWindow extends GuiContainer {

        int x, y, z;
        EntityPlayer entity;

        public GuiWindow(World world, int x, int y, int z, EntityPlayer entity) {
            super(new GuiContainerMod(world, x, y, z, entity));
            this.x = x;
            this.y = y;
            this.z = z;
            this.entity = entity;
            this.xSize = 176;
            this.ySize = 166;
        }

        private static final ResourceLocation texture = new ResourceLocation("testmod:textures/campfireprgui.png");

        @Override
        public void drawScreen(int mouseX, int mouseY, float partialTicks) {
            this.drawDefaultBackground();
            super.drawScreen(mouseX, mouseY, partialTicks);
            this.renderHoveredToolTip(mouseX, mouseY);
        }

        @Override
        protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            this.mc.renderEngine.bindTexture(texture);
            int k = (this.width - this.xSize) / 2;
            int l = (this.height - this.ySize) / 2;
            this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
            zLevel = 100.0F;
        }

        @Override
        protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
            try {
                super.mouseClicked(mouseX, mouseY, mouseButton);
            } catch (Exception ignored) {
            }
        }

        @Override
        public void updateScreen() {
            super.updateScreen();
        }

        @Override
        protected void keyTyped(char typedChar, int keyCode) {
            try {
                super.keyTyped(typedChar, keyCode);
            } catch (Exception ignored) {
            }
        }

        @Override
        protected void drawGuiContainerForegroundLayer(int par1, int par2) {
        }

        @Override
        public void onGuiClosed() {
            super.onGuiClosed();
            Keyboard.enableRepeatEvents(false);
        }

        @Override
        public void initGui() {
            super.initGui();
            this.guiLeft = (this.width - 176) / 2;
            this.guiTop = (this.height - 166) / 2;
            Keyboard.enableRepeatEvents(true);
            this.buttonList.clear();
        }

        @Override
        protected void actionPerformed(GuiButton button) {
            MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
            World world = server.getWorld(entity.dimension);
        }

        @Override
        public boolean doesGuiPauseGame() {
            return false;
        }
    }
}
 
7,099
324
1,510
Нужно, типа, задать логику transferStackInSlot, чтобы никогда не помещались предметы в 1 слот.

Если его не переопределять, то шифт+клик вообще не работает?
 

timaxa007

Модератор
5,831
409
672
Нулевой для загрузки предметов. Слот "1" уже вывод предмета
А такое впечетление что ты пытаешься использовать 9 слотов место двух.
---
он его забивает до стака
Всякое бывает. У меня нормально:
(github.com) fabrication_1.12.2
 
Сверху