-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChunkContainer.java
More file actions
45 lines (36 loc) · 1.1 KB
/
ChunkContainer.java
File metadata and controls
45 lines (36 loc) · 1.1 KB
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
package net.minecraft.src;
/**
* Container class for Chunk because Chunk does not implement equals/hashCode
* We dont want to modify Chunk itself, thus this Container wraps it.
*/
public class ChunkContainer
{
public Chunk c;
/* The position of the Chunk is immutable, we can therefore
* cache the hashCode */
private final int hashCode;
public ChunkContainer(Chunk c)
{
this.c = c;
/* Calculate the hashCode for this Chunk
* See ch. 3 of "Effective Java"
* for reasoning behind this hash funktion */
int result = 17;
result = 37 * result + getX();
result = 37 * result + getZ();
hashCode = result;
}
@Override
public boolean equals(Object o)
{
if ( o instanceof ChunkContainer && c.xPosition == ((ChunkContainer)o).c.xPosition && c.zPosition == ((ChunkContainer)o).c.zPosition )
return true;
return false;
}
@Override
public int hashCode() {
return hashCode;
}
public int getX() { return c.xPosition; }
public int getZ() { return c.zPosition; }
}