Jump to content

Custom inventory with 1 slot.


Raycoms

Recommended Posts

I currently want to create a custom inventory for a tileEntity.

 

My class inherits another inventory class which implements the rest of the methods

 

But I don't get slots which are not multiples of 9.

Is there a way to get that working without using the container class creating container, slots, inventory, GUI and all that overhead for only 1 slot inventory?

(I want the player to put in 1 item, and I want to read the content of the slot and nothing more).

 

/**
* The custom chest of the field.
*/
public class InventoryField extends InventoryCitizen
{
    private ItemStack[] stackResult = new ItemStack[1];
    private String customName = "";
    /**
     * Creates the inventory of the citizen.
     *
     * @param title         Title of the inventory.
     * @param localeEnabled Boolean whether the inventory has a custom name.
     */
    public InventoryField(final String title, final boolean localeEnabled)
    {
        super(title, localeEnabled);
        customName = title;
    }

    @Override
    public int getSizeInventory()
    {
        return 1;
    }

    @Override
    public int getInventoryStackLimit()
    {
        return 1;
    }

    @Override
    public int getHotbarSize()
    {
        return 0;
    }

    public ItemStack getStackInSlot(int index)
    {
        return this.stackResult[0];
    }

    @Override
    public boolean hasCustomName()
    {
        return true;
    }

    /**
     * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
     * @param index the slot to set the itemStack.
     * @param stack the itemStack to set.
     */
    @Override
    public void setInventorySlotContents(int index, ItemStack stack)
    {
        this.stackResult[index] = stack;

        if (stack != null && stack.stackSize > this.getInventoryStackLimit())
        {
            stack.stackSize = this.getInventoryStackLimit();
        }

        this.markDirty();
    }

    /**
     *  Get the name of this object. For citizens this returns their name.
     * @return the name of the inventory.
     */
    @Override
    public String getName()
    {
        return this.hasCustomName() ? this.customName : "field.inventory";
    }
}

Link to comment
Share on other sites

You should have your own Container and Gui. You will also need a GuiHandler which is a class that implements IGuiHandler. There are plenty of tutorials out there for those, as they haven't really changed much.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

I thought there may be a way to do this without any custom gui and container. Since it is only 1 single inventory slot and I do not need anything besides from this =D

 

But thank you for your help.

 

I'll get into all that container and GUI stuff then =D

Link to comment
Share on other sites

You can't.  GUIChest assumes that all inventories opened with it will have 9n inventory slots.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

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