@zardoy/flying-squid 0.0.2 → 0.0.4

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.
Files changed (207) hide show
  1. package/dist/app.d.ts +4 -0
  2. package/dist/app.js.map +1 -0
  3. package/dist/blockRenames.d.ts +1 -0
  4. package/dist/blockRenames.js +57 -0
  5. package/dist/blockRenames.js.map +1 -0
  6. package/dist/circularBuffer.d.ts +9 -0
  7. package/dist/circularBuffer.js +30 -0
  8. package/dist/circularBuffer.js.map +1 -0
  9. package/dist/index.d.ts +32 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/itemBlockRenames.json +2573 -0
  12. package/dist/lib/behavior.d.ts +2 -0
  13. package/dist/lib/behavior.js +40 -0
  14. package/dist/lib/behavior.js.map +1 -0
  15. package/dist/lib/command.d.ts +35 -0
  16. package/dist/lib/command.js +110 -0
  17. package/dist/lib/command.js.map +1 -0
  18. package/dist/lib/convertInventorySlotId.d.ts +2 -0
  19. package/dist/lib/convertInventorySlotId.js +32 -0
  20. package/dist/lib/convertInventorySlotId.js.map +1 -0
  21. package/dist/lib/experience.d.ts +4 -0
  22. package/dist/lib/experience.js +57 -0
  23. package/dist/lib/experience.js.map +1 -0
  24. package/dist/lib/generations.d.ts +6 -0
  25. package/dist/lib/generations.js +9 -0
  26. package/dist/lib/generations.js.map +1 -0
  27. package/dist/lib/modules/animations.d.ts +3 -0
  28. package/dist/lib/modules/animations.js +29 -0
  29. package/dist/lib/modules/animations.js.map +1 -0
  30. package/dist/lib/modules/behavior.d.ts +11 -0
  31. package/dist/lib/modules/behavior.js +16 -0
  32. package/dist/lib/modules/behavior.js.map +1 -0
  33. package/dist/lib/modules/blockUpdates.d.ts +16 -0
  34. package/dist/lib/modules/blockUpdates.js +162 -0
  35. package/dist/lib/modules/blockUpdates.js.map +1 -0
  36. package/dist/lib/modules/blocks.d.ts +32 -0
  37. package/dist/lib/modules/blocks.js +152 -0
  38. package/dist/lib/modules/blocks.js.map +1 -0
  39. package/dist/lib/modules/channels.d.ts +7 -0
  40. package/dist/lib/modules/channels.js +21 -0
  41. package/dist/lib/modules/channels.js.map +1 -0
  42. package/dist/lib/modules/chat.d.ts +16 -0
  43. package/dist/lib/modules/chat.js +178 -0
  44. package/dist/lib/modules/chat.js.map +1 -0
  45. package/dist/lib/modules/chest.d.ts +3 -0
  46. package/dist/lib/modules/chest.js +122 -0
  47. package/dist/lib/modules/chest.js.map +1 -0
  48. package/dist/lib/modules/commands.d.ts +21 -0
  49. package/dist/lib/modules/commands.js +406 -0
  50. package/dist/lib/modules/commands.js.map +1 -0
  51. package/dist/lib/modules/communication.d.ts +34 -0
  52. package/dist/lib/modules/communication.js +35 -0
  53. package/dist/lib/modules/communication.js.map +1 -0
  54. package/dist/lib/modules/daycycle.d.ts +13 -0
  55. package/dist/lib/modules/daycycle.js +91 -0
  56. package/dist/lib/modules/daycycle.js.map +1 -0
  57. package/dist/lib/modules/digging.d.ts +3 -0
  58. package/dist/lib/modules/digging.js +250 -0
  59. package/dist/lib/modules/digging.js.map +1 -0
  60. package/dist/lib/modules/effects.d.ts +6 -0
  61. package/dist/lib/modules/effects.js +122 -0
  62. package/dist/lib/modules/effects.js.map +1 -0
  63. package/dist/lib/modules/entities.d.ts +14 -0
  64. package/dist/lib/modules/entities.js +55 -0
  65. package/dist/lib/modules/entities.js.map +1 -0
  66. package/dist/lib/modules/errorHandler.d.ts +3 -0
  67. package/dist/lib/modules/errorHandler.js +29 -0
  68. package/dist/lib/modules/errorHandler.js.map +1 -0
  69. package/dist/lib/modules/experience.d.ts +28 -0
  70. package/dist/lib/modules/experience.js +77 -0
  71. package/dist/lib/modules/experience.js.map +1 -0
  72. package/dist/lib/modules/external.d.ts +16 -0
  73. package/dist/lib/modules/external.js +81 -0
  74. package/dist/lib/modules/external.js.map +1 -0
  75. package/dist/lib/modules/header.d.ts +5 -0
  76. package/dist/lib/modules/header.js +14 -0
  77. package/dist/lib/modules/header.js.map +1 -0
  78. package/dist/lib/modules/health.d.ts +11 -0
  79. package/dist/lib/modules/health.js +26 -0
  80. package/dist/lib/modules/health.js.map +1 -0
  81. package/dist/lib/modules/index.d.ts +2 -0
  82. package/dist/lib/modules/index.js +33 -0
  83. package/dist/lib/modules/index.js.map +1 -0
  84. package/dist/lib/modules/inventory.d.ts +5 -0
  85. package/dist/lib/modules/inventory.js +234 -0
  86. package/dist/lib/modules/inventory.js.map +1 -0
  87. package/dist/lib/modules/log.d.ts +18 -0
  88. package/dist/lib/modules/log.js +137 -0
  89. package/dist/lib/modules/log.js.map +1 -0
  90. package/dist/lib/modules/login.d.ts +14 -0
  91. package/dist/lib/modules/login.js +518 -0
  92. package/dist/lib/modules/login.js.map +1 -0
  93. package/dist/lib/modules/logout.d.ts +8 -0
  94. package/dist/lib/modules/logout.js +46 -0
  95. package/dist/lib/modules/logout.js.map +1 -0
  96. package/dist/lib/modules/moderation.d.ts +33 -0
  97. package/dist/lib/modules/moderation.js +455 -0
  98. package/dist/lib/modules/moderation.js.map +1 -0
  99. package/dist/lib/modules/particle.d.ts +23 -0
  100. package/dist/lib/modules/particle.js +55 -0
  101. package/dist/lib/modules/particle.js.map +1 -0
  102. package/dist/lib/modules/physics.d.ts +10 -0
  103. package/dist/lib/modules/physics.js +117 -0
  104. package/dist/lib/modules/physics.js.map +1 -0
  105. package/dist/lib/modules/placeBlock.d.ts +20 -0
  106. package/dist/lib/modules/placeBlock.js +214 -0
  107. package/dist/lib/modules/placeBlock.js.map +1 -0
  108. package/dist/lib/modules/players.d.ts +15 -0
  109. package/dist/lib/modules/players.js +266 -0
  110. package/dist/lib/modules/players.js.map +1 -0
  111. package/dist/lib/modules/portal.d.ts +4 -0
  112. package/dist/lib/modules/portal.js +103 -0
  113. package/dist/lib/modules/portal.js.map +1 -0
  114. package/dist/lib/modules/pvp.d.ts +22 -0
  115. package/dist/lib/modules/pvp.js +120 -0
  116. package/dist/lib/modules/pvp.js.map +1 -0
  117. package/dist/lib/modules/redstone.d.ts +13 -0
  118. package/dist/lib/modules/redstone.js +416 -0
  119. package/dist/lib/modules/redstone.js.map +1 -0
  120. package/dist/lib/modules/respawn.d.ts +3 -0
  121. package/dist/lib/modules/respawn.js +37 -0
  122. package/dist/lib/modules/respawn.js.map +1 -0
  123. package/dist/lib/modules/settings.d.ts +13 -0
  124. package/dist/lib/modules/settings.js +57 -0
  125. package/dist/lib/modules/settings.js.map +1 -0
  126. package/dist/lib/modules/signs.d.ts +3 -0
  127. package/dist/lib/modules/signs.js +48 -0
  128. package/dist/lib/modules/signs.js.map +1 -0
  129. package/dist/lib/modules/sound.d.ts +38 -0
  130. package/dist/lib/modules/sound.js +118 -0
  131. package/dist/lib/modules/sound.js.map +1 -0
  132. package/dist/lib/modules/spawn.d.ts +33 -0
  133. package/dist/lib/modules/spawn.js +446 -0
  134. package/dist/lib/modules/spawn.js.map +1 -0
  135. package/dist/lib/modules/stats.d.ts +3 -0
  136. package/dist/lib/modules/stats.js +13 -0
  137. package/dist/lib/modules/stats.js.map +1 -0
  138. package/dist/lib/modules/tabComplete.d.ts +19 -0
  139. package/dist/lib/modules/tabComplete.js +121 -0
  140. package/dist/lib/modules/tabComplete.js.map +1 -0
  141. package/dist/lib/modules/tick.d.ts +14 -0
  142. package/dist/lib/modules/tick.js +27 -0
  143. package/dist/lib/modules/tick.js.map +1 -0
  144. package/dist/lib/modules/tp.d.ts +3 -0
  145. package/dist/lib/modules/tp.js +60 -0
  146. package/dist/lib/modules/tp.js.map +1 -0
  147. package/dist/lib/modules/updatePositions.d.ts +19 -0
  148. package/dist/lib/modules/updatePositions.js +159 -0
  149. package/dist/lib/modules/updatePositions.js.map +1 -0
  150. package/dist/lib/modules/useItem.d.ts +3 -0
  151. package/dist/lib/modules/useItem.js +58 -0
  152. package/dist/lib/modules/useItem.js.map +1 -0
  153. package/dist/lib/modules/weather.d.ts +3 -0
  154. package/dist/lib/modules/weather.js +32 -0
  155. package/dist/lib/modules/weather.js.map +1 -0
  156. package/dist/lib/modules/world.d.ts +45 -0
  157. package/dist/lib/modules/world.js +459 -0
  158. package/dist/lib/modules/world.js.map +1 -0
  159. package/dist/lib/playerDat.d.ts +273 -0
  160. package/dist/lib/playerDat.js +472 -0
  161. package/dist/lib/playerDat.js.map +1 -0
  162. package/dist/lib/portal_detector.d.ts +30 -0
  163. package/dist/lib/portal_detector.js +119 -0
  164. package/dist/lib/portal_detector.js.map +1 -0
  165. package/dist/lib/requireindex.d.ts +2 -0
  166. package/dist/lib/requireindex.js +52 -0
  167. package/dist/lib/requireindex.js.map +1 -0
  168. package/dist/lib/user_error.d.ts +8 -0
  169. package/dist/lib/user_error.js +18 -0
  170. package/dist/lib/user_error.js.map +1 -0
  171. package/dist/lib/utils.d.ts +1 -0
  172. package/dist/lib/utils.js +8 -0
  173. package/dist/lib/utils.js.map +1 -0
  174. package/dist/lib/version.d.ts +1 -0
  175. package/dist/lib/version.js +5 -0
  176. package/dist/lib/version.js.map +1 -0
  177. package/dist/lib/worldGenerations/all_the_blocks.d.ts +4 -0
  178. package/dist/lib/worldGenerations/all_the_blocks.js +25 -0
  179. package/dist/lib/worldGenerations/all_the_blocks.js.map +1 -0
  180. package/dist/lib/worldGenerations/empty.d.ts +4 -0
  181. package/dist/lib/worldGenerations/empty.js +6 -0
  182. package/dist/lib/worldGenerations/empty.js.map +1 -0
  183. package/dist/lib/worldGenerations/grass_field.d.ts +4 -0
  184. package/dist/lib/worldGenerations/grass_field.js +23 -0
  185. package/dist/lib/worldGenerations/grass_field.js.map +1 -0
  186. package/dist/lib/worldGenerations/nether.d.ts +6 -0
  187. package/dist/lib/worldGenerations/nether.js +36 -0
  188. package/dist/lib/worldGenerations/nether.js.map +1 -0
  189. package/dist/lib/worldGenerations/superflat.d.ts +2 -0
  190. package/dist/lib/worldGenerations/superflat.js +48 -0
  191. package/dist/lib/worldGenerations/superflat.js.map +1 -0
  192. package/dist/modules.d.ts +80 -0
  193. package/dist/modules.js +3 -0
  194. package/dist/modules.js.map +1 -0
  195. package/dist/types.d.ts +44 -0
  196. package/dist/types.js +5 -0
  197. package/dist/types.js.map +1 -0
  198. package/dist/utils/index.d.ts +9 -0
  199. package/dist/utils/index.js +22 -0
  200. package/dist/utils/index.js.map +1 -0
  201. package/dist/utils/simpleUtils.test.d.ts +1 -0
  202. package/dist/utils/simpleUtils.test.js +55 -0
  203. package/dist/utils/simpleUtils.test.js.map +1 -0
  204. package/dist/utils/spiral.d.ts +1 -0
  205. package/dist/utils/spiral.js +29 -0
  206. package/dist/utils/spiral.js.map +1 -0
  207. package/package.json +3 -3
