Script API - v1.20.30
    Preparing search index...

    Defines this entity's inventory properties.

    const getEntityInventoryComponent = entity.getComponent("inventory");
    getEntityInventoryComponent.additionalSlotsPerStrength;
    getEntityInventoryComponent.canBeSiphonedFrom;
    const inventoryContainer = getEntityInventoryComponent.container;
    getEntityInventoryComponent.containerType;
    getEntityInventoryComponent.inventorySize;
    getEntityInventoryComponent.private;
    getEntityInventoryComponent.restrictToOwner;
    getEntityInventoryComponent.isValid();

    // Custom function to add an item to the inventory
    function addItemToInventory(itemStack) {
    return inventoryContainer.addItem(itemStack);
    }

    // Custom function to move an item within the inventory
    function moveItemWithinInventory(fromSlot, toSlot) {
    inventoryContainer.moveItem(fromSlot, toSlot, inventoryContainer);
    }

    // Custom function to transfer an item from inventory to another container
    function transferItemToContainer(fromSlot, targetContainer) {
    return inventoryContainer.transferItem(fromSlot, targetContainer);
    }

    // Example usage of the custom functions
    const newItemStack = new ItemStack("apple", 10); // Assuming "apple" is a valid item
    const addedItem = addItemToInventory(newItemStack);
    if (addedItem) {
    console.log("Item added to inventory:", addedItem);
    }

    const sourceSlot = 2;
    const destinationSlot = 5;
    moveItemWithinInventory(sourceSlot, destinationSlot);

    const targetContainer = someOtherContainer; // Assuming 'someOtherContainer' is an instance of another container
    const transferredItem = transferItemToContainer(0, targetContainer);
    if (transferredItem) {
    console.log("Item transferred to another container:", transferredItem);
    }

    Hierarchy (View Summary)

    Index

    Properties

    additionalSlotsPerStrength: number

    Number of slots that this entity can gain per extra strength.

    This property can throw when used.

    canBeSiphonedFrom: boolean

    If true, the contents of this inventory can be removed by a hopper.

    This property can throw when used.

    container: Container

    Defines the container for this entity.

    This property can throw when used.

    containerType: string

    Type of container this entity has.

    This property can throw when used.

    entity: Entity

    The entity that owns this component.

    inventorySize: number

    Number of slots the container has.

    This property can throw when used.

    private: boolean

    If true, the entity will not drop it's inventory on death.

    This property can throw when used.

    restrictToOwner: boolean

    If true, the entity's inventory can only be accessed by its owner or itself.

    This property can throw when used.

    typeId: string

    Identifier of the component.

    componentId: "minecraft:inventory" = 'minecraft:inventory'

    Methods

    • Returns boolean

      Whether the component is valid.

      Returns whether the component is valid. A component is considered valid if its owner is valid, in addition to any addition to any additional validation required by the component.