From 069e30cb7e1a12b03c3e6c0583fd059a459c2dda Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Sun, 20 May 2018 14:57:23 +0200 Subject: [PATCH] use block from inventory instead of heldItem in block_place : fix placing in 1.12 (without breaking 1.8) --- src/lib/plugins/login.js | 2 +- src/lib/plugins/placeBlock.js | 13 +++++++------ src/lib/plugins/useItem.js | 8 ++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/lib/plugins/login.js b/src/lib/plugins/login.js index 3ecd747..e5b1b4e 100644 --- a/src/lib/plugins/login.js +++ b/src/lib/plugins/login.js @@ -40,7 +40,7 @@ module.exports.player = function (player, serv, settings) { player.username = player._client.username serv.players.push(player) serv.uuidToPlayer[player._client.uuid] = player - player.heldItemSlot = 36 + player.heldItemSlot = 0 player.loadedChunks = {} } diff --git a/src/lib/plugins/placeBlock.js b/src/lib/plugins/placeBlock.js index 6b1d813..0cd0575 100644 --- a/src/lib/plugins/placeBlock.js +++ b/src/lib/plugins/placeBlock.js @@ -13,20 +13,21 @@ const materialToSound = { module.exports.player = function (player, serv, {version}) { const blocks = require('minecraft-data')(version).blocks - player._client.on('block_place', ({direction, heldItem, location} = {}) => { - if (direction === -1 || heldItem.blockId === -1 || !blocks[heldItem.blockId]) return + player._client.on('block_place', ({direction, location} = {}) => { + const heldItem = player.inventory.slots[36 + player.heldItemSlot] + if (direction === -1 || heldItem.type === -1 || !blocks[heldItem.type]) return const referencePosition = new Vec3(location.x, location.y, location.z) const directionVector = directionToVector[direction] const placedPosition = referencePosition.plus(directionVector) player.behavior('placeBlock', { direction: directionVector, heldItem: heldItem, - id: heldItem.blockId, - damage: heldItem.itemDamage, + id: heldItem.type, + damage: heldItem.metadata, position: placedPosition, reference: referencePosition, playSound: true, - sound: 'dig.' + (materialToSound[blocks[heldItem.blockId].material] || 'stone') + sound: 'dig.' + (materialToSound[blocks[heldItem.type].material] || 'stone') }, ({direction, heldItem, position, playSound, sound, id, damage}) => { if (playSound) { serv.playSound(sound, player.world, placedPosition.clone().add(new Vec3(0.5, 0.5, 0.5)), { @@ -36,7 +37,7 @@ module.exports.player = function (player, serv, {version}) { player.inventory.slots[36 + player.heldItemSlot]-- - if (heldItem.blockId !== 323) { + if (heldItem.type !== 323) { player.changeBlock(position, id, damage) } else if (direction === 1) { player.setBlock(position, 63, 0) diff --git a/src/lib/plugins/useItem.js b/src/lib/plugins/useItem.js index d0c5df8..de276a2 100644 --- a/src/lib/plugins/useItem.js +++ b/src/lib/plugins/useItem.js @@ -2,11 +2,11 @@ const Vec3 = require('vec3').Vec3 module.exports.player = function (player, serv, {version}) { const items = require('minecraft-data')(version).items - const Item = require('prismarine-item')(version) - player._client.on('block_place', ({direction, heldItem, location} = {}) => { - if (direction === -1 || heldItem.blockId === -1 || !items[heldItem.blockId]) return - const item = Item.fromNotch(heldItem) + player._client.on('block_place', ({direction, location} = {}) => { + const heldItem = player.inventory.slots[36 + player.heldItemSlot] + if (direction === -1 || heldItem.type === -1 || !items[heldItem.type]) return + const item = heldItem const referencePosition = new Vec3(location.x, location.y, location.z) const directionVector = directionToVector[direction] const position = referencePosition.plus(directionVector)