Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

}

 

 

  • Author

I've never worked with packets before. Do you know of any good tutorials or could you briefly explain it? Thank you

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.