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
80
81
82
|
package tectech.mechanics.enderStorage;
import java.io.Serializable;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fluids.IFluidHandler;
import com.google.common.base.Objects;
import com.gtnewhorizon.gtnhlib.util.CoordinatePacker;
public class EnderLinkTank implements Serializable {
private static final long serialVersionUID = 1030297456736434221L;
private final int X;
private final int Y;
private final int Z;
private final int D;
public EnderLinkTank(IFluidHandler fluidHandler) {
TileEntity tile = (TileEntity) fluidHandler;
X = tile.xCoord;
Y = tile.yCoord;
Z = tile.zCoord;
D = tile.getWorldObj().provider.dimensionId;
}
private EnderLinkTank(int x, int y, int z, int d) {
X = x;
Y = y;
Z = z;
D = d;
}
public IFluidHandler getFluidHandler() {
World world = DimensionManager.getWorld(D);
if (world == null) return null;
TileEntity tile = world.getTileEntity(X, Y, Z);
if (tile instanceof IFluidHandler fluidHandler) {
return fluidHandler;
} else {
return null;
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
EnderLinkTank that = (EnderLinkTank) o;
return X == that.X && Y == that.Y && Z == that.Z && D == that.D;
}
@Override
public int hashCode() {
return Objects.hashCode(X, Y, Z, D);
}
public NBTTagCompound save() {
NBTTagCompound data = new NBTTagCompound();
data.setLong("coords", CoordinatePacker.pack(X, Y, Z));
data.setInteger("dim", D);
return data;
}
public static EnderLinkTank load(NBTTagCompound data) {
long coords = data.getLong("coords");
int dim = data.getInteger("dim");
return new EnderLinkTank(
CoordinatePacker.unpackX(coords),
CoordinatePacker.unpackY(coords),
CoordinatePacker.unpackZ(coords),
dim);
}
}
|