mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-17 13:31:16 +00:00
Continuing attempt to implement abilities
This commit is contained in:
parent
0092af247e
commit
0adfc20a1f
7 changed files with 52 additions and 28 deletions
|
|
@ -840,7 +840,7 @@ Emitted when a player places a block
|
|||
- position: Position they're attempting to place the block
|
||||
- id: Id of block being placed
|
||||
- damage: Data of block being placed
|
||||
- reference (u): Reference block that was placed on
|
||||
- reference (u): Reference block (position) that was placed on
|
||||
- direction (u): Direction vector from reference to position
|
||||
- playSound: Which sound to play (Default: true)
|
||||
- sound: Sound to play (Default: default sound for that material)
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ var Vec3 = require("vec3").Vec3;
|
|||
|
||||
module.exports.player=function(player)
|
||||
{
|
||||
player._client.on('block_place', async ({location} = {}) => {
|
||||
var referencePosition=new Vec3(location.x,location.y,location.z);
|
||||
player.on('placeBlock_cancel', async (opt, cancel) => {
|
||||
if (player.crouching) return;
|
||||
try {
|
||||
var id = await player.world.getBlockType(referencePosition);
|
||||
var blockAbove = await player.world.getBlockType(referencePosition.clone().add(new Vec3(0, 1, 0)));
|
||||
var id = await player.world.getBlockType(opt.reference);
|
||||
var blockAbove = await player.world.getBlockType(opt.reference.plus(new Vec3(0, 1, 0)));
|
||||
if (id == 54) {
|
||||
opt.playSound = false;
|
||||
if (blockAbove) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@ module.exports.player=function(player)
|
|||
windowTitle: JSON.stringify("Chest"),
|
||||
slotCount: 9 * 3 + 8 // 3 rows, make nicer later
|
||||
});
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
catch(err) {
|
||||
|
|
|
|||
|
|
@ -121,8 +121,6 @@ module.exports.player=function(player, serv) {
|
|||
else setTimeout(() => {throw err;}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
player.selectorString = (str) => serv.selectorString(str, player.position.scaled(1/32), player.world);
|
||||
};
|
||||
|
||||
module.exports.entity = function(entity, serv) {
|
||||
|
|
|
|||
|
|
@ -48,4 +48,7 @@ module.exports.entity=function(entity,serv)
|
|||
|
||||
entity._writeOthersNearby = (packetName, packetFields) =>
|
||||
serv._writeArray(packetName, packetFields, entity.getNearbyPlayers());
|
||||
|
||||
entity._writeNearby = (packetName, packetFields) =>
|
||||
serv._writeArray(packetName, packetFields, entity.getNearbyPlayers().concat(entity.type == 'player' ? [entity] : []));
|
||||
};
|
||||
|
|
@ -94,6 +94,7 @@ module.exports.player=function(player,serv)
|
|||
gamemode: player.gameMode
|
||||
}]
|
||||
});
|
||||
player.sendAbilities();
|
||||
};
|
||||
|
||||
function fillTabList()
|
||||
|
|
@ -161,6 +162,7 @@ module.exports.player=function(player,serv)
|
|||
player.sendSpawnPosition();
|
||||
player.sendSelfPosition();
|
||||
player.updateHealth(player.health);
|
||||
player.sendAbilities();
|
||||
|
||||
|
||||
updateTime();
|
||||
|
|
@ -173,6 +175,5 @@ module.exports.player=function(player,serv)
|
|||
await player.waitPlayerLogin();
|
||||
player.sendRestMap();
|
||||
sendChunkWhenMove();
|
||||
player.sendAbilities();
|
||||
};
|
||||
};
|
||||
|
|
@ -37,6 +37,22 @@ module.exports.entity=function(entity){
|
|||
return { position: newPos, onGround: yBlock}
|
||||
};
|
||||
|
||||
entity.sendVelocity = (vel, maxVel) => {
|
||||
var velocity = vel.scaled(32).floored(); // Make fixed point
|
||||
var maxVelocity = maxVel.scaled(32).floored();
|
||||
var scaledVelocity = velocity.scaled(8000/32/20).floored(); // from fixed-position/second to unit => 1/8000 blocks per tick
|
||||
entity._writeNearby('entity_velocity', {
|
||||
entityId: entity.id,
|
||||
velocityX: scaledVelocity.x,
|
||||
velocityY: scaledVelocity.y,
|
||||
velocityZ: scaledVelocity.z
|
||||
});
|
||||
if (entity.type != 'player') {
|
||||
if (maxVelocity) entity.velocity = addVelocityWithMax(entity.velocity, velocity, maxVelocity);
|
||||
else entity.velocity.add(velocity);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function getMoveAmount(dir, block, entity, delta, sizeSigned) {
|
||||
if (block) {
|
||||
|
|
@ -70,4 +86,21 @@ module.exports.entity=function(entity){
|
|||
function clamp(a, b, c) {
|
||||
return Math.max(a, Math.min(b, c));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
module.exports.player = function(player, serv) {
|
||||
player.commands.add({
|
||||
base: 'velocity',
|
||||
info: 'Push velocity on player(s)',
|
||||
usage: '/velocity <player> <x> <y> <z>',
|
||||
op: true,
|
||||
parse(str) {
|
||||
return str.match(/(.+?) (\d+) (\d+) (\d+)/) || false;
|
||||
},
|
||||
action(params) {
|
||||
var selector = player.selectorString(params[1]);
|
||||
var vec = new Vec3(parseInt(params[2]), parseInt(params[3]), parseInt(params[4]));
|
||||
selector.forEach(e => e.sendVelocity(vec, vec.scaled(5)));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -69,9 +69,13 @@ module.exports.player=function(player)
|
|||
}
|
||||
|
||||
player.sendAbilities = () => {
|
||||
var f = (+(player.gameMode == 1)*1) + (+(player.gameMode == 1 || player.gameMode == 3)*2) + (+(player.gameMode == 1 || player.gamemode == 3)*4);
|
||||
var walkingSpeed = 1.0 + ((player.effects[1] != null ? (player.effects[1].amplifier + 1) : 0) * 0.2)
|
||||
var flyingSpeed = 0.2;
|
||||
var godmode = player.gameMode == 1 || player.gameMode == 3;
|
||||
var canFly = player.gameMode == 1 || player.gameMode == 3;
|
||||
var isFlying = !player.onGround && canFly;
|
||||
var creativeMode = player.gameMode == 1;
|
||||
var f = (+godmode*8) + (+canFly*4) + (+isFlying*2) + (+creativeMode*1);
|
||||
var walkingSpeed = 4.3/20 * (1 + (player.effects[1] != null ? (player.effects[1].amplifier + 1) : 0) * 0.2)
|
||||
var flyingSpeed = 1.0/20;
|
||||
console.log(walkingSpeed, flyingSpeed);
|
||||
player._client.write('abilities', {
|
||||
flags: f,
|
||||
|
|
@ -116,22 +120,6 @@ module.exports.entity=function(entity,serv){
|
|||
});
|
||||
};
|
||||
|
||||
entity.sendVelocity = (vel, maxVel) => {
|
||||
var velocity = vel.scaled(32).floored(); // Make fixed point
|
||||
var maxVelocity = maxVel.scaled(32).floored();
|
||||
var scaledVelocity = velocity.scaled(8000/32/20).floored(); // from fixed-position/second to unit => 1/8000 blocks per tick
|
||||
entity._writeOthersNearby('entity_velocity', {
|
||||
entityId: entity.id,
|
||||
velocityX: scaledVelocity.x,
|
||||
velocityY: scaledVelocity.y,
|
||||
velocityZ: scaledVelocity.z
|
||||
});
|
||||
if (entity.type != 'player') {
|
||||
if (maxVelocity) entity.velocity = addVelocityWithMax(entity.velocity, velocity, maxVelocity);
|
||||
else entity.velocity.add(velocity);
|
||||
}
|
||||
};
|
||||
|
||||
entity.teleport = (pos) => { // Overwritten in players inject above
|
||||
entity.sendPosition(pos.scaled(32), false, true);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue