Skip to content

Drawer Manipulation

This allows you to add and remove items from a drawer

INFO

Contents of this page are from the FTB docs.

Adding Items

Add

To request to add items to a drawer, send a script event with the id ftb_sd:add_item_v2 as JSON with the following data:

NameTypeDescription
dimIdstringThe dimension ID of the drawer
blockLocationVector3The location as of the drawer block
itemTypeIdstringThe item Id of the item to add
itemAmountnumberThe amount of the item to add (Not limited to 64)
slotsArray of Drawer SlotsOptional, the slots to add the item to, if not specified it will try to add to all drawer slots
feedbackIdstringOptional, the id of the feedback event to send when the item is added

Response

After items are added, a script event with the id ftb_sd:add_item_status_v2 responds with the data expect itemAmount is the number of items not added

Removing Items

Remove

To request to remove items to a drawer, send a script event with the id ftb_sd:remove_item_v2 as JSON with the following data:

NameTypeDescription
dimIdstringThe dimension ID of the drawer
blockLocationVector3The location as of the drawer block
itemTypeIdstringThe item Id of the item to remove
itemAmountnumberThe amount of the item to remove (Not limited to 64)
slotsArray of Drawer SlotsOptional, the slots to remove the item to, if not specified it will try to add to all drawer slots
feedbackIdstringOptional, the id of the feedback event to send when the item is removed

Response

After items are removed, a script event with the id ftb_sd:add_item_status_v2 responds with the data expect: itemAmount is the number of items not removed.

Status

Remove

To get the number of items in a drawer ftb_sd:status_v2 as JSON with the following data:

NameTypeDescription
dimIdstringThe dimension ID of the drawer
blockLocationVector3The location as of the drawer block
slotsArray of Drawer SlotsOptional, the slots to add the item to, if not specified it will try to add to all drawer slots
feedbackIdstringThe id of the feedback event to send when the item is added

Response

The status is returned with ftb_sd:status_status_v2

with the following data:

NameTypeDescription
dimIdstringThe dimension ID of the drawer
blockLocationVector3The location as of the drawer block
feedbackIdstringThe id of the feedback event
slotInfoMap of Drawer Slots to Slot InfoA map of the slots and their item info, where the key is the slot and the value is an object with amount and itemTypeId

Drawer Slots

Name
bottom
top

Slot Info

NameTypeDescription
amountnumberThe amount of the item to remove (Not limited to 64)
itemTypeIdstringThe item Id of the item to add

Code Example

ts
export enum DrawerSlot {
  BOTTOM,
  TOP,
}

export interface ModifyItem {
  dimId: string;
  blockLocation: Vector3;
  itemTypeId: string;
  itemAmount: number;
  slots?: DrawerSlot[];
  feedbackId?: string;
}

export interface StatusRequest {
  dimId: string;
  blockLocation: Vector3;
  slots?: DrawerSlot[];
  feedbackId: string;
}

export interface StatusResult {
  dimId: string;
  blockLocation: Vector3;
  feedbackId: string;
  slotInfo: Map<DrawerSlot, SlotInfo>;
}

export interface SlotInfo {
  amount: number;
  itemTypeId: string;
}

function addItem(addItem: ModifyItem): void {
  system.sendScriptEvent("ftb_sd:add_item_v2", JSON.stringify(addItem));
}

function removeItem(removeItem: ModifyItem): void {
  system.sendScriptEvent("ftb_sd:remove_item_v2", JSON.stringify(removeItem));
}

system.afterEvents.scriptEventReceive.subscribe((event) => {
  if (event?.id === "ftb_sd:add_item_status_v2") {
    const addItem = JSON.parse(event.data) as ModifyItem;
    // do something with the addItem response
    return;
  }

  if (event?.id === "ftb_sd:remove_item_status_v2") {
    const removeItem = JSON.parse(event.data) as ModifyItem;
    // do something with the removeItem response
    return;
  }

  if (event?.id === "ftb_sd:status_status_v2") {
    const result = JSON.parse(event.data) as StatusResult;
    // do something with the status result
    return;
  }
});
js
function addItem(addItem) {
  system.sendScriptEvent("ftb_sd:add_item_v2", JSON.stringify(addItem));
}

function removeItem(removeItem) {
  system.sendScriptEvent("ftb_sd:remove_item_v2", JSON.stringify(removeItem));
}

system.afterEvents.scriptEventReceive.subscribe((event) => {
  if (event?.id === "ftb_sd:add_item_status_v2") {
    const addItem = JSON.parse(event.data);
    // do something with the addItem response
    return;
  }

  if (event?.id === "ftb_sd:remove_item_status_v2") {
    const removeItem = JSON.parse(event.data);
    // do something with the removeItem response
    return;
  }

  if (event?.id === "ftb_sd:status_status_v2") {
    const result = JSON.parse(event.data);
    // do something with the status result
    return;
  }
});

Not associated with or approved by Mojang Studios or Microsoft