summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/EntitySnowball.java
blob: 5090077bb5d65ad38cfa59ecd818f721deed061f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package net.minecraft.server;

// CraftBukkit start
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.entity.CraftLivingEntity;
import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
// CraftBukkit end

public class EntitySnowball extends EntityProjectile {

    public EntitySnowball(World world) {
        super(world);
    }

    public EntitySnowball(World world, EntityLiving entityliving) {
        super(world, entityliving);
    }

    public EntitySnowball(World world, double d0, double d1, double d2) {
        super(world, d0, d1, d2);
    }

    protected void a(MovingObjectPosition movingobjectposition) {
        if (movingobjectposition.entity != null) {
            int b0 = 0; // CraftBukkit - byte -> int

            if (movingobjectposition.entity instanceof EntityBlaze) {
                b0 = 3;
            }
            // CraftBukkit start
            final Entity movingEntity = movingobjectposition.entity;
            boolean stick = false;

            if (movingEntity != null) {
                if (movingEntity instanceof EntityLiving) {
                    org.bukkit.entity.Entity damagee = movingEntity.getBukkitEntity();
                    Projectile projectile = (Projectile) this.getBukkitEntity();

                    EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, b0);
                    Bukkit.getPluginManager().callEvent(event);
                    this.shooter = (projectile.getShooter() == null) ? null : ((CraftLivingEntity) projectile.getShooter()).getHandle();
                    b0 = event.getDamage();

                    if (event.isCancelled()) {
                        stick = !projectile.doesBounce();
                    } else {
                        // this function returns if the snowball should stick in or not, i.e. !bounce
                        stick = movingEntity.damageEntity(DamageSource.projectile(this, this.shooter), b0);
                    }
                } else {
                    stick = movingEntity.damageEntity(DamageSource.projectile(this, this.shooter), b0);
                }
            }

            if (stick) {
                // CraftBukkit end
                ;
            }
        }

        for (int i = 0; i < 8; ++i) {
            this.world.a("snowballpoof", this.locX, this.locY, this.locZ, 0.0D, 0.0D, 0.0D);
        }

        if (!this.world.isStatic) {
            this.die();
        }
    }
}