mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-05 19:20:54 +00:00
use block from inventory instead of heldItem in block_place : fix placing in 1.12 (without breaking 1.8)
This commit is contained in:
parent
3b51a29ae1
commit
069e30cb7e
3 changed files with 12 additions and 11 deletions
|
|
@ -40,7 +40,7 @@ module.exports.player = function (player, serv, settings) {
|
||||||
player.username = player._client.username
|
player.username = player._client.username
|
||||||
serv.players.push(player)
|
serv.players.push(player)
|
||||||
serv.uuidToPlayer[player._client.uuid] = player
|
serv.uuidToPlayer[player._client.uuid] = player
|
||||||
player.heldItemSlot = 36
|
player.heldItemSlot = 0
|
||||||
player.loadedChunks = {}
|
player.loadedChunks = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,20 +13,21 @@ const materialToSound = {
|
||||||
module.exports.player = function (player, serv, {version}) {
|
module.exports.player = function (player, serv, {version}) {
|
||||||
const blocks = require('minecraft-data')(version).blocks
|
const blocks = require('minecraft-data')(version).blocks
|
||||||
|
|
||||||
player._client.on('block_place', ({direction, heldItem, location} = {}) => {
|
player._client.on('block_place', ({direction, location} = {}) => {
|
||||||
if (direction === -1 || heldItem.blockId === -1 || !blocks[heldItem.blockId]) return
|
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 referencePosition = new Vec3(location.x, location.y, location.z)
|
||||||
const directionVector = directionToVector[direction]
|
const directionVector = directionToVector[direction]
|
||||||
const placedPosition = referencePosition.plus(directionVector)
|
const placedPosition = referencePosition.plus(directionVector)
|
||||||
player.behavior('placeBlock', {
|
player.behavior('placeBlock', {
|
||||||
direction: directionVector,
|
direction: directionVector,
|
||||||
heldItem: heldItem,
|
heldItem: heldItem,
|
||||||
id: heldItem.blockId,
|
id: heldItem.type,
|
||||||
damage: heldItem.itemDamage,
|
damage: heldItem.metadata,
|
||||||
position: placedPosition,
|
position: placedPosition,
|
||||||
reference: referencePosition,
|
reference: referencePosition,
|
||||||
playSound: true,
|
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}) => {
|
}, ({direction, heldItem, position, playSound, sound, id, damage}) => {
|
||||||
if (playSound) {
|
if (playSound) {
|
||||||
serv.playSound(sound, player.world, placedPosition.clone().add(new Vec3(0.5, 0.5, 0.5)), {
|
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]--
|
player.inventory.slots[36 + player.heldItemSlot]--
|
||||||
|
|
||||||
if (heldItem.blockId !== 323) {
|
if (heldItem.type !== 323) {
|
||||||
player.changeBlock(position, id, damage)
|
player.changeBlock(position, id, damage)
|
||||||
} else if (direction === 1) {
|
} else if (direction === 1) {
|
||||||
player.setBlock(position, 63, 0)
|
player.setBlock(position, 63, 0)
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@ const Vec3 = require('vec3').Vec3
|
||||||
|
|
||||||
module.exports.player = function (player, serv, {version}) {
|
module.exports.player = function (player, serv, {version}) {
|
||||||
const items = require('minecraft-data')(version).items
|
const items = require('minecraft-data')(version).items
|
||||||
const Item = require('prismarine-item')(version)
|
|
||||||
|
|
||||||
player._client.on('block_place', ({direction, heldItem, location} = {}) => {
|
player._client.on('block_place', ({direction, location} = {}) => {
|
||||||
if (direction === -1 || heldItem.blockId === -1 || !items[heldItem.blockId]) return
|
const heldItem = player.inventory.slots[36 + player.heldItemSlot]
|
||||||
const item = Item.fromNotch(heldItem)
|
if (direction === -1 || heldItem.type === -1 || !items[heldItem.type]) return
|
||||||
|
const item = heldItem
|
||||||
const referencePosition = new Vec3(location.x, location.y, location.z)
|
const referencePosition = new Vec3(location.x, location.y, location.z)
|
||||||
const directionVector = directionToVector[direction]
|
const directionVector = directionToVector[direction]
|
||||||
const position = referencePosition.plus(directionVector)
|
const position = referencePosition.plus(directionVector)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue