Posted June 23, 201510 yr I was wondering if it was possible to get a projectile to read NBT data from the player's currently equipped item, preferably when it is spawned. I have had a look at a few vanilla projectiles but I couldn't see anything helpful (though it is late and I may have missed something in my fatigue), EntityPotion has a method for writing/reading entity NBT data though I am not sure how to use it to my advantage, and Google didn't turn up anything either.
June 23, 201510 yr Which player? Do you have an EntityPlayer available in your projectile, e.g. the thrower / shooter? If so, you can use player.getHeldItem() to get the currently held ItemStack, if any, and do whatever you want with it, e.g. stack.getTagCompound() to get the NBTTagCompound, if any. http://i.imgur.com/NdrFdld.png[/img]
June 23, 201510 yr Author Getting the thrower's held item and reading the NBT from there was what I thought I should do, but I was unsure where to put the code. If I put it in onImpact it would create a slight bug, and I couldn't see an 'onSpawn' type event for EntityThrowable. I have the code for handling the NBT and what to do for the result, just wondering where the most efficient place for it would be. Would I perhaps need to get the item to write to the entityNBT in the method that spawns the entity?
June 23, 201510 yr Author To be fair, diesieben07, I am new to Minecraft modding and I still have things to learn - I am doing my best to get by, by looking for answers in vanilla code, but obviously I don't know the best methods, or even all of them. That's why I was asking for the best way t do what I wanted to do. I am by no means an idiot just because I am uninformed, so I won't take your reaction personally. But thanks for the pointer in the right direction.
June 23, 201510 yr Author I'm looking at potions, at the moment, to see how thrown potions know what effects to do. I think I get the idea. Thanks.
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.