mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-05 11:10:44 +00:00
Attempting to convert Player into Entity
This commit is contained in:
parent
8d7523a995
commit
180799e045
17 changed files with 114 additions and 114 deletions
16
src/lib/behavior.js
Normal file
16
src/lib/behavior.js
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
module.exports = (obj) => {
|
||||||
|
return (eventName, data, func, opt) => {
|
||||||
|
var hiddenCancelled = false;
|
||||||
|
var cancelled = false;
|
||||||
|
var cancel = (hidden) => { // Hidden shouldn't be used often but it's not hard to implement so meh
|
||||||
|
if (hidden) hiddenCancelled = true;
|
||||||
|
else cancelled = true;
|
||||||
|
}
|
||||||
|
obj.emit(eventName + '_cancel', data, cancel);
|
||||||
|
obj.emit(eventName, data, cancelled);
|
||||||
|
|
||||||
|
if (!hiddenCancelled && !cancelled) func(data);
|
||||||
|
|
||||||
|
obj.emit(eventName + '_done', data, cancelled);
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/lib/entity.js
Normal file
14
src/lib/entity.js
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
var EventEmitter = require('events').EventEmitter;
|
||||||
|
var PrismarineEntity = require("prismarine-entity");
|
||||||
|
var util = require('util');
|
||||||
|
util.inherits(PrismarineEntity, EventEmitter);
|
||||||
|
|
||||||
|
class Entity extends PrismarineEntity
|
||||||
|
{
|
||||||
|
constructor(id) {
|
||||||
|
super(id);
|
||||||
|
EventEmitter.call(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Entity;
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
var EventEmitter = require('events').EventEmitter;
|
|
||||||
|
|
||||||
|
|
||||||
class Player extends EventEmitter
|
|
||||||
{
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this._client=null;
|
|
||||||
this.entity=null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Player;
|
|
||||||
|
|
@ -2,30 +2,21 @@ module.exports.player=function(player)
|
||||||
{
|
{
|
||||||
player._client.on("arm_animation", () =>
|
player._client.on("arm_animation", () =>
|
||||||
player._writeOthersNearby("animation", {
|
player._writeOthersNearby("animation", {
|
||||||
entityId: player.entity.id,
|
entityId: player.id,
|
||||||
animation: 0
|
animation: 0
|
||||||
}));
|
}));
|
||||||
|
|
||||||
function setMetadata(metadata)
|
|
||||||
{
|
|
||||||
player.entity.metadata = metadata;
|
|
||||||
player._writeOthersNearby("entity_metadata", {
|
|
||||||
entityId: player.entity.id,
|
|
||||||
metadata: player.entity.metadata
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
player._client.on("entity_action", ({actionId} = {}) => {
|
player._client.on("entity_action", ({actionId} = {}) => {
|
||||||
if(actionId == 3) {
|
if(actionId == 3) {
|
||||||
setMetadata([{"key":0,"type":0,"value": 0x08}]);
|
player.setMetadata([{"key":0,"type":0,"value": 0x08}]);
|
||||||
} else if(actionId == 4) {
|
} else if(actionId == 4) {
|
||||||
setMetadata([{"key":0,"type":0,"value": 0x00}]);
|
player.setMetadata([{"key":0,"type":0,"value": 0x00}]);
|
||||||
} else if(actionId == 0) {
|
} else if(actionId == 0) {
|
||||||
setMetadata([{"key":0,"type":0,"value": 0x02}]);
|
player.setMetadata([{"key":0,"type":0,"value": 0x02}]);
|
||||||
player.entity.crouching = true;
|
player.crouching = true;
|
||||||
} else if(actionId == 1) {
|
} else if(actionId == 1) {
|
||||||
setMetadata([{"key":0,"type":0,"value": 0x00}]);
|
player.setMetadata([{"key":0,"type":0,"value": 0x00}]);
|
||||||
player.entity.crouching = false;
|
player.crouching = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -11,7 +11,7 @@ module.exports.server=function(serv)
|
||||||
|
|
||||||
serv.getNearby= ({world,position,radius=8*16*32}) => serv.players.filter( player =>
|
serv.getNearby= ({world,position,radius=8*16*32}) => serv.players.filter( player =>
|
||||||
player.world == world &&
|
player.world == world &&
|
||||||
player.entity.position.distanceTo(position) <= radius
|
player.position.distanceTo(position) <= radius
|
||||||
);
|
);
|
||||||
|
|
||||||
serv.getNearbyEntities= ({world,position,radius=8*16*32}) => Object.keys(serv.entities)
|
serv.getNearbyEntities= ({world,position,radius=8*16*32}) => Object.keys(serv.entities)
|
||||||
|
|
@ -34,13 +34,12 @@ module.exports.player=function(player,serv)
|
||||||
|
|
||||||
player.getOthers = () => serv.players.filter((otherPlayer) => otherPlayer != player);
|
player.getOthers = () => serv.players.filter((otherPlayer) => otherPlayer != player);
|
||||||
|
|
||||||
player.getNearbyPlayers = (radius=player.entity.viewDistance*32) => serv.getNearby({
|
player.getNearbyPlayers = (radius=player.viewDistance*32) => serv.getNearby({
|
||||||
world: player.world,
|
world: player.world,
|
||||||
position: player.position,
|
position: player.position,
|
||||||
radius: radius
|
radius: radius
|
||||||
});
|
});
|
||||||
|
|
||||||
player.nearbyPlayers = (radius=player.entity.viewDistance*32) => player.entity.nearbyEntities
|
player.nearbyPlayers = (radius=player.viewDistance*32) => player.nearbyEntities
|
||||||
.filter(e => e.type == 'player')
|
.filter(e => e.type == 'player');
|
||||||
.map(e => e.player);
|
|
||||||
};
|
};
|
||||||
|
|
@ -93,6 +93,7 @@ module.exports.player=function(player,serv)
|
||||||
|
|
||||||
function creativeDigging(location)
|
function creativeDigging(location)
|
||||||
{
|
{
|
||||||
|
console.log('creative');
|
||||||
return player.changeBlock(location,0,0);
|
return player.changeBlock(location,0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
var Entity=require("prismarine-entity");
|
var Entity=require("../entity");
|
||||||
var util = require('util');
|
|
||||||
var EventEmitter = require('events').EventEmitter;
|
|
||||||
util.inherits(Entity, EventEmitter);
|
|
||||||
var Vec3 = require("vec3").Vec3;
|
var Vec3 = require("vec3").Vec3;
|
||||||
var entitiesByName=require("minecraft-data")(require("../version")).entitiesByName;
|
var entitiesByName=require("minecraft-data")(require("../version")).entitiesByName;
|
||||||
|
|
||||||
|
|
@ -14,7 +11,6 @@ module.exports.server=function(serv,options) {
|
||||||
serv.initEntity = (type, entityType, world, position) => {
|
serv.initEntity = (type, entityType, world, position) => {
|
||||||
serv.entityMaxId++;
|
serv.entityMaxId++;
|
||||||
var entity = new Entity(serv.entityMaxId);
|
var entity = new Entity(serv.entityMaxId);
|
||||||
EventEmitter.call(entity);
|
|
||||||
|
|
||||||
Object.keys(plugins)
|
Object.keys(plugins)
|
||||||
.filter(pluginName => plugins[pluginName].entity!=undefined)
|
.filter(pluginName => plugins[pluginName].entity!=undefined)
|
||||||
|
|
@ -99,7 +95,7 @@ module.exports.player=function(player,serv){
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
action({id}) {
|
action({id}) {
|
||||||
serv.spawnMob(id, player.world, player.entity.position.scaled(1/32), {
|
serv.spawnMob(id, player.world, player.position.scaled(1/32), {
|
||||||
velocity: Vec3((Math.random() - 0.5) * 10, Math.random()*10 + 10, (Math.random() - 0.5) * 10)
|
velocity: Vec3((Math.random() - 0.5) * 10, Math.random()*10 + 10, (Math.random() - 0.5) * 10)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -117,7 +113,7 @@ module.exports.player=function(player,serv){
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
action({id}) {
|
action({id}) {
|
||||||
serv.spawnObject(id, player.world, player.entity.position.scaled(1/32), {
|
serv.spawnObject(id, player.world, player.position.scaled(1/32), {
|
||||||
velocity: Vec3((Math.random() - 0.5) * 10, Math.random()*10 + 10, (Math.random() - 0.5) * 10)
|
velocity: Vec3((Math.random() - 0.5) * 10, Math.random()*10 + 10, (Math.random() - 0.5) * 10)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -133,7 +129,7 @@ module.exports.player=function(player,serv){
|
||||||
player.chat("No entity named "+name);
|
player.chat("No entity named "+name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
serv.spawnMob(entity.id, player.world, player.entity.position.scaled(1/32), {
|
serv.spawnMob(entity.id, player.world, player.position.scaled(1/32), {
|
||||||
velocity: Vec3((Math.random() - 0.5) * 10, Math.random()*10 + 10, (Math.random() - 0.5) * 10)
|
velocity: Vec3((Math.random() - 0.5) * 10, Math.random()*10 + 10, (Math.random() - 0.5) * 10)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -171,6 +167,7 @@ module.exports.entity=function(entity,serv){
|
||||||
entityId: entity.id,
|
entityId: entity.id,
|
||||||
metadata: data
|
metadata: data
|
||||||
}, entity);
|
}, entity);
|
||||||
|
entity.metadata = data;
|
||||||
};
|
};
|
||||||
|
|
||||||
entity.destroy = () => {
|
entity.destroy = () => {
|
||||||
|
|
@ -182,7 +179,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.player._client.uuid,
|
playerUUID: entity._client.uuid,
|
||||||
x: entity.position.x,
|
x: entity.position.x,
|
||||||
y: entity.position.y,
|
y: entity.position.y,
|
||||||
z: entity.position.z,
|
z: entity.position.z,
|
||||||
|
|
@ -238,9 +235,9 @@ module.exports.entity=function(entity,serv){
|
||||||
var entitiesToAdd=updatedEntities.filter(e => entity.nearbyEntities.indexOf(e)==-1);
|
var entitiesToAdd=updatedEntities.filter(e => entity.nearbyEntities.indexOf(e)==-1);
|
||||||
var entitiesToRemove=entity.nearbyEntities.filter(e => updatedEntities.indexOf(e)==-1);
|
var entitiesToRemove=entity.nearbyEntities.filter(e => updatedEntities.indexOf(e)==-1);
|
||||||
if (entity.type == 'player') {
|
if (entity.type == 'player') {
|
||||||
entity.player.despawnEntities(entitiesToRemove);
|
entity.despawnEntities(entitiesToRemove);
|
||||||
entitiesToAdd.forEach(entity.player.spawnEntity);
|
entitiesToAdd.forEach(entity.spawnEntity);
|
||||||
entity.player.lastPositionPlayersUpdated=entity.position.clone();
|
entity.lastPositionPlayersUpdated=entity.position.clone();
|
||||||
} else {
|
} else {
|
||||||
entity.lastPositionPlayersUpdated=entity.position.clone();
|
entity.lastPositionPlayersUpdated=entity.position.clone();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ module.exports.player=function(player)
|
||||||
}
|
}
|
||||||
player.heldItem = player.inventory[36+player.heldItemSlot];
|
player.heldItem = player.inventory[36+player.heldItemSlot];
|
||||||
player._writeOthersNearby("entity_equipment",{
|
player._writeOthersNearby("entity_equipment",{
|
||||||
entityId:player.entity.id,
|
entityId:player.id,
|
||||||
slot:0,
|
slot:0,
|
||||||
item:player.heldItem
|
item:player.heldItem
|
||||||
});
|
});
|
||||||
|
|
@ -23,31 +23,31 @@ module.exports.player=function(player)
|
||||||
player.inventory[slot]=item;
|
player.inventory[slot]=item;
|
||||||
if (slot==36)
|
if (slot==36)
|
||||||
player._writeOthersNearby("entity_equipment",{
|
player._writeOthersNearby("entity_equipment",{
|
||||||
entityId:player.entity.id,
|
entityId:player.id,
|
||||||
slot:0,
|
slot:0,
|
||||||
item:item
|
item:item
|
||||||
});
|
});
|
||||||
if (slot==5)
|
if (slot==5)
|
||||||
player._writeOthersNearby("entity_equipment",{
|
player._writeOthersNearby("entity_equipment",{
|
||||||
entityId:player.entity.id,
|
entityId:player.id,
|
||||||
slot:4,
|
slot:4,
|
||||||
item:item
|
item:item
|
||||||
});
|
});
|
||||||
if (slot==6)
|
if (slot==6)
|
||||||
player._writeOthersNearby("entity_equipment",{
|
player._writeOthersNearby("entity_equipment",{
|
||||||
entityId:player.entity.id,
|
entityId:player.id,
|
||||||
slot:3,
|
slot:3,
|
||||||
item:item
|
item:item
|
||||||
});
|
});
|
||||||
if (slot==7)
|
if (slot==7)
|
||||||
player._writeOthersNearby("entity_equipment",{
|
player._writeOthersNearby("entity_equipment",{
|
||||||
entityId:player.entity.id,
|
entityId:player.id,
|
||||||
slot:2,
|
slot:2,
|
||||||
item:item
|
item:item
|
||||||
});
|
});
|
||||||
if (slot==8)
|
if (slot==8)
|
||||||
player._writeOthersNearby("entity_equipment",{
|
player._writeOthersNearby("entity_equipment",{
|
||||||
entityId:player.entity.id,
|
entityId:player.id,
|
||||||
slot:1,
|
slot:1,
|
||||||
item:item
|
item:item
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ var Vec3 = require("vec3").Vec3
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var requireIndex = require('requireindex');
|
var requireIndex = require('requireindex');
|
||||||
var plugins = requireIndex(path.join(__dirname,'..', 'plugins'));
|
var plugins = requireIndex(path.join(__dirname,'..', 'plugins'));
|
||||||
var Player=require("../player");
|
|
||||||
var Command = require('../command');
|
var Command = require('../command');
|
||||||
|
|
||||||
module.exports.server=function(serv,options)
|
module.exports.server=function(serv,options)
|
||||||
|
|
@ -13,7 +12,7 @@ module.exports.server=function(serv,options)
|
||||||
client.on('error',error => serv.emit('clientError',client,error)));
|
client.on('error',error => serv.emit('clientError',client,error)));
|
||||||
|
|
||||||
serv._server.on('login', async (client) => {
|
serv._server.on('login', async (client) => {
|
||||||
var player=new Player();
|
var player = serv.initEntity('player', null, serv.overworld, new Vec3(0,0,0));
|
||||||
player._client=client;
|
player._client=client;
|
||||||
player.commands = new Command({});
|
player.commands = new Command({});
|
||||||
Object.keys(plugins)
|
Object.keys(plugins)
|
||||||
|
|
@ -34,14 +33,10 @@ module.exports.player=function(player,serv)
|
||||||
{
|
{
|
||||||
function addPlayer()
|
function addPlayer()
|
||||||
{
|
{
|
||||||
player.entity=serv.initEntity('player', null, serv.overworld, new Vec3(0,0,0));
|
player.type = 'player';
|
||||||
player.entity.type = 'player';
|
player.health = 20;
|
||||||
player.entity.player=player;
|
player.food = 20;
|
||||||
player.entity.health = 20;
|
player.crouching = false; // Needs added in prismarine-entity later
|
||||||
player.entity.food = 20;
|
|
||||||
player.entity.crouching = false; // Needs added in prismarine-entity later
|
|
||||||
player.view=10;
|
|
||||||
player.world=serv.overworld;
|
|
||||||
player.username=player._client.username;
|
player.username=player._client.username;
|
||||||
serv.players.push(player);
|
serv.players.push(player);
|
||||||
serv.uuidToPlayer[player._client.uuid] = player;
|
serv.uuidToPlayer[player._client.uuid] = player;
|
||||||
|
|
@ -51,8 +46,8 @@ module.exports.player=function(player,serv)
|
||||||
function sendPlayersWhenMove()
|
function sendPlayersWhenMove()
|
||||||
{
|
{
|
||||||
player.on("positionChanged",() => {
|
player.on("positionChanged",() => {
|
||||||
if(player.entity.position.distanceTo(player.lastPositionPlayersUpdated)>2*32)
|
if(player.position.distanceTo(player.lastPositionPlayersUpdated)>2*32)
|
||||||
player.entity.updateAndSpawn();
|
player.updateAndSpawn();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,7 +55,7 @@ module.exports.player=function(player,serv)
|
||||||
{
|
{
|
||||||
// send init data so client will start rendering world
|
// send init data so client will start rendering world
|
||||||
player._client.write('login', {
|
player._client.write('login', {
|
||||||
entityId: player.entity.id,
|
entityId: player.id,
|
||||||
levelType: 'default',
|
levelType: 'default',
|
||||||
gameMode: player.gameMode,
|
gameMode: player.gameMode,
|
||||||
dimension: 0,
|
dimension: 0,
|
||||||
|
|
@ -68,13 +63,13 @@ module.exports.player=function(player,serv)
|
||||||
reducedDebugInfo: false,
|
reducedDebugInfo: false,
|
||||||
maxPlayers: serv._server.maxPlayers
|
maxPlayers: serv._server.maxPlayers
|
||||||
});
|
});
|
||||||
player.entity.position=player.spawnPoint.toFixedPosition();
|
player.position=player.spawnPoint.toFixedPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendChunkWhenMove()
|
function sendChunkWhenMove()
|
||||||
{
|
{
|
||||||
player.on("positionChanged", () => {
|
player.on("positionChanged", () => {
|
||||||
if(!player.sendingChunks && player.entity.position.distanceTo(player.lastPositionChunkUpdated)>16*32)
|
if(!player.sendingChunks && player.position.distanceTo(player.lastPositionChunkUpdated)>16*32)
|
||||||
player.sendRestMap();
|
player.sendRestMap();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -165,12 +160,12 @@ module.exports.player=function(player,serv)
|
||||||
await player.sendMap();
|
await player.sendMap();
|
||||||
player.sendSpawnPosition();
|
player.sendSpawnPosition();
|
||||||
player.sendPosition();
|
player.sendPosition();
|
||||||
player.updateHealth(player.entity.health);
|
player.updateHealth(player.health);
|
||||||
|
|
||||||
|
|
||||||
updateTime();
|
updateTime();
|
||||||
fillTabList();
|
fillTabList();
|
||||||
player.entity.updateAndSpawn();
|
player.updateAndSpawn();
|
||||||
|
|
||||||
announceJoin();
|
announceJoin();
|
||||||
player.emit("spawned");
|
player.emit("spawned");
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ module.exports.player=function(player,serv)
|
||||||
});
|
});
|
||||||
|
|
||||||
player._client.on('end', () => {
|
player._client.on('end', () => {
|
||||||
if(player.entity) {
|
if(player) {
|
||||||
serv.broadcast(player.username + ' quit the game.', "yellow");
|
serv.broadcast(player.username + ' quit the game.', "yellow");
|
||||||
player._writeOthers('player_info', {
|
player._writeOthers('player_info', {
|
||||||
action: 4,
|
action: 4,
|
||||||
|
|
@ -20,7 +20,7 @@ module.exports.player=function(player,serv)
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
player.nearbyPlayers().forEach(otherPlayer => otherPlayer.despawnPlayers([player]));
|
player.nearbyPlayers().forEach(otherPlayer => otherPlayer.despawnPlayers([player]));
|
||||||
delete serv.entities[player.entity.id];
|
delete serv.entities[player.id];
|
||||||
player.emit('disconnected');
|
player.emit('disconnected');
|
||||||
var index = serv.players.indexOf(player);
|
var index = serv.players.indexOf(player);
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
|
|
|
||||||
|
|
@ -61,15 +61,15 @@ function modpeApi() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPlayerX() {
|
function getPlayerX() {
|
||||||
return player.entity.position.x/32;
|
return player.position.x/32;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPlayerY() {
|
function getPlayerY() {
|
||||||
return player.entity.position.y/32;
|
return player.position.y/32;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPlayerZ() {
|
function getPlayerZ() {
|
||||||
return player.entity.position.z/32;
|
return player.position.z/32;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPlayerEnt() {
|
function getPlayerEnt() {
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ module.exports.player=function(player,serv){
|
||||||
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.entity.position.scaled(1/32), {count: amount,size: size});
|
serv.emitParticle(particle, player.world, player.position.scaled(1/32), {count: amount,size: size});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -2,11 +2,11 @@ module.exports.player=function(player,serv)
|
||||||
{
|
{
|
||||||
|
|
||||||
player.updateHealth = (health) => {
|
player.updateHealth = (health) => {
|
||||||
player.entity.health = health;
|
player.health = health;
|
||||||
player._client.write('update_health', {
|
player._client.write('update_health', {
|
||||||
food: player.entity.food,
|
food: player.food,
|
||||||
foodSaturation: 0.0,
|
foodSaturation: 0.0,
|
||||||
health: player.entity.health
|
health: player.health
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -15,17 +15,17 @@ module.exports.player=function(player,serv)
|
||||||
if (!serv.entities[entityId]) return; // ?????
|
if (!serv.entities[entityId]) return; // ?????
|
||||||
var attackedPlayer = serv.entities[entityId].player;
|
var attackedPlayer = serv.entities[entityId].player;
|
||||||
if(!attackedPlayer || attackedPlayer.gameMode!=0) return;
|
if(!attackedPlayer || attackedPlayer.gameMode!=0) return;
|
||||||
attackedPlayer.updateHealth(attackedPlayer.entity.health - 1);
|
attackedPlayer.updateHealth(attackedplayer.health - 1);
|
||||||
serv.playSound('game.player.hurt', player.world, attackedPlayer.entity.position.scaled(1/32));
|
serv.playSound('game.player.hurt', player.world, attackedplayer.position.scaled(1/32));
|
||||||
|
|
||||||
if(attackedPlayer.entity.health==0)
|
if(attackedplayer.health==0)
|
||||||
attackedPlayer._writeOthers('entity_status',{
|
attackedPlayer._writeOthers('entity_status',{
|
||||||
entityId:attackedPlayer.entity.id,
|
entityId:attackedplayer.id,
|
||||||
entityStatus:3
|
entityStatus:3
|
||||||
});
|
});
|
||||||
else
|
else
|
||||||
attackedPlayer._writeOthers('animation',{
|
attackedPlayer._writeOthers('animation',{
|
||||||
entityId:attackedPlayer.entity.id,
|
entityId:attackedplayer.id,
|
||||||
animation:1
|
animation:1
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ module.exports.player=function(player)
|
||||||
});
|
});
|
||||||
player.sendPosition();
|
player.sendPosition();
|
||||||
player.updateHealth(20);
|
player.updateHealth(20);
|
||||||
player.entity.nearbyEntities=[];
|
player.nearbyEntities=[];
|
||||||
player.entity.updateAndSpawn();
|
player.updateAndSpawn();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -9,7 +9,7 @@ module.exports.server=function(serv) {
|
||||||
}));
|
}));
|
||||||
players.filter(player => blacklist.indexOf(player) == -1)
|
players.filter(player => blacklist.indexOf(player) == -1)
|
||||||
.forEach(player => {
|
.forEach(player => {
|
||||||
var pos = (position || player.entity.position.scaled(1/32)).scaled(8).floored();
|
var pos = (position || player.position.scaled(1/32)).scaled(8).floored();
|
||||||
player._client.write('named_sound_effect', {
|
player._client.write('named_sound_effect', {
|
||||||
soundName: sound,
|
soundName: sound,
|
||||||
x: pos.x,
|
x: pos.x,
|
||||||
|
|
@ -39,7 +39,7 @@ module.exports.player=function(player,serv) {
|
||||||
};
|
};
|
||||||
|
|
||||||
player._client.on('block_place', ({location}={}) => {
|
player._client.on('block_place', ({location}={}) => {
|
||||||
if (player.entity.crouching) return;
|
if (player.crouching) return;
|
||||||
var pos=new Vec3(location.x,location.y,location.z);
|
var pos=new Vec3(location.x,location.y,location.z);
|
||||||
player.world.getBlockType(pos).then((id) => {
|
player.world.getBlockType(pos).then((id) => {
|
||||||
if (id != 25) return;
|
if (id != 25) return;
|
||||||
|
|
@ -99,7 +99,7 @@ module.exports.player=function(player,serv) {
|
||||||
},
|
},
|
||||||
action({sound_name,volume,pitch}) {
|
action({sound_name,volume,pitch}) {
|
||||||
player.chat('Playing "'+sound_name+'" (volume: ' + volume + ', pitch: ' + pitch + ')');
|
player.chat('Playing "'+sound_name+'" (volume: ' + volume + ', pitch: ' + pitch + ')');
|
||||||
serv.playSound(sound_name, player.world, player.entity.position.scaled(1/32), {volume: volume,pitch: pitch});
|
serv.playSound(sound_name, player.world, player.position.scaled(1/32), {volume: volume,pitch: pitch});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -19,18 +19,18 @@ module.exports.player=function(player)
|
||||||
{
|
{
|
||||||
var convYaw=conv(yaw);
|
var convYaw=conv(yaw);
|
||||||
var convPitch=conv(pitch);
|
var convPitch=conv(pitch);
|
||||||
if (convYaw == player.entity.yaw && convPitch == player.entity.pitch) return;
|
if (convYaw == player.yaw && convPitch == player.pitch) return;
|
||||||
player._writeOthersNearby("entity_look", {
|
player._writeOthersNearby("entity_look", {
|
||||||
entityId: player.entity.id,
|
entityId: player.id,
|
||||||
yaw: convYaw,
|
yaw: convYaw,
|
||||||
pitch: convPitch,
|
pitch: convPitch,
|
||||||
onGround: onGround
|
onGround: onGround
|
||||||
});
|
});
|
||||||
player.entity.yaw = convYaw;
|
player.yaw = convYaw;
|
||||||
player.entity.pitch = convPitch;
|
player.pitch = convPitch;
|
||||||
player.entity.onGround = onGround;
|
player.onGround = onGround;
|
||||||
player._writeOthersNearby("entity_head_rotation", {
|
player._writeOthersNearby("entity_head_rotation", {
|
||||||
entityId: player.entity.id,
|
entityId: player.id,
|
||||||
headYaw: convYaw
|
headYaw: convYaw
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -44,23 +44,23 @@ module.exports.player=function(player)
|
||||||
});
|
});
|
||||||
|
|
||||||
function sendRelativePositionChange(newPosition, onGround) {
|
function sendRelativePositionChange(newPosition, onGround) {
|
||||||
if (player.entity.position.distanceTo(new Vec3(0, 0, 0)) != 0) {
|
if (player.position.distanceTo(new Vec3(0, 0, 0)) != 0) {
|
||||||
var diff = newPosition.minus(player.entity.position);
|
var diff = newPosition.minus(player.position);
|
||||||
if(diff.abs().x>127 || diff.abs().y>127 || diff.abs().z>127)
|
if(diff.abs().x>127 || diff.abs().y>127 || diff.abs().z>127)
|
||||||
{
|
{
|
||||||
player._writeOthersNearby('entity_teleport', {
|
player._writeOthersNearby('entity_teleport', {
|
||||||
entityId:player.entity.id,
|
entityId:player.id,
|
||||||
x: newPosition.x,
|
x: newPosition.x,
|
||||||
y: newPosition.y,
|
y: newPosition.y,
|
||||||
z: newPosition.z,
|
z: newPosition.z,
|
||||||
yaw: player.entity.yaw,
|
yaw: player.yaw,
|
||||||
pitch: player.entity.pitch,
|
pitch: player.pitch,
|
||||||
onGround: onGround
|
onGround: onGround
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (diff.distanceTo(new Vec3(0, 0, 0)) != 0) {
|
else if (diff.distanceTo(new Vec3(0, 0, 0)) != 0) {
|
||||||
player._writeOthersNearby('rel_entity_move', {
|
player._writeOthersNearby('rel_entity_move', {
|
||||||
entityId: player.entity.id,
|
entityId: player.id,
|
||||||
dX: diff.x,
|
dX: diff.x,
|
||||||
dY: diff.y,
|
dY: diff.y,
|
||||||
dZ: diff.z,
|
dZ: diff.z,
|
||||||
|
|
@ -68,18 +68,18 @@ module.exports.player=function(player)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
player.entity.position = newPosition;
|
player.position = newPosition;
|
||||||
player.entity.onGround = onGround;
|
player.onGround = onGround;
|
||||||
player.emit("positionChanged");
|
player.emit("positionChanged");
|
||||||
}
|
}
|
||||||
|
|
||||||
player.sendPosition = () => {
|
player.sendPosition = () => {
|
||||||
player._client.write('position', {
|
player._client.write('position', {
|
||||||
x: player.entity.position.x/32,
|
x: player.position.x/32,
|
||||||
y: player.entity.position.y/32,
|
y: player.position.y/32,
|
||||||
z: player.entity.position.z/32,
|
z: player.position.z/32,
|
||||||
yaw: player.entity.yaw,
|
yaw: player.yaw,
|
||||||
pitch: player.entity.pitch,
|
pitch: player.pitch,
|
||||||
flags: 0x00
|
flags: 0x00
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -91,9 +91,9 @@ module.exports.player=function(player,serv) {
|
||||||
|
|
||||||
player.sendNearbyChunks = (view,group) =>
|
player.sendNearbyChunks = (view,group) =>
|
||||||
{
|
{
|
||||||
player.lastPositionChunkUpdated=player.entity.position;
|
player.lastPositionChunkUpdated=player.position;
|
||||||
var playerChunkX=Math.floor(player.entity.position.x/16/32);
|
var playerChunkX=Math.floor(player.position.x/16/32);
|
||||||
var playerChunkZ=Math.floor(player.entity.position.z/16/32);
|
var playerChunkZ=Math.floor(player.position.z/16/32);
|
||||||
|
|
||||||
return spiral([view*2,view*2])
|
return spiral([view*2,view*2])
|
||||||
.map(t => ({
|
.map(t => ({
|
||||||
|
|
@ -145,7 +145,7 @@ module.exports.player=function(player,serv) {
|
||||||
if(player.world == world) return Promise.resolve();
|
if(player.world == world) return Promise.resolve();
|
||||||
opt = opt || {};
|
opt = opt || {};
|
||||||
player.world = world;
|
player.world = world;
|
||||||
player.entity.world = world;
|
player.world = world;
|
||||||
player.loadedChunks={};
|
player.loadedChunks={};
|
||||||
if (typeof opt.gamemode != 'undefined') player.gameMode = opt.gamemode;
|
if (typeof opt.gamemode != 'undefined') player.gameMode = opt.gamemode;
|
||||||
player._client.write("respawn",{
|
player._client.write("respawn",{
|
||||||
|
|
@ -154,9 +154,9 @@ module.exports.player=function(player,serv) {
|
||||||
gamemode: opt.gamemode || player.gameMode,
|
gamemode: opt.gamemode || player.gameMode,
|
||||||
levelType:'default'
|
levelType:'default'
|
||||||
});
|
});
|
||||||
player.entity.position=player.spawnPoint.toFixedPosition();
|
player.position=player.spawnPoint.toFixedPosition();
|
||||||
player.sendSpawnPosition();
|
player.sendSpawnPosition();
|
||||||
player.entity.updateAndSpawn();
|
player.updateAndSpawn();
|
||||||
|
|
||||||
await player.sendMap();
|
await player.sendMap();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue