TileEntityEnderChest .java

net.minecraft.tileentity.TileEntityEnderChest (class): members: closeChest, canBeUsed, openChest, numPlayersUsing, ticksSinceSync, prevLidAngle, lidAngle.

net.minecraft.tileentityclass112 linescommonextends TileEntity3.0 KB

Implements

API Surface (6)

void update()
boolean receiveClientEvent(int id, int type)
void invalidate()
void openChest()
void closeChest()
boolean canBeUsed(EntityPlayer p_145971_1_)

Fields & Constants (4)

lidAngle
prevLidAngle
numPlayersUsing
ticksSinceSync

String literals (2)

"random.chestopen"
"random.chestclosed"

Code Graph: Dependencies (5)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

TileEntityEnderChest.java112 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.tileentity;
2
3
import net.minecraft.entity.player.EntityPlayer;
4
import net.minecraft.init.Blocks;
5
import net.minecraft.util.ITickable;
6
7
public class TileEntityEnderChest extends TileEntity implements ITickable
8
{
9
    public float lidAngle;
10
11
    /** The angle of the ender chest lid last tick */
12
    public float prevLidAngle;
13
    public int numPlayersUsing;
14
    private int ticksSinceSync;
15
16
    /**
17
     * Like the old updateEntity(), except more generic.
18
     */
19
    public void update()
20
    {
21
        if (++this.ticksSinceSync % 20 * 4 == 0)
22
        {
23
            this.worldObj.addBlockEvent(this.pos, Blocks.ender_chest, 1, this.numPlayersUsing);
24
        }
25
26
        this.prevLidAngle = this.lidAngle;
27
        int i = this.pos.getX();
28
        int j = this.pos.getY();
29
        int k = this.pos.getZ();
30
        float f = 0.1F;
31
32
        if (this.numPlayersUsing > 0 && this.lidAngle == 0.0F)
33
        {
34
            double d0 = (double)i + 0.5D;
35
            double d1 = (double)k + 0.5D;
36
            this.worldObj.playSoundEffect(d0, (double)j + 0.5D, d1, "random.chestopen", 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F);
37
        }
38
39
        if (this.numPlayersUsing == 0 && this.lidAngle > 0.0F || this.numPlayersUsing > 0 && this.lidAngle < 1.0F)
40
        {
41
            float f2 = this.lidAngle;
42
43
            if (this.numPlayersUsing > 0)
44
            {
45
                this.lidAngle += f;
46
            }
47
            else
48
            {
49
                this.lidAngle -= f;
50
            }
51
52
            if (this.lidAngle > 1.0F)
53
            {
54
                this.lidAngle = 1.0F;
55
            }
56
57
            float f1 = 0.5F;
58
59
            if (this.lidAngle < f1 && f2 >= f1)
60
            {
61
                double d3 = (double)i + 0.5D;
62
                double d2 = (double)k + 0.5D;
63
                this.worldObj.playSoundEffect(d3, (double)j + 0.5D, d2, "random.chestclosed", 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F);
64
            }
65
66
            if (this.lidAngle < 0.0F)
67
            {
68
                this.lidAngle = 0.0F;
69
            }
70
        }
71
    }
72
73
    public boolean receiveClientEvent(int id, int type)
74
    {
75
        if (id == 1)
76
        {
77
            this.numPlayersUsing = type;
78
            return true;
79
        }
80
        else
81
        {
82
            return super.receiveClientEvent(id, type);
83
        }
84
    }
85
86
    /**
87
     * invalidates a tile entity
88
     */
89
    public void invalidate()
90
    {
91
        this.updateContainingBlockInfo();
92
        super.invalidate();
93
    }
94
95
    public void openChest()
96
    {
97
        ++this.numPlayersUsing;
98
        this.worldObj.addBlockEvent(this.pos, Blocks.ender_chest, 1, this.numPlayersUsing);
99
    }
100
101
    public void closeChest()
102
    {
103
        --this.numPlayersUsing;
104
        this.worldObj.addBlockEvent(this.pos, Blocks.ender_chest, 1, this.numPlayersUsing);
105
    }
106
107
    public boolean canBeUsed(EntityPlayer p_145971_1_)
108
    {
109
        return this.worldObj.getTileEntity(this.pos) != this ? false : p_145971_1_.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
110
    }
111
}
112

Deobfuscated MCP 1.8.9 source of TileEntityEnderChest from Marcelektro/MavenMCP-1.8.9 (net/minecraft/tileentity/TileEntityEnderChest.java), stored verbatim.