use block from inventory instead of heldItem in block_place : fix placing in 1.12 (without breaking 1.8)

This commit is contained in:
Romain Beaumont 2018-05-20 14:57:23 +02:00
parent 3b51a29ae1
commit 069e30cb7e
No known key found for this signature in database
GPG key ID: DB60E388B3BCF286
3 changed files with 12 additions and 11 deletions

View file

@ -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 = {}
}

View file

@ -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)

View file

@ -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)