Posted August 29, 201411 yr Hi, I created a custom level up system based on kills. To monitor player kills and level, I added 2 NBT values.On a keypress, I want the chat to print out the player stats (kill and level NBT values). To use those nbt values, I need an entity player. Usually when using the NBT values with other events, I use event.player or event.getSource, etc. But i can't seem to find anything like that using the KeyInputEvent. Does anyone know of a good way I can do this? Here is my key handler class public class SoulMenu { private final Minecraft mc; public static final int loc = 0; private static final String[] desc = {"menu.desc"}; private static final int[] keyValues = {Keyboard.KEY_L}; public static final KeyBinding[] keys = new KeyBinding[desc.length]; public SoulMenu() { mc = Minecraft.getMinecraft(); for(int i = 0; i < desc.length; ++i) { keys[i] = new KeyBinding(desc[i], keyValues[i], StatCollector.translateToLocal("soulcraft.label")); ClientRegistry.registerKeyBinding(keys[i]); Minecraft.getMinecraft().gameSettings.loadOptions(); } } @SubscribeEvent(priority = EventPriority.NORMAL) public void onKeyInput(KeyInputEvent event) { if(mc.inGameHasFocus) { if(keys[loc].isPressed()) { NBTSoulLevel.showLevel(/*i need a player*/); } } } } And this is the NBT class @SubscribeEvent public void Event(PlayerLoggedInEvent event) { NBTTagCompound tag = event.player.getEntityData(); NBTBase modeTag = tag.getTag("level"); } public static void incrementTag(EntityPlayer player) { if(player != null){ NBTTagCompound tag = player.getEntityData(); NBTBase modeTag = tag.getTag("level"); tag.setInteger("level", tag.getInteger("level") + 1);} } public static void setTag(int num, EntityPlayer player) { if(player != null){ NBTTagCompound tag = player.getEntityData(); NBTBase modeTag = tag.getTag("level"); tag.setInteger("level", num);} } public static int getTag(EntityPlayer player) { if(player != null){ NBTTagCompound tag = player.getEntityData(); NBTBase modeTag = tag.getTag("level"); return tag.getInteger("level"); } return 0; } public static void showLevel(EntityPlayer player){ GuiNewChat chat = Minecraft.getMinecraft().ingameGUI .getChatGUI(); chat.printChatMessage(new ChatComponentText( "Kills \u00a7b" + NBTKillCreate.getTag(player))); chat.printChatMessage(new ChatComponentText( "Level \u00a7b" + getTag(player))); chat.printChatMessage(new ChatComponentText( "Kills to next level \u00a7b" + NBTKillCreate.getTag(player))); } }
August 30, 201411 yr mc.thePlayer, but you'll have to make sure that the client-side data is updated from the server via packets. http://i.imgur.com/NdrFdld.png[/img]
August 30, 201411 yr Author I've never worked with packets before. Do you know of any good tutorials or could you briefly explain it? Thank you
August 30, 201411 yr You could try mine, but it might be a bit too complicated if you're not even familiar with packets yet. A better option to start with would be diesieben07's tutorial. http://i.imgur.com/NdrFdld.png[/img]
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.