Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I am trying to lock a slot in my inventory to a specific item, so i can oly inert THAT item in THAT slot and no other.

 

i tried it with "isItemValidForSlot" but i couldnt get it to work that way.

  • Author

thats how i tried it:

@Override
public boolean isItemValidForSlot(int slot, ItemStack item) {
if(slot == 0 && item.getItem() == ModItems.toolOsniumKnife) return true;
return false;
}

  • Author
package com.wizcraft.gui;

import com.wizcraft.tile.entity.TileEntityTableWittle;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

public class ContainerTableWittle extends Container {

protected TileEntityTableWittle tile;

public ContainerTableWittle(InventoryPlayer invPlayer, TileEntityTableWittle tile){
	this.tile = tile;
	this.addSlotToContainer(new Slot(tile, 0, 52, 7));
	this.addSlotToContainer(new Slot(tile, 1, 52, 34));
	this.addSlotToContainer(new Slot(tile, 2, 52, 61));
	this.addSlotToContainer(new Slot(tile, 3, 25, 34));
	this.addSlotToContainer(new Slot(tile, 4, 79, 34));
	this.addSlotToContainer(new Slot(tile, 5, 131, 34));

	bindPlayerInventory(invPlayer);
}

@Override
    public boolean canInteractWith(EntityPlayer player) {
            return tile.isUseableByPlayer(player);
    }


    protected void bindPlayerInventory(InventoryPlayer invPlayer) {
    	for(int i = 0; i<3;i++){
		for(int j = 0; j<9;j++){
			this.addSlotToContainer(new Slot(invPlayer, 9+j+i*9, 8 + j*18, 84+i*18));
		}
	}

	for(int i = 0; i<9;i++){
		this.addSlotToContainer(new Slot(invPlayer, i, 8 + i*18, 142));
	}
    }

    @Override
    public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
            ItemStack stack = null;
            Slot slotObject = (Slot) inventorySlots.get(slot);

            //null checks and checks if the item can be stacked (maxStackSize > 1)
            if (slotObject != null && slotObject.getHasStack()) {
                    ItemStack stackInSlot = slotObject.getStack();
                    stack = stackInSlot.copy();

                    //merges the item into player inventory since its in the tile
                    if (slot < tile.getSizeInventory()) {
                            if (!this.mergeItemStack(stackInSlot, tile.getSizeInventory(), 36+tile.getSizeInventory(), true)) {
                                    return null;
                            }
                    }
                    //places it into the tile is possible since its in the player inventory
                    else if (!this.mergeItemStack(stackInSlot, 0, tile.getSizeInventory(), false)) {
                            return null;
                    }

                    if (stackInSlot.stackSize == 0) {
                            slotObject.putStack(null);
                    } else {
                            slotObject.onSlotChanged();
                    }

                    if (stackInSlot.stackSize == stack.stackSize) {
                            return null;
                    }
                    slotObject.onPickupFromSlot(player, stackInSlot);
            }
            return stack;
    }
}

  • Author

I created a custom slot class and set the "isitemValid" to similar to what was in the method from the tileentity and now it works.

PS:

i never made a more complex gui than a chest before.

THANK YOU  :D

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.