world.afterEvents.pistonActivate.subscribe((eventData) => {
// If the purge is active, allow pistons to act normally
if (isPurgeActive) {
// console.warn("Purge is active - pistons can affect all blocks.");
return; // Exit early, do not cancel piston action
}
// If the purge is not active, proceed with checking claims
const pistonBlock = eventData.block;
const pistonLocation = pistonBlock.location;
const pistonClaim = checkClaimedChunks(pistonLocation);
const attachedBlocks = eventData.piston.getAttachedBlocks();
console.warn(JSON.stringify(attachedBlocks.typeId))
attachedBlocks.forEach(blockLoc => {
const adjacentLocations = getAdjacentLocations(blockLoc);
for (const adjacentLoc of adjacentLocations) {
const adjacentClaim = checkClaimedChunks(adjacentLoc);
if (pistonClaim !== adjacentClaim || (pistonClaim && adjacentClaim && pistonClaim.owner !== adjacentClaim.owner)) {
// Spawn the piston item at its location
const pistonItem = pistonBlock.getItemStack(1); // Get an ItemStack representing the piston
system.run(() => {
world.getDimension('overworld').spawnItem(pistonItem, pistonLocation);
// Set the piston block to air
pistonBlock.setType("minecraft:air");
});
return;
}
}
});
if (!eventData.cancel) {
//console.warn(`Piston action allowed`);
}
});```
im having an issue where the attachedBlocks are returning undefined and im not sure why
#pistonActivate afterEvent
1 messages · Page 1 of 1 (latest)
it returns the location of the block before it moved, but the block is now in a new position right? so is it thinking its air so it returns undefined?
Shouldn't it be empty array?
yes, but i think its grabbing the block location after the piston has moved it?
so its thinking its air but its the piston rod
ohhh
yeah i might have to adjust it a little bit
It only returns what's been removed
the thing is im coming from the before event they removed, it would test the blocks attached and it was easy to get that, but after it moves is where i need to check.
for the afterevent as im tryin to remove the blocks pushed
Then use afterevent...
thats what im doing
its just not grabbing the attachedblocks
just keeps saying undefined
attachedblocks is array...
so iterate? is that the issue?
perhaps map(b=>b.typeId)
hmm okay!
oh lol it grabbed the piston arm
as the attachedBlocks
didn't say the block it pushed was one
weird
Hmmm
without anything empty array
with block \
it pushes but only gets the psiton arm
so its grabbing after of course, so maybe i need to delay it?
for the check
of array
I'd just check whatever property there is
ok
can i get the direction a piston is facing, i didn't see anything about facing for them