aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/api/objects/minecraft/BlockPos.java
blob: d3e7f71eaf8f1a5be03218d5cb0abff11fefbff2 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package gtPlusPlus.api.objects.minecraft;

import java.io.Serializable;

import net.minecraft.world.World;

import gregtech.api.interfaces.tileentity.IGregTechTileEntity;

public class BlockPos implements Serializable {

    private static final long serialVersionUID = -7271947491316682006L;
    public final int xPos;
    public final int yPos;
    public final int zPos;
    public final int dim;

    public static BlockPos generateBlockPos(String sUUID) {
        String[] s2 = sUUID.split("@");
        return new BlockPos(s2);
    }

    public BlockPos(String[] s) {
        this(Integer.parseInt(s[1]), Integer.parseInt(s[2]), Integer.parseInt(s[3]), Integer.parseInt(s[0]));
    }

    public BlockPos(int x, int y, int z, int dim) {
        this.xPos = x;
        this.yPos = y;
        this.zPos = z;
        this.dim = dim;
    }

    public BlockPos(int x, int y, int z, World world) {
        this(x, y, z, world == null ? 0 : world.provider.dimensionId);
    }

    public BlockPos(IGregTechTileEntity b) {
        this(b.getXCoord(), b.getYCoord(), b.getZCoord(), b.getWorld());
    }

    public String getLocationString() {
        return "[X: " + this.xPos + "][Y: " + this.yPos + "][Z: " + this.zPos + "][Dim: " + this.dim + "]";
    }

    public String getUniqueIdentifier() {
        return this.dim + "@" + this.xPos + "@" + this.yPos + "@" + this.zPos;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash += (13 * this.xPos);
        hash += (19 * this.yPos);
        hash += (31 * this.zPos);
        hash += (17 * this.dim);
        return hash;
    }

    @Override
    public boolean equals(Object other) {
        if (other == null) {
            return false;
        }
        if (other == this) {
            return true;
        }
        if (!(other instanceof BlockPos otherPoint)) {
            return false;
        }
        return this.xPos == otherPoint.xPos && this.yPos == otherPoint.yPos
            && this.zPos == otherPoint.zPos
            && this.dim == otherPoint.dim;
    }

    public BlockPos getUp() {
        return new BlockPos(this.xPos, this.yPos + 1, this.zPos, this.dim);
    }

}