Skip to content

Instantly share code, notes, and snippets.

@Heath123
Created August 3, 2020 20:12
Show Gist options
  • Save Heath123/2c59db604ec4b982d335b6f95252cfb1 to your computer and use it in GitHub Desktop.
Save Heath123/2c59db604ec4b982d335b6f95252cfb1 to your computer and use it in GitHub Desktop.
Put it in the Scripts tab of https://github.com/Heath123/pakkit and tick "Enable scripting" BEFORE you join the proxy
// See the node-minecraft-protocol docs
// When editing your scripts, disable scripting or disconnect so
// you don't get lots of errors.
// Handles packets going from the client to the server
exports.upstreamHandler = function (meta, data, server, client) {
const breakTime = 8250 // Break time in ms, try changing this
if (meta.name === 'block_dig') {
if (data.status === 0) {
console.log('Dig start!', meta)
const newData = Object.assign({}, data)
newData.status = 2
const playerID = global.playerEntityID
const timeUnit = breakTime / 11
client.sendPacket('entity_effect',
{
"entityId": playerID,
"effectId": 4,
"amplifier": -1,
"duration": 20,
"hideParticles": 0
})
setTimeout(function() {
console.log('Stopping anim')
client.sendPacket('block_break_animation',
{ entityId: 12, location: data.location, destroyStage: 10 })
console.log('Sending break!')
// server.sendPacket(meta, newData)
server.sendPacket('chat',
{ message: '/setblock ' + data.location.x + ' ' + data.location.y + ' ' + data.location.z + ' minecraft:air destroy' });
}, breakTime)
for (i = 0; i < 10; i++) {
const newI = i
setTimeout(function() {
console.log('Sending anim ' + newI)
client.sendPacket('block_break_animation',
{ entityId: 123, location: data.location, destroyStage: newI })
}, (newI + 1) * timeUnit)
}
}
}
server.sendPacket(meta, data)
}
// Handles packets going from the server to the client
exports.downstreamHandler = function (meta, data, server, client) {
client.sendPacket(meta, data)
if (meta.name === 'login') {
global.playerEntityID = data.entityId
console.log('Set player entity ID:', global.playerEntityID)
}
// I can't make cancelling any animations that happened before the effect was applied to work
// Maybe destroy and replace the block?
/* else if (meta.name === 'acknowledge_player_digging') {
console.log('change packet')
// data.status = 1 // Cancelled digging
data.successful = false
// Stop animation
client.sendPacket('block_break_animation',
{ entityId: global.playerEntityID, location: data.location, destroyStage: 10 })
} */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment