-
Notifications
You must be signed in to change notification settings - Fork 497
/
ResourceId.java
executable file
·86 lines (67 loc) · 2.12 KB
/
ResourceId.java
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
83
84
85
86
/**
* Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* The BuildCraft API is distributed under the terms of the MIT License.
* Please check the contents of the license, which should be located
* as "LICENSE.API" in the BuildCraft source code distribution.
*/
package buildcraft.api.robots;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.BlockIndex;
public abstract class ResourceId {
public BlockIndex index = new BlockIndex();
public ForgeDirection side = ForgeDirection.UNKNOWN;
public int localId = 0;
protected ResourceId() {
}
@Override
public boolean equals(Object obj) {
if (obj.getClass() != getClass()) {
return false;
}
ResourceId compareId = (ResourceId) obj;
return index.equals(compareId.index)
&& side == compareId.side
&& localId == compareId.localId;
}
@Override
public int hashCode() {
return (((index != null ? index.hashCode() : 0) * 37) + (side != null ? side.ordinal() : 0) * 37) + localId;
}
public void writeToNBT(NBTTagCompound nbt) {
NBTTagCompound indexNBT = new NBTTagCompound();
index.writeTo(indexNBT);
nbt.setTag("index", indexNBT);
nbt.setByte("side", (byte) side.ordinal());
nbt.setInteger("localId", localId);
nbt.setString("resourceName", RobotManager.getResourceIdName(getClass()));
}
protected void readFromNBT(NBTTagCompound nbt) {
index = new BlockIndex(nbt.getCompoundTag("index"));
side = ForgeDirection.values()[nbt.getByte("side")];
localId = nbt.getInteger("localId");
}
public static ResourceId load(NBTTagCompound nbt) {
try {
Class cls = null;
if (nbt.hasKey("class")) {
// Migration support for 6.4.x
cls = RobotManager.getResourceIdByLegacyClassName(nbt.getString("class"));
} else {
cls = RobotManager.getResourceIdByName(nbt.getString("resourceName"));
}
ResourceId id = (ResourceId) cls.newInstance();
id.readFromNBT(nbt);
return id;
} catch (Throwable e) {
e.printStackTrace();
}
return null;
}
public void taken(long robotId) {
}
public void released(long robotId) {
}
}