]> git.lizzy.rs Git - LightOverlay.git/blob - common/src/main/java/me/shedaniel/lightoverlay/common/CubicChunkPos.java
576724e210615beca35ed593c5466b1293fa706e
[LightOverlay.git] / common / src / main / java / me / shedaniel / lightoverlay / common / CubicChunkPos.java
1 package me.shedaniel.lightoverlay.common;
2
3 import net.minecraft.core.BlockPos;
4
5 import java.util.Objects;
6
7 public class CubicChunkPos {
8     public final int x;
9     public final int y;
10     public final int z;
11     
12     public CubicChunkPos(int x, int y, int z) {
13         this.x = x;
14         this.y = y;
15         this.z = z;
16     }
17     
18     public CubicChunkPos(long l) {
19         this.x = getX(l);
20         this.y = getY(l);
21         this.z = getZ(l);
22     }
23     
24     public CubicChunkPos(BlockPos blockPos) {
25         this.x = blockPos.getX() >> 4;
26         this.y = blockPos.getY() >> 4;
27         this.z = blockPos.getZ() >> 4;
28     }
29     
30     public long toLong() {
31         return asLong(this.x, this.y, this.z);
32     }
33     
34     // Allocate 24 bits to x, 12 bits to y, 24 bits to z
35     public static long asLong(int x, int y, int z) {
36         return ((x & 0xffffffL) << 36) | ((y & 0xfffL) << 24) | (z & 0xffffffL);
37     }
38     
39     public static int getX(long l) {
40         return (int) (l >> 36 & 0xffffffL);
41     }
42     
43     public static int getY(long l) {
44         return (int) (l >> 24 & 0xfffL);
45     }
46     
47     public static int getZ(long l) {
48         return (int) (l & 0xffffffL);
49     }
50     
51     public int getMinBlockX() {
52         return this.x << 4;
53     }
54     
55     public int getMinBlockY() {
56         return this.y << 4;
57     }
58     
59     public int getMinBlockZ() {
60         return this.z << 4;
61     }
62     
63     public int getMaxBlockX() {
64         return (this.x << 4) + 15;
65     }
66     
67     public int getMaxBlockY() {
68         return (this.y << 4) + 15;
69     }
70     
71     public int getMaxBlockZ() {
72         return (this.z << 4) + 15;
73     }
74     
75     @Override
76     public boolean equals(Object o) {
77         if (this == o) return true;
78         if (o == null || getClass() != o.getClass()) return false;
79         CubicChunkPos that = (CubicChunkPos) o;
80         return x == that.x && y == that.y && z == that.z;
81     }
82     
83     @Override
84     public int hashCode() {
85         return Objects.hash(x, y, z);
86     }
87 }