MCPcopy Create free account
hub / github.com/BuildCraft/BuildCraft / readObject

Method readObject

common/buildcraft/lib/misc/NBTUtils.java:215–248  ·  view source on GitHub ↗
(NBTBase nbt)

Source from the content-addressed store, hash-verified

213 }
214
215 public static Object readObject(NBTBase nbt) {
216 if (nbt == null) return null;
217 if (nbt instanceof NBTPrimitive) {
218 NBTPrimitive prim = (NBTPrimitive) nbt;
219 if (prim instanceof NBTTagByte) return prim.getByte();
220 if (prim instanceof NBTTagShort) return prim.getShort();
221 if (prim instanceof NBTTagInt) return prim.getInt();
222 if (prim instanceof NBTTagLong) return prim.getLong();
223 if (prim instanceof NBTTagFloat) return prim.getFloat();
224 if (prim instanceof NBTTagDouble) return prim.getDouble();
225 else throw new Error("Seriously what? When was a new primitive NBT class added?");
226 }
227 if (nbt instanceof NBTTagString) return ((NBTTagString) nbt).getString();
228 if (nbt instanceof NBTTagCompound) {
229 NBTTagCompound comp = (NBTTagCompound) nbt;
230 if (comp.hasKey("boolean")) return comp.getBoolean("boolean");
231 if (comp.hasKey("type", Constants.NBT.TAG_STRING) && comp.hasKey("value")) {
232 String type = ((NBTTagCompound) nbt).getString("type");
233 NBTBase valueTag = comp.getTag("value");
234 if ("minecraft:enumfacing".equals(type)) return readEnum(valueTag, EnumFacing.class);
235 if (type.startsWith("enum:")) try {
236 Class<?> clazz = Class.forName(type.replace("enum:", ""));
237 if (clazz.isEnum()) {
238 return readEnum(valueTag, (Class<Enum>) clazz);
239 } else {
240 BCLog.logger.warn("The type " + type + " refered to a class that was not an enum type!");
241 }
242 } catch (ClassNotFoundException e) {
243 BCLog.logger.warn("Tried to load " + type + " but couldn't find the enum class!");
244 }
245 }
246 }
247 throw new Error("Tried to load an object from an unknown tag! " + nbt);
248 }
249
250 public static NBTBase writeDoubleArray(double[] data) {
251 NBTTagList list = new NBTTagList();

Callers

nothing calls this directly

Calls 8

readEnumMethod · 0.95
getLongMethod · 0.80
getDoubleMethod · 0.80
getBooleanMethod · 0.80
replaceMethod · 0.80
getTagMethod · 0.65
getStringMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected