Jump to content

Help with NBT & Key binds


somarani

Recommended Posts

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)));
}

}

 

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.