From efc4ab786db6be4422be292a8dc02ecf2b3eb4f1 Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Sun, 27 May 2018 18:24:59 +0200 Subject: [PATCH] fixed respawn and attach (/pile) --- src/lib/features.json | 20 ++++++++++++++++++++ src/lib/plugins/respawn.js | 12 ++++++++++-- src/lib/plugins/spawn.js | 27 ++++++++++++++++++--------- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/lib/features.json b/src/lib/features.json index 838e6e8..4238a92 100644 --- a/src/lib/features.json +++ b/src/lib/features.json @@ -38,5 +38,25 @@ "name": "entitySnakeCase", "description": "entity name are in snake case", "versions": ["1.12"] + }, + { + "name": "respawnIsPayload", + "description": "respawn field is payload", + "versions": ["1.8"] + }, + { + "name": "respawnIsActionId", + "description": "respawn field is action id", + "versions": ["1.12"] + }, + { + "name": "attachStackEntity", + "description": "attach is used to stack entities", + "versions": ["1.8"] + }, + { + "name": "setPassengerStackEntity", + "description": "set passengers is used to stack entities", + "versions": ["1.12"] } ] \ No newline at end of file diff --git a/src/lib/plugins/respawn.js b/src/lib/plugins/respawn.js index 71348c8..b914acb 100644 --- a/src/lib/plugins/respawn.js +++ b/src/lib/plugins/respawn.js @@ -1,6 +1,14 @@ module.exports.player = function (player, serv) { - player._client.on('client_command', ({payload}) => { - if (payload === 0) { + player._client.on('client_command', (data) => { + let actionId + + if (serv.supportFeature('respawnIsPayload')) { + actionId = data['payload'] + } else if (serv.supportFeature('respawnIsActionId')) { + actionId = data['actionId'] + } + + if (actionId === 0) { player.behavior('requestRespawn', {}, () => { player._client.write('respawn', { dimension: 0, diff --git a/src/lib/plugins/spawn.js b/src/lib/plugins/spawn.js index 9abebaf..1f2131c 100644 --- a/src/lib/plugins/spawn.js +++ b/src/lib/plugins/spawn.js @@ -152,15 +152,14 @@ module.exports.player = function (player, serv, options) { if (Object.keys(serv.entities).length > options['max-entities'] - entityTypes.length) { throw new UserError('Too many mobs !') } entityTypes.map(entity => { if (entity.type === 'mob') { - serv.spawnMob(entity.id, player.world, player.position, { + return serv.spawnMob(entity.id, player.world, player.position, { velocity: Vec3((Math.random() - 0.5) * 10, Math.random() * 10 + 10, (Math.random() - 0.5) * 10) }) } else if (entity.type === 'object') { - serv.spawnObject(entity.id, player.world, player.position, { + return serv.spawnObject(entity.id, player.world, player.position, { velocity: Vec3((Math.random() - 0.5) * 10, Math.random() * 10 + 10, (Math.random() - 0.5) * 10) }) } - return entity }) .reduce((prec, entity) => { if (prec !== null) { prec.attach(entity) } @@ -328,12 +327,22 @@ module.exports.entity = function (entity, serv) { } entity.attach = (attachedEntity, leash = false) => { - const p = { - entityId: attachedEntity.id, - vehicleId: entity.id, - leash: leash + if (serv.supportFeature('attachStackEntity') || (serv.supportFeature('setPassengerStackEntity') && leash)) { + const p = { + entityId: attachedEntity.id, + vehicleId: entity.id, + leash: leash + } + if (entity.type === 'player') { entity._client.write('attach_entity', p) } + entity._writeOthersNearby('attach_entity', p) + } + if (serv.supportFeature('setPassengerStackEntity')) { + const p = { + entityId: entity.id, + passengers: [ attachedEntity.id ] + } + if (entity.type === 'player') { entity._client.write('set_passengers', p) } + entity._writeOthersNearby('set_passengers', p) } - if (entity.type === 'player') { entity._client.write('attach_entity', p) } - entity._writeOthersNearby('attach_entity', p) } }