aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/api/objects/minecraft/DimChunkPos.java
blob: 6748b585370f1229f13206461b2dba8b11090ab6 (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
package gtPlusPlus.api.objects.minecraft;

import net.minecraft.client.Minecraft;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;

public class DimChunkPos {

    public final int dimension;
    public final int xPos;
    public final int zPos;
    public final Chunk mainChunk;

    public DimChunkPos(World world, BlockPos block) {
        this.dimension = world.provider.dimensionId;
        this.mainChunk = world.getChunkFromBlockCoords(block.xPos, block.zPos);
        this.xPos = this.mainChunk.xPosition;
        this.zPos = this.mainChunk.zPosition;
    }

    public DimChunkPos(TileEntity tile) {
        this.dimension = tile.getWorldObj().provider.dimensionId;
        this.mainChunk = tile.getWorldObj().getChunkFromBlockCoords(tile.xCoord, tile.zCoord);
        this.xPos = this.mainChunk.xPosition;
        this.zPos = this.mainChunk.zPosition;
    }

    public DimChunkPos(int dim, int x, int z) {
        this.dimension = dim;
        this.xPos = x;
        this.zPos = z;
        Chunk h = Minecraft.getMinecraft().getIntegratedServer().worldServerForDimension(dim)
                .getChunkFromChunkCoords(xPos, zPos);
        if (h == null) {
            this.mainChunk = null;
        } else {
            this.mainChunk = h;
        }
    }

    public Chunk getChunk() {
        if (this.mainChunk != null) {
            return this.mainChunk;
        }
        Chunk h = Minecraft.getMinecraft().getIntegratedServer().worldServerForDimension(this.dimension)
                .getChunkFromChunkCoords(xPos, zPos);
        return h;
    }
}