summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/FoodMetaData.java
blob: 29ea6efc6aadc4e2b8686f60b62f3fd5cce5994b (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
package net.minecraft.server;

public class FoodMetaData {

    // CraftBukkit start - all made public
    public int a = 20;
    public float b = 5.0F;
    public float c;
    public int d = 0;
    // CraftBukkit end
    private int e = 20;

    public FoodMetaData() {}

    public void a(int i, float f) {
        this.a = Math.min(i + this.a, 20);
        this.b = Math.min(this.b + (float) i * f * 2.0F, (float) this.a);
    }

    public void a(ItemFood itemfood) {
        this.a(itemfood.k(), itemfood.l());
    }

    public void a(EntityHuman entityhuman) {
        int i = entityhuman.world.spawnMonsters;

        this.e = this.a;
        if (this.c > 4.0F) {
            this.c -= 4.0F;
            if (this.b > 0.0F) {
                this.b = Math.max(this.b - 1.0F, 0.0F);
            } else if (i > 0) {
                this.a = Math.max(this.a - 1, 0);
            }
        }

        if (this.a >= 18 && entityhuman.W()) {
            ++this.d;
            if (this.d >= 80) {
                entityhuman.c(1);
                this.d = 0;
            }
        } else if (this.a <= 0) {
            ++this.d;
            if (this.d >= 80) {
                if (entityhuman.health > 10 || i >= 3 || entityhuman.health > 1 && i >= 2) {
                    entityhuman.damageEntity(DamageSource.f, 1);
                }

                this.d = 0;
            }
        } else {
            this.d = 0;
        }
    }

    public void a(NBTTagCompound nbttagcompound) {
        if (nbttagcompound.hasKey("foodLevel")) {
            this.a = nbttagcompound.e("foodLevel");
            this.d = nbttagcompound.e("foodTickTimer");
            this.b = nbttagcompound.g("foodSaturationLevel");
            this.c = nbttagcompound.g("foodExhaustionLevel");
        }
    }

    public void b(NBTTagCompound nbttagcompound) {
        nbttagcompound.a("foodLevel", this.a);
        nbttagcompound.a("foodTickTimer", this.d);
        nbttagcompound.a("foodSaturationLevel", this.b);
        nbttagcompound.a("foodExhaustionLevel", this.c);
    }

    public int a() {
        return this.a;
    }

    public boolean b() {
        return this.a < 20;
    }

    public void a(float f) {
        this.c = Math.min(this.c + f, 40.0F);
    }

    public float c() {
        return this.b;
    }
}