Beta
Private
constructorAdds a callback that will be called before a piston expands or retracts.
This function can't be called in read-only mode.
pistonBeforeEvent.ts
// set up a couple of piston blocks
let piston = overworld.getBlock(targetLocation);
let button = overworld.getBlock({ x: targetLocation.x, y: targetLocation.y + 1, z: targetLocation.z });
if (piston === undefined || button === undefined) {
log("Could not find block at location.");
return -1;
}
piston.setPermutation(mc.BlockPermutation.resolve('piston').withState('facing_direction', 3));
button.setPermutation(mc.BlockPermutation.resolve('acacia_button').withState('facing_direction', 1));
const uncanceledPistonLoc = {
x: Math.floor(targetLocation.x) + 2,
y: Math.floor(targetLocation.y),
z: Math.floor(targetLocation.z) + 2,
};
// this is our control.
let uncanceledPiston = overworld.getBlock(uncanceledPistonLoc);
let uncanceledButton = overworld.getBlock({
x: uncanceledPistonLoc.x,
y: uncanceledPistonLoc.y + 1,
z: uncanceledPistonLoc.z,
});
if (uncanceledPiston === undefined || uncanceledButton === undefined) {
log("Could not find block at location.");
return -1;
}
uncanceledPiston.setPermutation(mc.BlockPermutation.resolve('piston').withState('facing_direction', 3));
uncanceledButton.setPermutation(mc.BlockPermutation.resolve('acacia_button').withState('facing_direction', 1));
mc.world.beforeEvents.pistonActivate.subscribe((pistonEvent: mc.PistonActivateBeforeEvent) => {
let eventLoc = pistonEvent.piston.block.location;
if (eventLoc.x === targetLocation.x && eventLoc.y === targetLocation.y && eventLoc.z === targetLocation.z) {
log("Cancelling piston event");
pistonEvent.cancel = true;
}
});
Adds a callback that will be called before a piston expands or retracts.
This function can't be called in read-only mode.
pistonBeforeEvent.ts
// set up a couple of piston blocks
let piston = overworld.getBlock(targetLocation);
let button = overworld.getBlock({ x: targetLocation.x, y: targetLocation.y + 1, z: targetLocation.z });
if (piston === undefined || button === undefined) {
log("Could not find block at location.");
return -1;
}
piston.setPermutation(mc.BlockPermutation.resolve('piston').withState('facing_direction', 3));
button.setPermutation(mc.BlockPermutation.resolve('acacia_button').withState('facing_direction', 1));
const uncanceledPistonLoc = {
x: Math.floor(targetLocation.x) + 2,
y: Math.floor(targetLocation.y),
z: Math.floor(targetLocation.z) + 2,
};
// this is our control.
let uncanceledPiston = overworld.getBlock(uncanceledPistonLoc);
let uncanceledButton = overworld.getBlock({
x: uncanceledPistonLoc.x,
y: uncanceledPistonLoc.y + 1,
z: uncanceledPistonLoc.z,
});
if (uncanceledPiston === undefined || uncanceledButton === undefined) {
log("Could not find block at location.");
return -1;
}
uncanceledPiston.setPermutation(mc.BlockPermutation.resolve('piston').withState('facing_direction', 3));
uncanceledButton.setPermutation(mc.BlockPermutation.resolve('acacia_button').withState('facing_direction', 1));
mc.world.beforeEvents.pistonActivate.subscribe((pistonEvent: mc.PistonActivateBeforeEvent) => {
let eventLoc = pistonEvent.piston.block.location;
if (eventLoc.x === targetLocation.x && eventLoc.y === targetLocation.y && eventLoc.z === targetLocation.z) {
log("Cancelling piston event");
pistonEvent.cancel = true;
}
});
Manages callbacks that are connected to an event that fires before a piston is activated.