mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-05 03:00:46 +00:00
update to standard 12
This commit is contained in:
parent
7c0744d536
commit
43b665bb84
36 changed files with 112 additions and 112 deletions
|
|
@ -57,8 +57,8 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"jest": "^22.1.4",
|
"jest": "^22.1.4",
|
||||||
"longjohn": "^0.2.12",
|
"longjohn": "^0.2.12",
|
||||||
"mineflayer": "^2.6.1",
|
"mineflayer": "^2.7.3",
|
||||||
"require-self": "^0.2.1",
|
"require-self": "^0.2.1",
|
||||||
"standard": "^11.0.1"
|
"standard": "^12.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
module.exports = {distanceToXpLevel, getXpLevel, getXpRequired, getBaseXpFromLevel}
|
module.exports = { distanceToXpLevel, getXpLevel, getXpRequired, getBaseXpFromLevel }
|
||||||
|
|
||||||
function distanceToXpLevel (xp, toLevel) {
|
function distanceToXpLevel (xp, toLevel) {
|
||||||
const level = getXpLevel(xp)
|
const level = getXpLevel(xp)
|
||||||
|
|
|
||||||
|
|
@ -8,16 +8,16 @@ module.exports.player = function (player) {
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
player._client.on('entity_action', ({actionId} = {}) => {
|
player._client.on('entity_action', ({ actionId } = {}) => {
|
||||||
if (actionId === 3) {
|
if (actionId === 3) {
|
||||||
player.setAndUpdateMetadata([{'key': 0, 'type': 0, 'value': 0x08}])
|
player.setAndUpdateMetadata([{ 'key': 0, 'type': 0, 'value': 0x08 }])
|
||||||
} else if (actionId === 4) {
|
} else if (actionId === 4) {
|
||||||
player.setAndUpdateMetadata([{'key': 0, 'type': 0, 'value': 0x00}])
|
player.setAndUpdateMetadata([{ 'key': 0, 'type': 0, 'value': 0x00 }])
|
||||||
} else if (actionId === 0) {
|
} else if (actionId === 0) {
|
||||||
player.setAndUpdateMetadata([{'key': 0, 'type': 0, 'value': 0x02}])
|
player.setAndUpdateMetadata([{ 'key': 0, 'type': 0, 'value': 0x02 }])
|
||||||
player.crouching = true
|
player.crouching = true
|
||||||
} else if (actionId === 1) {
|
} else if (actionId === 1) {
|
||||||
player.setAndUpdateMetadata([{'key': 0, 'type': 0, 'value': 0x00}])
|
player.setAndUpdateMetadata([{ 'key': 0, 'type': 0, 'value': 0x00 }])
|
||||||
player.crouching = false
|
player.crouching = false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ module.exports.player = function (player, serv) {
|
||||||
position: position,
|
position: position,
|
||||||
blockType: blockType,
|
blockType: blockType,
|
||||||
blockData: blockData
|
blockData: blockData
|
||||||
}, ({position, blockType, blockData}) => {
|
}, ({ position, blockType, blockData }) => {
|
||||||
player._client.write('block_change', {
|
player._client.write('block_change', {
|
||||||
location: position,
|
location: position,
|
||||||
type: blockType << 4 | blockData
|
type: blockType << 4 | blockData
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
module.exports.server = function (serv) {
|
module.exports.server = function (serv) {
|
||||||
serv.broadcast = (message, {whitelist = serv.players, blacklist = [], system = false} = {}) => {
|
serv.broadcast = (message, { whitelist = serv.players, blacklist = [], system = false } = {}) => {
|
||||||
if (whitelist.type === 'player') whitelist = [whitelist]
|
if (whitelist.type === 'player') whitelist = [whitelist]
|
||||||
|
|
||||||
if (typeof message === 'string') message = serv.parseClassic(message)
|
if (typeof message === 'string') message = serv.parseClassic(message)
|
||||||
|
|
@ -120,9 +120,9 @@ module.exports.server = function (serv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.player = function (player, serv) {
|
module.exports.player = function (player, serv) {
|
||||||
player._client.on('chat', ({message} = {}) => {
|
player._client.on('chat', ({ message } = {}) => {
|
||||||
if (message[0] === '/') {
|
if (message[0] === '/') {
|
||||||
player.behavior('command', {command: message.slice(1)}, ({command}) => player.handleCommand(command))
|
player.behavior('command', { command: message.slice(1) }, ({ command }) => player.handleCommand(command))
|
||||||
} else {
|
} else {
|
||||||
player.behavior('chat', {
|
player.behavior('chat', {
|
||||||
message: message,
|
message: message,
|
||||||
|
|
@ -130,7 +130,7 @@ module.exports.player = function (player, serv) {
|
||||||
text: message,
|
text: message,
|
||||||
whitelist: serv.players,
|
whitelist: serv.players,
|
||||||
blacklist: []
|
blacklist: []
|
||||||
}, ({prefix, text, whitelist, blacklist}) => {
|
}, ({ prefix, text, whitelist, blacklist }) => {
|
||||||
const obj = serv.parseClassic(prefix)
|
const obj = serv.parseClassic(prefix)
|
||||||
if (!obj.extra) obj.extra = []
|
if (!obj.extra) obj.extra = []
|
||||||
obj.extra.push(serv.parseClassic(text))
|
obj.extra.push(serv.parseClassic(text))
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
const UserError = require('flying-squid').UserError
|
const UserError = require('flying-squid').UserError
|
||||||
|
|
||||||
module.exports.player = function (player, serv, {version}) {
|
module.exports.player = function (player, serv, { version }) {
|
||||||
player.commands.add({
|
player.commands.add({
|
||||||
base: 'help',
|
base: 'help',
|
||||||
info: 'to show all commands',
|
info: 'to show all commands',
|
||||||
|
|
@ -14,7 +14,7 @@ module.exports.player = function (player, serv, {version}) {
|
||||||
const search = params.join(' ')
|
const search = params.join(' ')
|
||||||
return { search: search, page: (page && page - 1) || 0 }
|
return { search: search, page: (page && page - 1) || 0 }
|
||||||
},
|
},
|
||||||
action ({search, page}) {
|
action ({ search, page }) {
|
||||||
if (page < 0) return 'Page # must be >= 1'
|
if (page < 0) return 'Page # must be >= 1'
|
||||||
const hash = player.commands.uniqueHash
|
const hash = player.commands.uniqueHash
|
||||||
|
|
||||||
|
|
@ -247,7 +247,7 @@ module.exports.server = function (serv) {
|
||||||
opt.forEach(o => {
|
opt.forEach(o => {
|
||||||
const match = o.match(/^([^=]+)=([^=]+)$/)
|
const match = o.match(/^([^=]+)=([^=]+)$/)
|
||||||
if (match === null) err = new UserError('Invalid selector option format: "' + o + '"')
|
if (match === null) err = new UserError('Invalid selector option format: "' + o + '"')
|
||||||
else optPair.push({key: match[1], val: match[2]})
|
else optPair.push({ key: match[1], val: match[2] })
|
||||||
})
|
})
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
|
|
@ -275,7 +275,7 @@ module.exports.server = function (serv) {
|
||||||
minScores: []
|
minScores: []
|
||||||
}
|
}
|
||||||
|
|
||||||
optPair.forEach(({key, val}) => {
|
optPair.forEach(({ key, val }) => {
|
||||||
if (['x', 'y', 'z'].indexOf(key) !== -1) pos[key] = val
|
if (['x', 'y', 'z'].indexOf(key) !== -1) pos[key] = val
|
||||||
else if (!optConversion[key]) {
|
else if (!optConversion[key]) {
|
||||||
data[key] = val
|
data[key] = val
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,12 @@ module.exports.server = function (serv) {
|
||||||
serv._writeNearby = (packetName, packetFields, loc) =>
|
serv._writeNearby = (packetName, packetFields, loc) =>
|
||||||
serv._writeArray(packetName, packetFields, serv.getNearby(loc))
|
serv._writeArray(packetName, packetFields, serv.getNearby(loc))
|
||||||
|
|
||||||
serv.getNearby = ({world, position, radius = 8 * 16}) => serv.players.filter(player =>
|
serv.getNearby = ({ world, position, radius = 8 * 16 }) => serv.players.filter(player =>
|
||||||
player.world === world &&
|
player.world === world &&
|
||||||
player.position.distanceTo(position) <= radius
|
player.position.distanceTo(position) <= radius
|
||||||
)
|
)
|
||||||
|
|
||||||
serv.getNearbyEntities = ({world, position, radius = 8 * 16}) => Object.keys(serv.entities)
|
serv.getNearbyEntities = ({ world, position, radius = 8 * 16 }) => Object.keys(serv.entities)
|
||||||
.map(eId => serv.entities[eId])
|
.map(eId => serv.entities[eId])
|
||||||
.filter(entity =>
|
.filter(entity =>
|
||||||
entity.world === world &&
|
entity.world === world &&
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ module.exports.server = function (serv) {
|
||||||
serv.behavior('changeTime', {
|
serv.behavior('changeTime', {
|
||||||
old: serv.time,
|
old: serv.time,
|
||||||
newTime: serv.time + 20
|
newTime: serv.time + 20
|
||||||
}, ({newTime}) => {
|
}, ({ newTime }) => {
|
||||||
serv.setTime(newTime % 24000) // Vanilla only does it every second
|
serv.setTime(newTime % 24000) // Vanilla only does it every second
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +48,7 @@ module.exports.player = function (player, serv) {
|
||||||
value: data[2] === 'day' ? 1000 : (data[2] === 'night' ? 13000 : parseInt(data[2]))
|
value: data[2] === 'day' ? 1000 : (data[2] === 'night' ? 13000 : parseInt(data[2]))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
action ({action, value}) {
|
action ({ action, value }) {
|
||||||
if (action === 'query') {
|
if (action === 'query') {
|
||||||
player.chat('It is ' + serv.time)
|
player.chat('It is ' + serv.time)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
const Vec3 = require('vec3').Vec3
|
const Vec3 = require('vec3').Vec3
|
||||||
|
|
||||||
module.exports.player = function (player, serv) {
|
module.exports.player = function (player, serv) {
|
||||||
function cancelDig ({position, block}) {
|
function cancelDig ({ position, block }) {
|
||||||
player.sendBlock(position, block.type, block.metadata)
|
player.sendBlock(position, block.type, block.metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
player._client.on('block_dig', async ({location, status, face}) => {
|
player._client.on('block_dig', async ({ location, status, face }) => {
|
||||||
let pos = new Vec3(location.x, location.y, location.z)
|
let pos = new Vec3(location.x, location.y, location.z)
|
||||||
|
|
||||||
const directionVector = directionToVector[face]
|
const directionVector = directionToVector[face]
|
||||||
|
|
@ -25,14 +25,14 @@ module.exports.player = function (player, serv) {
|
||||||
player.behavior('dig', { // Start dig survival
|
player.behavior('dig', { // Start dig survival
|
||||||
position: pos,
|
position: pos,
|
||||||
block: block
|
block: block
|
||||||
}, ({position}) => {
|
}, ({ position }) => {
|
||||||
return startDigging(position)
|
return startDigging(position)
|
||||||
}, cancelDig)
|
}, cancelDig)
|
||||||
} else if (status === 2) { completeDigging(pos) } else if (status === 1) {
|
} else if (status === 2) { completeDigging(pos) } else if (status === 1) {
|
||||||
player.behavior('cancelDig', { // Cancel dig survival
|
player.behavior('cancelDig', { // Cancel dig survival
|
||||||
position: pos,
|
position: pos,
|
||||||
block: block
|
block: block
|
||||||
}, ({position}) => {
|
}, ({ position }) => {
|
||||||
return cancelDigging(position)
|
return cancelDigging(position)
|
||||||
})
|
})
|
||||||
} else if (status === 0 && player.gameMode === 1) { return creativeDigging(pos) }
|
} else if (status === 0 && player.gameMode === 1) { return creativeDigging(pos) }
|
||||||
|
|
@ -71,7 +71,7 @@ module.exports.player = function (player, serv) {
|
||||||
start: startDigging,
|
start: startDigging,
|
||||||
timePassed: currentDiggingTime,
|
timePassed: currentDiggingTime,
|
||||||
position: location
|
position: location
|
||||||
}, ({state}) => {
|
}, ({ state }) => {
|
||||||
lastDestroyState = state
|
lastDestroyState = state
|
||||||
player._writeOthersNearby('block_break_animation', {
|
player._writeOthersNearby('block_break_animation', {
|
||||||
'entityId': currentAnimationId,
|
'entityId': currentAnimationId,
|
||||||
|
|
@ -127,7 +127,7 @@ module.exports.player = function (player, serv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function dropBlock ({blockDropPosition, blockDropWorld, blockDropVelocity, blockDropId, blockDropDamage, blockDropPickup, blockDropDeath}) {
|
function dropBlock ({ blockDropPosition, blockDropWorld, blockDropVelocity, blockDropId, blockDropDamage, blockDropPickup, blockDropDeath }) {
|
||||||
serv.spawnObject(2, blockDropWorld, blockDropPosition, {
|
serv.spawnObject(2, blockDropWorld, blockDropPosition, {
|
||||||
velocity: blockDropVelocity,
|
velocity: blockDropVelocity,
|
||||||
itemId: blockDropId,
|
itemId: blockDropId,
|
||||||
|
|
|
||||||
4
src/lib/plugins/effects.js
vendored
4
src/lib/plugins/effects.js
vendored
|
|
@ -5,7 +5,7 @@ module.exports.entity = function (entity, serv) {
|
||||||
entity.effects[i] = null // Just so we know it's a real potion and not undefined/not existant
|
entity.effects[i] = null // Just so we know it's a real potion and not undefined/not existant
|
||||||
}
|
}
|
||||||
|
|
||||||
entity.sendEffect = (effectId, {amplifier = 0, duration = 30 * 20, particles = true, whitelist, blacklist = []} = {}) => {
|
entity.sendEffect = (effectId, { amplifier = 0, duration = 30 * 20, particles = true, whitelist, blacklist = [] } = {}) => {
|
||||||
if (!whitelist) whitelist = serv.getNearby(entity)
|
if (!whitelist) whitelist = serv.getNearby(entity)
|
||||||
if (entity.type === 'player' && [1].indexOf(effectId) !== -1) entity.sendAbilities()
|
if (entity.type === 'player' && [1].indexOf(effectId) !== -1) entity.sendAbilities()
|
||||||
const sendTo = whitelist.filter(p => blacklist.indexOf(p) === -1)
|
const sendTo = whitelist.filter(p => blacklist.indexOf(p) === -1)
|
||||||
|
|
@ -19,7 +19,7 @@ module.exports.entity = function (entity, serv) {
|
||||||
serv._writeArray('entity_effect', data, sendTo)
|
serv._writeArray('entity_effect', data, sendTo)
|
||||||
}
|
}
|
||||||
|
|
||||||
entity.sendRemoveEffect = (effectId, {whitelist, blacklist = []} = {}) => {
|
entity.sendRemoveEffect = (effectId, { whitelist, blacklist = [] } = {}) => {
|
||||||
if (!whitelist) whitelist = serv.getNearby(entity)
|
if (!whitelist) whitelist = serv.getNearby(entity)
|
||||||
const sendTo = whitelist.filter(p => blacklist.indexOf(p) === -1)
|
const sendTo = whitelist.filter(p => blacklist.indexOf(p) === -1)
|
||||||
serv._writeArray('remove_entity_effect', {
|
serv._writeArray('remove_entity_effect', {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
const {distanceToXpLevel, getXpLevel, getBaseXpFromLevel} = require('flying-squid').experience
|
const { distanceToXpLevel, getXpLevel, getBaseXpFromLevel } = require('flying-squid').experience
|
||||||
|
|
||||||
module.exports.player = function (player, serv) {
|
module.exports.player = function (player, serv) {
|
||||||
player.xp = 0
|
player.xp = 0
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
const Vec3 = require('vec3')
|
const Vec3 = require('vec3')
|
||||||
|
|
||||||
module.exports.player = function (player, serv, {version}) {
|
module.exports.player = function (player, serv, { version }) {
|
||||||
const Item = require('prismarine-item')(version)
|
const Item = require('prismarine-item')(version)
|
||||||
const windows = require('prismarine-windows')(version).windows
|
const windows = require('prismarine-windows')(version).windows
|
||||||
|
|
||||||
|
|
@ -8,7 +8,7 @@ module.exports.player = function (player, serv, {version}) {
|
||||||
player.heldItem = new Item(256, 1)
|
player.heldItem = new Item(256, 1)
|
||||||
player.inventory = new windows.InventoryWindow(0, 'Inventory', 44)
|
player.inventory = new windows.InventoryWindow(0, 'Inventory', 44)
|
||||||
|
|
||||||
player._client.on('held_item_slot', ({slotId} = {}) => {
|
player._client.on('held_item_slot', ({ slotId } = {}) => {
|
||||||
player.heldItemSlot = slotId
|
player.heldItemSlot = slotId
|
||||||
player.setEquipment(0, player.inventory.slots[36 + player.heldItemSlot])
|
player.setEquipment(0, player.inventory.slots[36 + player.heldItemSlot])
|
||||||
|
|
||||||
|
|
@ -143,7 +143,7 @@ module.exports.player = function (player, serv, {version}) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
player._client.on('set_creative_slot', ({slot, item} = {}) => {
|
player._client.on('set_creative_slot', ({ slot, item } = {}) => {
|
||||||
if (item.blockId === -1) {
|
if (item.blockId === -1) {
|
||||||
player.inventory.updateSlot(slot, undefined)
|
player.inventory.updateSlot(slot, undefined)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ module.exports.player = function (player, serv) {
|
||||||
|
|
||||||
player.on('disconnected', () => serv.log('[INFO]: ' + player.username + ' disconnected'))
|
player.on('disconnected', () => serv.log('[INFO]: ' + player.username + ' disconnected'))
|
||||||
|
|
||||||
player.on('chat', ({message}) => serv.log('[INFO] ' + '<' + player.username + '>' + ' ' + message))
|
player.on('chat', ({ message }) => serv.log('[INFO] ' + '<' + player.username + '>' + ' ' + message))
|
||||||
|
|
||||||
player.on('kicked', (kicker, reason) =>
|
player.on('kicked', (kicker, reason) =>
|
||||||
serv.log(kicker.username + ' kicked ' + player.username + (reason ? ' (' + reason + ')' : '')))
|
serv.log(kicker.username + ' kicked ' + player.username + (reason ? ' (' + reason + ')' : '')))
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ module.exports.player = function (player, serv) {
|
||||||
reason: parts.join(' ')
|
reason: parts.join(' ')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
action ({username, reason}) {
|
action ({ username, reason }) {
|
||||||
const kickPlayer = serv.getPlayer(username)
|
const kickPlayer = serv.getPlayer(username)
|
||||||
if (!kickPlayer) {
|
if (!kickPlayer) {
|
||||||
player.chat(username + ' is not on this server!')
|
player.chat(username + ' is not on this server!')
|
||||||
|
|
@ -113,7 +113,7 @@ module.exports.player = function (player, serv) {
|
||||||
reason: parts.join(' ')
|
reason: parts.join(' ')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
action ({username, reason}) {
|
action ({ username, reason }) {
|
||||||
const banPlayer = serv.getPlayer(username)
|
const banPlayer = serv.getPlayer(username)
|
||||||
|
|
||||||
if (!banPlayer) {
|
if (!banPlayer) {
|
||||||
|
|
@ -148,7 +148,7 @@ module.exports.player = function (player, serv) {
|
||||||
reason: argv.shift()
|
reason: argv.shift()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
action ({IP, reason}) {
|
action ({ IP, reason }) {
|
||||||
serv.banIP(IP, reason)
|
serv.banIP(IP, reason)
|
||||||
player.chat('' + IP + ' was IP banned')
|
player.chat('' + IP + ' was IP banned')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
const Vec3 = require('vec3').Vec3
|
const Vec3 = require('vec3').Vec3
|
||||||
|
|
||||||
module.exports.server = function (serv) {
|
module.exports.server = function (serv) {
|
||||||
serv.emitParticle = (particle, world, position, {whitelist, blacklist = [], radius = 32, longDistance = true, size = new Vec3(1, 1, 1), count = 1} = {}) => {
|
serv.emitParticle = (particle, world, position, { whitelist, blacklist = [], radius = 32, longDistance = true, size = new Vec3(1, 1, 1), count = 1 } = {}) => {
|
||||||
const players = (typeof whitelist !== 'undefined' ? (whitelist instanceof Array ? whitelist : [whitelist]) : serv.getNearby({
|
const players = (typeof whitelist !== 'undefined' ? (whitelist instanceof Array ? whitelist : [whitelist]) : serv.getNearby({
|
||||||
world: world,
|
world: world,
|
||||||
position: position,
|
position: position,
|
||||||
|
|
@ -39,13 +39,13 @@ module.exports.player = function (player, serv) {
|
||||||
size: results[5] ? new Vec3(parseInt(results[3]), parseInt(results[4]), parseInt(results[5])) : new Vec3(1, 1, 1)
|
size: results[5] ? new Vec3(parseInt(results[3]), parseInt(results[4]), parseInt(results[5])) : new Vec3(1, 1, 1)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
action ({particle, amount, size}) {
|
action ({ particle, amount, size }) {
|
||||||
if (amount >= 100000) {
|
if (amount >= 100000) {
|
||||||
player.chat('You cannot emit more than 100,000 particles!')
|
player.chat('You cannot emit more than 100,000 particles!')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
player.chat('Emitting "' + particle + '" (count: ' + amount + ', size: ' + size.toString() + ')')
|
player.chat('Emitting "' + particle + '" (count: ' + amount + ', size: ' + size.toString() + ')')
|
||||||
serv.emitParticle(particle, player.world, player.position, {count: amount, size: size})
|
serv.emitParticle(particle, player.world, player.position, { count: amount, size: size })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
const Vec3 = require('vec3').Vec3
|
const Vec3 = require('vec3').Vec3
|
||||||
|
|
||||||
module.exports.entity = function (entity, serv, {version}) {
|
module.exports.entity = function (entity, serv, { version }) {
|
||||||
const blocks = require('minecraft-data')(version).blocks
|
const blocks = require('minecraft-data')(version).blocks
|
||||||
|
|
||||||
entity.calculatePhysics = async (delta) => {
|
entity.calculatePhysics = async (delta) => {
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,10 @@ const materialToSound = {
|
||||||
'wood': 'wood'
|
'wood': 'wood'
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.player = function (player, serv, {version}) {
|
module.exports.player = function (player, serv, { version }) {
|
||||||
const blocks = require('minecraft-data')(version).blocks
|
const blocks = require('minecraft-data')(version).blocks
|
||||||
|
|
||||||
player._client.on('block_place', ({direction, location} = {}) => {
|
player._client.on('block_place', ({ direction, location } = {}) => {
|
||||||
const heldItem = player.inventory.slots[36 + player.heldItemSlot]
|
const heldItem = player.inventory.slots[36 + player.heldItemSlot]
|
||||||
if (direction === -1 || heldItem.type === -1 || !blocks[heldItem.type]) return
|
if (direction === -1 || heldItem.type === -1 || !blocks[heldItem.type]) return
|
||||||
const referencePosition = new Vec3(location.x, location.y, location.z)
|
const referencePosition = new Vec3(location.x, location.y, location.z)
|
||||||
|
|
@ -28,7 +28,7 @@ module.exports.player = function (player, serv, {version}) {
|
||||||
reference: referencePosition,
|
reference: referencePosition,
|
||||||
playSound: true,
|
playSound: true,
|
||||||
sound: 'dig.' + (materialToSound[blocks[heldItem.type].material] || 'stone')
|
sound: 'dig.' + (materialToSound[blocks[heldItem.type].material] || 'stone')
|
||||||
}, ({direction, heldItem, position, playSound, sound, id, damage}) => {
|
}, ({ direction, heldItem, position, playSound, sound, id, damage }) => {
|
||||||
if (playSound) {
|
if (playSound) {
|
||||||
serv.playSound(sound, player.world, placedPosition.clone().add(new Vec3(0.5, 0.5, 0.5)), {
|
serv.playSound(sound, player.world, placedPosition.clone().add(new Vec3(0.5, 0.5, 0.5)), {
|
||||||
pitch: 0.8
|
pitch: 0.8
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ module.exports.player = function (player, serv) {
|
||||||
return parseInt(str)
|
return parseInt(str)
|
||||||
},
|
},
|
||||||
action (diff) {
|
action (diff) {
|
||||||
serv._writeAll('difficulty', {difficulty: diff})
|
serv._writeAll('difficulty', { difficulty: diff })
|
||||||
serv.difficulty = diff
|
serv.difficulty = diff
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
const Vec3 = require('vec3').Vec3
|
const Vec3 = require('vec3').Vec3
|
||||||
const UserError = require('flying-squid').UserError
|
const UserError = require('flying-squid').UserError
|
||||||
|
|
||||||
module.exports.player = function (player, serv, {version}) {
|
module.exports.player = function (player, serv, { version }) {
|
||||||
const {detectFrame, generatePortal, addPortalToWorld} = require('flying-squid').portal_detector(version)
|
const { detectFrame, generatePortal, addPortalToWorld } = require('flying-squid').portal_detector(version)
|
||||||
|
|
||||||
player.use_flint_and_steel = async (referencePosition, direction, position) => {
|
player.use_flint_and_steel = async (referencePosition, direction, position) => {
|
||||||
let block = await player.world.getBlock(referencePosition)
|
let block = await player.world.getBlock(referencePosition)
|
||||||
|
|
@ -18,7 +18,7 @@ module.exports.player = function (player, serv, {version}) {
|
||||||
player.changeBlock(position, 51, 0)
|
player.changeBlock(position, 51, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
player.on('dug', ({position, block}) => {
|
player.on('dug', ({ position, block }) => {
|
||||||
function destroyPortal (portal, positionAlreadyDone = null) {
|
function destroyPortal (portal, positionAlreadyDone = null) {
|
||||||
player.world.portals = player.world.portals.splice(player.world.portals.indexOf(portal), 1)
|
player.world.portals = player.world.portals.splice(player.world.portals.indexOf(portal), 1)
|
||||||
portal
|
portal
|
||||||
|
|
@ -28,14 +28,14 @@ module.exports.player = function (player, serv, {version}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block.name === 'obsidian') {
|
if (block.name === 'obsidian') {
|
||||||
const p = player.world.portals.filter(({bottom, top, left, right}) =>
|
const p = player.world.portals.filter(({ bottom, top, left, right }) =>
|
||||||
[].concat([], [bottom, left, right, top])
|
[].concat([], [bottom, left, right, top])
|
||||||
.reduce((acc, pos) => acc || pos.equals(position), false))
|
.reduce((acc, pos) => acc || pos.equals(position), false))
|
||||||
p.forEach(portal => destroyPortal(portal, position))
|
p.forEach(portal => destroyPortal(portal, position))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block.name === 'portal') {
|
if (block.name === 'portal') {
|
||||||
const p = player.world.portals.filter(({air}) => air.reduce((acc, pos) => acc || pos.equals(position), false))
|
const p = player.world.portals.filter(({ air }) => air.reduce((acc, pos) => acc || pos.equals(position), false))
|
||||||
p.forEach(portal => destroyPortal(portal, position))
|
p.forEach(portal => destroyPortal(portal, position))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -53,9 +53,9 @@ module.exports.player = function (player, serv, {version}) {
|
||||||
const bottomLeft = new Vec3(x, y, z)
|
const bottomLeft = new Vec3(x, y, z)
|
||||||
if (direction !== 'x' && direction !== 'z') { throw new UserError('Wrong Direction') }
|
if (direction !== 'x' && direction !== 'z') { throw new UserError('Wrong Direction') }
|
||||||
direction = direction === 'x' ? new Vec3(1, 0, 0) : new Vec3(0, 0, 1)
|
direction = direction === 'x' ? new Vec3(1, 0, 0) : new Vec3(0, 0, 1)
|
||||||
return {bottomLeft, direction, width, height}
|
return { bottomLeft, direction, width, height }
|
||||||
},
|
},
|
||||||
async action ({bottomLeft, direction, width, height}) {
|
async action ({ bottomLeft, direction, width, height }) {
|
||||||
if (width > 21 || height > 21) { throw new UserError('Portals can only be 21x21!') }
|
if (width > 21 || height > 21) { throw new UserError('Portals can only be 21x21!') }
|
||||||
const portal = generatePortal(bottomLeft, direction, width, height)
|
const portal = generatePortal(bottomLeft, direction, width, height)
|
||||||
await addPortalToWorld(player.world, portal, [], [], async (pos, type) => {
|
await addPortalToWorld(player.world, portal, [], [], async (pos, type) => {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ module.exports.player = function (player, serv) {
|
||||||
}, (o) => o.attackedEntity.takeDamage(o))
|
}, (o) => o.attackedEntity.takeDamage(o))
|
||||||
}
|
}
|
||||||
|
|
||||||
player._client.on('use_entity', ({mouse, target} = {}) => {
|
player._client.on('use_entity', ({ mouse, target } = {}) => {
|
||||||
if (!serv.entities[target]) {
|
if (!serv.entities[target]) {
|
||||||
let dragon
|
let dragon
|
||||||
for (dragon = target - 1; dragon >= target - 7 && !serv.entities[dragon]; dragon--) {}
|
for (dragon = target - 1; dragon >= target - 7 && !serv.entities[dragon]; dragon--) {}
|
||||||
|
|
@ -42,13 +42,13 @@ module.exports.player = function (player, serv) {
|
||||||
let arr = player.selectorString(sel)
|
let arr = player.selectorString(sel)
|
||||||
if (arr.length === 0) throw new UserError('Could not find player')
|
if (arr.length === 0) throw new UserError('Could not find player')
|
||||||
|
|
||||||
arr.map(entity => entity.takeDamage({damage: 20}))
|
arr.map(entity => entity.takeDamage({ damage: 20 }))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.entity = function (entity, serv) {
|
module.exports.entity = function (entity, serv) {
|
||||||
entity.takeDamage = ({sound = 'game.player.hurt', damage = 1, velocity = new Vec3(0, 0, 0), maxVelocity = new Vec3(4, 4, 4), animation = true}) => {
|
entity.takeDamage = ({ sound = 'game.player.hurt', damage = 1, velocity = new Vec3(0, 0, 0), maxVelocity = new Vec3(4, 4, 4), animation = true }) => {
|
||||||
entity.updateHealth(entity.health - damage)
|
entity.updateHealth(entity.health - damage)
|
||||||
serv.playSound(sound, entity.world, entity.position)
|
serv.playSound(sound, entity.world, entity.position)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ module.exports.player = async function (player, serv) {
|
||||||
player.findSpawnPoint = async () => {
|
player.findSpawnPoint = async () => {
|
||||||
player.spawnPoint = await serv.getSpawnPoint(player.world)
|
player.spawnPoint = await serv.getSpawnPoint(player.world)
|
||||||
}
|
}
|
||||||
player._client.on('settings', ({viewDistance}) => {
|
player._client.on('settings', ({ viewDistance }) => {
|
||||||
player.view = viewDistance
|
player.view = viewDistance
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
const Vec3 = require('vec3').Vec3
|
const Vec3 = require('vec3').Vec3
|
||||||
|
|
||||||
module.exports.server = function (serv) {
|
module.exports.server = function (serv) {
|
||||||
serv.playSound = (sound, world, position, {whitelist, blacklist = [], radius = 32, volume = 1.0, pitch = 1.0, soundCategory = 0} = {}) => {
|
serv.playSound = (sound, world, position, { whitelist, blacklist = [], radius = 32, volume = 1.0, pitch = 1.0, soundCategory = 0 } = {}) => {
|
||||||
const players = (typeof whitelist !== 'undefined' ? (typeof whitelist instanceof Array ? whitelist : [whitelist]) : serv.getNearby({
|
const players = (typeof whitelist !== 'undefined' ? (typeof whitelist instanceof Array ? whitelist : [whitelist]) : serv.getNearby({
|
||||||
world: world,
|
world: world,
|
||||||
position: position,
|
position: position,
|
||||||
|
|
@ -24,7 +24,7 @@ module.exports.server = function (serv) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
serv.playNoteBlock = (pitch, world, position, {instrument = 'harp', particle = true} = {}) => {
|
serv.playNoteBlock = (pitch, world, position, { instrument = 'harp', particle = true } = {}) => {
|
||||||
if (particle) {
|
if (particle) {
|
||||||
serv.emitParticle(23, world, position.clone().add(new Vec3(0.5, 1.5, 0.5)), {
|
serv.emitParticle(23, world, position.clone().add(new Vec3(0.5, 1.5, 0.5)), {
|
||||||
count: 1,
|
count: 1,
|
||||||
|
|
@ -43,7 +43,7 @@ module.exports.player = function (player, serv) {
|
||||||
serv.playSound(sound, player.world, null, opt)
|
serv.playSound(sound, player.world, null, opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
player.on('placeBlock_cancel', async ({reference}, cancel) => {
|
player.on('placeBlock_cancel', async ({ reference }, cancel) => {
|
||||||
if (player.crouching) return
|
if (player.crouching) return
|
||||||
const id = await player.world.getBlockType(reference)
|
const id = await player.world.getBlockType(reference)
|
||||||
if (id !== 25) return
|
if (id !== 25) return
|
||||||
|
|
@ -56,7 +56,7 @@ module.exports.player = function (player, serv) {
|
||||||
serv.playNoteBlock(data.note, player.world, reference)
|
serv.playNoteBlock(data.note, player.world, reference)
|
||||||
})
|
})
|
||||||
|
|
||||||
player.on('dig_cancel', async ({position}, cancel) => {
|
player.on('dig_cancel', async ({ position }, cancel) => {
|
||||||
const id = await player.world.getBlockType(position)
|
const id = await player.world.getBlockType(position)
|
||||||
if (id !== 25) return
|
if (id !== 25) return
|
||||||
cancel(false)
|
cancel(false)
|
||||||
|
|
@ -82,7 +82,7 @@ module.exports.player = function (player, serv) {
|
||||||
},
|
},
|
||||||
action (action) {
|
action (action) {
|
||||||
player.chat('Playing "' + action.sound_name + '" (volume: ' + action.volume + ', pitch: ' + action.pitch + ')')
|
player.chat('Playing "' + action.sound_name + '" (volume: ' + action.volume + ', pitch: ' + action.pitch + ')')
|
||||||
player.playSound(action.sound_name, {volume: action.volume, pitch: action.pitch})
|
player.playSound(action.sound_name, { volume: action.volume, pitch: action.pitch })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -102,7 +102,7 @@ module.exports.player = function (player, serv) {
|
||||||
},
|
},
|
||||||
action (action) {
|
action (action) {
|
||||||
player.chat('Playing "' + action.sound_name + '" (volume: ' + action.volume + ', pitch: ' + action.pitch + ')')
|
player.chat('Playing "' + action.sound_name + '" (volume: ' + action.volume + ', pitch: ' + action.pitch + ')')
|
||||||
serv.playSound(action.sound_name, player.world, player.position, {volume: action.volume, pitch: action.pitch})
|
serv.playSound(action.sound_name, player.world, player.position, { volume: action.volume, pitch: action.pitch })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ module.exports.server = function (serv, options) {
|
||||||
return entity
|
return entity
|
||||||
}
|
}
|
||||||
|
|
||||||
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.uuid = UUID.v4()
|
||||||
object.name = objectsById[type].name
|
object.name = objectsById[type].name
|
||||||
|
|
@ -48,7 +48,7 @@ module.exports.server = function (serv, options) {
|
||||||
object.updateAndSpawn()
|
object.updateAndSpawn()
|
||||||
}
|
}
|
||||||
|
|
||||||
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.uuid = UUID.v4()
|
||||||
mob.name = mobsById[type].name
|
mob.name = mobsById[type].name
|
||||||
|
|
@ -112,9 +112,9 @@ module.exports.player = function (player, serv, options) {
|
||||||
parse (str) {
|
parse (str) {
|
||||||
const args = str.split(' ')
|
const args = str.split(' ')
|
||||||
if (args.length !== 2) { return false }
|
if (args.length !== 2) { return false }
|
||||||
return {number: args[0], name: args[1]}
|
return { number: args[0], name: args[1] }
|
||||||
},
|
},
|
||||||
action ({number, name}) {
|
action ({ number, name }) {
|
||||||
if (Object.keys(serv.entities).length > options['max-entities'] - number) { throw new UserError('Too many mobs !') }
|
if (Object.keys(serv.entities).length > options['max-entities'] - number) { throw new UserError('Too many mobs !') }
|
||||||
const entity = entitiesByName[name]
|
const entity = entitiesByName[name]
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
|
|
@ -182,9 +182,9 @@ module.exports.player = function (player, serv, options) {
|
||||||
let attached = player.selectorString(args[1])
|
let attached = player.selectorString(args[1])
|
||||||
if (attached.length === 0) throw new UserError('one attached')
|
if (attached.length === 0) throw new UserError('one attached')
|
||||||
|
|
||||||
return {carrier: carrier[0], attached: attached[0]}
|
return { carrier: carrier[0], attached: attached[0] }
|
||||||
},
|
},
|
||||||
action ({carrier, attached}) {
|
action ({ carrier, attached }) {
|
||||||
carrier.attach(attached)
|
carrier.attach(attached)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
module.exports.player = function (player) {
|
module.exports.player = function (player) {
|
||||||
player._client.on('client_command', ({payload} = {}) => {
|
player._client.on('client_command', ({ payload } = {}) => {
|
||||||
if (payload === 1) {
|
if (payload === 1) {
|
||||||
// WIP: dummy
|
// WIP: dummy
|
||||||
player.system('WIP, press ESC')
|
player.system('WIP, press ESC')
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
const Vec3 = require('vec3').Vec3
|
const Vec3 = require('vec3').Vec3
|
||||||
|
|
||||||
module.exports.player = function (player) {
|
module.exports.player = function (player) {
|
||||||
player._client.on('look', ({yaw, pitch, onGround} = {}) => sendLook(yaw, pitch, onGround))
|
player._client.on('look', ({ yaw, pitch, onGround } = {}) => sendLook(yaw, pitch, onGround))
|
||||||
|
|
||||||
// float (degrees) --> byte (1/256 "degrees")
|
// float (degrees) --> byte (1/256 "degrees")
|
||||||
function conv (f) {
|
function conv (f) {
|
||||||
|
|
@ -37,11 +37,11 @@ module.exports.player = function (player) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
player._client.on('position', ({x, y, z, onGround} = {}) => {
|
player._client.on('position', ({ x, y, z, onGround } = {}) => {
|
||||||
player.sendPosition((new Vec3(x, y, z)), onGround)
|
player.sendPosition((new Vec3(x, y, z)), onGround)
|
||||||
})
|
})
|
||||||
|
|
||||||
player._client.on('position_look', ({x, y, z, onGround, yaw, pitch} = {}) => {
|
player._client.on('position_look', ({ x, y, z, onGround, yaw, pitch } = {}) => {
|
||||||
player.sendPosition((new Vec3(x, y, z)), onGround)
|
player.sendPosition((new Vec3(x, y, z)), onGround)
|
||||||
sendLook(yaw, pitch, onGround)
|
sendLook(yaw, pitch, onGround)
|
||||||
})
|
})
|
||||||
|
|
@ -89,7 +89,7 @@ module.exports.entity = function (entity, serv) {
|
||||||
position: position,
|
position: position,
|
||||||
onGround: onGround,
|
onGround: onGround,
|
||||||
teleport: teleport
|
teleport: teleport
|
||||||
}, ({position, onGround}) => {
|
}, ({ position, onGround }) => {
|
||||||
// known position is very important because the diff (/delta) send to players is floored hence is not precise enough
|
// known position is very important because the diff (/delta) send to players is floored hence is not precise enough
|
||||||
// storing the known position allows to compensate next time a diff is sent
|
// storing the known position allows to compensate next time a diff is sent
|
||||||
// without the known position, the error accumulate fast and player position is incorrect from the point of view
|
// without the known position, the error accumulate fast and player position is incorrect from the point of view
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
const Vec3 = require('vec3').Vec3
|
const Vec3 = require('vec3').Vec3
|
||||||
|
|
||||||
module.exports.player = function (player, serv, {version}) {
|
module.exports.player = function (player, serv, { version }) {
|
||||||
const items = require('minecraft-data')(version).items
|
const items = require('minecraft-data')(version).items
|
||||||
|
|
||||||
player._client.on('block_place', ({direction, location} = {}) => {
|
player._client.on('block_place', ({ direction, location } = {}) => {
|
||||||
const heldItem = player.inventory.slots[36 + player.heldItemSlot]
|
const heldItem = player.inventory.slots[36 + player.heldItemSlot]
|
||||||
if (direction === -1 || heldItem.type === -1 || !items[heldItem.type]) return
|
if (direction === -1 || heldItem.type === -1 || !items[heldItem.type]) return
|
||||||
const item = heldItem
|
const item = heldItem
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,13 @@ module.exports.player = function (player, serv) {
|
||||||
let condition = args[0]
|
let condition = args[0]
|
||||||
if (['clear', 'rain'].indexOf(condition) === -1) { return false }
|
if (['clear', 'rain'].indexOf(condition) === -1) { return false }
|
||||||
|
|
||||||
return {condition: condition}
|
return { condition: condition }
|
||||||
},
|
},
|
||||||
action ({condition}) {
|
action ({ condition }) {
|
||||||
if (condition === 'rain') {
|
if (condition === 'rain') {
|
||||||
serv._writeAll('game_state_change', {reason: 2, gameMode: 0})
|
serv._writeAll('game_state_change', { reason: 2, gameMode: 0 })
|
||||||
} else if (condition === 'clear') {
|
} else if (condition === 'clear') {
|
||||||
serv._writeAll('game_state_change', {reason: 1, gameMode: 0})
|
serv._writeAll('game_state_change', { reason: 1, gameMode: 0 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ const { level } = require('prismarine-provider-anvil')
|
||||||
const fsStat = promisify(fs.stat)
|
const fsStat = promisify(fs.stat)
|
||||||
const fsMkdir = promisify(fs.mkdir)
|
const fsMkdir = promisify(fs.mkdir)
|
||||||
|
|
||||||
module.exports.server = async function (serv, {version, worldFolder, generation = {'name': 'diamond_square', 'options': {'worldHeight': 80}}} = {}) {
|
module.exports.server = async function (serv, { version, worldFolder, generation = { 'name': 'diamond_square', 'options': { 'worldHeight': 80 } } } = {}) {
|
||||||
const World = require('prismarine-world')(version)
|
const World = require('prismarine-world')(version)
|
||||||
|
|
||||||
const newSeed = generation.options.seed || Math.floor(Math.random() * Math.pow(2, 31))
|
const newSeed = generation.options.seed || Math.floor(Math.random() * Math.pow(2, 31))
|
||||||
|
|
@ -27,7 +27,7 @@ module.exports.server = async function (serv, {version, worldFolder, generation
|
||||||
seed = levelData['RandomSeed'][0]
|
seed = levelData['RandomSeed'][0]
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
seed = newSeed
|
seed = newSeed
|
||||||
await level.writeLevel(worldFolder + '/level.dat', {'RandomSeed': [seed, 0]})
|
await level.writeLevel(worldFolder + '/level.dat', { 'RandomSeed': [seed, 0] })
|
||||||
}
|
}
|
||||||
} else { seed = newSeed }
|
} else { seed = newSeed }
|
||||||
generation.options.seed = seed
|
generation.options.seed = seed
|
||||||
|
|
@ -69,8 +69,8 @@ module.exports.server = async function (serv, {version, worldFolder, generation
|
||||||
.filter(player => player.world === world)
|
.filter(player => player.world === world)
|
||||||
.forEach(oPlayer => {
|
.forEach(oPlayer => {
|
||||||
chunks
|
chunks
|
||||||
.filter(({chunkX, chunkZ}) => oPlayer.loadedChunks[chunkX + ',' + chunkZ] !== undefined)
|
.filter(({ chunkX, chunkZ }) => oPlayer.loadedChunks[chunkX + ',' + chunkZ] !== undefined)
|
||||||
.forEach(({chunkX, chunkZ}) => oPlayer.unloadChunk(chunkX, chunkZ))
|
.forEach(({ chunkX, chunkZ }) => oPlayer.unloadChunk(chunkX, chunkZ))
|
||||||
oPlayer.sendRestMap()
|
oPlayer.sendRestMap()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -104,7 +104,7 @@ module.exports.player = function (player, serv, settings) {
|
||||||
x: chunkX,
|
x: chunkX,
|
||||||
z: chunkZ,
|
z: chunkZ,
|
||||||
chunk: column
|
chunk: column
|
||||||
}, ({x, z, chunk}) => {
|
}, ({ x, z, chunk }) => {
|
||||||
player._client.write('map_chunk', {
|
player._client.write('map_chunk', {
|
||||||
x: x,
|
x: x,
|
||||||
z: z,
|
z: z,
|
||||||
|
|
@ -140,19 +140,19 @@ module.exports.player = function (player, serv, settings) {
|
||||||
chunkX: playerChunkX + t[0] - view,
|
chunkX: playerChunkX + t[0] - view,
|
||||||
chunkZ: playerChunkZ + t[1] - view
|
chunkZ: playerChunkZ + t[1] - view
|
||||||
}))
|
}))
|
||||||
.filter(({chunkX, chunkZ}) => {
|
.filter(({ chunkX, chunkZ }) => {
|
||||||
const key = chunkX + ',' + chunkZ
|
const key = chunkX + ',' + chunkZ
|
||||||
const loaded = player.loadedChunks[key]
|
const loaded = player.loadedChunks[key]
|
||||||
if (!loaded) player.loadedChunks[key] = 1
|
if (!loaded) player.loadedChunks[key] = 1
|
||||||
return !loaded
|
return !loaded
|
||||||
})
|
})
|
||||||
.reduce((acc, {chunkX, chunkZ}) => {
|
.reduce((acc, { chunkX, chunkZ }) => {
|
||||||
const p = acc
|
const p = acc
|
||||||
.then(() => player.world.getColumn(chunkX, chunkZ))
|
.then(() => player.world.getColumn(chunkX, chunkZ))
|
||||||
.then((column) => player.sendChunk(chunkX, chunkZ, column))
|
.then((column) => player.sendChunk(chunkX, chunkZ, column))
|
||||||
return group ? p.then(() => sleep(5)) : p
|
return group ? p.then(() => sleep(5)) : p
|
||||||
}
|
}
|
||||||
, Promise.resolve())
|
, Promise.resolve())
|
||||||
}
|
}
|
||||||
|
|
||||||
function sleep (ms = 0) {
|
function sleep (ms = 0) {
|
||||||
|
|
@ -209,8 +209,8 @@ module.exports.player = function (player, serv, settings) {
|
||||||
usage: '/changeworld overworld|nether',
|
usage: '/changeworld overworld|nether',
|
||||||
op: true,
|
op: true,
|
||||||
action (world) {
|
action (world) {
|
||||||
if (world === 'nether') player.changeWorld(serv.netherworld, {dimension: -1})
|
if (world === 'nether') player.changeWorld(serv.netherworld, { dimension: -1 })
|
||||||
if (world === 'overworld') player.changeWorld(serv.overworld, {dimension: 0})
|
if (world === 'overworld') player.changeWorld(serv.overworld, { dimension: 0 })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ async function findPotentialLines (world, startingPoint, directionV) {
|
||||||
const firstLineDirection = directionV.y !== 0 ? [new Vec3(1, 0, 0), new Vec3(0, 0, 1)]
|
const firstLineDirection = directionV.y !== 0 ? [new Vec3(1, 0, 0), new Vec3(0, 0, 1)]
|
||||||
: [new Vec3(0, 1, 0)]
|
: [new Vec3(0, 1, 0)]
|
||||||
return (await Promise.all(firstLineDirection
|
return (await Promise.all(firstLineDirection
|
||||||
.map(async d => ({direction: d, line: (await findLine(world, startingPoint, 'obsidian', d, directionV))}))))
|
.map(async d => ({ direction: d, line: (await findLine(world, startingPoint, 'obsidian', d, directionV)) }))))
|
||||||
.filter(line => (line.line.length >= 3 && line.direction.y !== 0) ||
|
.filter(line => (line.line.length >= 3 && line.direction.y !== 0) ||
|
||||||
(line.line.length >= 2 && line.direction.y === 0))
|
(line.line.length >= 2 && line.direction.y === 0))
|
||||||
}
|
}
|
||||||
|
|
@ -32,7 +32,7 @@ function positiveOrder (line, direction) {
|
||||||
return line
|
return line
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findBorder (world, {line, direction}, directionV) {
|
async function findBorder (world, { line, direction }, directionV) {
|
||||||
let bottom = line
|
let bottom = line
|
||||||
if (bottom.length === 0) { return [] }
|
if (bottom.length === 0) { return [] }
|
||||||
let left = await findLineInDirection(world, bottom[0].plus(direction.scaled(-1).plus(directionV)), 'obsidian', directionV, direction)
|
let left = await findLineInDirection(world, bottom[0].plus(direction.scaled(-1).plus(directionV)), 'obsidian', directionV, direction)
|
||||||
|
|
@ -57,7 +57,7 @@ async function findBorder (world, {line, direction}, directionV) {
|
||||||
|
|
||||||
if (bottom.length < 2 || top.length < 2 || left.length < 3 || right.length < 3) { return null }
|
if (bottom.length < 2 || top.length < 2 || left.length < 3 || right.length < 3) { return null }
|
||||||
|
|
||||||
return {bottom, left, right, top}
|
return { bottom, left, right, top }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function detectFrame (world, startingPoint, directionV) {
|
async function detectFrame (world, startingPoint, directionV) {
|
||||||
|
|
@ -66,8 +66,8 @@ async function detectFrame (world, startingPoint, directionV) {
|
||||||
return asyncFilter((await Promise.all(potentialLines
|
return asyncFilter((await Promise.all(potentialLines
|
||||||
.map(line => findBorder(world, line, directionV))))
|
.map(line => findBorder(world, line, directionV))))
|
||||||
.filter(border => border !== null)
|
.filter(border => border !== null)
|
||||||
.map(({bottom, left, right, top}) => ({bottom, left, right, top, air: getAir({bottom, left, right, top})})),
|
.map(({ bottom, left, right, top }) => ({ bottom, left, right, top, air: getAir({ bottom, left, right, top }) })),
|
||||||
async ({air}) => isAllAir(world, air))
|
async ({ air }) => isAllAir(world, air))
|
||||||
}
|
}
|
||||||
|
|
||||||
async function asyncEvery (array, pred) {
|
async function asyncEvery (array, pred) {
|
||||||
|
|
@ -85,7 +85,7 @@ async function isAllAir (world, blocks) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAir (border) {
|
function getAir (border) {
|
||||||
const {bottom, top} = border
|
const { bottom, top } = border
|
||||||
return flatMap(bottom, pos => range(1, top[0].y - bottom[0].y).map(i => pos.offset(0, i, 0)))
|
return flatMap(bottom, pos => range(1, top[0].y - bottom[0].y).map(i => pos.offset(0, i, 0)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,7 +110,7 @@ function generatePortal (bottomLeft, direction, width, height) {
|
||||||
|
|
||||||
function addPortalToWorld (world, portal, additionalAir, additionalObsidian, setBlockType = null) {
|
function addPortalToWorld (world, portal, additionalAir, additionalObsidian, setBlockType = null) {
|
||||||
if (setBlockType === null) { setBlockType = world.setBlockType.bind(world) }
|
if (setBlockType === null) { setBlockType = world.setBlockType.bind(world) }
|
||||||
const {bottom, left, right, top, air} = portal
|
const { bottom, left, right, top, air } = portal
|
||||||
|
|
||||||
const p = flatMap([bottom, left, right, top], border => border.map(pos => setBlockType(pos, 49)))
|
const p = flatMap([bottom, left, right, top], border => border.map(pos => setBlockType(pos, 49)))
|
||||||
p.push(air.map(pos => setBlockType(pos, 0)))
|
p.push(air.map(pos => setBlockType(pos, 0)))
|
||||||
|
|
@ -131,7 +131,7 @@ async function makeWorldWithPortal (portal, additionalAir, additionalObsidian) {
|
||||||
function loader (version) {
|
function loader (version) {
|
||||||
World = require('prismarine-world')(version)
|
World = require('prismarine-world')(version)
|
||||||
Chunk = require('prismarine-chunk')(version)
|
Chunk = require('prismarine-chunk')(version)
|
||||||
return {detectFrame, findPotentialLines, findBorder, getAir, generateLine, generatePortal, addPortalToWorld, makeWorldWithPortal}
|
return { detectFrame, findPotentialLines, findBorder, getAir, generateLine, generatePortal, addPortalToWorld, makeWorldWithPortal }
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = loader
|
module.exports = loader
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
const features = require('./features')
|
const features = require('./features')
|
||||||
|
|
||||||
module.exports = (feature, version) =>
|
module.exports = (feature, version) =>
|
||||||
features.some(({name, versions}) => name === feature && versions.includes(version))
|
features.some(({ name, versions }) => name === feature && versions.includes(version))
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
const Vec3 = require('vec3').Vec3
|
const Vec3 = require('vec3').Vec3
|
||||||
|
|
||||||
function generation ({version}) {
|
function generation ({ version }) {
|
||||||
const Chunk = require('prismarine-chunk')(version)
|
const Chunk = require('prismarine-chunk')(version)
|
||||||
const blocks = require('minecraft-data')(version).blocks
|
const blocks = require('minecraft-data')(version).blocks
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
const Vec3 = require('vec3').Vec3
|
const Vec3 = require('vec3').Vec3
|
||||||
|
|
||||||
function generation ({version}) {
|
function generation ({ version }) {
|
||||||
const Chunk = require('prismarine-chunk')(version)
|
const Chunk = require('prismarine-chunk')(version)
|
||||||
|
|
||||||
function generateSimpleChunk () {
|
function generateSimpleChunk () {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
const Vec3 = require('vec3').Vec3
|
const Vec3 = require('vec3').Vec3
|
||||||
const rand = require('random-seed')
|
const rand = require('random-seed')
|
||||||
|
|
||||||
function generation ({version, seed, level = 50} = {}) {
|
function generation ({ version, seed, level = 50 } = {}) {
|
||||||
const Chunk = require('prismarine-chunk')(version)
|
const Chunk = require('prismarine-chunk')(version)
|
||||||
|
|
||||||
function generateChunk (chunkX, chunkZ) {
|
function generateChunk (chunkX, chunkZ) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
const Vec3 = require('vec3').Vec3
|
const Vec3 = require('vec3').Vec3
|
||||||
|
|
||||||
function generation ({version, opt = 'default', bottomId = 7, middleId = 1, topId = 2, middleThickness = 3, debug = false} = {}) {
|
function generation ({ version, opt = 'default', bottomId = 7, middleId = 1, topId = 2, middleThickness = 3, debug = false } = {}) {
|
||||||
const Chunk = require('prismarine-chunk')(version)
|
const Chunk = require('prismarine-chunk')(version)
|
||||||
|
|
||||||
function generateChunk () {
|
function generateChunk () {
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ squid.supportedVersions.forEach((supportedVersion, i) => {
|
||||||
const pos = bot.entity.position.offset(0, -1, 0).floored()
|
const pos = bot.entity.position.offset(0, -1, 0).floored()
|
||||||
bot.dig(bot.blockAt(pos))
|
bot.dig(bot.blockAt(pos))
|
||||||
|
|
||||||
let [, newBlock] = await once(bot2, 'blockUpdate', {array: true})
|
let [, newBlock] = await once(bot2, 'blockUpdate', { array: true })
|
||||||
assertPosEqual(newBlock.position, pos)
|
assertPosEqual(newBlock.position, pos)
|
||||||
expect(newBlock.type).toEqual(0)
|
expect(newBlock.type).toEqual(0)
|
||||||
})
|
})
|
||||||
|
|
@ -145,7 +145,7 @@ squid.supportedVersions.forEach((supportedVersion, i) => {
|
||||||
const pos = bot.entity.position.offset(0, -2, 0).floored()
|
const pos = bot.entity.position.offset(0, -2, 0).floored()
|
||||||
bot.dig(bot.blockAt(pos))
|
bot.dig(bot.blockAt(pos))
|
||||||
|
|
||||||
let [, newBlock] = await once(bot2, 'blockUpdate', {array: true})
|
let [, newBlock] = await once(bot2, 'blockUpdate', { array: true })
|
||||||
assertPosEqual(newBlock.position, pos)
|
assertPosEqual(newBlock.position, pos)
|
||||||
expect(newBlock.type).toEqual(0)
|
expect(newBlock.type).toEqual(0)
|
||||||
|
|
||||||
|
|
@ -158,7 +158,7 @@ squid.supportedVersions.forEach((supportedVersion, i) => {
|
||||||
|
|
||||||
bot.placeBlock(bot.blockAt(pos.offset(0, -1, 0)), new Vec3(0, 1, 0));
|
bot.placeBlock(bot.blockAt(pos.offset(0, -1, 0)), new Vec3(0, 1, 0));
|
||||||
|
|
||||||
[, newBlock] = await once(bot2, 'blockUpdate', {array: true})
|
[, newBlock] = await once(bot2, 'blockUpdate', { array: true })
|
||||||
assertPosEqual(newBlock.position, pos)
|
assertPosEqual(newBlock.position, pos)
|
||||||
expect(newBlock.type).toEqual(1)
|
expect(newBlock.type).toEqual(1)
|
||||||
})
|
})
|
||||||
|
|
@ -246,7 +246,7 @@ squid.supportedVersions.forEach((supportedVersion, i) => {
|
||||||
test('can use /setblock', async () => {
|
test('can use /setblock', async () => {
|
||||||
await Promise.all([waitSpawnZone(bot, 2), onGround(bot)])
|
await Promise.all([waitSpawnZone(bot, 2), onGround(bot)])
|
||||||
bot.chat('/setblock 1 2 3 95 0')
|
bot.chat('/setblock 1 2 3 95 0')
|
||||||
let [, newBlock] = await once(bot, 'blockUpdate:' + new Vec3(1, 2, 3), {array: true})
|
let [, newBlock] = await once(bot, 'blockUpdate:' + new Vec3(1, 2, 3), { array: true })
|
||||||
expect(newBlock.type).toEqual(95)
|
expect(newBlock.type).toEqual(95)
|
||||||
})
|
})
|
||||||
test('can use /xp', async () => {
|
test('can use /xp', async () => {
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ squid.supportedVersions.forEach((supportedVersion, i) => {
|
||||||
additionalObsidian: [new Vec3(2, 1, 1), new Vec3(5, 1, 1), new Vec3(2, 6, 1), new Vec3(5, 6, 1)]
|
additionalObsidian: [new Vec3(2, 1, 1), new Vec3(5, 1, 1), new Vec3(2, 6, 1), new Vec3(5, 6, 1)]
|
||||||
})
|
})
|
||||||
|
|
||||||
const {bottom, left, right, top, air} = generatePortal(new Vec3(2, 1, 2), new Vec3(1, 0, 0), 4, 5)
|
const { bottom, left, right, top, air } = generatePortal(new Vec3(2, 1, 2), new Vec3(1, 0, 0), 4, 5)
|
||||||
|
|
||||||
portalData.push({
|
portalData.push({
|
||||||
name: '2 portals',
|
name: '2 portals',
|
||||||
|
|
@ -103,11 +103,11 @@ squid.supportedVersions.forEach((supportedVersion, i) => {
|
||||||
additionalObsidian: []
|
additionalObsidian: []
|
||||||
})
|
})
|
||||||
|
|
||||||
portalData.forEach(({name, bottomLeft, direction, width, height, additionalAir, additionalObsidian}) => {
|
portalData.forEach(({ name, bottomLeft, direction, width, height, additionalAir, additionalObsidian }) => {
|
||||||
const portal = generatePortal(bottomLeft, direction, width, height)
|
const portal = generatePortal(bottomLeft, direction, width, height)
|
||||||
const {bottom, left, right, top, air} = portal
|
const { bottom, left, right, top, air } = portal
|
||||||
describe('Detect ' + name, () => {
|
describe('Detect ' + name, () => {
|
||||||
const expectedBorder = {bottom, left, right, top}
|
const expectedBorder = { bottom, left, right, top }
|
||||||
|
|
||||||
let world
|
let world
|
||||||
beforeAll(async function () {
|
beforeAll(async function () {
|
||||||
|
|
@ -233,9 +233,9 @@ squid.supportedVersions.forEach((supportedVersion, i) => {
|
||||||
additionalObsidian: [new Vec3(4, 3, 1)]
|
additionalObsidian: [new Vec3(4, 3, 1)]
|
||||||
})
|
})
|
||||||
|
|
||||||
portalData.forEach(({name, bottomLeft, direction, width, height, additionalAir, additionalObsidian}) => {
|
portalData.forEach(({ name, bottomLeft, direction, width, height, additionalAir, additionalObsidian }) => {
|
||||||
const portal = generatePortal(bottomLeft, direction, width, height)
|
const portal = generatePortal(bottomLeft, direction, width, height)
|
||||||
const {bottom, right, top} = portal
|
const { bottom, right, top } = portal
|
||||||
describe("doesn't detect detect " + name, () => {
|
describe("doesn't detect detect " + name, () => {
|
||||||
let world
|
let world
|
||||||
beforeAll(async function () {
|
beforeAll(async function () {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue