Solved Getting when a player hits a FallingBlock

Discussion in 'Plugin Development' started by LarsNitro, Apr 18, 2014.

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

    LarsNitro

    I am developing an "Avatar: The Last Airbender" plugin for experience and fun. I have it set up so that if an earthbender sneaks on a block with the ability selected, it'll launch the block a little ways up, for the player to hit. Then I want it to get shot forwards when the player hits it. I am able to pull this off when the player right-clicks, but that's not what I want. I can't use the EntityDamageByEntityEvent because it's not Damageable. PlayerInteractEntityEvent just registers right clicks, and PlayerInteractEvent has no way of getting the Entity that the player is looking at (that I know of). Any help?

    What I want:

    @EventHandler
    Player sneaks:
    Block jumps.

    @EventHandler
    Player punches jumping block:
    Block gets shot forwards.
     
  2. Offline

    Heirteir

    LarsNitro
    Code:java
    1. @EventHandler
    2. public void hitblock(EntityDamageByEntityEvent e){
    3. if (e.getEntity() instanceof FallingBlock){
    4. //Do Code
    5.  
    6. }
    7. }


    Also Please don't bump early.

    (Untested but I hope it works)

    P.S:please let me know if it works!

    --Heirteir
     
  3. Offline

    LarsNitro

    Heirteir
    Thank you for the suggestion :)
     
  4. Offline

    Heirteir

    LarsNitro
    Sorry about that hmm let me research a little and Ill see if I can return with good news

    LarsNitro
    Have you tried the EntityChangeBlockEvent to detect for a left click?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  5. Offline

    LarsNitro

    Heirteir
    That means a stationary Block changed by a non-player entity. That won't work :)
     
  6. Offline

    iMarv

    Why don't you use minecraft's gravity and let the block float in the air instead of making it a falling entity?
    It would save you a lot of work and would be totally fine as we are in the minecraft universe :)
     
  7. Offline

    Heirteir

    LarsNitro
    You know "Entites" are also players right....
    Example of how to use code
    Code:java
    1. @EventHandler
    2. public void onBlockChange(final EntityChangeBlockEvent e){
    3. e.setCancelled(true);
    4. if (e.getEntity() instanceof FallingBlock){
    5. FallingBlock fb = (FallingBlock) e.getEntity();
    6. fb.getWorld().playEffect(fb.getLocation(), Effect.STEP_SOUND, fb.getMaterial());
    7. fb.remove();
    8. }
    9. }


    It works on fallen blocks here is there thread I retrieved it from maybe could help you some to
    https://forums.bukkit.org/threads/falling-block-help.243541/

    --Heirteir
     
  8. Offline

    LarsNitro

    iMarv That won't look as cool ;)

    Heirteir I don't want to do anything when the FallingBlock lands, I want it to reply to left-clicks when falling. :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  9. Offline

    iMarv

    But would be way easier for the player.
    Punching a falling block is not as easy as it sounds
     
  10. Offline

    LarsNitro

    iMarv The player sneaks at a Block, and the Block jumps up to about eye hight and falls down again, so almost staying still at eye hight.
     
  11. Offline

    LarsNitro

    I got it working (sort of) using Player.hasLineOfSight(Entity) in the PlayerInteractEvent method. Thank you, everyone! :D You don't have to look directly at it, but it's better than what I had before.
     
Thread Status:
Not open for further replies.

Share This Page