@@ -0,0 +1,38 @@
1
+ export declare const server: (serv: Server) => void;
2
+ export declare const player: (player: Player, serv: Server) => void;
3
+ export declare const entity: (entity: Entity, serv: Server) => void;
4
+ declare global {
5
+ interface Server {
6
+ /** Plays `sound` (string, google "minecraft sound list") to all players in `opt.radius`.
7
+ * If position is null, will play at the location of every player (taking into account whitelist and blacklist).
8
+ *
9
+ * Opt:
10
+ * - whitelist: Array of players that can hear the sound (can be a player object)
11
+ * - blacklist: Array of players who cannot hear the sound
12
+ * - radius: Radius that sound can be heard (in fixed position so remember to multiply by 32, default 32*32)
13
+ * - volume: float from 0-1 (default 1.0)
14
+ * - pitch: float from 0.5 to 2 (default 1.0)
15
+ */
16
+ 'playSound': (sound: any, world: any, position: any, { whitelist, blacklist, radius, volume, pitch, soundCategory }?: {
17
+ whitelist?: any;
18
+ blacklist?: any[] | undefined;
19
+ radius?: number | undefined;
20
+ volume?: number | undefined;
21
+ pitch?: number | undefined;
22
+ soundCategory?: number | undefined;
23
+ }) => void;
24
+ /** Plays noteblock in world at position. `pitch` is from 0-24 */
25
+ "playNoteBlock": (pitch: any, world: any, position: any, { instrument, particle }?: {
26
+ instrument?: string | undefined;
27
+ particle?: boolean | undefined;
28
+ }) => void;
29
+ /** Get pitch. `note` should be between 0-24 and your output is from 0.5 to 2.0 */
30
+ "getNote": (note: any) => number;
31
+ }
32
+ interface Player {
33
+ /** Easy way to only play a sound for one player. Same opt as serv.playSound except no `whitelist`. */
34
+ "playSound": (sound: any, opt?: {}) => void;
35
+ }
36
+ interface Entity {
37
+ }
38
+ }
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.entity = exports.player = exports.server = void 0;
4
+ const utils_1 = require("../utils");
5
+ const vec3_1 = require("vec3");
6
+ const server = function (serv) {
7
+ serv.playSound = (sound, world, position, { whitelist, blacklist = [], radius = 32, volume = 1.0, pitch = 1.0, soundCategory = 0 } = {}) => {
8
+ const players = (typeof whitelist !== 'undefined'
9
+ ? (whitelist instanceof Array ? whitelist : [whitelist])
10
+ : serv.getNearby({
11
+ world,
12
+ position,
13
+ radius
14
+ }));
15
+ players.filter(player => blacklist.indexOf(player) === -1)
16
+ .forEach(player => {
17
+ const iniPos = position ? position.scaled(1 / 32) : player.position.scaled(1 / 32);
18
+ const pos = iniPos.scaled(8).floored();
19
+ // only packet still in fixed position in all versions
20
+ player._client.write('named_sound_effect', {
21
+ soundName: sound,
22
+ soundCategory,
23
+ x: pos.x,
24
+ y: pos.y,
25
+ z: pos.z,
26
+ volume,
27
+ pitch: Math.round(pitch * 63)
28
+ });
29
+ });
30
+ };
31
+ serv.playNoteBlock = (pitch, world, position, { instrument = 'harp', particle = true } = {}) => {
32
+ if (particle) {
33
+ serv.emitParticle(23, world, position.clone().add(new vec3_1.Vec3(0.5, 1.5, 0.5)), {
34
+ count: 1,
35
+ size: new vec3_1.Vec3(0, 0, 0)
36
+ });
37
+ }
38
+ serv.playSound('note.' + instrument, world, position, { pitch: serv.getNote(pitch) });
39
+ };
40
+ serv.getNote = note => 0.5 * Math.pow(Math.pow(2, 1 / 12), note);
41
+ serv.commands.add({
42
+ base: 'playsoundforall',
43
+ info: 'to play sound for everyone',
44
+ usage: '/playsoundforall <sound_name> [volume] [pitch]',
45
+ onlyPlayer: true,
46
+ op: true,
47
+ parse(str) {
48
+ const results = str.match(/([^ ]+)(?: ([^ ]+))?(?: ([^ ]+))?/);
49
+ if (!results)
50
+ return false;
51
+ return {
52
+ sound_name: (0, utils_1.skipMcPrefix)(results[1]),
53
+ volume: results[2] ? parseFloat(results[2]) : 1.0,
54
+ pitch: results[3] ? parseFloat(results[3]) : 1.0
55
+ };
56
+ },
57
+ action(action, ctx) {
58
+ ctx.player.chat('Playing "' + action.sound_name + '" (volume: ' + action.volume + ', pitch: ' + action.pitch + ')');
59
+ serv.playSound(action.sound_name, ctx.player.world, ctx.player.position, { volume: action.volume, pitch: action.pitch });
60
+ }
61
+ });
62
+ serv.commands.add({
63
+ base: 'playsound',
64
+ info: 'to play sound for yourself',
65
+ usage: '/playsound <sound_name> [volume] [pitch]',
66
+ onlyPlayer: true,
67
+ op: true,
68
+ parse(str) {
69
+ const results = str.match(/([^ ]+)(?: ([^ ]+))?(?: ([^ ]+))?/);
70
+ if (!results)
71
+ return false;
72
+ return {
73
+ sound_name: (0, utils_1.skipMcPrefix)(results[1]),
74
+ volume: results[2] ? parseFloat(results[2]) : 1.0,
75
+ pitch: results[3] ? parseFloat(results[3]) : 1.0
76
+ };
77
+ },
78
+ action(action, ctx) {
79
+ ctx.player.chat('Playing "' + action.sound_name + '" (volume: ' + action.volume + ', pitch: ' + action.pitch + ')');
80
+ ctx.player.playSound(action.sound_name, { volume: action.volume, pitch: action.pitch });
81
+ }
82
+ });
83
+ };
84
+ exports.server = server;
85
+ const player = function (player, serv) {
86
+ player.playSound = (sound, opt = {}) => {
87
+ serv.playSound(sound, player.world, null, { ...opt, whitelist: player });
88
+ };
89
+ // player.on('placeBlock_cancel', async ({ reference }, cancel) => {
90
+ // if (player.crouching) return
91
+ // const id = await player.world.getBlockType(reference)
92
+ // if (id !== 25) return
93
+ // cancel(false)
94
+ // if (!player.world.blockEntityData[reference.toString()]) player.world.blockEntityData[reference.toString()] = {}
95
+ // const data = player.world.blockEntityData[reference.toString()]
96
+ // if (typeof data.note === 'undefined') data.note = -1
97
+ // data.note++
98
+ // data.note %= 25
99
+ // serv.playNoteBlock(data.note, player.world, reference)
100
+ // })
101
+ // player.on('dig_cancel', async ({ position }, cancel) => {
102
+ // const id = await player.world.getBlockType(position)
103
+ // if (id !== 25) return
104
+ // cancel(false)
105
+ // if (!player.world.blockEntityData[position.toString()]) player.world.blockEntityData[position.toString()] = {}
106
+ // const data = player.world.blockEntityData[position.toString()]
107
+ // if (typeof data.note === 'undefined') data.note = 0
108
+ // serv.playNoteBlock(data.note, player.world, position)
109
+ // })
110
+ };
111
+ exports.player = player;
112
+ const entity = function (entity, serv) {
113
+ entity.playSoundAtSelf = (sound, opt = {}) => {
114
+ serv.playSound(sound, entity.world, entity.position, opt);
115
+ };
116
+ };
117
+ exports.entity = entity;
118
+ //# sourceMappingURL=sound.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sound.js","sourceRoot":"","sources":["../../../src/lib/modules/sound.ts"],"names":[],"mappings":";;;AAAA,oCAAuC;AAEvC,+BAA2B;AAEpB,MAAM,MAAM,GAAG,UAAU,IAAY;IAC1C,IAAI,CAAC,SAAS,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,SAAS,GAAG,EAAE,EAAE,MAAM,GAAG,EAAE,EAAE,MAAM,GAAG,GAAG,EAAE,KAAK,GAAG,GAAG,EAAE,aAAa,GAAG,CAAC,KAAU,EAAE,EAAE,EAAE;QAC9I,MAAM,OAAO,GAAG,CAAC,OAAO,SAAS,KAAK,WAAW;YAC/C,CAAC,CAAC,CAAC,SAAS,YAAY,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;YACxD,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;gBACf,KAAK;gBACL,QAAQ;gBACR,MAAM;aACP,CAAC,CAAC,CAAA;QACL,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;aACvD,OAAO,CAAC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,MAAM,GAAG,UAAU,MAAc,EAAE,IAAY;IAC1D,MAAM,CAAC,SAAS,GAAG,CAAC,KAAK,EAAE,GAAG,GAAG,EAAE,EAAE,EAAE;QACrC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAA;IAC1E,CAAC,CAAA;IAED,oEAAoE;IACpE,iCAAiC;IACjC,0DAA0D;IAC1D,0BAA0B;IAC1B,kBAAkB;IAClB,qHAAqH;IACrH,oEAAoE;IACpE,yDAAyD;IACzD,gBAAgB;IAChB,oBAAoB;IACpB,2DAA2D;IAC3D,KAAK;IAEL,4DAA4D;IAC5D,yDAAyD;IACzD,0BAA0B;IAC1B,kBAAkB;IAClB,mHAAmH;IACnH,mEAAmE;IACnE,wDAAwD;IACxD,0DAA0D;IAC1D,KAAK;AACP,CAAC,CAAA;AA3BY,QAAA,MAAM,UA2BlB;AAEM,MAAM,MAAM,GAAG,UAAU,MAAc,EAAE,IAAY;IAC1D,MAAM,CAAC,eAAe,GAAG,CAAC,KAAK,EAAE,GAAG,GAAG,EAAE,EAAE,EAAE;QAC3C,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;IAC3D,CAAC,CAAA;AACH,CAAC,CAAA;AAJY,QAAA,MAAM,UAIlB"}
@@ -0,0 +1,33 @@
1
+ import { Vec3 } from 'vec3';
2
+ import { CustomWorld } from './world';
3
+ export declare const server: (serv: Server, options: Options) => void;
4
+ export declare const player: (player: Player, serv: Server, options: Options) => void;
5
+ export declare const entity: (entity: Entity, serv: Server) => void;
6
+ declare global {
7
+ interface Server {
8
+ }
9
+ interface Player {
10
+ }
11
+ interface Entity {
12
+ /** Only applies to gravity, really. You can still apply a velocity larger than terminal velocity. */
13
+ terminalvelocity: Vec3;
14
+ /** If a block drop, what item id */
15
+ itemId?: number;
16
+ /** If a block drop, what item damage */
17
+ itemDamage?: number;
18
+ /** World object entity is in */
19
+ world: CustomWorld;
20
+ /** Numerical type of the entity. */
21
+ entityType: number;
22
+ /** List of entities that the entity believes is nearby. */
23
+ nearbyEntities: Entity[];
24
+ /** How far away entities are loaded/unloaded (used for players ATM) */
25
+ viewDistance: number;
26
+ /** When an entity was born. Used with pickupTime and deathTime (time in epoch) */
27
+ bornTime: number;
28
+ /** Metadata for the entity (not like block metadata/damage). Contains stuff like NBT. */
29
+ metadata: any;
30
+ /** Pitch of entity's head */
31
+ headPitch: number;
32
+ }
33
+ }
@@ -0,0 +1,446 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.entity = exports.player = exports.server = void 0;
30
+ const uuid_1345_1 = __importDefault(require("uuid-1345"));
31
+ const utils_1 = require("../utils");
32
+ const vec3_1 = require("vec3");
33
+ const plugins = __importStar(require("./index"));
34
+ const user_error_1 = __importDefault(require("../user_error"));
35
+ const server = function (serv, options) {
36
+ const version = options.version;
37
+ const Entity = require('prismarine-entity')(version);
38
+ const mcData = serv.mcData;
39
+ const mobsById = mcData.mobs;
40
+ const objectsById = mcData.objects;
41
+ serv.initEntity = (type, entityType, world, position) => {
42
+ if (Object.keys(serv.entities).length > options['max-entities']) {
43
+ throw new Error('Too many mobs !');
44
+ }
45
+ serv.entityMaxId++;
46
+ const entity = new Entity(serv.entityMaxId);
47
+ for (const plugin of plugins.builtinPlugins)
48
+ plugin.entity?.(entity, serv, options);
49
+ entity.initEntity(type, entityType, world, position);
50
+ serv.emit('newEntity', entity);
51
+ return entity;
52
+ };
53
+ serv.spawnObject = (type, world, position, { pitch = 0, yaw = 0, velocity = new vec3_1.Vec3(0, 0, 0), data = 1, itemId, itemDamage = 0, itemCount = 1, pickupTime = undefined, deathTime = undefined }) => {
54
+ const object = serv.initEntity('object', type, world, position);
55
+ object.uuid = uuid_1345_1.default.v4();
56
+ // TODO: don't use objectsById, it doesn't exist
57
+ object.name = objectsById[type] === undefined ? 'unknown' : objectsById[type].name;
58
+ object.data = data;
59
+ object.velocity = velocity;
60
+ object.pitch = pitch;
61
+ object.yaw = yaw;
62
+ object.gravity = new vec3_1.Vec3(0, -20, 0);
63
+ object.terminalvelocity = new vec3_1.Vec3(27, 27, 27);
64
+ object.friction = new vec3_1.Vec3(15, 0, 15);
65
+ object.size = new vec3_1.Vec3(0.25, 0.25, 0.25); // Hardcoded, will be dependent on type!
66
+ object.deathTime = deathTime;
67
+ object.pickupTime = pickupTime;
68
+ object.itemId = itemId;
69
+ object.itemDamage = itemDamage;
70
+ object.itemCount = itemCount;
71
+ object.metadata = [
72
+ { key: 0, type: 0, value: 0 },
73
+ { key: 1, type: 1, value: 300 },
74
+ { key: 2, type: 5 },
75
+ { key: 3, type: 7, value: false },
76
+ { key: 4, type: 7, value: false }
77
+ ];
78
+ let key = 5;
79
+ if (mcData.version['>=']('1.10')) {
80
+ object.metadata.push({ key, type: 7, value: false });
81
+ ++key;
82
+ if (mcData.version['>=']('1.14')) {
83
+ object.metadata.push({ key, type: 18, value: 0 });
84
+ ++key;
85
+ }
86
+ }
87
+ object.metadata.push({
88
+ key,
89
+ type: 6,
90
+ value: {
91
+ present: true,
92
+ itemId,
93
+ itemCount
94
+ }
95
+ });
96
+ object.updateAndSpawn();
97
+ return object;
98
+ };
99
+ serv.spawnMob = (type, world, position, { pitch = 0, yaw = 0, headPitch = 0, velocity = new vec3_1.Vec3(0, 0, 0), metadata = [] } = {}) => {
100
+ const mob = serv.initEntity('mob', type, world, position);
101
+ mob.uuid = uuid_1345_1.default.v4();
102
+ mob.name = mobsById[type].name;
103
+ mob.velocity = velocity;
104
+ mob.pitch = pitch;
105
+ mob.headPitch = headPitch;
106
+ mob.yaw = yaw;
107
+ mob.gravity = new vec3_1.Vec3(0, -20, 0);
108
+ mob.terminalvelocity = new vec3_1.Vec3(27, 27, 27);
109
+ mob.friction = new vec3_1.Vec3(15, 0, 15);
110
+ mob.size = new vec3_1.Vec3(0.75, 1.75, 0.75);
111
+ mob.health = 20;
112
+ mob.metadata = metadata;
113
+ mob.updateAndSpawn();
114
+ return mob;
115
+ };
116
+ serv.destroyEntity = entity => {
117
+ entity._writeOthersNearby('entity_destroy', {
118
+ entityIds: [entity.id]
119
+ });
120
+ delete serv.entities[entity.id];
121
+ };
122
+ const entitiesByName = serv.mcData.entitiesByName;
123
+ serv.commands.add({
124
+ base: 'summon',
125
+ info: 'Summon an entity',
126
+ usage: '/summon <entity_name>',
127
+ onlyPlayer: true,
128
+ tab: ['entity'],
129
+ op: true,
130
+ action(name, ctx) {
131
+ if (Object.keys(serv.entities).length > options['max-entities']) {
132
+ throw new user_error_1.default('Too many mobs !');
133
+ }
134
+ const entity = entitiesByName[(0, utils_1.skipMcPrefix)(name)];
135
+ if (!entity) {
136
+ return 'No entity named ' + name;
137
+ }
138
+ if (entity.type === 'mob') {
139
+ serv.spawnMob(entity.id, ctx.player.world, ctx.player.position, {
140
+ velocity: new vec3_1.Vec3((Math.random() - 0.5) * 10, Math.random() * 10 + 10, (Math.random() - 0.5) * 10)
141
+ });
142
+ }
143
+ else if (entity.type === 'object') {
144
+ serv.spawnObject(entity.id, ctx.player.world, ctx.player.position, {
145
+ velocity: new vec3_1.Vec3((Math.random() - 0.5) * 10, Math.random() * 10 + 10, (Math.random() - 0.5) * 10)
146
+ });
147
+ }
148
+ }
149
+ });
150
+ serv.commands.add({
151
+ base: 'summonMany',
152
+ info: 'Summon many entities',
153
+ usage: '/summonMany <number> <entity_name>',
154
+ tab: ['number', 'entity'],
155
+ onlyPlayer: true,
156
+ op: true,
157
+ parse(str) {
158
+ const args = str.split(' ');
159
+ if (args.length !== 2) {
160
+ return false;
161
+ }
162
+ return { number: +args[0], name: args[1] };
163
+ },
164
+ action({ number, name }, ctx) {
165
+ if (Object.keys(serv.entities).length > options['max-entities'] - number) {
166
+ throw new user_error_1.default('Too many mobs !');
167
+ }
168
+ const entity = entitiesByName[(0, utils_1.skipMcPrefix)(name)];
169
+ if (!entity) {
170
+ return 'No entity named ' + name;
171
+ }
172
+ const s = Math.floor(Math.sqrt(number));
173
+ for (let i = 0; i < number; i++) {
174
+ if (entity.type === 'mob') {
175
+ serv.spawnMob(entity.id, ctx.player.world, ctx.player.position.offset(Math.floor(i / s * 10), 0, i % s * 10), {
176
+ velocity: new vec3_1.Vec3((Math.random() - 0.5) * 10, Math.random() * 10 + 10, (Math.random() - 0.5) * 10)
177
+ });
178
+ }
179
+ else if (entity.type === 'object') {
180
+ serv.spawnObject(entity.id, ctx.player.world, ctx.player.position.offset(Math.floor(i / s * 10), 0, i % s * 10), {
181
+ velocity: new vec3_1.Vec3((Math.random() - 0.5) * 10, Math.random() * 10 + 10, (Math.random() - 0.5) * 10)
182
+ });
183
+ }
184
+ }
185
+ }
186
+ });
187
+ serv.commands.add({
188
+ base: 'pile',
189
+ info: 'make a pile of entities',
190
+ usage: '/pile <entities types>',
191
+ onlyPlayer: true,
192
+ op: true,
193
+ parse(str) {
194
+ const args = str.split(' ');
195
+ if (args.length === 0) {
196
+ return false;
197
+ }
198
+ return args
199
+ .map(name => entitiesByName[name])
200
+ .filter(entity => !!entity);
201
+ },
202
+ action(entityTypes, ctx) {
203
+ if (Object.keys(serv.entities).length > options['max-entities'] - entityTypes.length) {
204
+ throw new user_error_1.default('Too many mobs !');
205
+ }
206
+ entityTypes.map(entity => {
207
+ if (entity.type === 'mob') {
208
+ return serv.spawnMob(entity.id, ctx.player.world, ctx.player.position, {
209
+ velocity: new vec3_1.Vec3((Math.random() - 0.5) * 10, Math.random() * 10 + 10, (Math.random() - 0.5) * 10)
210
+ });
211
+ }
212
+ else if (entity.type === 'object') {
213
+ return serv.spawnObject(entity.id, ctx.player.world, ctx.player.position, {
214
+ velocity: new vec3_1.Vec3((Math.random() - 0.5) * 10, Math.random() * 10 + 10, (Math.random() - 0.5) * 10)
215
+ });
216
+ }
217
+ else {
218
+ return Promise.resolve();
219
+ }
220
+ })
221
+ .reduce((prec, entity) => {
222
+ if (prec !== null) {
223
+ prec.attach(entity);
224
+ }
225
+ return entity;
226
+ }, null);
227
+ }
228
+ });
229
+ serv.commands.add({
230
+ base: 'attach',
231
+ info: 'attach an entity on an other entity',
232
+ usage: '/attach <carrier> <attached>',
233
+ op: true,
234
+ parse(str, ctx) {
235
+ const args = str.split(' ');
236
+ if (args.length !== 2) {
237
+ return false;
238
+ }
239
+ const carrier = ctx.player ? ctx.player.selectorString(args[0]) : serv.selectorString(args[0]);
240
+ if (carrier.length === 0)
241
+ throw new user_error_1.default('one carrier');
242
+ const attached = ctx.player ? ctx.player.selectorString(args[1]) : serv.selectorString(args[1]);
243
+ if (attached.length === 0)
244
+ throw new user_error_1.default('one attached');
245
+ return { carrier: carrier[0], attached: attached[0] };
246
+ },
247
+ action({ carrier, attached }) {
248
+ carrier.attach(attached);
249
+ }
250
+ });
251
+ };
252
+ exports.server = server;
253
+ const player = function (player, serv, options) {
254
+ const version = options.version;
255
+ const Item = require('prismarine-item')(version);
256
+ player.spawnEntity = entity => {
257
+ player._client.write(entity.spawnPacketName, entity.getSpawnPacket());
258
+ if (serv.supportFeature('entityMetadataSentSeparately')) {
259
+ entity.sendMetadata(entity.metadata);
260
+ }
261
+ if (typeof entity.itemId !== 'undefined') {
262
+ if (serv.supportFeature('theFlattening')) {
263
+ entity.sendMetadata([{
264
+ key: 6,
265
+ type: 6,
266
+ value: {
267
+ present: true,
268
+ itemId: entity.itemId,
269
+ itemCount: entity.itemCount
270
+ }
271
+ }]);
272
+ }
273
+ else {
274
+ entity.sendMetadata([{
275
+ key: 10,
276
+ type: 5,
277
+ value: {
278
+ blockId: entity.itemId,
279
+ itemDamage: entity.itemDamage,
280
+ itemCount: entity.itemCount
281
+ }
282
+ }]);
283
+ }
284
+ }
285
+ if (serv.supportFeature('allEntityEquipmentInOne')) {
286
+ const equipments = [];
287
+ entity.equipment.forEach((equipment, slot) => {
288
+ if (equipment !== undefined) {
289
+ equipments.push({
290
+ slot,
291
+ item: Item.toNotch(equipment)
292
+ });
293
+ }
294
+ });
295
+ if (equipments.length > 0) {
296
+ player._client.write('entity_equipment', {
297
+ entityId: entity.id,
298
+ equipments
299
+ });
300
+ }
301
+ }
302
+ else {
303
+ entity.equipment.forEach((equipment, slot) => {
304
+ if (equipment !== undefined) {
305
+ player._client.write('entity_equipment', {
306
+ entityId: entity.id,
307
+ slot,
308
+ item: Item.toNotch(equipment)
309
+ });
310
+ }
311
+ });
312
+ }
313
+ };
314
+ };
315
+ exports.player = player;
316
+ const entity = function (entity, serv) {
317
+ entity.initEntity = (type, entityType, world, position) => {
318
+ entity.type = type;
319
+ entity.spawnPacketName = '';
320
+ entity.entityType = entityType;
321
+ entity.world = world;
322
+ entity.position = position;
323
+ entity.lastPositionPlayersUpdated = entity.position.clone();
324
+ entity.nearbyEntities = [];
325
+ entity.viewDistance = 150;
326
+ entity.score = {};
327
+ entity.bornTime = Date.now();
328
+ serv.entities[entity.id] = entity;
329
+ if (entity.type === 'player')
330
+ entity.spawnPacketName = 'named_entity_spawn';
331
+ else if (entity.type === 'object')
332
+ entity.spawnPacketName = 'spawn_entity';
333
+ else if (entity.type === 'mob')
334
+ entity.spawnPacketName = 'spawn_entity_living';
335
+ };
336
+ entity.getSpawnPacket = () => {
337
+ let scaledVelocity = entity.velocity.scaled(8000 / 20); // from fixed-position/second to unit => 1/8000 blocks per tick
338
+ if (serv.supportFeature('fixedPointPosition')) {
339
+ scaledVelocity = scaledVelocity.scaled(1 / 32);
340
+ }
341
+ scaledVelocity = scaledVelocity.floored();
342
+ let entityPosition;
343
+ if (serv.supportFeature('fixedPointPosition')) {
344
+ entityPosition = entity.position.scaled(32).floored();
345
+ }
346
+ else if (serv.supportFeature('doublePosition')) {
347
+ entityPosition = entity.position;
348
+ }
349
+ if (entity.type === 'player') {
350
+ return {
351
+ entityId: entity.id,
352
+ playerUUID: entity.uuid,
353
+ x: entityPosition.x,
354
+ y: entityPosition.y,
355
+ z: entityPosition.z,
356
+ yaw: entity.yaw,
357
+ pitch: entity.pitch,
358
+ currentItem: 0,
359
+ metadata: entity.metadata
360
+ };
361
+ }
362
+ else if (entity.type === 'object') {
363
+ return {
364
+ entityId: entity.id,
365
+ objectUUID: entity.uuid,
366
+ type: entity.entityType,
367
+ x: entityPosition.x,
368
+ y: entityPosition.y,
369
+ z: entityPosition.z,
370
+ pitch: entity.pitch,
371
+ yaw: entity.yaw,
372
+ objectData: entity.data,
373
+ velocityX: scaledVelocity.x,
374
+ velocityY: scaledVelocity.y,
375
+ velocityZ: scaledVelocity.z
376
+ };
377
+ }
378
+ else if (entity.type === 'mob') {
379
+ return {
380
+ entityId: entity.id,
381
+ entityUUID: entity.uuid,
382
+ type: entity.entityType,
383
+ x: entityPosition.x,
384
+ y: entityPosition.y,
385
+ z: entityPosition.z,
386
+ yaw: entity.yaw,
387
+ pitch: entity.pitch,
388
+ headPitch: entity.headPitch,
389
+ velocityX: scaledVelocity.x,
390
+ velocityY: scaledVelocity.y,
391
+ velocityZ: scaledVelocity.z,
392
+ metadata: entity.metadata
393
+ };
394
+ }
395
+ };
396
+ entity.updateAndSpawn = () => {
397
+ const updatedEntities = entity.getNearby();
398
+ const entitiesToAdd = updatedEntities.filter(e => entity.nearbyEntities.indexOf(e) === -1);
399
+ const entitiesToRemove = entity.nearbyEntities.filter(e => updatedEntities.indexOf(e) === -1);
400
+ if (entity.type === 'player') {
401
+ entity.despawnEntities(entitiesToRemove);
402
+ entitiesToAdd.forEach(entity.spawnEntity);
403
+ }
404
+ entity.lastPositionPlayersUpdated = entity.position.clone();
405
+ const playersToAdd = entitiesToAdd.filter(e => e.type === 'player');
406
+ const playersToRemove = entitiesToRemove.filter(e => e.type === 'player');
407
+ playersToRemove.forEach(p => p.despawnEntities([entity]));
408
+ playersToRemove.forEach(p => { p.nearbyEntities = p.getNearby(); });
409
+ playersToAdd.forEach(p => p.spawnEntity(entity));
410
+ playersToAdd.forEach(p => { p.nearbyEntities = p.getNearby(); });
411
+ entity.nearbyEntities = updatedEntities;
412
+ };
413
+ entity.on('move', () => {
414
+ if (entity.position.distanceTo(entity.lastPositionPlayersUpdated) > 2) {
415
+ entity.updateAndSpawn();
416
+ }
417
+ });
418
+ entity.destroy = () => {
419
+ serv.destroyEntity(entity);
420
+ };
421
+ entity.attach = (attachedEntity, leash = false) => {
422
+ if (serv.supportFeature('attachStackEntity') || (serv.supportFeature('setPassengerStackEntity') && leash)) {
423
+ const p = {
424
+ entityId: attachedEntity.id,
425
+ vehicleId: entity.id,
426
+ leash
427
+ };
428
+ if (entity.type === 'player') {
429
+ entity._client.write('attach_entity', p);
430
+ }
431
+ entity._writeOthersNearby('attach_entity', p);
432
+ }
433
+ if (serv.supportFeature('setPassengerStackEntity')) {
434
+ const p = {
435
+ entityId: entity.id,
436
+ passengers: [attachedEntity.id]
437
+ };
438
+ if (entity.type === 'player') {
439
+ entity._client.write('set_passengers', p);
440
+ }
441
+ entity._writeOthersNearby('set_passengers', p);
442
+ }
443
+ };
444
+ };
445
+ exports.entity = entity;
446
+ //# sourceMappingURL=spawn.js.map