-
Notifications
You must be signed in to change notification settings - Fork 497
/
ResourceId.java
executable file
·81 lines (61 loc) · 1.86 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
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core.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.hashCode() * 37) + side.ordinal() * 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("class", getClass().getCanonicalName());
}
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 clas = Class.forName(nbt.getString("class"));
ResourceId id = (ResourceId) clas.newInstance();
id.readFromNBT(nbt);
return id;
} catch (Throwable e) {
e.printStackTrace();
}
return null;
}
public void taken(long robotId) {
}
public void released(long robotId) {
}
}