fixed respawn and attach (/pile)

This commit is contained in:
Romain Beaumont 2018-05-27 18:24:59 +02:00
parent d127704022
commit efc4ab786d
No known key found for this signature in database
GPG key ID: DB60E388B3BCF286
3 changed files with 48 additions and 11 deletions

View file

@ -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"]
}
]

View file

@ -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,

View file

@ -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)
}
}