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

Method writeObject

common/buildcraft/lib/misc/NBTUtils.java:187–213  ·  view source on GitHub ↗
(Object obj)

Source from the content-addressed store, hash-verified

185 }
186
187 public static NBTBase writeObject(Object obj) {
188 if (obj == null) throw new NullPointerException("obj");
189 if (obj instanceof Byte) return new NBTTagByte((Byte) obj);
190 if (obj instanceof Short) return new NBTTagShort((Short) obj);
191 if (obj instanceof Integer) return new NBTTagInt((Integer) obj);
192 if (obj instanceof Long) return new NBTTagLong((Long) obj);
193 if (obj instanceof Float) return new NBTTagFloat((Float) obj);
194 if (obj instanceof Double) return new NBTTagDouble((Double) obj);
195 if (obj instanceof Boolean) {
196 NBTTagCompound nbt = new NBTTagCompound();
197 nbt.setBoolean("boolean", (Boolean) obj);
198 return nbt;
199 }
200 if (obj instanceof EnumFacing) {
201 NBTTagCompound nbt = new NBTTagCompound();
202 nbt.setString("type", "minecraft:enumfacing");
203 nbt.setTag("value", writeEnum((EnumFacing) obj));
204 return nbt;
205 }
206 if (obj instanceof Enum<?>) {
207 NBTTagCompound nbt = new NBTTagCompound();
208 nbt.setString("type", "enum:" + obj.getClass().getName());
209 nbt.setTag("value", writeEnum((Enum) obj));
210 return nbt;
211 }
212 throw new IllegalArgumentException("Cannot write class " + obj.getClass() + " directly to NBT!");
213 }
214
215 public static Object readObject(NBTBase nbt) {
216 if (nbt == null) return null;

Callers 1

writeToNBTMethod · 0.95

Calls 2

writeEnumMethod · 0.95
getNameMethod · 0.45

Tested by

no test coverage detected