-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
PatchNBTTagCompound.java
172 lines (154 loc) · 5.17 KB
/
PatchNBTTagCompound.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package me.nallar.patched.nbt;
import java.util.Map;
import me.nallar.tickthreading.patcher.Declare;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagByteArray;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagDouble;
import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.nbt.NBTTagIntArray;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagLong;
import net.minecraft.nbt.NBTTagShort;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.ReportedException;
public abstract class PatchNBTTagCompound extends NBTTagCompound {
@Override
public synchronized NBTBase copy() {
NBTTagCompound var1 = new NBTTagCompound(this.getName());
for (Map.Entry<String, NBTBase> o : ((Map<String, NBTBase>) this.tagMap).entrySet()) {
var1.setTag(o.getKey(), o.getValue().copy());
}
return var1;
}
@Override
public byte getByte(String tag) {
try {
NBTTagByte nbtTagByte = (NBTTagByte) tagMap.get(tag);
return nbtTagByte == null ? 0 : nbtTagByte.data;
} catch (ClassCastException e) {
throw new ReportedException(this.createCrashReport(tag, 1, e));
}
}
@Override
public short getShort(String tag) {
try {
NBTTagShort nbtTagShort = (NBTTagShort) tagMap.get(tag);
return nbtTagShort == null ? 0 : nbtTagShort.data;
} catch (ClassCastException e) {
throw new ReportedException(this.createCrashReport(tag, 2, e));
}
}
@Override
public int getInteger(String tag) {
try {
NBTTagInt nbtTagInt = (NBTTagInt) tagMap.get(tag);
return nbtTagInt == null ? 0 : nbtTagInt.data;
} catch (ClassCastException e) {
throw new ReportedException(this.createCrashReport(tag, 3, e));
}
}
@Override
public long getLong(String tag) {
try {
NBTTagLong nbtTagLong = (NBTTagLong) tagMap.get(tag);
return nbtTagLong == null ? 0 : nbtTagLong.data;
} catch (ClassCastException e) {
throw new ReportedException(this.createCrashReport(tag, 4, e));
}
}
@Override
public float getFloat(String tag) {
try {
NBTTagFloat nbtTagFloat = (NBTTagFloat) tagMap.get(tag);
return nbtTagFloat == null ? 0 : nbtTagFloat.data;
} catch (ClassCastException e) {
throw new ReportedException(this.createCrashReport(tag, 5, e));
}
}
@Override
public double getDouble(String tag) {
try {
NBTTagDouble nbtTagDouble = (NBTTagDouble) tagMap.get(tag);
return nbtTagDouble == null ? 0 : nbtTagDouble.data;
} catch (ClassCastException e) {
throw new ReportedException(this.createCrashReport(tag, 6, e));
}
}
@Override
public String getString(String tag) {
try {
NBTTagString nbtTagString = (NBTTagString) tagMap.get(tag);
return nbtTagString == null ? "" : nbtTagString.data;
} catch (ClassCastException e) {
throw new ReportedException(this.createCrashReport(tag, 8, e));
}
}
@Override
public byte[] getByteArray(String tag) {
try {
NBTTagByteArray nbtTagByteArray = (NBTTagByteArray) tagMap.get(tag);
return nbtTagByteArray == null ? new byte[0] : nbtTagByteArray.byteArray;
} catch (ClassCastException e) {
throw new ReportedException(this.createCrashReport(tag, 7, e));
}
}
@Override
public int[] getIntArray(String tag) {
try {
NBTTagIntArray nbtTagIntArray = (NBTTagIntArray) tagMap.get(tag);
return nbtTagIntArray == null ? new int[0] : nbtTagIntArray.intArray;
} catch (ClassCastException e) {
throw new ReportedException(this.createCrashReport(tag, 11, e));
}
}
@Override
public NBTTagCompound getCompoundTag(String tag) {
try {
NBTTagCompound nbtTagCompound = (NBTTagCompound) tagMap.get(tag);
return nbtTagCompound == null ? new NBTTagCompound(tag) : nbtTagCompound;
} catch (ClassCastException e) {
throw new ReportedException(this.createCrashReport(tag, 10, e));
}
}
@Override
public NBTTagList getTagList(String tag) {
try {
NBTTagList nbtTagList = (NBTTagList) tagMap.get(tag);
return nbtTagList == null ? new NBTTagList(tag) : nbtTagList;
} catch (ClassCastException e) {
throw new ReportedException(this.createCrashReport(tag, 9, e));
}
}
@Override
@Declare
public Map getTagMap() {
return tagMap;
}
@Override
public boolean equals(Object o) {
if (o instanceof NBTTagCompound) {
NBTBase other = (NBTBase) o;
if (this.getId() == other.getId() && ((this.getRawName() != null || other.getRawName() == null) && (this.getRawName() == null || other.getRawName() != null) && (this.getRawName() == null || this.getRawName().equals(other.getRawName())))) {
NBTTagCompound nbttagcompound = (NBTTagCompound) o;
Map map = tagMap;
Map otherMap = nbttagcompound.getTagMap();
if (map.size() == otherMap.size()) {
synchronized (this) {
for (Map.Entry entry : (Iterable<Map.Entry>) map.entrySet()) {
Object value = entry.getValue();
Object otherValue = otherMap.get(entry.getKey());
if (!(value == otherValue || (value != null && value.equals(otherValue)))) {
return false;
}
}
}
return true;
}
}
}
return false;
}
}