mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-07 12:10:46 +00:00
Fix stuff, add a small implementation of picking up blocks (doesn't go into inventory)
This commit is contained in:
parent
a02983c2bd
commit
2a376626e6
5 changed files with 36 additions and 12 deletions
|
|
@ -1,5 +1,3 @@
|
||||||
var Vec3 = require("vec3").Vec3;
|
|
||||||
|
|
||||||
module.exports.player=function(player,serv)
|
module.exports.player=function(player,serv)
|
||||||
{
|
{
|
||||||
player.changeBlock=async (position,blockType,blockData) =>
|
player.changeBlock=async (position,blockType,blockData) =>
|
||||||
|
|
@ -33,7 +31,7 @@ module.exports.player=function(player,serv)
|
||||||
action(params) {
|
action(params) {
|
||||||
var res = params.map((num, i) => { // parseInt paramaters
|
var res = params.map((num, i) => { // parseInt paramaters
|
||||||
if (num.indexOf('~') == 0) {
|
if (num.indexOf('~') == 0) {
|
||||||
return (player.entity.position[['', 'x', 'y', 'z'][i]] >> 5) + parseInt(num.slice(1) || 0);
|
return (player.position[['', 'x', 'y', 'z'][i]] >> 5) + parseInt(num.slice(1) || 0);
|
||||||
} else {
|
} else {
|
||||||
return parseInt(num); // return parseInt>>5 if position, not id
|
return parseInt(num); // return parseInt>>5 if position, not id
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ module.exports.player=function(player)
|
||||||
{
|
{
|
||||||
player._client.on('block_place', async ({location} = {}) => {
|
player._client.on('block_place', async ({location} = {}) => {
|
||||||
var referencePosition=new Vec3(location.x,location.y,location.z);
|
var referencePosition=new Vec3(location.x,location.y,location.z);
|
||||||
if (player.entity.crouching) return;
|
if (player.crouching) return;
|
||||||
try {
|
try {
|
||||||
var id = await player.world.getBlockType(referencePosition);
|
var id = await player.world.getBlockType(referencePosition);
|
||||||
var blockAbove = await player.world.getBlockType(referencePosition.clone().add(new Vec3(0, 1, 0)));
|
var blockAbove = await player.world.getBlockType(referencePosition.clone().add(new Vec3(0, 1, 0)));
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ module.exports.player=function(player,serv)
|
||||||
player.changeBlock(location,0,0);
|
player.changeBlock(location,0,0);
|
||||||
// Drop block
|
// Drop block
|
||||||
serv.spawnObject(2, player.world, location.offset(0.5, 0.5, 0.5), {
|
serv.spawnObject(2, player.world, location.offset(0.5, 0.5, 0.5), {
|
||||||
velocity: Vec3(Math.random()*4 - 2, Math.random()*2 + 2, Math.random()*4 - 2),
|
velocity: new Vec3(Math.random()*4 - 2, Math.random()*2 + 2, Math.random()*4 - 2),
|
||||||
itemId: currentlyDugBlock.type,
|
itemId: currentlyDugBlock.type,
|
||||||
itemDamage: currentlyDugBlock.metadata
|
itemDamage: currentlyDugBlock.metadata
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ module.exports.server=function(serv,options) {
|
||||||
object.friction = (new Vec3(10*32, 0, 10*32)).floored();
|
object.friction = (new Vec3(10*32, 0, 10*32)).floored();
|
||||||
object.size = new Vec3(0.25*32, 0.25*32, 0.25*32); // Hardcoded, will be dependent on type!
|
object.size = new Vec3(0.25*32, 0.25*32, 0.25*32); // Hardcoded, will be dependent on type!
|
||||||
object.deathTime = 60*1000; // 60 seconds
|
object.deathTime = 60*1000; // 60 seconds
|
||||||
|
object.pickupTime = 200;
|
||||||
object.itemId = itemId;
|
object.itemId = itemId;
|
||||||
object.itemDamage = itemDamage;
|
object.itemDamage = itemDamage;
|
||||||
|
|
||||||
|
|
@ -72,6 +73,16 @@ module.exports.server=function(serv,options) {
|
||||||
if (entity.deathTime && Date.now() - entity.bornTime >= entity.deathTime) {
|
if (entity.deathTime && Date.now() - entity.bornTime >= entity.deathTime) {
|
||||||
entity.destroy();
|
entity.destroy();
|
||||||
return;
|
return;
|
||||||
|
} else if (entity.pickupTime && Date.now() - entity.bornTime >= entity.pickupTime) {
|
||||||
|
var players = serv.getNearby({
|
||||||
|
world: entity.world,
|
||||||
|
position: entity.position,
|
||||||
|
radius: 1.5*32 // Seems good for now
|
||||||
|
});
|
||||||
|
if (players.length) {
|
||||||
|
players[0].collect(entity);
|
||||||
|
entity.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!entity.velocity || !entity.size) return;
|
if (!entity.velocity || !entity.size) return;
|
||||||
var oldPosAndOnGround = await entity.calculatePhysics(delta);
|
var oldPosAndOnGround = await entity.calculatePhysics(delta);
|
||||||
|
|
@ -241,19 +252,28 @@ module.exports.entity=function(entity,serv){
|
||||||
if (entity.type == 'player') {
|
if (entity.type == 'player') {
|
||||||
entity.despawnEntities(entitiesToRemove);
|
entity.despawnEntities(entitiesToRemove);
|
||||||
entitiesToAdd.forEach(entity.spawnEntity);
|
entitiesToAdd.forEach(entity.spawnEntity);
|
||||||
entity.lastPositionPlayersUpdated=entity.position.clone();
|
|
||||||
} else {
|
|
||||||
entity.lastPositionPlayersUpdated=entity.position.clone();
|
|
||||||
}
|
}
|
||||||
|
entity.lastPositionPlayersUpdated=entity.position.clone();
|
||||||
|
|
||||||
var playersToAdd = entitiesToAdd.filter(e => e.type == 'player').map(e => e.player);
|
var playersToAdd = entitiesToAdd.filter(e => e.type == 'player');
|
||||||
var playersToRemove = entitiesToRemove.filter(e => e.type == 'player').map(e => e.player);
|
var playersToRemove = entitiesToRemove.filter(e => e.type == 'player');
|
||||||
|
|
||||||
playersToRemove.forEach(p => p.despawnEntities([entity]));
|
playersToRemove.forEach(p => p.despawnEntities([entity]));
|
||||||
playersToRemove.forEach(p => p.entity.nearbyEntities=p.entity.getNearby());
|
playersToRemove.forEach(p => p.nearbyEntities=p.getNearby());
|
||||||
playersToAdd.forEach(p => p.spawnEntity(entity));
|
playersToAdd.forEach(p => p.spawnEntity(entity));
|
||||||
playersToAdd.forEach(p => p.entity.nearbyEntities=p.entity.getNearby());
|
playersToAdd.forEach(p => p.nearbyEntities=p.getNearby());
|
||||||
|
|
||||||
entity.nearbyEntities=updatedEntities;
|
entity.nearbyEntities=updatedEntities;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
entity.collect = (collectEntity) => {
|
||||||
|
if (entity.type != 'player') serv.emit('error', 'Non-player entity (ttype ' + entity.type + ') cannot collect another entity');
|
||||||
|
else {
|
||||||
|
serv._writeNearby('collect', {
|
||||||
|
collectedEntityId: collectEntity.id,
|
||||||
|
collectorEntityId: entity.id
|
||||||
|
}, collectEntity);
|
||||||
|
entity.playSoundAtSelf('random.pop');
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -102,4 +102,10 @@ module.exports.player=function(player,serv) {
|
||||||
serv.playSound(sound_name, player.world, player.position.scaled(1/32), {volume: volume,pitch: pitch});
|
serv.playSound(sound_name, player.world, player.position.scaled(1/32), {volume: volume,pitch: pitch});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.entity=function(entity,serv) {
|
||||||
|
entity.playSoundAtSelf = (sound, opt={}) => {
|
||||||
|
serv.playSound(sound, entity.world, entity.position.scaled(1/32), opt);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
Loading…
Reference in a new issue