Jump to content

Iterating an AOE only effects specifc blocks? [1.11.2]


Acrogenous

Recommended Posts

public boolean onBlockDestroyed(ItemStack p_onBlockDestroyed_1_, World world, IBlockState blockstate, BlockPos block, EntityLivingBase player) {
        if(player.isSneaking())
        {
            int x = 0-aoe;
            int y = 0-aoe;
            int z = 0-aoe;
            while(z != aoe)
            {
                while(y != aoe)
                {
                    while(x != aoe)
                    {
                        if(world.getBlockState(new BlockPos(x,y,z)).getBlock()== Blocks.STONE)
                        {
                            world.destroyBlock(new BlockPos(block.getX() +x, block.getY() +y, block.getZ() +z), true);
                        }
                        x++;

                    }
                    x= 0-aoe;
                    y++;
                }
                y= 0-aoe;
                z++;


            }
        }
        return super.onBlockDestroyed(p_onBlockDestroyed_1_, world, blockstate, block, player);
    }

so when you shift mine something it is suppose to mine all blocks around it in "aoe" radius, there are 2 problems however;

1 it still mines things that aren't stone and 2 it doesn't mine all the stone,

thanks in advanced.

Edited by Acrogenous
added a version
Link to comment
Share on other sites

Ew. Ew ew ew.

 

Ok, so, 1. for-loops are a Thing. As are negative variables. You don't need those 0s.

 

for(int x = -aoe; x <= aoe; x++) { ... }

 

Two: new BlockPos(x,y,z) (where you're checking to see if the block is stone) != new BlockPos(block.getX() +x, block.getY() +y, block.getZ() +z) (where you are removing the block)

 

Three, BlockPos.getAllInBox(...) is a Thing.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

thank you Draco18s; 

5 minutes ago, Draco18s said:

Ok, so, 1. for-loops are a Thing. As are negative variables. You don't need those 0s.

 

for(int x = -aoe; x <= aoe; x++) { ... }

I know for loops are a thing, but don't both my method and your method have roughly the same amount of characters? I can see it is neater however so I will try and use this in the future. I wasn't aware of negative variables (Java isn't my main language but it probably exists in other languages I've just never known)

8 minutes ago, Draco18s said:

Two: new BlockPos(x,y,z) (where you're checking to see if the block is stone) != new BlockPos(block.getX() +x, block.getY() +y, block.getZ() +z) (where you are removing the block

this is my problem, thanks

8 minutes ago, Draco18s said:

Three, BlockPos.getAllInBox(...) is a Thing.

I didn't know this, it would make the code neater.

 

My code isn't generally neat, (which are effectively points 1 and 3 here) and I will try and work on this aspect, so thanks for the advice!

Link to comment
Share on other sites

13 minutes ago, Acrogenous said:

thank you Draco18s; 

I know for loops are a thing, but don't both my method and your method have roughly the same amount of characters? I can see it is neater however so I will try and use this in the future.

Character length only matters for Code Golf.

 

That said, if you wanted to use a while loop, you can save characters:

Instead of:

int x = -aoe;
...
{
  while(x != aoe) {
      x++;
  }
  x= -aoe;
  y++;
}

You can do:

...
{
  int x = -aoe;
  while(x != aoe) {
      x++;
  }
  y++;
}

By declaring the value at the top of the loop you save having to reset it at the end.

Edited by Draco18s
  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.