mojira.dev
MCPE-176276

faceLocation and blockFace in 1.6.0-beta for playerPlaceBlock and itemUseOn are backwards

Description
faceLocation in playerPlaceBlock (after doesn't have the property) and itemUseOn for the side that the place on is 0 instead of being negative slightly less than zero quantity so that the user can easily get the placeLocation by Vector.add(block.location, faceLocation).
face in playerPlaceBlock (after doesn't have the property) and blockFace in itemUseOn for z direction (south and north) placements are backwards.

Scenarios
In these examples, the player would be facing exactly in these directions with the other components of their view vector being 0. The facingLocation will be floored and it will be a beforeEvents.ItemUseOn as they seem to be the same.

West Block Place (x - 1):
  Expected:

    facingLocation: {x: 1, y: 0, z: 0}

    blockFace: "East"

  Observed:

    facingLocation: {x: 1, y: 0, z: 0}

    blockFace: "East"

{+}East Block Place (x + 1){+}:
  Expected:

    facingLocation: {x: -1, y: 0, z: 0}

    blockFace: "West"

  Observed:

    facingLocation: {x: 0, y: 0, z: 0}

    blockFace: "West"

South Block Place (z - 1):
  Expected:

    facingLocation: {x: 0, y: 0, z: 1}

    blockFace: "North"

  Observed:

    facingLocation: {x: 0, y: 0, z: 1}

    blockFace: "South"

{+}North Block Place (z + 1){+}:
  Expected:

    facingLocation: {x: 0, y: 0, z: -1}

    blockFace: "North"

  Observed:

    facingLocation: {x: 0, y: 0, z: 0}

    blockFace: "North"

{+}Up Block Place (y + 1){+}:
  Expected:

    facingLocation: {x: 0, y: -1, z: 0}

    blockFace: "Down"

  Observed:

    facingLocation: {x: 0, y: 0, z: 0}

    blockFace: "Down"

Down Block Place (y - 1):
  Expected:

    facingLocation: {x: 0, y: 1, z: 0}

    blockFace: "Up"

  Observed:

    facingLocation: {x: 0, y: 1, z: 0}

    blockFace: "Up"

Conclusion
facingLocation doesn't go negative and blockFace in the z direction is backwards.
facingLocation for the positive placements should be slightly less than 0 quantity so that flooring works correctly and users don't have to do extra conversions to get the block the player placed at. (mostly to check if the player can place it based on position then if not cancel the event).

Attachments

Comments 4

import { world, Vector, system, Direction } from '@minecraft/server';

const DirectionToVector = {
	[Direction.Down]: Vector.down,
	[Direction.Up]: Vector.up,
	[Direction.North]: Vector.forward,
	[Direction.South]: Vector.back,
	[Direction.West]: Vector.left,
	[Direction.East]: Vector.right,
};
function floorVector3(vector) {
	return {
		x: Math.floor(vector.x),
		y: Math.floor(vector.y),
		z: Math.floor(vector.z),
	};
}
world.beforeEvents.itemUseOn.subscribe(async (event) => {
	try {

		const { source, block, blockFace, faceLocation } = event;


		// logVector3(DirectionToVector[blockFace]);
		const placeLocation = Vector.add(block.location, DirectionToVector[blockFace]);
		const predictedPlaceLocation = Vector.add(block.location, floorVector3(faceLocation));
		await null;
		world.sendMessage('============================================');
		world.sendMessage(JSON.stringify({ "§7not Floored faceLocation§f": faceLocation }, null));
		world.sendMessage(JSON.stringify({ blockFace, "§7Floored faceLocation§f": floorVector3(faceLocation) }));
		world.sendMessage('§7Floored faceLocation + block.location: §cminecraft:villager_angry paricle and red_stained_glass');
		world.sendMessage('§7blockFace converted to vector + block.location: §aminecraft:villager_happy paricle and lime_stained_glass\n§7(if place location for both is correct it will be lime)');
		world.sendMessage('§7block.location: §fminecraft:endrod paricle(will be where faceLocation is relitive from) and glass ');
		source.dimension.spawnParticle('minecraft:villager_angry', predictedPlaceLocation);
		source.dimension.spawnParticle('minecraft:endrod', block.location);
		source.dimension.spawnParticle('minecraft:villager_happy', placeLocation);
		source.dimension.getBlock(block.location).setType('glass');
		source.dimension.getBlock(predictedPlaceLocation).setType('red_stained_glass');
		source.dimension.getBlock(placeLocation).setType('lime_stained_glass');
	} catch (error) {
		console.warn(error, error.stack);
	}
});
function rotationToDirection(rotation) {
	let { x, y } = rotation;

	x = (x / 45 + 2) | 0;
	y = ((y + 45) / 90 + 2) | 0;
	if (x < 1) return 'Up (y + 1)';
	else if ((x > 2)) return 'Down (y - 1)';
	switch (y) {
		case 2:
			return 'North (z + 1)';
		case 4:
		case 0:
			return 'South (z - 1)';
		case 1:
			return 'East (x + 1)';
		case 3:
			return 'West (x - 1)';
	}
};
system.runInterval(() => {
	const players = world.getAllPlayers();
	players.forEach(player => {
		player.onScreenDisplay.setActionBar(rotationToDirection(player.getRotation()) ?? "None" + '\n(based off Direction Enum on docs)');
	});
});

reference for each direction: https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/direction
The docs could be wrong for why blockFace is backwards in the z direction but idk

Edit:
cleaned up the code so it better represents the cases and doesn't need content log on
Pack has the same code

Thank you for your report!

However, this issue has been temporarily closed as Awaiting Response.

Could you please attach an example addon showcasing the issue?

This ticket will automatically reopen when you reply.

Quick Links:
📓 Issue Guidelines – 💬 Mojang Support – 📓 Project Summary – 📧 Suggestions – 📖 Minecraft Wiki

[media]


Pack as requested
only works for 1.19.30
sub minor updates don't matter. it will work as long as the current beta version for release is 1.6.0-beta

Resolving temporarily as Awaiting Response. Is this an issue in the latest API version (1.11.0-beta)?
This ticket will reopen automatically when you reply.

mrpatches123

(Unassigned)

Unconfirmed

Multiple

Windows 11

Script-API

1.20.32 Hotfix

Retrieved