PrivateconstructorReadonlyblockThis property can't be read in early-execution mode.
Optional ReadonlycontainerThe container which holds an ItemStack.
This property can't be read in early-execution mode.
import { world } from "@minecraft/server";
world.afterEvents.playerInteractWithBlock.subscribe(({ player, block }) => {
const inventoryComponent = block.getComponent("minecraft:inventory");
if (!inventoryComponent?.container) {
player.sendMessage("This block does not have an inventory container.");
return;
}
const { emptySlotsCount, size } = inventoryComponent.container;
player.sendMessage(`${emptySlotsCount} out of ${size} slots are free.`);
});
ReadonlyisReturns 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.
This property can't be read in early-execution mode.
ReadonlytypeThis property can't be read in early-execution mode.
Static Readonlycomponent
Represents the inventory of a block in the world. Used with blocks like chests.
Example: placeItemsInChest.ts
Source