Cant detect water in your reach...

Discussion in 'Plugin Development' started by DoveDevic, Jan 17, 2013.

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

    DoveDevic

    Ok, so i am making a simple plugin where if you are holing a glass bottle aka an empty water bottle, and you try to fill it, you recieve a potion that can be customized. So for clarifiacation, i walk up to a pond, i right click to fill my water bottle, and instead of getting water, i get say, a potion of healing...

    heres what ive got so far... but it only works on the farthest block... meaning, the furthest block i can reach, it works... what am i doing wrong/not doing? thanks, devic!


    Code:
        public Block getSelectedBlock(Player p) {
           
              Block b = p.getTargetBlock(null, 5);
              return b;
            }
        @EventHandler
        public void onPlayerInteractBlock(PlayerInteractEvent event){
            //see if the item is an empty glass bottle
          if(event.getPlayer().getItemInHand().getTypeId() == Material.GLASS_BOTTLE.getId()){
     
             
             
              //max reach is 5 blocks
              Block b = event.getPlayer().getTargetBlock(null, 5);
              //just a visual in-game check for me
              event.getPlayer().sendMessage(b.toString());
              int blcID = b.getTypeId();
                 
                  //if the block is any type of water...
              if(blcID == Material.STATIONARY_WATER.getId() || blcID == Material.WATER.getId()){
              {
                Player p = event.getPlayer();
                PlayerInventory inventory = p.getInventory();
                //16340
                //373, 1, (short) 16340
                //create an item stack for a custom potion (this one is potion of harming)
                ItemStack cstmPTN = new ItemStack(61,1);
                //creates an item stack for the water bottle that will appear
                ItemStack wtr = new ItemStack(Material.POTION,1);
                //remove the waterbottle
                inventory.removeItem(wtr);
     
                //and place the new potion in the inventory
                inventory.addItem(cstmPTN);
               
                //this was kinda redundent because if i had three water bottles, it would take me down to 1... D:
                //inventory.remove(Material.GLASS_BOTTLE);
                }
              }
            }
        }
     
  2. Offline

    fireblast709

    List<Block> los = player.getLineOfSight(null, 5); is what you want.
     
  3. Offline

    DoveDevic

    can you explain on how to use this command?
     
  4. Offline

    polaris120990

    player.getLineOfSight retrieves all of the blocks within the player's line of sight up to in this case 5 blocks away. Whereas player.getTargetBlock only retrieves a single block that is in this case 5 blocks away, I hope this was helpful. For more detail click here.
     
Thread Status:
Not open for further replies.

Share This Page