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

For my mod I want to make a item that on "f" key pressed will despawn the item and give the player a different item. How is this done?

"You can create a keyhandler."

And that is only the beginning...

 

You will need your KeyBinding to sent Packet to server (Bindings are client-side). The server will have to operate with data sent, which is sender.

You will have to pull inventory from sender (player) and set current slot to different item (current = in hand).

player.inventory.currentItem;

Remember to 1st check if slot is not null. To override slot simply use something like setInventorySlotContents() (Idk if it's exact name)

 

Packet tutorials:

http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/2137055-1-7-2-customizing-packet-handling-with

Shorter:

http://www.minecraftforge.net/forum/index.php/topic,20135.0.html

1.7.10 is no longer supported by forge, you are on your own.

public class KeyHandler
{
public static KeyBinding pawnItem = new KeyBinding("Pawn Item", Keyboard.KEY_K, "key.categories.hud");

public KeyHandler()
{
	ClientRegistry.registerKeyBinding(awnItem);
}

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void playerTick(PlayerTickEvent event)
{
	if (event.side == Side.SERVER) return;
	if (event.phase == Phase.START)
	{
		Minecraft mc = Minecraft.getMinecraft();
		if (pawnItem.getIsKeyPressed())
		{
			//send packet to server, on receiver side (server) you can get sender (player) and modify his inventory
		}
	}
}
}

1.7.10 is no longer supported by forge, you are on your own.

  • 1 month later...

I am still really lost I have no idea where to put what the key does.

Do I put in in the class of the item?

 

No.  You create a NEW class that is your key event handler.  You then have to do all the networking stuff, which is likely going to involve (at a minimum) two more classes, IIRC: the packet itself and the packet handler.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.