"blockAt" condition for multiple blocks?

Started by Sweddy on Sat, 10/15/2016 - 17:53

Topic category: General discussion

Last seen on 16:40, 4. Oct 2018
Joined Sep 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
"blockAt" condition for multiple blocks?
Sat, 10/15/2016 - 17:53

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.

 

Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
  • wiki contributor
  • moderator
Ok , so if I am right , you
Sat, 10/15/2016 - 18:20

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.

 

 

Last seen on 16:40, 4. Oct 2018
Joined Sep 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
RE:Ok , so if I am right , you
Sat, 10/15/2016 - 18:40

@#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.

 

Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
  • wiki contributor
  • moderator
Then use || .
Sat, 10/15/2016 - 20:36

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

Last seen on 16:40, 4. Oct 2018
Joined Sep 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
RE:Then use || .
Sun, 10/16/2016 - 06:38

@#2 thanks