public void readUpdatePacketData(NBTTagCompound tag) { int amt = tag.getInteger("partAmount"); List<BPPart> found = new ArrayList<BPPart>(); for (int i = 0; i < amt; i++) { String type = tag.getString("partType" + i); UUID id = UUID.fromString(tag.getString("partId" + i)); NBTTagCompound t = tag.getCompoundTag("part" + i); BPPart p = getPartForId(id); if (p == null) addPart(p = PartRegistry.getInstance().createPart(type), id); p.load(t); found.add(p); } List<BPPart> removed = new ArrayList<BPPart>(); for (BPPart p : getParts()) { if (!found.contains(p)) { removed.add(p); } } for (BPPart p : removed) removePart(p); found.clear(); removed.clear(); shouldReRender = true; }
@Override public void readFromNBT(NBTTagCompound tag) { super.readFromNBT(tag); int amt = tag.getInteger("partAmount"); for (int i = 0; i < amt; i++) { String type = tag.getString("partType" + i); NBTTagCompound t = tag.getCompoundTag("part" + i); BPPart p = PartRegistry.getInstance().createPart(type); p.load(t); addPart(p); } }