All possible blocks under player

Discussion in 'Plugin Development' started by Kentakis, Aug 31, 2015.

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

    Kentakis

    Hello.

    I try to write function which return list of blocks under player


    Could you help me ? I think that there are possible 1,2 or 4 blocks that player standing at the sime time

    Code:
        public List<Block> getBlocks(Player p){
            List<Block> blocks = new ArrayList<>();
            if(((Entity)p).isOnGround()){
                double p_x=p.getLocation().getX(),p_y=p.getLocation().getY()-1,p_z = p.getLocation().getZ();
                int ip_x=(int) p_x,ip_y=(int) p_y,ip_z=(int) p_z;
                if(config_manager.current_world == null)
                    return null;
               
                Block b1 = config_manager.current_world.getBlockAt(ip_x,ip_y,ip_z);
                Block b2 = config_manager.current_world.getBlockAt(ip_x+1,ip_y,ip_z+1);
                Block b3 = config_manager.current_world.getBlockAt(ip_x+1,ip_y,ip_z-1);
                Block b4 = config_manager.current_world.getBlockAt(ip_x-1,ip_y,ip_z+1);
                
                //DONT WORK \/\/\/\/\/\/
                if(b1.getType() != Material.AIR && p_x > ip_x && p_x < ip_x && p_z > ip_z && p_z < ip_z){
                    System.out.print("ADD");
                    blocks.add(b1);
                }
                if(b2.getType() != Material.AIR && p_x > ip_x+1 && p_x < ip_x+1 && p_z > ip_z+1 && p_z < ip_z+1){
                    blocks.add(b2);
                }
                if(b3.getType() != Material.AIR && p_x > ip_x+1 && p_x < ip_x+1 && p_z > ip_z-1 && p_z < ip_z-1){
                    blocks.add(b3);
                }
                if(b4.getType() != Material.AIR && p_x > ip_x-1 && p_x < ip_x-1 && p_z > ip_z+1 && p_z < ip_z+1){
                    blocks.add(b4);
                }
               
            }
            return blocks;
        }
     
  2. Offline

    caderape

    @Kentakis It's always one block under the player. That will be really difficult to do what you want.
    You will have to check the location#double and see if the number is closer or no from a direction. Then you can suppose he is walking on two blocks. etc...
     
  3. Offline

    Kentakis

    @caderape Not only one...

    Could you give me a example how to check that ?
     
Thread Status:
Not open for further replies.

Share This Page