public void load(T state, CompoundTag compound) { String checkId = ((StringTag) compound.getValue().get("id")).getValue(); if (!id.equalsIgnoreCase(checkId)) { throw new IllegalArgumentException( "Invalid ID loading tile entity, expected " + id + " got " + checkId); } int checkX = ((IntTag) compound.getValue().get("x")).getValue(), x = state.getX(); int checkY = ((IntTag) compound.getValue().get("y")).getValue(), y = state.getY(); int checkZ = ((IntTag) compound.getValue().get("z")).getValue(), z = state.getZ(); if (x != checkX || y != checkY || z != checkZ) { throw new IllegalArgumentException( "Invalid coords loading tile entity, expected (" + x + "," + y + "," + z + ") got (" + checkX + "," + checkY + "," + checkZ + ")"); } }
public ItemStack readItemStack(CompoundTag compound) { ItemStack stack = null; Tag idTag = compound.getValue().get("id"); Tag damageTag = compound.getValue().get("Damage"); Tag countTag = compound.getValue().get("Count"); short id = (idTag == null) ? 0 : ((ShortTag) idTag).getValue(); short damage = (damageTag == null) ? 0 : ((ShortTag) damageTag).getValue(); byte count = (countTag == null) ? 0 : ((ByteTag) countTag).getValue(); if (id != 0 && count != 0) { stack = new ItemStack(id, count, damage); } return stack; }
@Override public void load(GlowItem entity, CompoundTag compound) { if (compound.getValue().containsKey("Item")) { ItemStack stack = readItemStack((CompoundTag) compound.getValue().get("Item")); entity.setItemStack(stack); } if (compound.getValue().containsKey("Health")) { // item.setHealth(((IntTag)compound.getValue().get("Health")).getValue()); } if (compound.getValue().containsKey("Age")) { // item.setAge(((IntTag)compound.getValue().get("Age")).getValue()); } }
@Override public GlowItem load(GlowServer server, GlowWorld world, CompoundTag compound) { ItemStack stack = null; if (compound.getValue().containsKey("Item")) { stack = readItemStack((CompoundTag) compound.getValue().get("Item")); } GlowItem item = new GlowItem(server, world, stack); if (compound.getValue().containsKey("Health")) { // item.setHealth(((IntTag)compound.getValue().get("Health")).getValue()); } if (compound.getValue().containsKey("Age")) { // item.setAge(((IntTag)compound.getValue().get("Age")).getValue()); } return item; }
/** * Loads NBT data from the given file. * * @param file File to load from. */ public void load(String file) { File f = new File(file); if (!f.exists()) { if (!f.getParentFile().exists()) { f.getParentFile().mkdirs(); } try { f.createNewFile(); } catch (IOException e) { OpenClassic.getLogger() .severe("Failed to create new file for NBTData " + this.data.getName() + "!"); e.printStackTrace(); return; } return; } NBTInputStream in = null; try { in = new NBTInputStream(new FileInputStream(f)); CompoundTag tag = (CompoundTag) in.readTag(); this.data.clear(); for (String name : tag.keySet()) { this.data.put(name, tag.get(name)); } } catch (EOFException e) { this.data.clear(); return; } catch (IOException e) { OpenClassic.getLogger() .severe("Failed to open stream for NBTData " + this.data.getName() + "!"); e.printStackTrace(); return; } finally { IOUtils.closeQuietly(in); } }
/** * Writes a <code>TAG_Compound</code> tag. * * @param tag The tag. * @throws IOException if an I/O error occurs. */ private void writeCompoundTagPayload(CompoundTag tag) throws IOException { for (Tag childTag : tag.getValue().values()) { writeTag(childTag); } os.writeByte((byte) 0); // end tag - better way? }
/** * Puts a CompoundTag. * * @param compound Tag to put. * @return The resulting Tag. */ public Tag put(CompoundTag compound) { return this.data.put(compound.getName(), compound); }