MineJSv0.7.0

Container

Source: container.ts:24

Represent a container (such as inventory, chest, anvil, ...)


Constructors

new Container( id: number, type: number, rawTitle: TextComponent, ): Container

Parameters

  • id (number) — The ID of this container.Used for interact and close it.
  • type (number)
  • rawTitle (TextComponent)

Returns

Container


Properties

id: number

The ID of this container.

Used for interact and close it.

properties: Record<string, number>

Data from Set Container Property packet

Default: {}

  • See:
    • - https://minecraft.wiki/w/Java_Edition_protocol/Packets#Set_Container_Property

      | Field | Meaning | |------------------------------------------|---------| | # **Furnace / Blast furnace / Smoker** | ------- | | fuel_left | counting from fuel burn time down to 0 | | max_burn_time | fuel burn time or 0 (in-game ticks) | | progress_arrow | counting from 0 to maximum progress (in-game ticks) | | max_progress | always 200 on the vanilla server | | # **Enchantment table** | ------- | | level_requirement_for_top_enchantment | | | level_requirement_for_middle_enchantment | The enchantment's xp level requirement | | level_requirement_for_bottom_enchantment | | | enchantment_seed | Used for drawing the enchantment names (in SGA) clientside. The same seed is used to calculate enchantments, but some of the data isn't sent to the client to prevent easily guessing the entire list (the seed value here is the regular seed bitwise and 0xFFFFFFF0). | | enchant_id_of_top_enchantment | | | enchant_id_of_middle_enchantment | The enchantment ID (set to -1 to hide it), see below for values | | enchant_id_of_bottom_enchantment | | | enchant_level_of_top_enchantment | | | enchant_level_of_middle_enchantment | The enchantment level (1 = I, 2 = II, 6 = VI, etc.), or -1 if no enchant | | enchant_level_of_bottom_enchantment | | | # **Beacon** | ------- | | power_level | 0-4, controls what effect buttons are enabled | | first_effect | Potion effect ID for the first effect, or -1 if no effect | | second_level | Potion effect ID for the second effect, or -1 if no effect | | # **Anvil** | ------- | | repair_cost | The repair's cost in XP levels | | # **Brewing stand** | ------- | | brew_time | 0 – 400, with 400 making the arrow empty, and 0 making the arrow full | | fuel_time | 0 - 20, with 0 making the arrow empty, and 20 making the arrow full | | # **Stonecutter** | ------- | | selected_recipe | The index of the selected recipe. -1 means none is selected | | # **Loom** | ------- | | selected_pattern | The index of the selected pattern. 0 means none is selected, 0 is also the internal ID of the "base" pattern | | # **Lectern** | ------- | | page_number | The current page number, starting from 0. | | # **Smithing table** | ------- | | has_recipe_error | True if greater than zero | | # **Crafter** | ------- | | slot_0_disabled | | | slot_1_disabled | | | slot_2_disabled | | | slot_3_disabled | | | slot_4_disabled | 0 If the slot is enabled, 1 if the slot is disabled | | slot_5_disabled | | | slot_6_disabled | | | slot_7_disabled | | | slot_8_disabled | | - https://minecraft.wiki/w/Java_Edition_data_values#Effects For effect ID

rawTitle: TextComponent

slots: Slot[]

Slots data

Default: []

stateId: number

State ID

You SHOULD NOT edit this field since this field is for syncing state from client and server

Default: 0

type: number

Methods

click(slot: number, mouse: Button, shift?: boolean): void

Click the container slot.

Left click let you pick up all of the item in that slot.

When right-clicking on a stack of items, half the stack will be picked up and half left in the slot. If the stack is an odd number, the half left in the slot will be the smaller of the amounts

Shift left click and Shift right click do the same job is moving the item to your hotbar, inventory, and containers.

Parameters

  • slot (number) — The slot to interact
  • mouse (Button) — The mouse button
  • shift (boolean, optional) — Use Shift key

Returns

  • void

Throws

  • If the slot is exceeding the total slot

doubleClick(slot: number): void

Double click a slot. This action will collect all of the item, with the same type, in the container to a stack.

Parameters

  • slot (number)

Returns

  • void

drop(slot: number, ctrl?: boolean): void

Drop the item in the slot.

Without Ctrl button, it will only drop one item at a time.

With Ctrl, it will drop all of the item in that slot.

Parameters

  • slot (number) — The slot want to drop item
  • ctrl (boolean, optional) — Use Ctrl to drop all item

Returns

  • void

Throws

  • If the slot is exceeding the total slot

paint(button: Button): PaintingMode

Start the paint mode.

The Minecraft wiki explain this mode:

CODE
Starting from version 1.5, “painting mode” is available for use in inventory windows. It is done by picking up 
a stack of something (more than 1 item), then holding Left Mouse Button, Right Mouse Button or Middle Mouse Button 
and dragging the held stack over empty (or same type in case of right button) slots

Basically, this mode help you split the item you holding.

Left click will distribute the item. Right click just place one item in each slot.

Parameters

  • button (Button) — The mouse button

Returns

Throws

  • If the slot is exceeding the total slot

Example

CODE
// Get the `container` object from `client.getOpeningContainer` method or listen to event `openContainer`
container.click(1, Button.LeftMouse); // Take all of the item
container.paint(Button.LeftMouse) // Start the paint mode
    .select(6) // Move the cursor to slot 6, 7, 8
    .select(7)
    .select(8)
    .done(); // Confirm the paint mode

setProperty(property: number, data: number): void

Parameters

  • property (number)
  • data (number)

Returns

  • void

Static Properties

sendClickContainer: (windowId: number, stateId: number, slot: number, button: number, mode: number) => void