Posted August 21, 201411 yr Hello, i'm trying to read strings from NBT. i have attached the code for read and write. My problem is that he reads the both Strings groupName and ownerName and set the fields in the entity. but when i acces them in the onBlockActivated method, they are empty. For the Inventory stuff, everything work fine but i'm using the same method for the groupName and the ownerName. Can someone explain me the odd behavior or say me how to fix this ? public void writeToNBT(NBTTagCompound par1) { super.writeToNBT(par1); NBTTagList itemList = new NBTTagList(); for (int i = 0; i < inv.length; i++) { ItemStack stack = inv[i]; if (stack != null) { NBTTagCompound tag = new NBTTagCompound(); tag.setByte("Slot", (byte) i); stack.writeToNBT(tag); itemList.appendTag(tag); } } par1.setTag("Inventory", itemList); NBTTagList theMatterSettings = new NBTTagList(); NBTTagCompound baseMatter = new NBTTagCompound(); baseMatter.setString("groupName", groupName); baseMatter.setString("ownerName", ownerName); theMatterSettings.appendTag(baseMatter); par1.setTag("thematter", theMatterSettings); NBTTagList groupMembers2 = new NBTTagList(); for(String name:groupMembers) { NBTTagCompound tagName = new NBTTagCompound(); tagName.setString("name", name); groupMembers2.appendTag(tagName); } par1.setTag("themattergroupmembers", groupMembers2); System.out.println("Write to NTB"); System.out.println(groupName); } @Override public void readFromNBT(NBTTagCompound par1) { super.readFromNBT(par1); NBTTagList tagList = par1.getTagList("Inventory",par1.getId()); for (int i = 0; i < tagList.tagCount(); i++) { NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i); byte slot = tag.getByte("Slot"); if (slot >= 0 && slot < inv.length) { inv[slot] = ItemStack.loadItemStackFromNBT(tag); } } NBTTagList theMatterSettings = par1.getTagList("thematter",par1.getId()); if(theMatterSettings.tagCount() > 0) { NBTTagCompound baseMatter =theMatterSettings.getCompoundTagAt(0); groupName = baseMatter.getString("groupName"); ownerName = baseMatter.getString("ownerName"); NBTTagList groupTagList = par1.getTagList("themattergroupmembers",par1.getId()); groupMembers.clear(); for (int i = 0; i < groupTagList.tagCount(); i++) { groupMembers.add(groupTagList.getCompoundTagAt(i).getString("name")); } } System.out.println("Read from NTB"); System.out.println(this.groupName); } //EDIT: Found the bug. The values are only set on the server (world.isRemote=false). is there a way to automatically sync the entity with the client?
August 22, 201411 yr Author Ich gehe mal davon aus das du Deutsch bist (wegen dem Namen) Nee ich setze in dem Entity den Namen des Spielers dem der Block gehört. Derjenige kann mit nem bestimmten Gegenstand den Block aktivieren und andere nicht. Darum muss ich den Owner zum Client syncen.
August 22, 201411 yr Author Yes i know this. i do the checks on the server not on the client. The informations are only for the GUI. i used the SimleNetworkWrapper now to send Changes to the client who stores the informations in the entity, is that a good way?
August 22, 201411 yr Author Okay THX then i have to use a handler ^^. i will notice u in my credits when i release the mod
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.