Jump to content

Recommended Posts

Posted

So I am Making a weapon(not really a sword), and have some NBT that goes with the weapon. I was thinking that I wanted souls that will go into the NBT and change the weapons stats. Now where I need help is with the best way to implement this, as in should I have a item GUI or should I do it when the soul is right clicked. I was thinking the soul is right clicked, but wasn't sure if there was a way to check if the weapon was in players inventory. 

 

Edit: I guess I am asking two things

 

1: how should I go about doing my task.

2: If I go the one rout how can I do it .

~SureShotM/Leo~ gaming coding all around fun!

Posted

Right-clicking, assuming you mean while the sword is in hand, would be the simplest implementation - you already know that the player is holding your sword by the fact that your sword's Item#onItemRightClick method was called, and you won't have to deal with all the complications of a GUI (IGuiHandler, opening the GUI, sending packets to server, etc.).

 

onItemRightClick is called on both client and server, so you can do all the server-side things (such as changing the ItemStack NBT) directly from there.

 

If you want the 'soul' is an entity, though, it might be better to handle this from your Entity class' interact method (or whatever it's callled - don't have my IDE open right now), since it can be tricky to get the clicked entity from the Item method. Then you just have to check the held item of the entity that is interacting with the soul using #getHeldItem().

Posted

Hmmmm? the thought of having the soul as an entity never crossed my mind, I was thinking the soul as an item that when you right click it will change the swords NBT. Now I have some more thinking to do, brb if anymore questions pop up. 

~SureShotM/Leo~ gaming coding all around fun!

Posted

Would it be more approachable if you were to have multiple "material" types that you could convert to? I imagine you could right-click the SWORD and consume a soul item, then swap materials, or even swap entire swords, removing the one clicked from your inventory and placing the new one in its place. If you had multiple "types" of swords, then you could use a series of "if" statements to determine which souls would be prioritized for consumption. I don't know enough about your ideal game-mechanics to flesh this idea out, but this is how I would do it.

Posted

@Exo594 that is a good idea as well but I think I have a better idea.

 

My question for this idea would be, is it possible to have a Item talk to another Item.

 

ex: In sword class. if baubles item is equiped and if it has NBT tag of soul do what ever to change the sword(increase damage, or enchant sword ect.

~SureShotM/Leo~ gaming coding all around fun!

Posted

If you just want the damage to change based on number of souls, you would simply override Item#getAttributeModifiers(ItemStack) to return a multimap with the appropriately leveled AttributeModifier for attack damage according to the ItemStack NBT.

 

If you need access to another item in the player's inventory (vanilla or otherwise), it becomes slightly more complicated. There is no way to know about any other items or other player-related info in the method mentioned above, so you'd probably have to use the LivingHurtEvent to modify damage and the PlayerTickEvent to check for the equipped item every tick and apply or remove whatever enchantment, but you'd also need to make sure the item tooltip displays the correct damage amount, prevent the re-equip animation from playing each time you update the NBT, etc.

 

Lots more things to think about in the second situation, as you can see, which is why I would recommend you start with the simpler version and go from there. It's far easier to make something simple that works more complicated, rather than trying to make something complicated immediately and trying to figure out why it's not working. One step at a time.

Posted

Okay so I finally got the soul function to work, now I forgot about the one other function that was asked for and that was no matter how much damage the souls increase it will always do .5 more damage to players.

 

Would I need to use,

 

@Override

public void onHitEntity(not sure what goes in here){

}

 

To achieve this, if so can some one link  me to an example of how it is used.

~SureShotM/Leo~ gaming coding all around fun!

Posted

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.

Posted

Okay one last question and I should be good.

 

Is there a way to remove an enchantment.

 

What I have so far is mt weapon adds enchantments on right click.

 

What I want to do now is on update if the weapons nbt Boolean is false it will remove the enchantments, how would I achieve this since I do not see a removeEnchantment as a function under ItemStack.

~SureShotM/Leo~ gaming coding all around fun!

Posted

There is no easy way to remove an enchantment, but it can be done by iterating through the enchantment list stored in the ItemStack's NBT and removing a specific enchantment that way.

 

E.g.

NBTTagList enchList = stack.getTagCompound().getTagList("ench", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < enchList.tagCount(); ++i) {
NBTTagCompound compound = enchList.getCompoundTagAt(i);
if (compound.getShort("id") == Enchantment.whatever.effectId) {
	enchList.remove(i); // example only - you should use Iterators when removing elements from a Collection
}
}

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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