@zardoy/flying-squid 0.0.115 → 0.0.117

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.js CHANGED
@@ -158,7 +158,7 @@ class MCServer extends events_1.EventEmitter {
158
158
  };
159
159
  patchServer(server);
160
160
  const promises = [];
161
- const coreModules = ['utils', 'communication', 'tick', 'settings', 'commands', 'tabComplete'];
161
+ const coreModules = ['utils', 'communication', 'tick', 'settings', 'commands', 'tabComplete', 'log'];
162
162
  server.modules = builtinModules.builtinPlugins;
163
163
  // Sort modules so core modules are first in specified order
164
164
  const sortedModules = {};
@@ -31,13 +31,18 @@ const server = (serv, options) => {
31
31
  const isValidResponse = (obj) => {
32
32
  return typeof obj === 'object' && obj !== null &&
33
33
  typeof obj.requestId === 'number' &&
34
- Array.isArray(obj.entityIds) &&
35
- obj.entityIds.every(id => typeof id === 'number');
34
+ Array.isArray(obj.entities) &&
35
+ obj.entities.every((entity) => typeof entity === 'object' && entity !== null &&
36
+ typeof entity.entityId === 'number' &&
37
+ typeof entity.position === 'object' && entity.position !== null &&
38
+ typeof entity.position.x === 'number' &&
39
+ typeof entity.position.y === 'number' &&
40
+ typeof entity.position.z === 'number');
36
41
  };
37
42
  if (!isValidResponse(parsed)) {
38
43
  throw new Error('Invalid response format');
39
44
  }
40
- const { requestId, entityIds } = parsed;
45
+ const { requestId, entities } = parsed;
41
46
  // Verify this is a response to our last request
42
47
  const lastRequest = module.lastSyncRequests.get(player.uuid);
43
48
  if (!lastRequest || lastRequest.requestId !== requestId) {
@@ -48,7 +53,7 @@ const server = (serv, options) => {
48
53
  player._client.latency = latency;
49
54
  // Clean up the request
50
55
  module.lastSyncRequests.delete(player.uuid);
51
- const trackedIds = new Set(entityIds);
56
+ const trackedIds = new Set(entities.map(e => e.entityId));
52
57
  const expectedIds = new Set();
53
58
  // Find entities that should be visible to the player
54
59
  for (const entity of Object.values(serv.entities)) {
@@ -64,6 +69,38 @@ const server = (serv, options) => {
64
69
  expectedIds.add(entity.id);
65
70
  }
66
71
  }
72
+ // Check position deltas and send teleport packets if needed
73
+ for (const clientEntity of entities) {
74
+ const entity = serv.entities[clientEntity.entityId];
75
+ if (!entity)
76
+ continue;
77
+ // Calculate position delta
78
+ const deltaX = Math.abs(entity.position.x - clientEntity.position.x);
79
+ const deltaY = Math.abs(entity.position.y - clientEntity.position.y);
80
+ const deltaZ = Math.abs(entity.position.z - clientEntity.position.z);
81
+ const maxDelta = Math.max(deltaX, deltaY, deltaZ);
82
+ // If delta is more than 3 blocks, send entity_teleport packet
83
+ if (maxDelta > 3) {
84
+ serv.warn(`Player ${player.username} entity ${clientEntity.entityId} position desync (delta: ${maxDelta.toFixed(2)}), sending teleport... (ping: ${latency}ms)`);
85
+ // Send entity_teleport packet to sync position
86
+ let entityPosition;
87
+ if (serv.supportFeature('fixedPointPosition')) {
88
+ entityPosition = entity.position.scaled(32).floored();
89
+ }
90
+ else if (serv.supportFeature('doublePosition')) {
91
+ entityPosition = entity.position;
92
+ }
93
+ player.writePacket('entity_teleport', {
94
+ entityId: entity.id,
95
+ x: entityPosition.x,
96
+ y: entityPosition.y,
97
+ z: entityPosition.z,
98
+ yaw: entity.yaw,
99
+ pitch: entity.pitch,
100
+ onGround: entity.onGround
101
+ });
102
+ }
103
+ }
67
104
  // Find missing entities
68
105
  for (const entityId of expectedIds) {
69
106
  if (!trackedIds.has(entityId)) {
@@ -15,10 +15,12 @@ const player = function (player, serv) {
15
15
  let lastAttackTime = 0;
16
16
  function attackEntity(entityId) {
17
17
  const attackedEntity = serv.entities[entityId];
18
- const attackedPlayer = attackedEntity.type === 'player' ? attackedEntity : undefined;
19
18
  if (!attackedEntity)
20
19
  return;
21
- if (attackedPlayer && (attackedPlayer.gameMode === 1 || attackedPlayer.gameMode === 3 || attackedPlayer.invincible))
20
+ const attackedPlayer = attackedEntity.type === 'player' ? attackedEntity : undefined;
21
+ if (!attackedPlayer)
22
+ return;
23
+ if (attackedPlayer.gameMode === 1 || attackedPlayer.gameMode === 3 || attackedPlayer.invincible)
22
24
  return;
23
25
  // Anti-cheat: Distance check
24
26
  const distance = player.position.distanceTo(attackedEntity.position);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zardoy/flying-squid",
3
3
  "description": "A minecraft server written in TS",
4
- "version": "0.0.115",
4
+ "version": "0.0.117",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "bin": "dist/app.js",