use of minechem.handler.message.JournalMessage in project Minechem by iopleke.
the class JournalItem method writeKnowledge.
/**
* Writes knowledge to the journal
*
* @param itemStack the journal stack
* @param player the player that writes the knowledge
* @param isRemote is the world remote on true it will send a {@link minechem.handler.message.JournalMessage} to the server
*/
public void writeKnowledge(ItemStack itemStack, EntityPlayer player, boolean isRemote) {
if (isRemote) {
MessageHandler.INSTANCE.sendToServer(new JournalMessage(player));
return;
}
NBTTagCompound tagCompound = itemStack.stackTagCompound;
Set<String> playerKnowledge = ResearchRegistry.getInstance().getResearchFor(player);
if (playerKnowledge == null) {
return;
}
Set<String> bookKnowledge = new LinkedHashSet<String>();
if (tagCompound == null) {
tagCompound = new NBTTagCompound();
} else if (tagCompound.hasKey("research")) {
NBTTagList bookKnowledgeTag = tagCompound.getTagList("research", 8);
for (int i = 0; i < bookKnowledgeTag.tagCount(); i++) {
bookKnowledge.add(bookKnowledgeTag.getStringTagAt(i));
}
}
bookKnowledge.addAll(playerKnowledge);
NBTTagList bookKnowledgeTag = new NBTTagList();
for (String knowledgeKey : bookKnowledge) {
bookKnowledgeTag.appendTag(new NBTTagString(knowledgeKey));
}
tagCompound.setTag("research", bookKnowledgeTag);
Set<String> authors = new LinkedHashSet<String>();
if (tagCompound.hasKey("authors")) {
NBTTagList authorsTag = tagCompound.getTagList("authors", 8);
for (int i = 0; i < authorsTag.tagCount(); i++) {
authors.add(authorsTag.getStringTagAt(i));
}
}
authors.add(player.getDisplayName());
NBTTagList authorsTag = new NBTTagList();
for (String author : authors) {
authorsTag.appendTag(new NBTTagString(author));
}
tagCompound.setTag("authors", authorsTag);
itemStack.setTagCompound(tagCompound);
}
Aggregations