@zardoy/flying-squid 0.0.91 → 0.0.93
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/config/default-settings.json +11 -9
- package/dist/lib/behavior.d.ts +21 -1
- package/dist/lib/behavior.js +29 -17
- package/dist/lib/modules/animations.d.ts +5 -0
- package/dist/lib/modules/animations.js +7 -5
- package/dist/lib/modules/behavior.d.ts +6 -1
- package/dist/lib/modules/blockUpdates.js +3 -1
- package/dist/lib/modules/blocks.d.ts +15 -0
- package/dist/lib/modules/chat.d.ts +74 -29
- package/dist/lib/modules/chat.js +87 -13
- package/dist/lib/modules/chest.js +1 -1
- package/dist/lib/modules/crafting.js +1 -1
- package/dist/lib/modules/customBlockBreakTime.d.ts +1 -0
- package/dist/lib/modules/customBlockBreakTime.js +1 -1
- package/dist/lib/modules/database.js +0 -4
- package/dist/lib/modules/digging.d.ts +42 -0
- package/dist/lib/modules/digging.js +26 -17
- package/dist/lib/modules/effects.d.ts +1 -1
- package/dist/lib/modules/effects.js +7 -5
- package/dist/lib/modules/header.js +9 -5
- package/dist/lib/modules/inventory.d.ts +18 -3
- package/dist/lib/modules/inventory.js +6 -1
- package/dist/lib/modules/logout.js +2 -1
- package/dist/lib/modules/particle.js +7 -1
- package/dist/lib/modules/placeBlock.d.ts +27 -1
- package/dist/lib/modules/placeBlock.js +30 -2
- package/dist/lib/modules/playerLogin.js +37 -24
- package/dist/lib/modules/pvp.d.ts +13 -0
- package/dist/lib/modules/pvp.js +4 -0
- package/dist/lib/modules/respawn.d.ts +8 -0
- package/dist/lib/modules/safeZones.d.ts +2 -2
- package/dist/lib/modules/safeZones.js +129 -50
- package/dist/lib/modules/sound.js +35 -13
- package/dist/lib/modules/spawn.js +25 -48
- package/dist/lib/modules/updatePositions.d.ts +18 -0
- package/dist/lib/modules/updatePositions.js +22 -7
- package/dist/lib/modules/useItem.js +2 -2
- package/dist/lib/modules/world.d.ts +10 -1
- package/dist/lib/modules/world.js +1 -0
- package/dist/modules.d.ts +5 -1
- package/package.json +1 -1
|
@@ -7,8 +7,11 @@ const vec3_1 = require("vec3");
|
|
|
7
7
|
// Also includes anti-cheat features for block collision and movement speed.
|
|
8
8
|
const THRESHOLD = 0.5;
|
|
9
9
|
const PLAYER_SIZE = new vec3_1.Vec3(0.6, 1.8, 0.6); // Standard Minecraft player hitbox
|
|
10
|
-
|
|
11
|
-
const
|
|
10
|
+
// Vanilla-like movement validation constants (from ServerGamePacketListenerImpl.java)
|
|
11
|
+
const VANILLA_SPEED_LIMIT_NORMAL = 0.3 / 1.69; // Normal movement limit (squared distance)
|
|
12
|
+
const VANILLA_SPEED_LIMIT_FLYING = 0.8 / 1.69; // Elytra/flying limit (squared distance)
|
|
13
|
+
const KNOCKBACK_VELOCITY = 8; // From pvp.ts KNOCKBACK_MULTIPLIER
|
|
14
|
+
const KNOCKBACK_GRACE_PERIOD = 2000; // Allow higher speed for 2 seconds after damage
|
|
12
15
|
const server = (serv) => {
|
|
13
16
|
serv.safeZones ??= [];
|
|
14
17
|
serv.resetSafeZones = () => {
|
|
@@ -21,44 +24,83 @@ const server = (serv) => {
|
|
|
21
24
|
};
|
|
22
25
|
};
|
|
23
26
|
exports.server = server;
|
|
24
|
-
const player = (player, serv, { basePositionAntiCheat = false,
|
|
27
|
+
const player = (player, serv, { basePositionAntiCheat = false, positionAntiCheatNotifyPlayer = false }) => {
|
|
25
28
|
let lastMovementTime = Date.now();
|
|
26
|
-
let
|
|
29
|
+
let packetCount = 0; // Track move packets per tick (vanilla approach)
|
|
30
|
+
serv.on('tick', (deltaTime, tickCount) => {
|
|
31
|
+
packetCount = 0;
|
|
32
|
+
});
|
|
27
33
|
player.onReady.then(() => {
|
|
28
|
-
|
|
34
|
+
player.knownPosition ??= player.position.clone();
|
|
29
35
|
});
|
|
30
36
|
// Enforce safe areas on client-provided movement
|
|
31
37
|
player.on('move_cancel', ({ position, onGround, teleport }, cancel) => {
|
|
38
|
+
const lastPosition = player.knownPosition;
|
|
32
39
|
// Allow server teleports/moves to pass through
|
|
33
|
-
|
|
40
|
+
const currentTime = Date.now();
|
|
41
|
+
// Check if this is a response to our teleport
|
|
42
|
+
if (player.pendingTeleport) {
|
|
43
|
+
if (position.distanceTo(player.pendingTeleport) < 0.1) {
|
|
44
|
+
lastMovementTime = currentTime;
|
|
45
|
+
// player.knownPosition = position.clone()
|
|
46
|
+
player.pendingTeleport = null;
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// Allow server teleports
|
|
51
|
+
if (teleport) {
|
|
52
|
+
lastMovementTime = currentTime;
|
|
34
53
|
return;
|
|
54
|
+
}
|
|
55
|
+
const deltaTime = (currentTime - lastMovementTime) / 1000; // Convert to seconds
|
|
56
|
+
lastMovementTime = currentTime;
|
|
35
57
|
// Anti-cheat: Block collision detection
|
|
36
|
-
if (basePositionAntiCheat && isPlayerInsideBlock(player, serv, position)) {
|
|
58
|
+
if (basePositionAntiCheat && isPlayerInsideBlock(player, serv, position) && lastPosition) {
|
|
37
59
|
cancel(false);
|
|
38
|
-
if (
|
|
39
|
-
player.chat(`
|
|
60
|
+
if (positionAntiCheatNotifyPlayer) {
|
|
61
|
+
player.chat(`[safeZones] Block collision detected. Teleporting to safe position.`);
|
|
40
62
|
}
|
|
41
|
-
player.teleport(findSafePosition(player, serv, position));
|
|
63
|
+
player.teleport(isPlayerInsideBlock(player, serv, lastPosition) ? lastPosition : findSafePosition(player, serv, position));
|
|
42
64
|
return;
|
|
43
65
|
}
|
|
44
|
-
// Anti-cheat: Movement speed limit
|
|
45
|
-
const currentTime = Date.now();
|
|
46
|
-
const deltaTime = (currentTime - lastMovementTime) / 1000; // Convert to seconds
|
|
66
|
+
// Anti-cheat: Movement speed limit (vanilla-like approach)
|
|
47
67
|
if (basePositionAntiCheat && lastPosition && !teleport) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
68
|
+
packetCount++;
|
|
69
|
+
// Limit packet count per tick like vanilla (max 5 meaningful packets)
|
|
70
|
+
if (packetCount > 5) {
|
|
71
|
+
packetCount = 1;
|
|
72
|
+
}
|
|
73
|
+
const speedCheck = validateMovementSpeed(player, lastPosition, position, packetCount);
|
|
74
|
+
// Add debug fields to player
|
|
75
|
+
player['debugMaxVelocity'] = speedCheck.distanceSquared;
|
|
76
|
+
player['debugVelocityAllowanceMax'] = speedCheck.speedLimit;
|
|
77
|
+
player['debugVelocityDiff'] = speedCheck.distanceSquared - speedCheck.speedLimit;
|
|
78
|
+
player['debugExcessMovement'] = speedCheck.distanceSquared - speedCheck.currentVelocitySquared;
|
|
79
|
+
player['debugIsValid'] = speedCheck.isValid;
|
|
80
|
+
player['debugPacketCount'] = packetCount;
|
|
81
|
+
// Debug output for all movements (temporary)
|
|
82
|
+
// if (positionAntiCheatNotifyPlayer && speedCheck.distanceSquared > 0.001) {
|
|
83
|
+
// player.chat(
|
|
84
|
+
// `[DEBUG] distance²=${speedCheck.distanceSquared.toFixed(3)}, ` +
|
|
85
|
+
// `limit=${speedCheck.speedLimit.toFixed(3)}, ` +
|
|
86
|
+
// `excess=${player['debugExcessMovement'].toFixed(3)}, ` +
|
|
87
|
+
// `valid=${speedCheck.isValid}, packets=${packetCount}`
|
|
88
|
+
// )
|
|
89
|
+
// }
|
|
90
|
+
if (!speedCheck.isValid) {
|
|
91
|
+
if (positionAntiCheatNotifyPlayer) {
|
|
92
|
+
player.chat(`[safeZones] ${speedCheck.reason} ` +
|
|
93
|
+
`(distance²=${speedCheck.distanceSquared.toFixed(2)}, ` +
|
|
94
|
+
`limit=${speedCheck.speedLimit.toFixed(2)}, ` +
|
|
95
|
+
`velocity²=${speedCheck.currentVelocitySquared.toFixed(2)}, ` +
|
|
96
|
+
`excess=${player['debugExcessMovement'].toFixed(2)})`);
|
|
53
97
|
}
|
|
54
98
|
cancel(false);
|
|
55
99
|
player.teleport(lastPosition);
|
|
56
100
|
return;
|
|
57
101
|
}
|
|
58
102
|
}
|
|
59
|
-
//
|
|
60
|
-
lastMovementTime = currentTime;
|
|
61
|
-
lastPosition = position.clone();
|
|
103
|
+
// lastPosition = position.clone()
|
|
62
104
|
// Safe zones enforcement (original logic)
|
|
63
105
|
const zones = serv.safeZones ?? [];
|
|
64
106
|
if (zones.length === 0)
|
|
@@ -83,8 +125,8 @@ const player = (player, serv, { basePositionAntiCheat = false, logToChatPosition
|
|
|
83
125
|
// Otherwise, clamp back inside from direction of attempted position
|
|
84
126
|
const corrected = clampToAABBFromDirection(position, zone);
|
|
85
127
|
// Prevent default cancel handling and perform corrective teleport ourselves
|
|
86
|
-
if (
|
|
87
|
-
player.chat(`
|
|
128
|
+
if (positionAntiCheatNotifyPlayer) {
|
|
129
|
+
player.chat(`[safeZones] Out of bounds. Teleporting to safe position.`);
|
|
88
130
|
}
|
|
89
131
|
cancel(false);
|
|
90
132
|
player.teleport(corrected);
|
|
@@ -94,19 +136,18 @@ exports.player = player;
|
|
|
94
136
|
// Anti-cheat helper functions
|
|
95
137
|
function isPlayerInsideBlock(player, serv, position) {
|
|
96
138
|
const blocks = serv.mcData.blocksByStateId;
|
|
97
|
-
const
|
|
98
|
-
const chunk = chunks[position.x >> 4][position.z >> 4];
|
|
139
|
+
const chunk = player.world.getLoadedColumnAt(position);
|
|
99
140
|
if (!chunk)
|
|
100
141
|
return false;
|
|
101
|
-
//
|
|
142
|
+
// Player hitbox is 0.6 x 1.8 x 0.6, so check the two blocks that could contain the player
|
|
143
|
+
// Floor the position to get the base block coordinates
|
|
144
|
+
const baseX = Math.floor(position.x);
|
|
145
|
+
const baseY = Math.floor(position.y);
|
|
146
|
+
const baseZ = Math.floor(position.z);
|
|
147
|
+
// Check the two blocks: base block and the block above (since player height is 1.8)
|
|
102
148
|
const checkPositions = [
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
position.offset(-PLAYER_SIZE.x / 2, 0, PLAYER_SIZE.z / 2), // Top-left corner
|
|
106
|
-
position.offset(PLAYER_SIZE.x / 2, 0, -PLAYER_SIZE.z / 2), // Bottom-right corner
|
|
107
|
-
position.offset(-PLAYER_SIZE.x / 2, 0, -PLAYER_SIZE.z / 2), // Bottom-left corner
|
|
108
|
-
position.offset(0, PLAYER_SIZE.y / 2, 0), // Top center
|
|
109
|
-
position.offset(0, PLAYER_SIZE.y, 0) // Head position
|
|
149
|
+
new vec3_1.Vec3(baseX & 15, baseY, baseZ & 15), // Base block (feet level)
|
|
150
|
+
new vec3_1.Vec3(baseX & 15, baseY + 1, baseZ & 15) // Block above (head level)
|
|
110
151
|
];
|
|
111
152
|
for (const checkPos of checkPositions) {
|
|
112
153
|
try {
|
|
@@ -123,28 +164,66 @@ function isPlayerInsideBlock(player, serv, position) {
|
|
|
123
164
|
}
|
|
124
165
|
return false;
|
|
125
166
|
}
|
|
126
|
-
function
|
|
127
|
-
|
|
128
|
-
|
|
167
|
+
function validateMovementSpeed(player, lastPosition, newPosition, packetCount) {
|
|
168
|
+
// Calculate movement delta (like vanilla)
|
|
169
|
+
const deltaX = newPosition.x - lastPosition.x;
|
|
170
|
+
const deltaY = newPosition.y - lastPosition.y;
|
|
171
|
+
const deltaZ = newPosition.z - lastPosition.z;
|
|
172
|
+
// Calculate squared distance moved (vanilla approach for efficiency)
|
|
173
|
+
const distanceSquared = deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
|
|
174
|
+
// Get player's current velocity squared (would be from entity.getDeltaMovement().lengthSqr() in vanilla)
|
|
175
|
+
// Since we don't track this exactly, we'll use a reasonable estimate
|
|
176
|
+
// Vanilla subtracts current velocity from distance to allow for momentum
|
|
177
|
+
// We'll use a moderate estimate to allow for normal sprinting movement
|
|
178
|
+
const estimatedVelocitySquared = Math.min(distanceSquared * 0.6, 50); // Allow some momentum, capped
|
|
179
|
+
// Determine speed limit based on player state
|
|
180
|
+
let speedLimit = VANILLA_SPEED_LIMIT_NORMAL;
|
|
181
|
+
let mode = 'walking';
|
|
182
|
+
// Assume player is always sprinting (as requested) - increases speed by ~30%
|
|
183
|
+
// Sprinting in vanilla increases movement by 1.3x, so squared distance by 1.69x
|
|
184
|
+
speedLimit *= 1.69; // 1.3^2 for sprinting
|
|
185
|
+
mode = 'sprinting';
|
|
186
|
+
// Check if player is flying/creative (higher limit)
|
|
187
|
+
if (player.gameMode === 1 || player.gameMode === 3 || player.flying) {
|
|
188
|
+
speedLimit = VANILLA_SPEED_LIMIT_FLYING * 1.69; // Also apply sprinting to creative
|
|
189
|
+
mode = 'creative/flying+sprint';
|
|
190
|
+
}
|
|
191
|
+
// Apply speed effect multiplier if present (effect ID 1 = speed)
|
|
129
192
|
if (player.effects?.[1]) {
|
|
130
193
|
const amplifier = player.effects[1].amplifier || 0;
|
|
131
|
-
|
|
194
|
+
const speedMultiplier = 1 + (amplifier + 1) * 0.2;
|
|
195
|
+
speedLimit *= speedMultiplier * speedMultiplier; // Square it since we're comparing squared distances
|
|
196
|
+
mode = `speed ${amplifier}`;
|
|
132
197
|
}
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
|
|
198
|
+
// Check if player was recently damaged (allow higher speed for knockback)
|
|
199
|
+
const now = Date.now();
|
|
200
|
+
const lastDamageTime = player.lastDamageTime || 0;
|
|
201
|
+
if (now - lastDamageTime < KNOCKBACK_GRACE_PERIOD) {
|
|
202
|
+
speedLimit = Math.max(speedLimit, KNOCKBACK_VELOCITY * KNOCKBACK_VELOCITY * 4); // Very generous for knockback
|
|
203
|
+
mode = 'knockback';
|
|
136
204
|
}
|
|
137
|
-
//
|
|
138
|
-
const
|
|
139
|
-
|
|
205
|
+
// Apply packet count multiplier (vanilla does this)
|
|
206
|
+
const adjustedLimit = speedLimit * packetCount;
|
|
207
|
+
// Vanilla check: distanceSquared - currentVelocitySquared > limit
|
|
208
|
+
const excessMovement = distanceSquared - estimatedVelocitySquared;
|
|
209
|
+
const isValid = excessMovement <= adjustedLimit;
|
|
210
|
+
return {
|
|
211
|
+
isValid,
|
|
212
|
+
reason: isValid ? 'valid' : `Movement too fast (${mode})`,
|
|
213
|
+
distanceSquared,
|
|
214
|
+
speedLimit: adjustedLimit,
|
|
215
|
+
currentVelocitySquared: estimatedVelocitySquared
|
|
216
|
+
};
|
|
140
217
|
}
|
|
141
218
|
function findSafePosition(player, serv, attemptedPosition) {
|
|
142
219
|
// Start from the attempted position and search nearby for a safe spot
|
|
143
220
|
const basePosition = attemptedPosition.floored();
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
221
|
+
const getBlock = (pos) => {
|
|
222
|
+
const chunk = player.world.getLoadedColumnAt(pos);
|
|
223
|
+
if (!chunk)
|
|
224
|
+
return null;
|
|
225
|
+
return chunk.getBlockStateId(new vec3_1.Vec3(Math.floor(pos.x) & 15, Math.floor(pos.y), Math.floor(pos.z) & 15));
|
|
226
|
+
};
|
|
148
227
|
// Search in expanding radius for a safe position
|
|
149
228
|
for (let radius = 0; radius <= 3; radius++) {
|
|
150
229
|
for (let x = -radius; x <= radius; x++) {
|
|
@@ -155,10 +234,9 @@ function findSafePosition(player, serv, attemptedPosition) {
|
|
|
155
234
|
let isSafe = true;
|
|
156
235
|
for (let y = 0; y < Math.ceil(PLAYER_SIZE.y); y++) {
|
|
157
236
|
const checkPos = testPos.offset(0, y, 0);
|
|
158
|
-
const pos = new vec3_1.Vec3(Math.floor(checkPos.x) & 15, Math.floor(checkPos.y), Math.floor(checkPos.z) & 15);
|
|
159
237
|
try {
|
|
160
|
-
const blockStateId =
|
|
161
|
-
if (serv.mcData.blocksByStateId[blockStateId]?.boundingBox === 'block') {
|
|
238
|
+
const blockStateId = getBlock(checkPos);
|
|
239
|
+
if (blockStateId === null || serv.mcData.blocksByStateId[blockStateId]?.boundingBox === 'block') {
|
|
162
240
|
isSafe = false;
|
|
163
241
|
break;
|
|
164
242
|
}
|
|
@@ -176,6 +254,7 @@ function findSafePosition(player, serv, attemptedPosition) {
|
|
|
176
254
|
}
|
|
177
255
|
}
|
|
178
256
|
}
|
|
257
|
+
serv.warn('[safeZones] no safe position found');
|
|
179
258
|
// If no safe position found, return player's current position
|
|
180
259
|
return player.position;
|
|
181
260
|
}
|
|
@@ -31,16 +31,35 @@ const server = function (serv) {
|
|
|
31
31
|
.forEach(player => {
|
|
32
32
|
const iniPos = position ? position.scaled(1 / 32) : player.position.scaled(1 / 32);
|
|
33
33
|
const pos = iniPos.scaled(8).floored();
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
if (serv.supportFeature('removedNamedSoundEffectPacket')) { // 1.19.3 removes named_sound_effect
|
|
35
|
+
player._client.write('sound_effect', {
|
|
36
|
+
soundId: 0,
|
|
37
|
+
soundEvent: {
|
|
38
|
+
resource: finalSoundName,
|
|
39
|
+
range: undefined
|
|
40
|
+
},
|
|
41
|
+
soundCategory,
|
|
42
|
+
x: pos.x,
|
|
43
|
+
y: pos.y,
|
|
44
|
+
z: pos.z,
|
|
45
|
+
volume,
|
|
46
|
+
pitch: Math.round(pitch * 63),
|
|
47
|
+
seed: 0
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
// only packet still in fixed position in all versions
|
|
52
|
+
player._client.write('named_sound_effect', {
|
|
53
|
+
soundName: finalSoundName,
|
|
54
|
+
soundCategory,
|
|
55
|
+
x: pos.x,
|
|
56
|
+
y: pos.y,
|
|
57
|
+
z: pos.z,
|
|
58
|
+
volume,
|
|
59
|
+
pitch: Math.round(pitch * 63),
|
|
60
|
+
seed: 0
|
|
61
|
+
});
|
|
62
|
+
}
|
|
44
63
|
});
|
|
45
64
|
};
|
|
46
65
|
serv.playNoteBlock = (pitch, world, position, { instrument = 'harp', particle = true } = {}) => {
|
|
@@ -63,7 +82,8 @@ const server = function (serv) {
|
|
|
63
82
|
player._client.write('stop_sound', {
|
|
64
83
|
flags: 3, // Both source and sound
|
|
65
84
|
source: soundInfo.soundCategory,
|
|
66
|
-
sound: soundInfo.soundName
|
|
85
|
+
sound: soundInfo.soundName,
|
|
86
|
+
seed: 0
|
|
67
87
|
});
|
|
68
88
|
delete player.savedSounds[soundId];
|
|
69
89
|
}
|
|
@@ -134,7 +154,8 @@ const player = function (player, serv) {
|
|
|
134
154
|
player._client.write('stop_sound', {
|
|
135
155
|
flags: 3, // Both source and sound
|
|
136
156
|
source: soundInfo.soundCategory,
|
|
137
|
-
sound: soundInfo.soundName
|
|
157
|
+
sound: soundInfo.soundName,
|
|
158
|
+
seed: 0
|
|
138
159
|
});
|
|
139
160
|
delete player.savedSounds[soundId];
|
|
140
161
|
}
|
|
@@ -142,7 +163,8 @@ const player = function (player, serv) {
|
|
|
142
163
|
else {
|
|
143
164
|
// Stop all sounds
|
|
144
165
|
player._client.write('stop_sound', {
|
|
145
|
-
flags: 0 // Stop all sounds
|
|
166
|
+
flags: 0, // Stop all sounds
|
|
167
|
+
seed: 0
|
|
146
168
|
});
|
|
147
169
|
// Clear saved sounds storage
|
|
148
170
|
player.savedSounds = {};
|
|
@@ -332,8 +332,12 @@ const entity = function (entity, serv) {
|
|
|
332
332
|
entity.spawnPacketName = 'named_entity_spawn';
|
|
333
333
|
else if (entity.type === 'object')
|
|
334
334
|
entity.spawnPacketName = 'spawn_entity';
|
|
335
|
-
else if (entity.type === 'mob')
|
|
336
|
-
|
|
335
|
+
else if (entity.type === 'mob') {
|
|
336
|
+
if (serv.supportFeature('consolidatedEntitySpawnPacket'))
|
|
337
|
+
entity.spawnPacketName = 'spawn_entity';
|
|
338
|
+
else
|
|
339
|
+
entity.spawnPacketName = 'spawn_entity_living';
|
|
340
|
+
}
|
|
337
341
|
};
|
|
338
342
|
entity.getSpawnPacket = () => {
|
|
339
343
|
let scaledVelocity = entity.velocity.scaled(8000 / 20); // from fixed-position/second to unit => 1/8000 blocks per tick
|
|
@@ -361,52 +365,25 @@ const entity = function (entity, serv) {
|
|
|
361
365
|
// Ensure we stay within protocol limits
|
|
362
366
|
return Math.max(-128, Math.min(127, b));
|
|
363
367
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
y: entityPosition.y,
|
|
384
|
-
z: entityPosition.z,
|
|
385
|
-
pitch: convToProtocol(entity.pitch),
|
|
386
|
-
yaw: convToProtocol(entity.yaw),
|
|
387
|
-
objectData: entity.data,
|
|
388
|
-
velocityX: scaledVelocity.x,
|
|
389
|
-
velocityY: scaledVelocity.y,
|
|
390
|
-
velocityZ: scaledVelocity.z
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
else if (entity.type === 'mob') {
|
|
394
|
-
return {
|
|
395
|
-
entityId: entity.id,
|
|
396
|
-
entityUUID: entity.uuid,
|
|
397
|
-
type: entity.entityType,
|
|
398
|
-
x: entityPosition.x,
|
|
399
|
-
y: entityPosition.y,
|
|
400
|
-
z: entityPosition.z,
|
|
401
|
-
yaw: convToProtocol(entity.yaw),
|
|
402
|
-
pitch: convToProtocol(entity.pitch),
|
|
403
|
-
headPitch: convToProtocol(entity.headPitch),
|
|
404
|
-
velocityX: scaledVelocity.x,
|
|
405
|
-
velocityY: scaledVelocity.y,
|
|
406
|
-
velocityZ: scaledVelocity.z,
|
|
407
|
-
metadata: entity.metadata
|
|
408
|
-
};
|
|
409
|
-
}
|
|
368
|
+
return {
|
|
369
|
+
entityId: entity.id,
|
|
370
|
+
playerUUID: entity.uuid,
|
|
371
|
+
entityUUID: entity.uuid,
|
|
372
|
+
objectUUID: entity.uuid,
|
|
373
|
+
type: entity.entityType,
|
|
374
|
+
x: entityPosition.x,
|
|
375
|
+
y: entityPosition.y,
|
|
376
|
+
z: entityPosition.z,
|
|
377
|
+
yaw: convToProtocol(entity.yaw),
|
|
378
|
+
pitch: convToProtocol(entity.pitch),
|
|
379
|
+
headPitch: convToProtocol(entity.headPitch),
|
|
380
|
+
currentItem: 0,
|
|
381
|
+
objectData: entity.data,
|
|
382
|
+
velocityX: scaledVelocity.x,
|
|
383
|
+
velocityY: scaledVelocity.y,
|
|
384
|
+
velocityZ: scaledVelocity.z,
|
|
385
|
+
metadata: entity.metadata
|
|
386
|
+
};
|
|
410
387
|
};
|
|
411
388
|
const isPlayer = (arg) => arg.type === 'player';
|
|
412
389
|
entity.updateAndSpawn = () => {
|
|
@@ -4,6 +4,8 @@ export declare const entity: (entity: Entity, serv: Server) => void;
|
|
|
4
4
|
declare global {
|
|
5
5
|
interface Player {
|
|
6
6
|
"sendAbilities": () => void;
|
|
7
|
+
/** Position we're expecting the client to move to after teleport */
|
|
8
|
+
pendingTeleport?: Vec3 | null;
|
|
7
9
|
}
|
|
8
10
|
interface Entity {
|
|
9
11
|
/** ID of entity on server */
|
|
@@ -18,4 +20,20 @@ declare global {
|
|
|
18
20
|
pitch: number;
|
|
19
21
|
"teleport": (pos: Vec3) => void;
|
|
20
22
|
}
|
|
23
|
+
interface PlayerBehaviorInputMap {
|
|
24
|
+
'move': {
|
|
25
|
+
_input: {
|
|
26
|
+
position: Vec3;
|
|
27
|
+
onGround: boolean;
|
|
28
|
+
teleport: boolean;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
'look': {
|
|
32
|
+
_input: {
|
|
33
|
+
yaw: number;
|
|
34
|
+
pitch: number;
|
|
35
|
+
onGround: boolean;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}
|
|
21
39
|
}
|
|
@@ -68,12 +68,24 @@ const player = function (player) {
|
|
|
68
68
|
teleportId: 1
|
|
69
69
|
});
|
|
70
70
|
if (sendChunks)
|
|
71
|
-
player.
|
|
71
|
+
player.sendChunkWhenMove();
|
|
72
72
|
};
|
|
73
|
+
let oldSetTimeout;
|
|
73
74
|
player.teleport = async (position) => {
|
|
75
|
+
// Track pending teleport for anti-cheat
|
|
76
|
+
if (oldSetTimeout)
|
|
77
|
+
clearTimeout(oldSetTimeout);
|
|
78
|
+
player.pendingTeleport = position.clone();
|
|
74
79
|
const notCancelled = await player.sendPosition(position, false, true);
|
|
75
|
-
if (notCancelled)
|
|
76
|
-
|
|
80
|
+
if (!notCancelled)
|
|
81
|
+
return;
|
|
82
|
+
player.sendSelfPosition();
|
|
83
|
+
// Clear pending teleport after a short delay to handle network latency
|
|
84
|
+
oldSetTimeout = player.setTimeout(() => {
|
|
85
|
+
if (player.pendingTeleport?.equals(position)) {
|
|
86
|
+
player.pendingTeleport = null;
|
|
87
|
+
}
|
|
88
|
+
}, 1000); // 1 second timeout
|
|
77
89
|
};
|
|
78
90
|
player.sendAbilities = () => {
|
|
79
91
|
const isInvulnerable = player.gameMode === 1 || player.gameMode === 3; // Creative or Spectator
|
|
@@ -98,12 +110,13 @@ const player = function (player) {
|
|
|
98
110
|
};
|
|
99
111
|
exports.player = player;
|
|
100
112
|
const entity = function (entity, serv) {
|
|
101
|
-
entity.sendPosition = (position, onGround, teleport = false) => {
|
|
113
|
+
entity.sendPosition = async (position, onGround, teleport = false) => {
|
|
102
114
|
if (typeof position === 'undefined')
|
|
103
|
-
throw new Error('
|
|
115
|
+
throw new Error('position is undefined');
|
|
104
116
|
if (entity.position.equals(position) && entity.onGround === onGround)
|
|
105
|
-
return
|
|
106
|
-
|
|
117
|
+
return true;
|
|
118
|
+
let cancelled = false;
|
|
119
|
+
await entity.behavior('move', {
|
|
107
120
|
position,
|
|
108
121
|
onGround,
|
|
109
122
|
teleport
|
|
@@ -161,9 +174,11 @@ const entity = function (entity, serv) {
|
|
|
161
174
|
entity.position = position;
|
|
162
175
|
entity.onGround = onGround;
|
|
163
176
|
}, () => {
|
|
177
|
+
cancelled = true;
|
|
164
178
|
if (entity.type === 'player')
|
|
165
179
|
entity.sendSelfPosition();
|
|
166
180
|
});
|
|
181
|
+
return !cancelled;
|
|
167
182
|
};
|
|
168
183
|
entity.teleport = (pos) => {
|
|
169
184
|
entity.sendPosition(pos, false, true);
|
|
@@ -33,7 +33,7 @@ const server = (serv, { version }) => {
|
|
|
33
33
|
else {
|
|
34
34
|
if (serv.supportFeature('entityMCPrefixed')) { // 1.12 support
|
|
35
35
|
serv.onItemPlace('spawn_egg', ({ item, player, placedPosition }) => {
|
|
36
|
-
serv.spawnMob(getEntID(item.nbt
|
|
36
|
+
serv.spawnMob(getEntID(item.nbt?.value?.EntityTag?.value?.id?.value), player.world, placedPosition);
|
|
37
37
|
return { id: -1, data: 0 };
|
|
38
38
|
});
|
|
39
39
|
}
|
|
@@ -46,7 +46,7 @@ const server = (serv, { version }) => {
|
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
48
|
serv.onItemPlace('spawn_egg', ({ item, player, placedPosition }) => {
|
|
49
|
-
serv.spawnMob(getEntID('minecraft:' + item.nbt
|
|
49
|
+
serv.spawnMob(getEntID('minecraft:' + item.nbt?.value?.EntityTag?.value?.id?.value), player.world, placedPosition);
|
|
50
50
|
return { id: -1, data: 0 };
|
|
51
51
|
});
|
|
52
52
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { World } from 'prismarine-world/types/world';
|
|
1
|
+
import { Chunk, World } from 'prismarine-world/types/world';
|
|
2
2
|
import { LevelDatFull } from 'prismarine-provider-anvil/src/level';
|
|
3
3
|
import { Vec3 } from 'vec3';
|
|
4
4
|
export declare const server: ServerModule;
|
|
@@ -52,4 +52,13 @@ declare global {
|
|
|
52
52
|
*/
|
|
53
53
|
'changeWorld': (world: any, opt: any) => Promise<void>;
|
|
54
54
|
}
|
|
55
|
+
interface PlayerBehaviorInputMap {
|
|
56
|
+
'sendChunk': {
|
|
57
|
+
_input: {
|
|
58
|
+
x: number;
|
|
59
|
+
z: number;
|
|
60
|
+
chunk: Chunk;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
}
|
|
55
64
|
}
|
|
@@ -462,6 +462,7 @@ const player = function (player, serv, settings) {
|
|
|
462
462
|
groundUp: bitMap !== undefined ? true : undefined,
|
|
463
463
|
//note: it's a flag that tells the client to trust the edges of the chunk, meaning that the client can render the chunk without having to wait for the edges to be sent
|
|
464
464
|
trustEdges: true, // should be false when a chunk section is updated instead of the whole chunk being overwritten, do we ever do that?
|
|
465
|
+
suppressLightUpdates: true, // 1.19.2
|
|
465
466
|
bitMap: bitMap,
|
|
466
467
|
...serv.supportFeature('blockStateId') && serv.looseProtocolMode ? {
|
|
467
468
|
// groundUp: false,
|
package/dist/modules.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Client } from 'minecraft-protocol';
|
|
|
2
2
|
import TypedEmitter from 'typed-emitter';
|
|
3
3
|
import EventEmitter from 'events';
|
|
4
4
|
import { IndexedData, Block as MinecraftDataBlock } from 'minecraft-data';
|
|
5
|
+
import { BehaviorEventMap } from './lib/behavior';
|
|
5
6
|
declare global {
|
|
6
7
|
interface PlayerEvents {
|
|
7
8
|
asap: () => void;
|
|
@@ -45,9 +46,12 @@ declare global {
|
|
|
45
46
|
interface Server extends TypedEmitter<ServerEvents> {
|
|
46
47
|
mcData: IndexedData;
|
|
47
48
|
}
|
|
48
|
-
interface Player extends Omit<Entity, keyof TypedEmitter<{}>>, TypedEmitter<PlayerEvents
|
|
49
|
+
interface Player extends Omit<Entity, keyof TypedEmitter<{}>>, TypedEmitter<PlayerEvents & BehaviorEventMap<{
|
|
50
|
+
[K in keyof PlayerBehaviorInputMap]: PlayerBehaviorInputMap[K];
|
|
51
|
+
}>> {
|
|
49
52
|
dimension: string | number;
|
|
50
53
|
_client: Client;
|
|
54
|
+
disconnected?: boolean;
|
|
51
55
|
}
|
|
52
56
|
interface Entity extends EventEmitter {
|
|
53
57
|
_client: Client;
|