ExtendedBlockStorage .java

net.minecraft.world.chunk.storage.ExtendedBlockStorage (class): members: getExtBlocklightValue, setExtBlocklightValue, getExtBlockMetadata, blockRefCount.

net.minecraft.world.chunk.storageclass224 linescommon5.9 KB

API Surface (18)

IBlockState get(int x, int y, int z)
void set(int x, int y, int z, IBlockState state)
Block getBlockByExtId(int x, int y, int z)
int getExtBlockMetadata(int x, int y, int z)
boolean isEmpty()
boolean getNeedsRandomTick()
int getYLocation()
void setExtSkylightValue(int x, int y, int z, int value)
int getExtSkylightValue(int x, int y, int z)
void setExtBlocklightValue(int x, int y, int z, int value)
int getExtBlocklightValue(int x, int y, int z)
void removeInvalidBlocks()
char[] getData()
void setData(char[] dataArray)
NibbleArray getBlocklightArray()
NibbleArray getSkylightArray()
void setBlocklightArray(NibbleArray newBlocklightArray)
void setSkylightArray(NibbleArray newSkylightArray)

Fields & Constants (6)

yBase
blockRefCount
tickRefCount
data
blocklightArray
skylightArray

Code Graph: Dependencies (4)

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

Full Source

ExtendedBlockStorage.java224 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.world.chunk.storage;
2
3
import net.minecraft.block.Block;
4
import net.minecraft.block.state.IBlockState;
5
import net.minecraft.init.Blocks;
6
import net.minecraft.world.chunk.NibbleArray;
7
8
public class ExtendedBlockStorage
9
{
10
    /**
11
     * Contains the bottom-most Y block represented by this ExtendedBlockStorage. Typically a multiple of 16.
12
     */
13
    private int yBase;
14
15
    /**
16
     * A total count of the number of non-air blocks in this block storage's Chunk.
17
     */
18
    private int blockRefCount;
19
20
    /**
21
     * Contains the number of blocks in this block storage's parent chunk that require random ticking. Used to cull the
22
     * Chunk from random tick updates for performance reasons.
23
     */
24
    private int tickRefCount;
25
    private char[] data;
26
27
    /** The NibbleArray containing a block of Block-light data. */
28
    private NibbleArray blocklightArray;
29
30
    /** The NibbleArray containing a block of Sky-light data. */
31
    private NibbleArray skylightArray;
32
33
    public ExtendedBlockStorage(int y, boolean storeSkylight)
34
    {
35
        this.yBase = y;
36
        this.data = new char[4096];
37
        this.blocklightArray = new NibbleArray();
38
39
        if (storeSkylight)
40
        {
41
            this.skylightArray = new NibbleArray();
42
        }
43
    }
44
45
    public IBlockState get(int x, int y, int z)
46
    {
47
        IBlockState iblockstate = (IBlockState)Block.BLOCK_STATE_IDS.getByValue(this.data[y << 8 | z << 4 | x]);
48
        return iblockstate != null ? iblockstate : Blocks.air.getDefaultState();
49
    }
50
51
    public void set(int x, int y, int z, IBlockState state)
52
    {
53
        IBlockState iblockstate = this.get(x, y, z);
54
        Block block = iblockstate.getBlock();
55
        Block block1 = state.getBlock();
56
57
        if (block != Blocks.air)
58
        {
59
            --this.blockRefCount;
60
61
            if (block.getTickRandomly())
62
            {
63
                --this.tickRefCount;
64
            }
65
        }
66
67
        if (block1 != Blocks.air)
68
        {
69
            ++this.blockRefCount;
70
71
            if (block1.getTickRandomly())
72
            {
73
                ++this.tickRefCount;
74
            }
75
        }
76
77
        this.data[y << 8 | z << 4 | x] = (char)Block.BLOCK_STATE_IDS.get(state);
78
    }
79
80
    /**
81
     * Returns the block for a location in a chunk, with the extended ID merged from a byte array and a NibbleArray to
82
     * form a full 12-bit block ID.
83
     */
84
    public Block getBlockByExtId(int x, int y, int z)
85
    {
86
        return this.get(x, y, z).getBlock();
87
    }
88
89
    /**
90
     * Returns the metadata associated with the block at the given coordinates in this ExtendedBlockStorage.
91
     */
92
    public int getExtBlockMetadata(int x, int y, int z)
93
    {
94
        IBlockState iblockstate = this.get(x, y, z);
95
        return iblockstate.getBlock().getMetaFromState(iblockstate);
96
    }
97
98
    /**
99
     * Returns whether or not this block storage's Chunk is fully empty, based on its internal reference count.
100
     */
101
    public boolean isEmpty()
102
    {
103
        return this.blockRefCount == 0;
104
    }
105
106
    /**
107
     * Returns whether or not this block storage's Chunk will require random ticking, used to avoid looping through
108
     * random block ticks when there are no blocks that would randomly tick.
109
     */
110
    public boolean getNeedsRandomTick()
111
    {
112
        return this.tickRefCount > 0;
113
    }
114
115
    /**
116
     * Returns the Y location of this ExtendedBlockStorage.
117
     */
118
    public int getYLocation()
119
    {
120
        return this.yBase;
121
    }
122
123
    /**
124
     * Sets the saved Sky-light value in the extended block storage structure.
125
     */
126
    public void setExtSkylightValue(int x, int y, int z, int value)
127
    {
128
        this.skylightArray.set(x, y, z, value);
129
    }
130
131
    /**
132
     * Gets the saved Sky-light value in the extended block storage structure.
133
     */
134
    public int getExtSkylightValue(int x, int y, int z)
135
    {
136
        return this.skylightArray.get(x, y, z);
137
    }
138
139
    /**
140
     * Sets the saved Block-light value in the extended block storage structure.
141
     */
142
    public void setExtBlocklightValue(int x, int y, int z, int value)
143
    {
144
        this.blocklightArray.set(x, y, z, value);
145
    }
146
147
    /**
148
     * Gets the saved Block-light value in the extended block storage structure.
149
     */
150
    public int getExtBlocklightValue(int x, int y, int z)
151
    {
152
        return this.blocklightArray.get(x, y, z);
153
    }
154
155
    public void removeInvalidBlocks()
156
    {
157
        this.blockRefCount = 0;
158
        this.tickRefCount = 0;
159
160
        for (int i = 0; i < 16; ++i)
161
        {
162
            for (int j = 0; j < 16; ++j)
163
            {
164
                for (int k = 0; k < 16; ++k)
165
                {
166
                    Block block = this.getBlockByExtId(i, j, k);
167
168
                    if (block != Blocks.air)
169
                    {
170
                        ++this.blockRefCount;
171
172
                        if (block.getTickRandomly())
173
                        {
174
                            ++this.tickRefCount;
175
                        }
176
                    }
177
                }
178
            }
179
        }
180
    }
181
182
    public char[] getData()
183
    {
184
        return this.data;
185
    }
186
187
    public void setData(char[] dataArray)
188
    {
189
        this.data = dataArray;
190
    }
191
192
    /**
193
     * Returns the NibbleArray instance containing Block-light data.
194
     */
195
    public NibbleArray getBlocklightArray()
196
    {
197
        return this.blocklightArray;
198
    }
199
200
    /**
201
     * Returns the NibbleArray instance containing Sky-light data.
202
     */
203
    public NibbleArray getSkylightArray()
204
    {
205
        return this.skylightArray;
206
    }
207
208
    /**
209
     * Sets the NibbleArray instance used for Block-light values in this particular storage block.
210
     */
211
    public void setBlocklightArray(NibbleArray newBlocklightArray)
212
    {
213
        this.blocklightArray = newBlocklightArray;
214
    }
215
216
    /**
217
     * Sets the NibbleArray instance used for Sky-light values in this particular storage block.
218
     */
219
    public void setSkylightArray(NibbleArray newSkylightArray)
220
    {
221
        this.skylightArray = newSkylightArray;
222
    }
223
}
224

Deobfuscated MCP 1.8.9 source of ExtendedBlockStorage from Marcelektro/MavenMCP-1.8.9 (net/minecraft/world/chunk/storage/ExtendedBlockStorage.java), stored verbatim.