Solved Help with 3x3 mining enchant.

Discussion in 'Plugin Development' started by DeathWizsh, Mar 1, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    DeathWizsh

    Hey guys, I'm new to minecraft plugins, and I've ran into something I need help with.
    My first plugin I'm currently developing is a sort of "power" effects on tools.
    I've already created a working treefelling effect for axes, and I'm now trying to create a 3x3 mining effect for pickaxes.

    I want to create the effect that whatever side you face you'll mine a 3x3 area.
    Currently I've got it working for all sides except for up and down.
    I've tried puzzeling with the pitch but I couldn't get it working.

    My current code, without the pitch.

    Code:
        
    Block b = event.getBlock();              
    Location loc = player.getLocation();
    int yaw = (int)loc.getYaw();
    
    if(yaw < 0) {
    yaw += 360;
    yaw = (yaw + 45) / 90;}
    else { yaw = (yaw + 45) / 90; }
              
    if(yaw % 2 == 1) {
    b.breakNaturally();
    b.getRelative(BlockFace.UP).breakNaturally();
    b.getRelative(BlockFace.DOWN).breakNaturally();
    b.getRelative(BlockFace.NORTH).breakNaturally();
    b.getRelative(BlockFace.SOUTH).breakNaturally();
    b.getRelative(BlockFace.UP).getRelative(BlockFace.NORTH).breakNaturally();
    b.getRelative(BlockFace.UP).getRelative(BlockFace.SOUTH).breakNaturally();
    b.getRelative(BlockFace.DOWN).getRelative(BlockFace.NORTH).breakNaturally();
    b.getRelative(BlockFace.DOWN).getRelative(BlockFace.SOUTH).breakNaturally();
    }
                             
    else if(yaw % 2 == 0) {
    b.breakNaturally();
    b.getRelative(BlockFace.UP).breakNaturally();
    b.getRelative(BlockFace.DOWN).breakNaturally();
    b.getRelative(BlockFace.EAST).breakNaturally();
    b.getRelative(BlockFace.WEST).breakNaturally();
    b.getRelative(BlockFace.UP).getRelative(BlockFace.EAST).breakNaturally();
    b.getRelative(BlockFace.UP).getRelative(BlockFace.WEST).breakNaturally();
    b.getRelative(BlockFace.DOWN).getRelative(BlockFace.EAST).breakNaturally();
    b.getRelative(BlockFace.DOWN).getRelative(BlockFace.WEST).breakNaturally();
    }
     
    Last edited: Mar 15, 2015
  2. Offline

    PreFiXAUT

    This will do the exact same. Nonsence.

    So I guess you want to have something like: Break the blocks around the mined block. And this depends on how he mines it (Mines top, then the block itself, and all around that the player sees).
    In that case you need to know where the Player is currently looking at (with yaw and pitch liek you did). I have made a Direction-Helper (https://github.com/prefixaut/PreKit/blob/master/net/prefixaut/prekit/v100/DirectionHelper.java). With this you can check the yaw at least.

    Don't know how to handle the pitch yet, but an Idea would be to ignore it and to check it with the y-location (Get the Players eye-height and check with that). Otherwise I wouldn't make it too complicated and say >50 = top, < -50 = down (Just a Idea/hint, depends on how you want to implement it).

    A Problem that I see are corners tho :/
     
  3. Offline

    DeathWizsh

    Actually made a mistake when I removed the pitch I tried.
    I updated the code in the main post. The code snipped I got from an old thread.
    I just want the 6 directions not 16, <- Z -> <- X - > and <- Y ->.

    I was also thinking about letting the face of the block the player clicked to decide how the 3x3 area will be mined.
    I'm gonna try and see if I can get something like that working.
     
  4. Offline

    DeathWizsh

    Been busy with work, din't had much time to continue on this project.
    However I figured it out how to use the pitch in order to mine a 3x3 area up and down.
    Underneath my current solution.

    Code:
    Block b = event.getBlock();            
    Location loc = player.getLocation();
    int yaw = (int)loc.getYaw();
    int pitch = (int)loc.getPitch();
    
    if(yaw < 0) {
    yaw += 360;
    yaw = (yaw + 45) / 90;}
    else { yaw = (yaw + 45) / 90; }
    
    if(pitch <= -45 && pitch >= -90 || pitch >= 45 && pitch <= 90) {
    b.getRelative(BlockFace.NORTH).breakNaturally();
    b.getRelative(BlockFace.SOUTH).breakNaturally();
    b.getRelative(BlockFace.WEST).breakNaturally();
    b.getRelative(BlockFace.EAST).breakNaturally();
    b.getRelative(BlockFace.NORTH).getRelative(BlockFace.WEST).breakNaturally();
    b.getRelative(BlockFace.NORTH).getRelative(BlockFace.WEST).breakNaturally();
    b.getRelative(BlockFace.SOUTH).getRelative(BlockFace.EAST).breakNaturally();
    b.getRelative(BlockFace.SOUTH).getRelative(BlockFace.EAST).breakNaturally();
    }
             
    elseif(yaw % 2 == 1) {
    b.breakNaturally();
    b.getRelative(BlockFace.UP).breakNaturally();
    b.getRelative(BlockFace.DOWN).breakNaturally();
    b.getRelative(BlockFace.NORTH).breakNaturally();
    b.getRelative(BlockFace.SOUTH).breakNaturally();
    b.getRelative(BlockFace.UP).getRelative(BlockFace.NORTH).breakNaturally();
    b.getRelative(BlockFace.UP).getRelative(BlockFace.SOUTH).breakNaturally();
    b.getRelative(BlockFace.DOWN).getRelative(BlockFace.NORTH).breakNaturally();
    b.getRelative(BlockFace.DOWN).getRelative(BlockFace.SOUTH).breakNaturally();
    }
                           
    else if(yaw % 2 == 0) {
    b.breakNaturally();
    b.getRelative(BlockFace.UP).breakNaturally();
    b.getRelative(BlockFace.DOWN).breakNaturally();
    b.getRelative(BlockFace.EAST).breakNaturally();
    b.getRelative(BlockFace.WEST).breakNaturally();
    b.getRelative(BlockFace.UP).getRelative(BlockFace.EAST).breakNaturally();
    b.getRelative(BlockFace.UP).getRelative(BlockFace.WEST).breakNaturally();
    b.getRelative(BlockFace.DOWN).getRelative(BlockFace.EAST).breakNaturally();
    b.getRelative(BlockFace.DOWN).getRelative(BlockFace.WEST).breakNaturally();
    }
    
    Edit: Changed topic prefix to solved.
     
  5. @DeathWizsh Here is how I am doing my 3x3

    Code:
    Block block;
        for(int xOff = -1; xOff <= 1; ++xOff){
            for(int yOff = -1; yOff <= 1; ++yOff){
                for(int zOff = -1; zOff <= 1; ++zOff){
                    block = b.getRelative(xOff, yOff, zOff);
                    block.breakNaturally();
                }
            }
        }
    This has a lot less code
     
  6. Offline

    DeathWizsh

    Ah, thanks!
    I should really learn the ins and outs of certain functions like the `for` loops.
     
Thread Status:
Not open for further replies.

Share This Page