Snowball hit Block

Discussion in 'Plugin Development' started by andre111, Sep 13, 2012.

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

    andre111

    Is there any way to check if an Snowball has hit an Block, and then also get which Block was hit.
    Checking if it hit an Entity is easy, for that I have this code:
    Code:
    public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
                Entity entity = event.getDamager();
               
                if (entity instanceof Snowball) {
    ...
    I also experimented with this:
    Code:
    public void onProjectileHit(ProjectileHitEvent event) {
            Entity entity = event.getEntity();
            if (entity instanceof Snowball) {
                Location loc = entity.getLocation();
                System.out.println(loc.getBlock().getTypeId());
    ...
    But it only works if an not fully solid Block is hit(like an halfslab), otherwise the Block is 0(Air) because the Snowball never entered the hit Block.
    Maybe adding to the Location in the direction the snowball was flying would work, but I have no idea how to do this.

    Ok I got this now:
    Code:
    public void onProjectileHit(ProjectileHitEvent event) {
            Entity entity = event.getEntity();
            if (entity instanceof Snowball) {
                Location loc = entity.getLocation();
                Vector vec = entity.getVelocity();
                Location loc2 = new Location(loc.getWorld(), loc.getX()+vec.getX(), loc.getY()+vec.getY(), loc.getZ()+vec.getZ());
                System.out.println(loc2.getBlock().getTypeId());
                if (loc2.getBlock().getTypeId()==Block.SNOW_BLOCK.id)
                {
    ...
    and it seems to work in most cases, which is enough for my purposes

    But now I have another question:
    Can I somehow set the "brokeness" off a Block?
    (Like if a Player was mining it at the Moment)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  2. Offline

    stirante

    You have to send Packet55BlockBreakAnimation to player. I don't know which params I have to pass.
    Code:
    ((CraftPlayer)player).getHandle().netServerHandler.sendPacket(new Packet55BlockBreakAnimation(params));
     
  3. Offline

    andre111

    Thanks this works almost.
    Also the parameters are:
    BlockID,PosX,PosY,PosZ,BreakingState

    BlockID seems to be used to determine where the Breaking animation should be shown.
    You can even make broken Air :p

    Ok now there is another Problem:
    Only one Block can look broken at the same time, but you should be able to have multiple broken Blocks st the same time, because this can happen in vanilla Minecraft too.
    Here's my code:
    Code:
    ((CraftPlayer)player).getHandle().netServerHandler.sendPacket(new Packet55BlockBreakAnimation(Block.SNOW_BLOCK.id, loc2.getBlockX(),loc2.getBlockY(),loc2.getBlockZ(), data+1));
    It resets the old one every time I set another Block to be broken.
     
Thread Status:
Not open for further replies.

Share This Page