Finding out the block type a player was looking at during a onPlayerItem event

Discussion in 'Plugin Development' started by spoonikle, Mar 1, 2011.

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

    spoonikle

    Ok, so I am the author of the plug-in BigCatch, but i have run into a major design flaw.
    I forgot to check if the player was fishing in water. I never imagined that a player would throw a fishing rod and wait 15 seconds on some dirt instead of water.

    So now i need some help.

    How do you find out what block type a player was looking at when they used their fishing rod, regardless of distance.

    I would really appreciate an answer, and if you where to go to my plug-in thread - you would see that no contribution goes without credit, on the topic page and in the code.
     
  2. Offline

    Edward Hand

    player.getTargetBlock(null,50).getType()

    (50 is for setting the maximum range. You can change that to whatever you want.)
     
  3. Offline

    spoonikle

    awesome thanks!

    dose the range hurt performance?
     
  4. Offline

    fullwall

    It can do. Best way to test is just some real life server tests.
     
  5. Offline

    spoonikle

    yeah, i figured that, so i decided to go with a range of 10. if you fish any farther than that your crazy anyway.
     
  6. Offline

    Raphfrk

    It shouldn't be that slow really :), Grum insisted on hyper-efficiency (overkill really :)).

    Also, if you are using fishing, you might want to use non-null for the first input. This allows you decide what blocks are transparent. For example, if you wanted air and water to be transparent, you would use need to setup a HashSet with:

    Code:
    HashSet<Byte> transparent = new HashSet<Byte>();
    transparent.add((byte)Material.AIR.getId());
    transparent.add((byte)Material.WATER.getId());
    transparent.add((byte)Material.STATIONARY_WATER.getId());
    
    and then when actually finding the target:

    Code:
    player.getTargetBlock(transparent,50).getType()
    
     
  7. Offline

    Nohup

    also, as I learned with my Snowballz plugin, the angle of the person's head greatly affects this as you can clip just a sliver of an earlier block and have that block returned. It will be one of those things where folks have to play around with how they look at something to get it exact if you were looking down at something (such as during fishing).
     
Thread Status:
Not open for further replies.

Share This Page