Skip to content

Commit 9433cd4

Browse files
author
Simeon Kummer
committed
Fix cartography table for newer MC versions
- Add 'minecraft:generic' to allowed window types for 1.19+ - Use moveSlotItem instead of transfer for put operations - Fix chunk packet generation for newer versions (bitMap computing)
1 parent cbc7518 commit 9433cd4

File tree

2 files changed

+38
-22
lines changed

2 files changed

+38
-22
lines changed

lib/plugins/cartography_table.js

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const assert = require('assert')
33
module.exports = inject
44

55
function inject (bot) {
6-
const allowedWindowTypes = ['minecraft:cartography']
6+
const allowedWindowTypes = ['minecraft:cartography', 'minecraft:generic']
77

88
function matchWindowType (window) {
99
for (const type of allowedWindowTypes) {
@@ -18,14 +18,18 @@ function inject (bot) {
1818
throw new Error('This is not a cartographyTable-like window')
1919
}
2020

21+
const mapSlot = 0
22+
const modifierSlot = 1
23+
const outputSlot = 2
24+
2125
cartographyTable.takeMap = takeMap
2226
cartographyTable.takeModifier = takeModifier
2327
cartographyTable.takeOutput = takeOutput
2428
cartographyTable.putMap = putMap
2529
cartographyTable.putModifier = putModifier
26-
cartographyTable.mapItem = function () { return this.slots[0] }
27-
cartographyTable.modifierItem = function () { return this.slots[1] }
28-
cartographyTable.outputItem = function () { return this.slots[2] }
30+
cartographyTable.mapItem = function () { return this.slots[mapSlot] }
31+
cartographyTable.modifierItem = function () { return this.slots[modifierSlot] }
32+
cartographyTable.outputItem = function () { return this.slots[outputSlot] }
2933

3034
return cartographyTable
3135

@@ -47,26 +51,31 @@ function inject (bot) {
4751
return takeSomething(cartographyTable.outputItem())
4852
}
4953

50-
async function putSomething (destSlot, itemType, metadata, count) {
51-
const options = {
52-
window: cartographyTable,
53-
itemType,
54-
metadata,
55-
count,
56-
sourceStart: cartographyTable.inventoryStart,
57-
sourceEnd: cartographyTable.inventoryEnd,
58-
destStart: destSlot,
59-
destEnd: destSlot + 1
54+
async function putMap (itemType, metadata, count) {
55+
const sourceSlot = findItemInInventory(itemType, metadata)
56+
if (sourceSlot === null) {
57+
throw new Error(`Cannot find item ${itemType} in inventory`)
6058
}
61-
await bot.transfer(options)
59+
await bot.moveSlotItem(sourceSlot, mapSlot)
6260
}
6361

64-
async function putMap (itemType, metadata, count) {
65-
await putSomething(0, itemType, metadata, count)
62+
async function putModifier (itemType, metadata, count) {
63+
const sourceSlot = findItemInInventory(itemType, metadata)
64+
if (sourceSlot === null) {
65+
throw new Error(`Cannot find item ${itemType} in inventory`)
66+
}
67+
await bot.moveSlotItem(sourceSlot, modifierSlot)
6668
}
6769

68-
async function putModifier (itemType, metadata, count) {
69-
await putSomething(1, itemType, metadata, count)
70+
function findItemInInventory (itemType, metadata) {
71+
const inventory = bot.inventory
72+
for (let i = inventory.inventoryStart; i < inventory.inventoryEnd; i++) {
73+
const item = inventory.slots[i]
74+
if (item && item.type === itemType && (metadata === null || item.metadata === metadata)) {
75+
return i
76+
}
77+
}
78+
return null
7079
}
7180
}
7281

test/internalTest.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,28 @@ for (const supportedVersion of mineflayer.testedVersions) {
2222
: JSON.stringify({ text })
2323
}
2424

25-
function generateChunkPacket (chunk) {
25+
function generateChunkPacket (chunk, version) {
2626
const lights = chunk.dumpLight()
27+
const biomes = chunk.dumpBiomes?.()
28+
let bitMap = chunk.getMask()
29+
if (bitMap === undefined && chunk.numSections) {
30+
for (let i = 0; i < chunk.numSections; i++) {
31+
bitMap |= (1 << i)
32+
}
33+
}
2734
return {
2835
x: 0,
2936
z: 0,
3037
groundUp: true,
31-
biomes: chunk.dumpBiomes !== undefined ? chunk.dumpBiomes() : undefined,
38+
biomes: biomes !== undefined ? biomes : undefined,
3239
heightmaps: {
3340
type: 'compound',
3441
name: '',
3542
value: {
3643
MOTION_BLOCKING: { type: 'longArray', value: new Array(36).fill([0, 0]) }
3744
}
3845
}, // send fake heightmap
39-
bitMap: chunk.getMask(),
46+
bitMap,
4047
chunkData: chunk.dump(),
4148
blockEntities: [],
4249
trustEdges: false,

0 commit comments

Comments
 (0)