mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-07 12:10:46 +00:00
fix entities in 1.12 : uuid support
This commit is contained in:
parent
c213a06c38
commit
ed2f5df538
9 changed files with 47 additions and 30 deletions
|
|
@ -32,7 +32,6 @@
|
||||||
"minecraft-protocol": "^1.5.2",
|
"minecraft-protocol": "^1.5.2",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
"moment": "^2.10.6",
|
"moment": "^2.10.6",
|
||||||
"node-uuid": "^1.4.3",
|
|
||||||
"prismarine-chunk": "^1.9.0",
|
"prismarine-chunk": "^1.9.0",
|
||||||
"prismarine-entity": "^0.2.0",
|
"prismarine-entity": "^0.2.0",
|
||||||
"prismarine-item": "^1.0.1",
|
"prismarine-item": "^1.0.1",
|
||||||
|
|
@ -44,6 +43,7 @@
|
||||||
"request": "^2.83.0",
|
"request": "^2.83.0",
|
||||||
"request-promise": "^4.1.0",
|
"request-promise": "^4.1.0",
|
||||||
"spiralloop": "^1.0.2",
|
"spiralloop": "^1.0.2",
|
||||||
|
"uuid-1345": "^0.99.6",
|
||||||
"vec3": "^0.1.3"
|
"vec3": "^0.1.3"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
||||||
|
|
@ -28,5 +28,15 @@
|
||||||
"name": "fixedPointDelta128",
|
"name": "fixedPointDelta128",
|
||||||
"description": "Delta of position are represented with fixed point numbers times 128",
|
"description": "Delta of position are represented with fixed point numbers times 128",
|
||||||
"versions": ["1.12"]
|
"versions": ["1.12"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "entityCamelCase",
|
||||||
|
"description": "entity names are in camel case",
|
||||||
|
"versions": ["1.8"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "entitySnakeCase",
|
||||||
|
"description": "entity name are in snake case",
|
||||||
|
"versions": ["1.12"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -13,7 +13,7 @@ module.exports.server = function (serv) {
|
||||||
const players = serv.getNearby({
|
const players = serv.getNearby({
|
||||||
world: entity.world,
|
world: entity.world,
|
||||||
position: entity.position,
|
position: entity.position,
|
||||||
radius: 1.5 * 32 // Seems good for now
|
radius: 1.5 // Seems good for now
|
||||||
})
|
})
|
||||||
if (players.length) {
|
if (players.length) {
|
||||||
players[0].collect(entity)
|
players[0].collect(entity)
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,9 @@ module.exports.player = function (player, serv, settings) {
|
||||||
player.crouching = false // Needs added in prismarine-entity later
|
player.crouching = false // Needs added in prismarine-entity later
|
||||||
player.op = settings['everybody-op'] // REMOVE THIS WHEN OUT OF TESTING
|
player.op = settings['everybody-op'] // REMOVE THIS WHEN OUT OF TESTING
|
||||||
player.username = player._client.username
|
player.username = player._client.username
|
||||||
|
player.uuid = player._client.uuid
|
||||||
serv.players.push(player)
|
serv.players.push(player)
|
||||||
serv.uuidToPlayer[player._client.uuid] = player
|
serv.uuidToPlayer[player.uuid] = player
|
||||||
player.heldItemSlot = 0
|
player.heldItemSlot = 0
|
||||||
player.loadedChunks = {}
|
player.loadedChunks = {}
|
||||||
}
|
}
|
||||||
|
|
@ -80,7 +81,7 @@ module.exports.player = function (player, serv, settings) {
|
||||||
serv._writeAll('player_info', {
|
serv._writeAll('player_info', {
|
||||||
action: 1,
|
action: 1,
|
||||||
data: [{
|
data: [{
|
||||||
UUID: player._client.uuid,
|
UUID: player.uuid,
|
||||||
gamemode: player.gameMode
|
gamemode: player.gameMode
|
||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
|
|
@ -91,7 +92,7 @@ module.exports.player = function (player, serv, settings) {
|
||||||
player._writeOthers('player_info', {
|
player._writeOthers('player_info', {
|
||||||
action: 0,
|
action: 0,
|
||||||
data: [{
|
data: [{
|
||||||
UUID: player._client.uuid,
|
UUID: player.uuid,
|
||||||
name: player.username,
|
name: player.username,
|
||||||
properties: player.profileProperties,
|
properties: player.profileProperties,
|
||||||
gamemode: player.gameMode,
|
gamemode: player.gameMode,
|
||||||
|
|
@ -102,7 +103,7 @@ module.exports.player = function (player, serv, settings) {
|
||||||
player._client.write('player_info', {
|
player._client.write('player_info', {
|
||||||
action: 0,
|
action: 0,
|
||||||
data: serv.players.map((otherPlayer) => ({
|
data: serv.players.map((otherPlayer) => ({
|
||||||
UUID: otherPlayer._client.uuid,
|
UUID: otherPlayer.uuid,
|
||||||
name: otherPlayer.username,
|
name: otherPlayer.username,
|
||||||
properties: otherPlayer.profileProperties,
|
properties: otherPlayer.profileProperties,
|
||||||
gamemode: otherPlayer.gameMode,
|
gamemode: otherPlayer.gameMode,
|
||||||
|
|
@ -112,7 +113,7 @@ module.exports.player = function (player, serv, settings) {
|
||||||
setInterval(() => player._client.write('player_info', {
|
setInterval(() => player._client.write('player_info', {
|
||||||
action: 2,
|
action: 2,
|
||||||
data: serv.players.map(otherPlayer => ({
|
data: serv.players.map(otherPlayer => ({
|
||||||
UUID: otherPlayer._client.uuid,
|
UUID: otherPlayer.uuid,
|
||||||
ping: otherPlayer._client.latency
|
ping: otherPlayer._client.latency
|
||||||
}))
|
}))
|
||||||
}), 5000)
|
}), 5000)
|
||||||
|
|
@ -135,12 +136,12 @@ module.exports.player = function (player, serv, settings) {
|
||||||
}
|
}
|
||||||
|
|
||||||
player.login = async () => {
|
player.login = async () => {
|
||||||
if (serv.uuidToPlayer[player._client.uuid]) {
|
if (serv.uuidToPlayer[player.uuid]) {
|
||||||
player.kick('You are already connected')
|
player.kick('You are already connected')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (serv.bannedPlayers[player._client.uuid]) {
|
if (serv.bannedPlayers[player.uuid]) {
|
||||||
player.kick(serv.bannedPlayers[player._client.uuid].reason)
|
player.kick(serv.bannedPlayers[player.uuid].reason)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (serv.bannedIPs[player._client.socket.remoteAddress]) {
|
if (serv.bannedIPs[player._client.socket.remoteAddress]) {
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ module.exports.player = function (player, serv) {
|
||||||
player._writeOthers('player_info', {
|
player._writeOthers('player_info', {
|
||||||
action: 4,
|
action: 4,
|
||||||
data: [{
|
data: [{
|
||||||
UUID: player._client.uuid
|
UUID: player.uuid
|
||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
player.nearbyPlayers().forEach(otherPlayer => otherPlayer.despawnEntities([player]))
|
player.nearbyPlayers().forEach(otherPlayer => otherPlayer.despawnEntities([player]))
|
||||||
|
|
@ -32,7 +32,7 @@ module.exports.player = function (player, serv) {
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
serv.players.splice(index, 1)
|
serv.players.splice(index, 1)
|
||||||
}
|
}
|
||||||
delete serv.uuidToPlayer[player._client.uuid]
|
delete serv.uuidToPlayer[player.uuid]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
const moment = require('moment')
|
const moment = require('moment')
|
||||||
const rp = require('request-promise')
|
const rp = require('request-promise')
|
||||||
const nodeUuid = require('node-uuid')
|
const UUID = require('uuid-1345')
|
||||||
|
|
||||||
module.exports.server = function (serv) {
|
module.exports.server = function (serv) {
|
||||||
serv.ban = (uuid, reason) => {
|
serv.ban = (uuid, reason) => {
|
||||||
|
|
@ -20,7 +20,7 @@ module.exports.server = function (serv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function uuidInParts (plainUUID) {
|
function uuidInParts (plainUUID) {
|
||||||
return nodeUuid.unparse(nodeUuid.parse(plainUUID))
|
return UUID.stringify(UUID.parse(plainUUID))
|
||||||
}
|
}
|
||||||
|
|
||||||
serv.getUUIDFromUsername = username => {
|
serv.getUUIDFromUsername = username => {
|
||||||
|
|
@ -65,7 +65,7 @@ module.exports.player = function (player, serv) {
|
||||||
player.ban = reason => {
|
player.ban = reason => {
|
||||||
reason = reason || 'You were banned!'
|
reason = reason || 'You were banned!'
|
||||||
player.kick(reason)
|
player.kick(reason)
|
||||||
const uuid = player._client.uuid
|
const uuid = player.uuid
|
||||||
serv.ban(uuid, reason)
|
serv.ban(uuid, reason)
|
||||||
}
|
}
|
||||||
player.banIP = reason => {
|
player.banIP = reason => {
|
||||||
|
|
@ -74,7 +74,7 @@ module.exports.player = function (player, serv) {
|
||||||
serv.banIP(player._client.socket.remoteAddress)
|
serv.banIP(player._client.socket.remoteAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
player.pardon = () => serv.pardon(player._client.uuid)
|
player.pardon = () => serv.pardon(player.uuid)
|
||||||
|
|
||||||
player.commands.add({
|
player.commands.add({
|
||||||
base: 'kick',
|
base: 'kick',
|
||||||
|
|
|
||||||
|
|
@ -60,9 +60,9 @@ module.exports.entity = function (entity, serv, {version}) {
|
||||||
function getMoveAmount (dir, block, entity, delta, sizeSigned) {
|
function getMoveAmount (dir, block, entity, delta, sizeSigned) {
|
||||||
if (block) {
|
if (block) {
|
||||||
entity.velocity[dir] = 0
|
entity.velocity[dir] = 0
|
||||||
return Math.floor(-1 * (entity.position[dir] + sizeSigned / 2 - floorInDirection(entity.position[dir], -sizeSigned)))
|
return -1 * (entity.position[dir] + sizeSigned / 2 - entity.position[dir])
|
||||||
} else {
|
} else {
|
||||||
return Math.floor(entity.velocity[dir] * delta)
|
return entity.velocity[dir] * delta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,10 +70,6 @@ module.exports.entity = function (entity, serv, {version}) {
|
||||||
return new Vec3(Math.sign(vec.x), Math.sign(vec.y), Math.sign(vec.z))
|
return new Vec3(Math.sign(vec.x), Math.sign(vec.y), Math.sign(vec.z))
|
||||||
}
|
}
|
||||||
|
|
||||||
function floorInDirection (a, b) {
|
|
||||||
return b < 0 ? Math.floor(a) : Math.ceil(a)
|
|
||||||
}
|
|
||||||
|
|
||||||
function addGravity (entity, dir, delta) {
|
function addGravity (entity, dir, delta) {
|
||||||
if (entity.velocity[dir] < entity.terminalvelocity[dir] && entity.velocity[dir] > -entity.terminalvelocity[dir]) {
|
if (entity.velocity[dir] < entity.terminalvelocity[dir] && entity.velocity[dir] > -entity.terminalvelocity[dir]) {
|
||||||
entity.velocity[dir] = clamp(-entity.terminalvelocity[dir], entity.velocity[dir] + entity.gravity[dir] * delta, entity.terminalvelocity[dir])
|
entity.velocity[dir] = clamp(-entity.terminalvelocity[dir], entity.velocity[dir] + entity.gravity[dir] * delta, entity.terminalvelocity[dir])
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ const path = require('path')
|
||||||
const requireIndex = require('../requireindex')
|
const requireIndex = require('../requireindex')
|
||||||
const plugins = requireIndex(path.join(__dirname, '..', 'plugins'))
|
const plugins = requireIndex(path.join(__dirname, '..', 'plugins'))
|
||||||
const UserError = require('flying-squid').UserError
|
const UserError = require('flying-squid').UserError
|
||||||
|
const UUID = require('uuid-1345')
|
||||||
const Vec3 = require('vec3').Vec3
|
const Vec3 = require('vec3').Vec3
|
||||||
|
|
||||||
module.exports.server = function (serv, options) {
|
module.exports.server = function (serv, options) {
|
||||||
|
|
@ -30,6 +30,7 @@ module.exports.server = function (serv, options) {
|
||||||
|
|
||||||
serv.spawnObject = (type, world, position, {pitch = 0, yaw = 0, velocity = new Vec3(0, 0, 0), data = 1, itemId, itemDamage = 0, pickupTime = undefined, deathTime = undefined}) => {
|
serv.spawnObject = (type, world, position, {pitch = 0, yaw = 0, velocity = new Vec3(0, 0, 0), data = 1, itemId, itemDamage = 0, pickupTime = undefined, deathTime = undefined}) => {
|
||||||
const object = serv.initEntity('object', type, world, position)
|
const object = serv.initEntity('object', type, world, position)
|
||||||
|
object.uuid = UUID.v4()
|
||||||
object.name = objectsById[type].name
|
object.name = objectsById[type].name
|
||||||
object.data = data
|
object.data = data
|
||||||
object.velocity = velocity
|
object.velocity = velocity
|
||||||
|
|
@ -49,6 +50,7 @@ module.exports.server = function (serv, options) {
|
||||||
|
|
||||||
serv.spawnMob = (type, world, position, {pitch = 0, yaw = 0, headPitch = 0, velocity = new Vec3(0, 0, 0), metadata = []} = {}) => {
|
serv.spawnMob = (type, world, position, {pitch = 0, yaw = 0, headPitch = 0, velocity = new Vec3(0, 0, 0), metadata = []} = {}) => {
|
||||||
const mob = serv.initEntity('mob', type, world, position)
|
const mob = serv.initEntity('mob', type, world, position)
|
||||||
|
mob.uuid = UUID.v4()
|
||||||
mob.name = mobsById[type].name
|
mob.name = mobsById[type].name
|
||||||
mob.velocity = velocity
|
mob.velocity = velocity
|
||||||
mob.pitch = pitch
|
mob.pitch = pitch
|
||||||
|
|
@ -250,7 +252,7 @@ module.exports.entity = function (entity, serv) {
|
||||||
if (entity.type === 'player') {
|
if (entity.type === 'player') {
|
||||||
return {
|
return {
|
||||||
entityId: entity.id,
|
entityId: entity.id,
|
||||||
playerUUID: entity._client.uuid,
|
playerUUID: entity.uuid,
|
||||||
x: entityPosition.x,
|
x: entityPosition.x,
|
||||||
y: entityPosition.y,
|
y: entityPosition.y,
|
||||||
z: entityPosition.z,
|
z: entityPosition.z,
|
||||||
|
|
@ -262,6 +264,7 @@ module.exports.entity = function (entity, serv) {
|
||||||
} else if (entity.type === 'object') {
|
} else if (entity.type === 'object') {
|
||||||
return {
|
return {
|
||||||
entityId: entity.id,
|
entityId: entity.id,
|
||||||
|
objectUUID: entity.uuid,
|
||||||
type: entity.entityType,
|
type: entity.entityType,
|
||||||
x: entityPosition.x,
|
x: entityPosition.x,
|
||||||
y: entityPosition.y,
|
y: entityPosition.y,
|
||||||
|
|
@ -278,6 +281,7 @@ module.exports.entity = function (entity, serv) {
|
||||||
} else if (entity.type === 'mob') {
|
} else if (entity.type === 'mob') {
|
||||||
return {
|
return {
|
||||||
entityId: entity.id,
|
entityId: entity.id,
|
||||||
|
entityUUID: entity.uuid,
|
||||||
type: entity.entityType,
|
type: entity.entityType,
|
||||||
x: entityPosition.x,
|
x: entityPosition.x,
|
||||||
y: entityPosition.y,
|
y: entityPosition.y,
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ squid.supportedVersions.forEach((supportedVersion, i) => {
|
||||||
let bot
|
let bot
|
||||||
let bot2
|
let bot2
|
||||||
let serv
|
let serv
|
||||||
|
let entityName
|
||||||
|
|
||||||
async function onGround (bot) {
|
async function onGround (bot) {
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
|
|
@ -81,6 +82,11 @@ squid.supportedVersions.forEach((supportedVersion, i) => {
|
||||||
options['version'] = version.minecraftVersion
|
options['version'] = version.minecraftVersion
|
||||||
|
|
||||||
serv = squid.createMCServer(options)
|
serv = squid.createMCServer(options)
|
||||||
|
if (serv.supportFeature('entityCamelCase')) {
|
||||||
|
entityName = 'EnderDragon'
|
||||||
|
} else {
|
||||||
|
entityName = 'ender_dragon'
|
||||||
|
}
|
||||||
|
|
||||||
await once(serv, 'listening')
|
await once(serv, 'listening')
|
||||||
const port = serv._server.socketServer.address().port
|
const port = serv._server.socketServer.address().port
|
||||||
|
|
@ -159,7 +165,7 @@ squid.supportedVersions.forEach((supportedVersion, i) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('commands', () => {
|
describe('commands', () => {
|
||||||
jest.setTimeout(10 * 1000)
|
jest.setTimeout(20 * 1000)
|
||||||
test('has an help command', async () => {
|
test('has an help command', async () => {
|
||||||
await waitLoginMessage(bot)
|
await waitLoginMessage(bot)
|
||||||
bot.chat('/help')
|
bot.chat('/help')
|
||||||
|
|
@ -177,7 +183,7 @@ squid.supportedVersions.forEach((supportedVersion, i) => {
|
||||||
function waitDragon () {
|
function waitDragon () {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const listener = (entity) => {
|
const listener = (entity) => {
|
||||||
if (entity.name === 'EnderDragon') {
|
if (entity.name === entityName) {
|
||||||
bot.removeListener('entitySpawn', listener)
|
bot.removeListener('entitySpawn', listener)
|
||||||
resolve()
|
resolve()
|
||||||
}
|
}
|
||||||
|
|
@ -187,15 +193,15 @@ squid.supportedVersions.forEach((supportedVersion, i) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
test('can use /summon', async () => {
|
test('can use /summon', async () => {
|
||||||
bot.chat('/summon EnderDragon')
|
bot.chat('/summon ' + entityName)
|
||||||
await waitDragon()
|
await waitDragon()
|
||||||
})
|
})
|
||||||
test('can use /kill', async () => {
|
test('can use /kill', async () => {
|
||||||
bot.chat('/summon EnderDragon')
|
bot.chat('/summon ' + entityName)
|
||||||
await waitDragon()
|
await waitDragon()
|
||||||
bot.chat('/kill @e[type=EnderDragon]')
|
bot.chat('/kill @e[type=' + entityName + ']')
|
||||||
const entity = await once(bot, 'entityDead')
|
const entity = await once(bot, 'entityDead')
|
||||||
expect(entity.name).toEqual('EnderDragon')
|
expect(entity.name).toEqual(entityName)
|
||||||
})
|
})
|
||||||
describe('can use /tp', () => {
|
describe('can use /tp', () => {
|
||||||
test('can tp myself', async () => {
|
test('can tp myself', async () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue