Posted December 6, 201410 yr 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?
December 6, 201410 yr You can create a keyhandler. You can use ClientRegistry#registerKeyBinding to bind the keys you want. Forge Wiki Page: http://www.minecraftforge.net/wiki/Key_Binding PM me if you want further help, or just reply to this post for others to help you. Good luck c:
December 6, 201410 yr "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.
December 6, 201410 yr 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.
January 24, 201510 yr Author 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?
January 24, 201510 yr 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.