Перейти к основному содержанию

BackpackAPI

BackpackAPI — a library that allows you to create backpacks.

Downloads

VersionChangelogReleased at
v1010.11.20
v916.10.20
v815.05.20
v724.04.20
v6Added support for store id of container inside extra data of item21.04.20
v5Fixed bugs, code optimization16.10.19
v4Fixed bugs11.09.19
v3New properties - items, title10.09.19
v1First release09.03.18

Terms of Use

  • You are not allowed to distribute this library on any other sites without a link to the official community
  • You are not allowed to change the code of the library
  • You are not allowed to copy the code in other libraries or mods

By using this library, you automatically agree to these rules

Documentation

For registering backpack use method register from BackpackRegistry, import it from library

IMPORT("BackpackAPI");

IDRegistry.genItemID("backpackTest");
Item.createItem("backpackTest", "Test Backpack", {
name: "backpackMiners", meta: 0
}, { stack: 1 });

BackpackRegistry.register(ItemID.backpackTest, {
title: "My Backpack",
slots: 80,
slotsCenter: true,
inRow: 10,
items: ["^ore.+", "^ingot.+", 1, {
id: 345, data: "^[1-3]$"
}]
});

First argument - item id, when clicked will open the backpack interface for item with this id

  • title — title of the backpack window
  • slots — number of slots in the backpack
  • inRow — number of slots in a row
  • slotsCenter — center the slots in the width
  • kind — defines the way to store the unique backpack id. Can have values BackpackKind.EXTRA and BackpackKind.META. If the first value is set, the id will be stored in the __backpack_id extra, the second - in the item metadata
  • items — array of items that can be placed in the backpack. The regular expressions are described, the item id or object with id and data (both can be specified by regular expression)

In object you can call method isValidItem(id, data, count);

If it returned true, the item will be placed in the slot. If it is not, the standard will be set, which allows to move all items described in items array, except other backpacks. In this example, you can place only stone:

BackpackRegistry.register(ItemID.backpackTest, {
slots: 20,
isValidItem: function (id, data, count) {
return id === 1;
},
});

For backpacks you can set custom interfaces, but in this case all fields described above will be ignored.

let gui = new UI.StandartWindow({
standart: {
header: {
text: {
text: 'Custom Gui',
},
},
inventory: {
standart: true,
},
background: {
standart: true,
},
},
drawing: [],
elements: {},
});

IDRegistry.genItemID('backpackTest');
Item.createItem('backpackTest', 'Test Backpack', {
name: 'backpackMiners', meta: 0
}, { stack: 1 });

BackpackRegistry.register(ItemID.backpackTest, {
gui: gui,
});