Ms_Raven Posted January 10, 2016 Share Posted January 10, 2016 If the player is holding a magic rod when a key is pressed it should cast a fireball and damage the rod. But I'm not sure how to go about doing that. I'm assuming the code I have won't work (I haven't made the projectile or packets yet so I haven't tested it) since it's getting the equipped item of the client player? If not, how do I get the regular EntityPlayer from that in a packet? Would simply passing the client player through the packet parameters and casting it to EntityPlayer be enough? @SubscribeEvent public void onKeyPress(KeyInputEvent event) { if (Keybinds.fire.isPressed()) { ItemStack stack = Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem(); if (stack.getItem() instanceof Rod) { if (stack.getItemDamage() < stack.getMaxDamage() - 1) { // TODO packet stack.damageItem(1, Minecraft.getMinecraft().thePlayer); } } } } Quote Link to comment Share on other sites More sharing options...
Choonster Posted January 10, 2016 Share Posted January 10, 2016 Just send a packet to the server saying "the player pressed the fire key", you don't actually need to send any data in it. On the server side, you'll have access to the player that sent the packet so you can check if they're holding a rod and then spawn the fireball and damage the rod (I'd recommend creating a method to do this in your Rod class). Forge's Read the Docs site has a section on networking here. This includes the Simple Network Implementation, which is what you should use to send the packet. Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future. Link to comment Share on other sites More sharing options...
Recommended Posts
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.