@zardoy/flying-squid 0.0.98 → 0.0.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -0
- package/dist/index.js +11 -6
- package/dist/lib/modules/communication.d.ts +1 -0
- package/dist/lib/modules/communication.js +6 -0
- package/dist/lib/modules/customBlockBreakTime.js +2 -0
- package/dist/lib/modules/inventory.d.ts +20 -3
- package/dist/lib/modules/inventory.js +161 -2
- package/dist/lib/modules/placeBlock.js +1 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { supportedVersions } from './lib/version';
|
|
|
3
3
|
import Command from './lib/command';
|
|
4
4
|
import { Server as ProtocolServer } from 'minecraft-protocol';
|
|
5
5
|
import { IndexedData } from 'minecraft-data';
|
|
6
|
+
import PrismarineItem from 'prismarine-item';
|
|
7
|
+
import PrismarineBlock from 'prismarine-block';
|
|
6
8
|
import './types';
|
|
7
9
|
import './modules';
|
|
8
10
|
export interface FullServer extends Server {
|
|
@@ -22,6 +24,8 @@ type Cleanup = () => void;
|
|
|
22
24
|
type MaybePromise<T> = T | Promise<T>;
|
|
23
25
|
declare global {
|
|
24
26
|
interface Server {
|
|
27
|
+
PrismarineItem: ReturnType<typeof PrismarineItem>;
|
|
28
|
+
PrismarineBlock: ReturnType<typeof PrismarineBlock>;
|
|
25
29
|
commands: Command;
|
|
26
30
|
pluginsReady: boolean;
|
|
27
31
|
_server: ProtocolServer;
|
package/dist/index.js
CHANGED
|
@@ -44,6 +44,9 @@ Object.defineProperty(exports, "supportedVersions", { enumerable: true, get: fun
|
|
|
44
44
|
const command_1 = __importDefault(require("./lib/command"));
|
|
45
45
|
const builtinModules = __importStar(require("./lib/modules"));
|
|
46
46
|
const events_1 = require("events");
|
|
47
|
+
const prismarine_item_1 = __importDefault(require("prismarine-item"));
|
|
48
|
+
const prismarine_block_1 = __importDefault(require("prismarine-block"));
|
|
49
|
+
const minecraft_data_1 = __importDefault(require("minecraft-data"));
|
|
47
50
|
require("./types"); // include Server declarations from all modules
|
|
48
51
|
require("./modules");
|
|
49
52
|
// #region RUNTIME PREPARE
|
|
@@ -82,15 +85,15 @@ class MCServer extends events_1.EventEmitter {
|
|
|
82
85
|
server.cleanupFunctions = [
|
|
83
86
|
() => this.abortController.abort()
|
|
84
87
|
];
|
|
85
|
-
const mcData =
|
|
88
|
+
const mcData = (0, minecraft_data_1.default)(options.version);
|
|
86
89
|
server.mcData = mcData;
|
|
87
90
|
if (mcData === null)
|
|
88
91
|
throw new Error(`Version ${options.version} is not supported as it doesn't have the data.`);
|
|
89
|
-
const
|
|
90
|
-
if (!version_1.supportedVersions.some(v => v.includes(
|
|
91
|
-
console.warn(`Version ${
|
|
92
|
+
const _version = mcData.version;
|
|
93
|
+
if (!version_1.supportedVersions.some(v => v.includes(_version.majorVersion))) {
|
|
94
|
+
console.warn(`Version ${_version.minecraftVersion} might not be supported.`);
|
|
92
95
|
}
|
|
93
|
-
server.supportFeature = feature => {
|
|
96
|
+
server.supportFeature = (feature) => {
|
|
94
97
|
if (feature === 'theFlattening')
|
|
95
98
|
feature = 'blockStateId';
|
|
96
99
|
if (feature === 'dimensionDataIsAvailable')
|
|
@@ -98,6 +101,8 @@ class MCServer extends events_1.EventEmitter {
|
|
|
98
101
|
return mcData.supportFeature(feature);
|
|
99
102
|
};
|
|
100
103
|
server.commands = new command_1.default({});
|
|
104
|
+
server.PrismarineItem = (0, prismarine_item_1.default)(options.version);
|
|
105
|
+
server.PrismarineBlock = (0, prismarine_block_1.default)(options.version);
|
|
101
106
|
// pass version, motd, port, max-players, online-mode
|
|
102
107
|
const oldServer = options.oldServerData;
|
|
103
108
|
server._server = oldServer?._server ?? (0, minecraft_protocol_1.createServer)({
|
|
@@ -151,7 +156,7 @@ class MCServer extends events_1.EventEmitter {
|
|
|
151
156
|
};
|
|
152
157
|
patchServer(server);
|
|
153
158
|
const promises = [];
|
|
154
|
-
const coreModules = ['utils', 'communication', 'tick', 'commands', '
|
|
159
|
+
const coreModules = ['utils', 'communication', 'tick', 'settings', 'commands', 'tabComplete'];
|
|
155
160
|
server.modules = builtinModules.builtinPlugins;
|
|
156
161
|
// Sort modules so core modules are first in specified order
|
|
157
162
|
const sortedModules = {};
|
|
@@ -56,5 +56,6 @@ declare global {
|
|
|
56
56
|
interface Player {
|
|
57
57
|
"bridge": ServerPacketBridger;
|
|
58
58
|
"writePacket": <T extends keyof ClientOnMap>(packetName: T, data: ClientOnMap[T]) => void;
|
|
59
|
+
onPacket: <T extends keyof ClientWriteMap>(packetName: T, callback: (data: ClientWriteMap[T]) => void) => (() => void);
|
|
59
60
|
}
|
|
60
61
|
}
|
|
@@ -65,6 +65,12 @@ const player = function (player, serv) {
|
|
|
65
65
|
serv.emit('error', err, { type: 'toPlayerPacket', name: packetName, data, player: player });
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
|
+
player.onPacket = (packetName, callback) => {
|
|
69
|
+
player._client.on(packetName, callback);
|
|
70
|
+
return () => {
|
|
71
|
+
player._client.off(packetName, callback);
|
|
72
|
+
};
|
|
73
|
+
};
|
|
68
74
|
player.bridge = new mc_bridge_1.ServerPacketBridger(serv.mcData.version.minecraftVersion, (packetName, data) => {
|
|
69
75
|
player.writePacket(packetName, data);
|
|
70
76
|
});
|
|
@@ -27,6 +27,8 @@ const server = (serv) => {
|
|
|
27
27
|
};
|
|
28
28
|
exports.server = server;
|
|
29
29
|
function sendBreakTimeConfig(player, serv) {
|
|
30
|
+
if (!serv.customPlayersBreakTime[player.uuid])
|
|
31
|
+
return;
|
|
30
32
|
const config = serv.customPlayersBreakTime[player.uuid];
|
|
31
33
|
const data = {
|
|
32
34
|
customBreakTime: config?.blocks ?? {},
|
|
@@ -1,19 +1,35 @@
|
|
|
1
|
-
import { Item } from 'prismarine-item';
|
|
2
|
-
import { Window } from 'prismarine-windows';
|
|
1
|
+
import { type Item } from 'prismarine-item';
|
|
2
|
+
import { type Window } from 'prismarine-windows';
|
|
3
3
|
export declare const player: (player: Player, serv: Server, { version }: Options) => void;
|
|
4
|
+
export type CustomWindow = Window & {
|
|
5
|
+
close: () => void;
|
|
6
|
+
};
|
|
7
|
+
type Post1_14Windows = 'minecraft:inventory' | 'minecraft:generic_9x1' | 'minecraft:generic_9x2' | 'minecraft:generic_9x3' | 'minecraft:generic_9x4' | 'minecraft:generic_9x5' | 'minecraft:generic_9x6' | 'minecraft:generic_3x3' | 'minecraft:crafter_3x3' | 'minecraft:anvil' | 'minecraft:beacon' | 'minecraft:blast_furnace' | 'minecraft:brewing_stand' | 'minecraft:crafting' | 'minecraft:enchantment' | 'minecraft:furnace' | 'minecraft:grindstone' | 'minecraft:hopper' | 'minecraft:lectern' | 'minecraft:loom' | 'minecraft:merchant' | 'minecraft:shulker_box' | 'minecraft:smithing' | 'minecraft:smoker' | 'minecraft:cartography' | 'minecraft:stonecutter';
|
|
8
|
+
type Pre1_14Windows = 'minecraft:inventory' | 'minecraft:chest' | 'minecraft:crafting_table' | 'minecraft:furnace' | 'minecraft:dispenser' | 'minecraft:enchanting_table' | 'minecraft:brewing_stand' | 'minecraft:container' | 'minecraft:villager' | 'minecraft:beacon' | 'minecraft:anvil' | 'minecraft:hopper' | 'minecraft:dropper' | 'minecraft:shulker_box' | 'EntityHorse';
|
|
9
|
+
interface OpenCustomWindowOptions {
|
|
10
|
+
inventoryType: Post1_14Windows | Pre1_14Windows;
|
|
11
|
+
title: string;
|
|
12
|
+
windowSlots: Record<number, Item>;
|
|
13
|
+
resultSlot?: Item;
|
|
14
|
+
noPlayerInventory?: boolean;
|
|
15
|
+
onClose?: (window: Window) => void;
|
|
16
|
+
onSlotClick?: (slot: number, oldItem: Item | null, newItem: Item | null, closeWindow: () => void) => void;
|
|
17
|
+
}
|
|
4
18
|
declare global {
|
|
5
19
|
interface Entity {
|
|
6
20
|
setEquipment: (slot: number, item: any) => void;
|
|
7
21
|
}
|
|
8
22
|
interface Player {
|
|
23
|
+
lockInventory?: boolean;
|
|
9
24
|
heldItemSlot: number;
|
|
10
25
|
heldItem: Item;
|
|
11
26
|
inventory: Window;
|
|
12
|
-
customWindow:
|
|
27
|
+
customWindow: CustomWindow | undefined;
|
|
13
28
|
"collect": (collectEntity: Entity & {
|
|
14
29
|
itemId: number;
|
|
15
30
|
damage: number;
|
|
16
31
|
}) => void;
|
|
32
|
+
openCustomWindow: (options: OpenCustomWindowOptions) => CustomWindow;
|
|
17
33
|
}
|
|
18
34
|
interface PlayerBehaviorInputMap {
|
|
19
35
|
'changeHeldItemSlot': {
|
|
@@ -24,3 +40,4 @@ declare global {
|
|
|
24
40
|
};
|
|
25
41
|
}
|
|
26
42
|
}
|
|
43
|
+
export {};
|
|
@@ -5,14 +5,128 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.player = void 0;
|
|
7
7
|
const vec3_1 = require("vec3");
|
|
8
|
-
const prismarine_item_1 = __importDefault(require("prismarine-item"));
|
|
9
8
|
const prismarine_windows_1 = __importDefault(require("prismarine-windows"));
|
|
10
9
|
const player = function (player, serv, { version }) {
|
|
11
|
-
const Item = (0, prismarine_item_1.default)(version);
|
|
12
10
|
const windows = (0, prismarine_windows_1.default)(version);
|
|
11
|
+
const Item = serv.PrismarineItem;
|
|
13
12
|
player.heldItemSlot = 0;
|
|
14
13
|
// player.heldItem = new Item(256, 1)
|
|
15
14
|
player.inventory = windows.createWindow(1, 'minecraft:inventory', 'inv', 36);
|
|
15
|
+
player.openCustomWindow = (options) => {
|
|
16
|
+
const windowInfo = windows.windows[options.inventoryType];
|
|
17
|
+
if (!windowInfo) {
|
|
18
|
+
throw new Error(`Invalid inventory type: ${options.inventoryType}`);
|
|
19
|
+
}
|
|
20
|
+
const craftSlot = windowInfo.craft;
|
|
21
|
+
const window = windows.createWindow(1, windowInfo.type, options.title);
|
|
22
|
+
// todo fix in prismarine-windows
|
|
23
|
+
window.type = windowInfo.type;
|
|
24
|
+
for (let i = 0; i < window.inventoryStart; i++) {
|
|
25
|
+
window.slots[i] = options.windowSlots[i] ?? null;
|
|
26
|
+
}
|
|
27
|
+
if (craftSlot !== undefined && craftSlot !== -1 && options.resultSlot) {
|
|
28
|
+
window.slots[craftSlot] = options.resultSlot;
|
|
29
|
+
}
|
|
30
|
+
for (let i = window.inventoryStart; i < window.inventoryEnd; i++) {
|
|
31
|
+
if (!options.noPlayerInventory) {
|
|
32
|
+
window.slots[i] = player.inventory.slots[i - window.inventoryStart + player.inventory.inventoryStart];
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
window.slots[i] = options.windowSlots[i] ?? null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (player.windowId === undefined) {
|
|
39
|
+
player.windowId = 1;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
player.windowId = player.windowId + 1;
|
|
43
|
+
}
|
|
44
|
+
player.writePacket('open_window', {
|
|
45
|
+
windowId: player.windowId,
|
|
46
|
+
inventoryType: window.type,
|
|
47
|
+
windowTitle: serv._createChatComponent(options.title).toNetworkFormat(),
|
|
48
|
+
entityId: player.id,
|
|
49
|
+
slotCount: window.slots.length,
|
|
50
|
+
useProvidedTitle: true,
|
|
51
|
+
});
|
|
52
|
+
const sendItems = () => {
|
|
53
|
+
// Sending container content
|
|
54
|
+
player.writePacket('window_items', {
|
|
55
|
+
windowId: player.windowId,
|
|
56
|
+
stateId: 1,
|
|
57
|
+
items: window.slots.map(item => Item.toNotch(item)),
|
|
58
|
+
carriedItem: { present: false }
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
sendItems();
|
|
62
|
+
const updateSlotBackInInventory = (slot, item) => {
|
|
63
|
+
if (slot < window.inventoryStart || slot > window.inventoryEnd || player.lockInventory || options.noPlayerInventory)
|
|
64
|
+
return;
|
|
65
|
+
player.inventory.updateSlot(slot - window.inventoryStart + player.inventory.inventoryStart, item);
|
|
66
|
+
};
|
|
67
|
+
let closed = false;
|
|
68
|
+
const onWindowClosed = () => {
|
|
69
|
+
if (closed)
|
|
70
|
+
return;
|
|
71
|
+
closed = true;
|
|
72
|
+
player.writePacket('window_items', {
|
|
73
|
+
windowId: 0,
|
|
74
|
+
stateId: 1,
|
|
75
|
+
items: player.inventory.slots.map(item => Item.toNotch(item)),
|
|
76
|
+
carriedItem: { present: false }
|
|
77
|
+
});
|
|
78
|
+
player.customWindow = undefined;
|
|
79
|
+
};
|
|
80
|
+
const listener = ({ windowId }) => {
|
|
81
|
+
if (windowId !== player.windowId)
|
|
82
|
+
return;
|
|
83
|
+
onWindowClosed();
|
|
84
|
+
unlisten();
|
|
85
|
+
};
|
|
86
|
+
const unlisten = player.onPacket('close_window', listener);
|
|
87
|
+
//@ts-ignore
|
|
88
|
+
window.on('updateSlot', (oldSlot, oldItem, newItem) => {
|
|
89
|
+
updateSlotBackInInventory(oldSlot, oldItem);
|
|
90
|
+
options.onSlotClick?.(oldSlot, oldItem, newItem, closeWindow);
|
|
91
|
+
});
|
|
92
|
+
const closeWindow = () => {
|
|
93
|
+
player.writePacket('close_window', {
|
|
94
|
+
windowId: player.windowId,
|
|
95
|
+
});
|
|
96
|
+
onWindowClosed();
|
|
97
|
+
};
|
|
98
|
+
window.close = closeWindow;
|
|
99
|
+
return window;
|
|
100
|
+
};
|
|
101
|
+
serv.tabComplete.add('inventoryType', () => {
|
|
102
|
+
return Object.keys(windows.windows);
|
|
103
|
+
});
|
|
104
|
+
serv.commands.add({
|
|
105
|
+
base: 'testwindow',
|
|
106
|
+
info: 'testwindow',
|
|
107
|
+
usage: '/testwindow <inventoryType>',
|
|
108
|
+
parse(string, ctx) {
|
|
109
|
+
return string.split(' ');
|
|
110
|
+
},
|
|
111
|
+
tab: [
|
|
112
|
+
'inventoryType'
|
|
113
|
+
],
|
|
114
|
+
action: (data, ctx) => {
|
|
115
|
+
const [inventoryType] = data;
|
|
116
|
+
if (!inventoryType) {
|
|
117
|
+
return 'Usage: /testwindow <inventoryType>';
|
|
118
|
+
}
|
|
119
|
+
player.openCustomWindow({
|
|
120
|
+
inventoryType: inventoryType,
|
|
121
|
+
title: 'Test Window',
|
|
122
|
+
windowSlots: new Array(52).fill(null).map((_, i) => new serv.PrismarineItem(1, 1, 0)),
|
|
123
|
+
resultSlot: new serv.PrismarineItem(serv.mcData.itemsByName.redstone_block.id, 1, 0),
|
|
124
|
+
onSlotClick: (slot, oldItem, newItem, closeWindow) => {
|
|
125
|
+
closeWindow();
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
});
|
|
16
130
|
player._client.on('held_item_slot', async ({ slotId } = {}) => {
|
|
17
131
|
const { cancelled } = await player.behavior('changeHeldItemSlot', { slot: slotId, item: player.inventory.slots[36 + slotId] });
|
|
18
132
|
if (cancelled) {
|
|
@@ -154,6 +268,15 @@ const player = function (player, serv, { version }) {
|
|
|
154
268
|
return;
|
|
155
269
|
}
|
|
156
270
|
}
|
|
271
|
+
if (!player.customWindow && player.lockInventory) {
|
|
272
|
+
player._client.write('window_items', {
|
|
273
|
+
windowId: 0,
|
|
274
|
+
stateId: 1,
|
|
275
|
+
items: player.inventory.slots.map(item => Item.toNotch(item)),
|
|
276
|
+
carriedItem: { present: false }
|
|
277
|
+
});
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
157
280
|
const window = (player.customWindow || player.inventory);
|
|
158
281
|
const formAcceptClickData = (index) => {
|
|
159
282
|
return {
|
|
@@ -256,3 +379,39 @@ const player = function (player, serv, { version }) {
|
|
|
256
379
|
};
|
|
257
380
|
};
|
|
258
381
|
exports.player = player;
|
|
382
|
+
const allWindowTypes = [
|
|
383
|
+
'minecraft:inventory',
|
|
384
|
+
'minecraft:generic_9x1',
|
|
385
|
+
'minecraft:generic_9x2',
|
|
386
|
+
'minecraft:generic_9x3',
|
|
387
|
+
'minecraft:generic_9x4',
|
|
388
|
+
'minecraft:generic_9x5',
|
|
389
|
+
'minecraft:generic_9x6',
|
|
390
|
+
'minecraft:generic_3x3',
|
|
391
|
+
'minecraft:crafter_3x3',
|
|
392
|
+
'minecraft:anvil',
|
|
393
|
+
'minecraft:beacon',
|
|
394
|
+
'minecraft:blast_furnace',
|
|
395
|
+
'minecraft:brewing_stand',
|
|
396
|
+
'minecraft:crafting',
|
|
397
|
+
'minecraft:enchantment',
|
|
398
|
+
'minecraft:furnace',
|
|
399
|
+
'minecraft:grindstone',
|
|
400
|
+
'minecraft:hopper',
|
|
401
|
+
'minecraft:lectern',
|
|
402
|
+
'minecraft:loom',
|
|
403
|
+
'minecraft:merchant',
|
|
404
|
+
'minecraft:shulker_box',
|
|
405
|
+
'minecraft:smithing',
|
|
406
|
+
'minecraft:smoker',
|
|
407
|
+
'minecraft:cartography',
|
|
408
|
+
'minecraft:stonecutter',
|
|
409
|
+
'minecraft:chest',
|
|
410
|
+
'minecraft:crafting_table',
|
|
411
|
+
'minecraft:dispenser',
|
|
412
|
+
'minecraft:enchanting_table',
|
|
413
|
+
'minecraft:container',
|
|
414
|
+
'minecraft:villager',
|
|
415
|
+
'minecraft:dropper',
|
|
416
|
+
'EntityHorse',
|
|
417
|
+
];
|
|
@@ -105,7 +105,6 @@ const server = (serv, { version }) => {
|
|
|
105
105
|
}
|
|
106
106
|
blockInteractHandler.set(block.id, handler);
|
|
107
107
|
};
|
|
108
|
-
const PrismarineBlock = require('prismarine-block')(version);
|
|
109
108
|
const { blocksArray: blocks } = serv.mcData;
|
|
110
109
|
// todo use map for speed
|
|
111
110
|
// doors/gates opening/closing
|
|
@@ -121,7 +120,7 @@ const server = (serv, { version }) => {
|
|
|
121
120
|
...block.getProperties(),
|
|
122
121
|
};
|
|
123
122
|
props.open = !props.open;
|
|
124
|
-
const newBlock = PrismarineBlock.fromProperties(block.type, props, block.biome.id);
|
|
123
|
+
const newBlock = serv.PrismarineBlock.fromProperties(block.type, props, block.biome.id);
|
|
125
124
|
player.setBlock(block.position, newBlock.stateId);
|
|
126
125
|
};
|
|
127
126
|
toggleDoorState(block.position);
|