MeskenasBoii
Verified Member
How can I check for a specific blocks to be check upon so that the event could occur?
First message. I had to sorry.You of course have to know the coordinates of the block you want to check. If you have a Location instance you can call getBlock() on it which returns a value from the Materail enum, so you can then compare it in an if statement, which will return true if a block with the specified type is present at your location.
Use a for loop. Here's one in my ability that I made, hope it helps.Oh right, but how do I check for the number of blocks in the specified radius?
You can iterate over a Collection using a loop (for or while). In your case you could use both.Oh right, but how do I check for the number of blocks in the specified radius?
int counter = 0;
for (Block block : yourListWithBlocks) {
// this code runs for all elements in the list
if (block.getType() == SomeMaterial) {
counter++;
}
}
Iterator<Block> iterator = yourListWithBlocks.iterator(); // get the list's iterator
while (iterator.hasNext()) { // while there is a next entry in the iterator
Block block = iterator.next(); // move to the next element
if (block.getType() != SomeMaterial) {
it.remove(); // if the block's type is not equal to 'SomeMaterial', remove it
}
}