test structure and video of bug in 1.21.31
not sure how to remove the duplicated attachment but I guess it is fine.
This issue still exists on Minecraft for IOS. On windows however, global resources work fine for realms.
in 1.20.51 the hierarchy (heirs to the leader and the leader) switches to the new villagers when more villagers are added to the village via breeding. Will do more testing soon.
Edit.
even if the leader can sleep in its bed, the leader position can be assigned to newly created villages breading or spawning.
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
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
affects 1.20.30
Could this get swapped to bedrock edition instead of bds some how didn’t see it. Think something messed up as when I first copied it, it was MCPE-174596 which points towards BDS-18672 which is what it is currently.
affects 1.19.73
The code below ran in preview 1.19.70.22 if the player uses on the block, for instance, x: 1, y: 2, z: 3. should output:
import { world } from "@minecraft/server";
world.events.beforeItemUseOn.subscribe((event) => {
const blockLocation = event.getBlockLocation();
let keys = [];
for (const key in event) {
keys.push(key);
}
const { x, y, z } = blockLocation ?? {};
console.warn('hello, ', x, y, z, keys.join(', '));
});[Scripting][warning]-hello, 1 2 3 getBlockLocation, item, source, blockFace, faceLocationX, faceLocationY, cancel
but instead outputs
[Scripting][warning]-hello, undefined undefined undefined getBlockLocation, item, source, blockFace, faceLocationX, faceLocationY, cancel
As you can see the method getBlockLocation is defined on the BeforeItemUseOnEvent class instance passed as a parameter in the event callback so the method always returns undefined.
new code and console output to further prove getBlockLocation is defined on the BeforeItemUseOnEvent instance.
import { world } from "@minecraft/server";world.events.beforeItemUseOn.subscribe((event) => {
const blockLocation = event.getBlockLocation();
let eventClone = {};
for (const key in event) {
eventClone[key] = typeof event[key];
}
const { x = 'undefined', y = 'undefined', z = 'undefined' } = blockLocation ?? {};
world.sendMessage(JSON.stringify({ t: 'test', blockLocation: { x, y, z }, eventClone }, null, 4));
});
Happens in 1.19.20 as well.
bds works but idk. follow https://docs.microsoft.com/en-us/minecraft/creator/documents/scriptingservers
this happens in 1.18.12.
Happens in 1.18.0 realms
still happens but a loading bar appears.
happens in 1.17.41
You do have to wait a about 10 seconds for the op to be removed since the command will execute immediately after the op is removed and will not run after a few seconds.
you set 1 to a string ie "1" it must be an int ie "minecraft:direction": 1
1.21.131*