summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/EntitySlime.java
blob: c2ad891b85fc1a7200f81ba88fe534c156413d8e (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package net.minecraft.server;

// CraftBukkit start
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.entity.CraftSlime;
// CraftBukkit stop

public class EntitySlime extends EntityLiving implements IMonster {

    public float a;
    public float b;
    private int d = 0;
    public int c = 1;

    public EntitySlime(World world) {
        super(world);
        this.texture = "/mob/slime.png";
        this.c = 1 << this.random.nextInt(3);
        this.height = 0.0F;
        this.d = this.random.nextInt(20) + 10;
        this.a(this.c);

        // CraftBukkit start
        CraftServer server = ((WorldServer) this.world).getServer();
        this.bukkitEntity = new CraftSlime(server, this);
        // CraftBukkit end
    }

    public void a(int i) {
        this.c = i;
        this.a(0.6F * (float) i, 0.6F * (float) i);
        this.health = i * i;
        this.a(this.locX, this.locY, this.locZ);
    }

    public void a(NBTTagCompound nbttagcompound) {
        super.a(nbttagcompound);
        nbttagcompound.a("Size", this.c - 1);
    }

    public void b(NBTTagCompound nbttagcompound) {
        super.b(nbttagcompound);
        this.c = nbttagcompound.d("Size") + 1;
    }

    public void b_() {
        this.b = this.a;
        boolean flag = this.onGround;

        super.b_();
        if (this.onGround && !flag) {
            for (int i = 0; i < this.c * 8; ++i) {
                float f = this.random.nextFloat() * 3.1415927F * 2.0F;
                float f1 = this.random.nextFloat() * 0.5F + 0.5F;
                float f2 = MathHelper.a(f) * (float) this.c * 0.5F * f1;
                float f3 = MathHelper.b(f) * (float) this.c * 0.5F * f1;

                this.world.a("slime", this.locX + (double) f2, this.boundingBox.b, this.locZ + (double) f3, 0.0D, 0.0D, 0.0D);
            }

            if (this.c > 2) {
                this.world.a(this, "mob.slime", this.i(), ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) / 0.8F);
            }

            this.a = -0.5F;
        }

        this.a *= 0.6F;
    }

    protected void d() {
        EntityHuman entityhuman = this.world.a(this, 16.0D);

        if (entityhuman != null) {
            this.b(entityhuman, 10.0F);
        }

        if (this.onGround && this.d-- <= 0) {
            this.d = this.random.nextInt(20) + 10;
            if (entityhuman != null) {
                this.d /= 3;
            }

            this.bA = true;
            if (this.c > 1) {
                this.world.a(this, "mob.slime", this.i(), ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) * 0.8F);
            }

            this.a = 1.0F;
            this.bx = 1.0F - this.random.nextFloat() * 2.0F;
            this.by = (float) (1 * this.c);
        } else {
            this.bA = false;
            if (this.onGround) {
                this.bx = this.by = 0.0F;
            }
        }
    }

    public void q() {
        if (this.c > 1 && this.health == 0) {
            for (int i = 0; i < 4; ++i) {
                float f = ((float) (i % 2) - 0.5F) * (float) this.c / 4.0F;
                float f1 = ((float) (i / 2) - 0.5F) * (float) this.c / 4.0F;
                EntitySlime entityslime = new EntitySlime(this.world);

                entityslime.a(this.c / 2);
                entityslime.c(this.locX + (double) f, this.locY + 0.5D, this.locZ + (double) f1, this.random.nextFloat() * 360.0F, 0.0F);
                this.world.a((Entity) entityslime);
            }
        }

        super.q();
    }

    public void b(EntityHuman entityhuman) {
        // CraftBukkit - add cast to Entity                      VVVVVVVV
        if (this.c > 1 && this.i(entityhuman) && (double) this.a((Entity) entityhuman) < 0.6D * (double) this.c && entityhuman.a(this, this.c)) {
            this.world.a(this, "mob.slimeattack", 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
        }
    }

    protected String f() {
        return "mob.slime";
    }

    protected String g() {
        return "mob.slime";
    }

    protected int h() {
        return this.c == 1 ? Item.SLIME_BALL.id : 0;
    }

    public boolean b() {
        Chunk chunk = this.world.b(MathHelper.b(this.locX), MathHelper.b(this.locZ));

        return (this.c == 1 || this.world.k > 0) && this.random.nextInt(10) == 0 && chunk.a(987234911L).nextInt(10) == 0 && this.locY < 16.0D;
    }

    protected float i() {
        return 0.6F;
    }
}