Started by
Sweddy
on
Topic category: General discussion
The "blockAt[i, j, k] == item/block" condition is very useful, but I'd like it to select multiple blocks so I don't have to add a bunch of seperate events. I assume there's some neat trick you can do in the code to let it select multiple blocks but I don't know how to do that.
Please enlighten me.
Ok , so if I am right , you want check for multiple coords if are some block , and you do not want to manually check for every value?
Well you can use stacked for loops , like this:
boolean isBlockOnAllCoords = true;
for(int x = SOME_START_VALUE;x < SOME_END_VALUE;x++){
for(int y = SOME_START_VALUE;y < SOME_END_VALUE;y++){
for(int z = SOME_START_VALUE ;z < SOME_END_VALUE;z++){
if(world.getBlockState(new BlockPos(x,y,z)).getBlock != Blocks.stone){
isBlockOnAllCoords = false;
}
}
}
}
Then you can use the boolean for some other actions.
@#1
That's useful information but not what I asked for.
For example: Let's say I have some block that turns into another block if there's a Diamond Block above it OR a Gold Block.
Then use || .
This two lines simply in java means OR
So in code:
if(world.getBlockState(new BlockPos(x,y,z)).getBlock== Blocks.stone || world.getBlockState(new BlockPos(x,y,z)).getBlock== Blocks.dirt ){
Or in event condition (should work) this:
blockAt[i, j, k] == Blocks.stone || blockAt[i, j, k] == Blocks.dirt
@#2 thanks