Posted May 19, 201312 yr When I read the string via my connection handler class inside the playerLoggedIn() method (connection handler class extends IConnectionHandler), it reads the string as it should be. But when I try to read the string from any of my items, addInformation() methods, the string returns as either null, or "". So either A) how do I fix this, or, B) what am I doing wrong? Code for PlayerInformation: package rpg.playerinfo; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; public final class PlayerInformation implements IExtendedEntityProperties { public static enum CountableKarmaEvent { PIGMEN_ATTACK(1), CREATE_SNOWGOLEM(2), CREATE_IRONGOLEM(3); private final int maxCount; private CountableKarmaEvent(int maxCount) { this.maxCount = maxCount; } public int getMaxCount() { return maxCount; } } public static final String IDENTIFIER = "minepg_playerinfo"; public static final int MAX_KARMA_VALUE = 99999999; public static PlayerInformation forPlayer(Entity player) { return (PlayerInformation) player.getExtendedProperties(IDENTIFIER); } // called by the ASM hook in EntityPlayer.clonePlayer public static void handlePlayerClone(EntityPlayer source, EntityPlayer target) { target.registerExtendedProperties(IDENTIFIER, source.getExtendedProperties(IDENTIFIER)); } public boolean dirty = true; private float karma = 0; public byte[] eventAmounts = new byte[PlayerInformation.CountableKarmaEvent .values().length]; private String playersClass; private int danris = 0; private final EntityPlayer player; public PlayerInformation(EntityPlayer player) { this.player = player; } public int getCurrency() { return danris; } public byte getEventAmount(CountableKarmaEvent event) { return eventAmounts[event.ordinal()]; } public float getKarma() { return karma; } public String getPlayersClass() { return playersClass; } public boolean increaseEventAmount( PlayerInformation.CountableKarmaEvent event) { return setEventAmount(event, eventAmounts[event.ordinal()] + 1); } @Override public void init(Entity entity, World world) { } @Override public void loadNBTData(NBTTagCompound playerNbt) { NBTTagCompound nbt = playerNbt.getCompoundTag(IDENTIFIER); playersClass = nbt.getString("playersClass"); System.out .println("Debug message. If this has been printed to the console then NBTData has been read."); danris = nbt.getInteger("danris"); karma = nbt.getFloat("karma"); NBTTagList eventList = nbt.getTagList("events"); for (int i = 0; i < eventList.tagCount(); i++) { NBTTagCompound evtInfo = (NBTTagCompound) eventList.tagAt(i); byte eventId = evtInfo.getByte("id"); if (eventId >= 0 && eventId < eventAmounts.length) { eventAmounts[eventId] = evtInfo.getByte("value"); } } } public float modifyKarma(float modifier) { player.worldObj.playSoundAtEntity(player, "minepg.karma" + (modifier < 0 ? "down" : "up"), 1, 1); return setKarma(karma + modifier); } public float modifyKarmaWithMax(float modifier, float max) { if (karma < max) { modifyKarma(modifier); } return karma; } public float modifyKarmaWithMin(float modifier, float min) { if (karma > min) { modifyKarma(modifier); } return karma; } @Override public void saveNBTData(NBTTagCompound compound) { NBTTagCompound nbt = new NBTTagCompound(); nbt.setString("playersClass", playersClass); nbt.setInteger("danris", danris); nbt.setFloat("karma", karma); NBTTagList eventList = new NBTTagList(); for (int i = 0; i < eventAmounts.length; i++) { NBTTagCompound evtInfo = new NBTTagCompound(); evtInfo.setByte("id", (byte) i); evtInfo.setByte("value", eventAmounts[i]); eventList.appendTag(evtInfo); } nbt.setTag("events", eventList); compound.setCompoundTag(IDENTIFIER, nbt); } public int setCurrency(int danris) { if (this.danris != danris) { this.danris = danris; setDirty(); } if (this.danris > 999999) { this.danris = 999999; setDirty(); } return this.danris; } /** * marks that this needs to be resend to the client */ public void setDirty() { dirty = true; } public boolean setEventAmount(CountableKarmaEvent event, int amount) { if (amount < event.getMaxCount() && eventAmounts[event.ordinal()] != amount) { eventAmounts[event.ordinal()] = (byte) amount; setDirty(); return true; } else return false; } public float setKarma(float karma) { if (this.karma != karma) { this.karma = karma; if (this.karma > MAX_KARMA_VALUE) { this.karma = MAX_KARMA_VALUE; } if (this.karma < -MAX_KARMA_VALUE) { this.karma = -MAX_KARMA_VALUE; } setDirty(); } return this.karma; } public String setPlayersClass(String playersClass) { if (this.playersClass != playersClass) { this.playersClass = playersClass; setDirty(); } return this.playersClass; } } Code for ConnectionHandler: package rpg.comm; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.INetworkManager; import net.minecraft.network.NetLoginHandler; import net.minecraft.network.packet.NetHandler; import net.minecraft.network.packet.Packet1Login; import net.minecraft.server.MinecraftServer; import rpg.RPG; import rpg.enums.EnumGui; import rpg.network.packet.PacketUpdatePlayersClassName; import rpg.playerinfo.PlayerInformation; import rpg.sounds.SoundLoader; import cpw.mods.fml.common.network.IConnectionHandler; import cpw.mods.fml.common.network.Player; public class ConnectionHandler implements IConnectionHandler { @Override public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login) { } @Override public void connectionClosed(INetworkManager manager) { } @Override public void connectionOpened(NetHandler netClientHandler, MinecraftServer server, INetworkManager manager) { } @Override public void connectionOpened(NetHandler netClientHandler, String server, int port, INetworkManager manager) { } @Override public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager) { return null; } @Override public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager) { PlayerInformation playerInfo = PlayerInformation .forPlayer((EntityPlayerMP) player); if (playerInfo.getPlayersClass().equals("")) { ((EntityPlayerMP) player).openGui(RPG.instance, EnumGui.LoreStartingPage.getIndex(), ((EntityPlayerMP) player).worldObj, 0, 0, 0); } else { ((EntityPlayerMP) player) .sendChatToPlayer("<Mysterious Voice> Welcome back master " + playerInfo.getPlayersClass()); new PacketUpdatePlayersClassName().sendToServer(); } if (SoundLoader.didSoundsLoad == true) { ((EntityPlayerMP) player) .sendChatToPlayer("[MinePG Sound Loader] Loaded Sounds Successfully"); } else if (SoundLoader.didSoundsLoad == false) { ((EntityPlayerMP) player) .sendChatToPlayer("[MinePG Sound Loader] Failed to load one or more sounds"); } } } Code for an item's addInformation() method: @Override @SuppressWarnings({ "rawtypes", "unchecked" }) public void addInformation(ItemStack par1ItemStack, EntityPlayer player, List par3List, boolean par4) { PlayerInformation playerInfo = PlayerInformation.forPlayer(player); // Checks the players class and colored item name // accordingly if (playerInfo.getPlayersClass() == "Warrior" && player.experienceLevel >= 1) { par3List.add("Class: §AWarrior"); par3List.add("Level: §A1"); } else if (playerInfo.getPlayersClass() == "Warrior" && player.experienceLevel != 1) { par3List.add("Class: §AWarrior"); par3List.add("Level: §41"); } else if (playerInfo.getPlayersClass() != "Warrior" && player.experienceLevel == 1) { par3List.add("Class: §4Warrior"); par3List.add("Level: §A1"); } else { par3List.add("Class: §4Warrior"); par3List.add("Level: §41"); } } [sIDE NOTE] As the code for the addInformation() method is above, it returns as "", but if I use the proper .equals("String here"), it returns as null. I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes. I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there
May 19, 201312 yr Author So I would need to make a packet that first, got the data needed, then second, sent the data to the client, and thirdly, take the received data to a String variable inside the item class, and lastly, do what I was doing before? I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes. I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there
May 19, 201312 yr Author I can't quite figure it out... I will try again a bit later. but any pointers in the right direction would be helpful. I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes. I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there
May 20, 201312 yr Author Bump for no particular reason. Except for the fact that diesieben07 seems to be the only one who really helps me... Can anyone else be of assistance? I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes. I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there
May 20, 201312 yr Author Once again I am bumping this so that the great diesieben07 can see this and finish off the help he started giving. I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes. I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there
May 20, 201312 yr Author Thats the thing, your point in the right direction was good, I just didn't quite get what the packet should contain, and how to obtain the string from the packet I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes. I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there
May 20, 201312 yr Author Uhh, what system? Just so you know, you haven't updated the Github repo for questology in a mater of months therefore anything added in that time is not known about. So I don't think that system is in there.... And I don't get how I retrieve the string from the packet from inside the item class. How do I set it? Its confusing me I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes. I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there
May 21, 201312 yr Author BUMP And can you give me an example? I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes. I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there
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.