Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@
- [furnace.outputItem()](#furnaceoutputitem)
- [furnace.fuel](#furnacefuel)
- [furnace.progress](#furnaceprogress)
- [mineflayer.CartographyTable](#mineflayercartographytable)
- [cartographyTable.takeMap()](#cartographytabletakemap)
- [cartographyTable.takeModifier()](#cartographytabletakemodifier)
- [cartographyTable.takeOutput()](#cartographytabletakeoutput)
- [cartographyTable.putMap(itemType, metadata, count)](#cartographytableputmapitemtype-metadata-count)
- [cartographyTable.putModifier(itemType, metadata, count)](#cartographytableputmodifieritemtype-metadata-count)
- [cartographyTable.mapItem()](#cartographytablemapitem)
- [cartographyTable.modifierItem()](#cartographytablemodifieritem)
- [cartographyTable.outputItem()](#cartographytableoutputitem)
- [mineflayer.EnchantmentTable](#mineflayerenchantmenttable)
- [enchantmentTable "ready"](#enchantmenttable-ready)
- [enchantmentTable.targetItem()](#enchantmenttabletargetitem)
Expand Down Expand Up @@ -325,6 +334,7 @@
- [bot.openContainer(containerBlock or containerEntity, direction?, cursorPos?)](#botopencontainercontainerblock-or-containerentity-direction-cursorpos)
- [bot.openChest(chestBlock or minecartchestEntity, direction?, cursorPos?)](#botopenchestchestblock-or-minecartchestentity-direction-cursorpos)
- [bot.openFurnace(furnaceBlock)](#botopenfurnacefurnaceblock)
- [bot.openCartographyTable(cartographyTableBlock)](#botopencartographytablecartographytableblock)
- [bot.openDispenser(dispenserBlock)](#botopendispenserdispenserblock)
- [bot.openEnchantmentTable(enchantmentTableBlock)](#botopenenchantmenttableenchantmenttableblock)
- [bot.openAnvil(anvilBlock)](#botopenanvilanvilblock)
Expand Down Expand Up @@ -543,6 +553,47 @@ How much fuel is left between 0 and 1.

How much cooked the input is between 0 and 1.

### mineflayer.CartographyTable

Extends windows.Window for cartography table
See `bot.openCartographyTable(cartographyTableBlock)`.

#### cartographyTable.takeMap()

This function returns a `Promise`, with `item` as its argument upon completion.


#### cartographyTable.takeModifier()

This function returns a `Promise`, with `item` as its argument upon completion.


#### cartographyTable.takeOutput()

This function returns a `Promise`, with `item` as its argument upon completion.


#### cartographyTable.putMap(itemType, metadata, count)

This function returns a `Promise`, with `void` as its argument upon completion.

#### cartographyTable.putModifier(itemType, metadata, count)

This function returns a `Promise`, with `void` as its argument upon completion.

#### cartographyTable.mapItem()

Returns `Item` instance which is the filled map being affected.

#### cartographyTable.modifierItem()

Returns `Item` instance which is the item being used to effect the filled map, e.g. Glass Pane, paper, empty map, etc.

#### cartographyTable.outputItem()

Returns `Item` instance which is the output (aka the modified map).


### mineflayer.EnchantmentTable

Extends windows.Window for enchantment tables
Expand Down Expand Up @@ -2083,6 +2134,10 @@ Deprecated. Same as `openContainer`

Returns a promise on a `Furnace` instance which represents the furnace you are opening.

#### bot.openCartographyTable(cartographyTableBlock)

Returns a promise on a `CartographyTable` instance which represents the cartography table you are opening.

#### bot.openDispenser(dispenserBlock)

Deprecated. Same as `openContainer`
Expand Down
1 change: 1 addition & 0 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const plugins = {
explosion: require('./plugins/explosion'),
fishing: require('./plugins/fishing'),
furnace: require('./plugins/furnace'),
cartography_table: require('./plugins/cartography_table'),
game: require('./plugins/game'),
health: require('./plugins/health'),
inventory: require('./plugins/inventory'),
Expand Down
75 changes: 75 additions & 0 deletions lib/plugins/cartography_table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const assert = require('assert')

module.exports = inject

function inject(bot) {
const allowedWindowTypes = ['minecraft:cartography']

function matchWindowType(window) {
for (const type of allowedWindowTypes) {
if (window.type.startsWith(type)) return true
}
return false
}

async function openCartographyTable(cartographyTableBlock) {
const cartographyTable = await bot.openBlock(cartographyTableBlock)
if (!matchWindowType(cartographyTable)) {
throw new Error('This is not a cartographyTable-like window')
}

cartographyTable.takeMap = takeMap
cartographyTable.takeModifier = takeModifier
cartographyTable.takeOutput = takeOutput
cartographyTable.putMap = putMap
cartographyTable.putModifier = putModifier
cartographyTable.mapItem = function () { return this.slots[0] }
cartographyTable.modifierItem = function () { return this.slots[1] }
cartographyTable.outputItem = function () { return this.slots[2] }

return cartographyTable

async function takeSomething(item) {
assert.ok(item)
await bot.putAway(item.slot)
return item
}

async function takeMap() {
return takeSomething(cartographyTable.mapItem())
}

async function takeModifier() {
return takeSomething(cartographyTable.modifierItem())
}

async function takeOutput() {
return takeSomething(cartographyTable.outputItem())
}

async function putSomething(destSlot, itemType, metadata, count) {
const options = {
window: cartographyTable,
itemType,
metadata,
count,
sourceStart: cartographyTable.inventoryStart,
sourceEnd: cartographyTable.inventoryEnd,
destStart: destSlot,
destEnd: destSlot + 1
}
await bot.transfer(options)
}

async function putMap(itemType, metadata, count) {
await putSomething(0, itemType, metadata, count)
}

async function putModifier(itemType, metadata, count) {
await putSomething(1, itemType, metadata, count)
}
}

bot.openCartographyTable = openCartographyTable

}
Loading