Jump to content

[1.7.10] How would I damage the player's held item from a keybind?


Recommended Posts

Posted

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

Posted

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.

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.

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I created a modded Minecraft pack and subsequent server for My Fiance and I to play on, we are both new to modding, and have no experience of what mods go together. We gave it a shot and made a pretty good pack, based on some mods we saw previously in All The Mods 9, plus some other building and fun mods. Everything was great, server was running for 10 days(?) and went through multiple subsequent restart cycles (wasn't online 24/7). We were wrapping up for the night, I did /saveall in game, and the command said the world was finished saving. I then did /stop. Following morning we attempted to start the server and it will not get past: [19:25:04] [Server thread/INFO] [minecraft/MinecraftServer]: Preparing start region for dimension minecraft:overworld I attempted to take out the world, and load it on Singleplayer, however same issue, world wont load. I deleted the "serverconfig" directory and it will also not load. I removed the world from the server, thus allowing it to generate a new world, and that worked fine. But our current world will not load anywhere. I am aware of some errors in the logs due to some mismatching, and incompatibilities; I didn't know what was strictly client-side, and what needed to go onto the server, I also didn't know what performance mods did what, so there is a potential multiple were doing the same thing, however this shouldn't be responsible for the crash, as no new mods have been added for atleast 10 restart cycles and everything worked smoothly. I know there is an error about Canary conflicting with Better Chunk Loading, however that error has occured since the beginning of the server and nothing new. It is to be noted that there isn't actually a crash happening. ---> Full Log <--- If this world is corrupted, is there any way to fix it? I have a backup of the world from 4 days ago, but I also dont want to have to roll back that far, I would really like to deal with the issue at hand.
    • Can be anything - start with mods having some addons like Create etc
    • Hello everyone!   I recently switched my broadband provider from BT to Hey, and I ran into a frustrating issue when trying to connect to Minecraft. I kept receiving the error message:   “Failed to connect to the server. Please disconnect from your VPN or proxy and rejoin.”   This was strange since I wasn’t using a VPN or proxy at the time. After some troubleshooting, I discovered that my new ISP might have been flagging my connection incorrectly.   To resolve this, I used a tool called Home page, which helped me manage my online profiles more effectively. By setting up a new profile, I was able to bypass the detection issue and connect to Minecraft without any problems.   If you’re facing similar issues after switching ISPs or encountering connection errors, I recommend exploring tools like Multilogin to help manage your connections.   Hope this helps someone out there!
    • do yk what kinds of mods i should test removing first? Like world generation mods first right?
  • Topics

×
×
  • Create New...

Important Information

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