Jump to content

[1.15.2] Enchantment Weight and Item Stack Transformation


Cryotron

Recommended Posts

Alright, so I've looked into enchantments for awhile and there are so many things that perplexes me. I've seen a lot of tutorials that creates the custom enchants that grants various effects of the modders desire. However, my intent with the enchantments are creating items that has specialized different weights as well as functions like an enchantment book but with a capability. In fact, there are two things that I would like to accomplish:

 

1. If I put the custom item in the Enchanting Table and select one of the three given enchantment options, the item becomes its enchanted version of it and put the selected enchantment on it and only the selected enchantment. Currently, I'm struggling to understand how can an item stack such as a book turning into enchantment book and there are a lot of different class files that checks the book that's all over the place. This is kind of a reason why I asked if there is such a thing for an Enchantment Event. So how do I transform an item stack on an enchantment table much like the book? Is there a way to limit the number of enchantments applied on that item?

 

2. How do I adjust the weight of the enchantment rarity based on the item that the Enchantment Table is enchanting? For instance, I have Ruby that has a fixed weight for Sharpness, Fire Aspect, Power, Flame and Impale in contrasts of their normal weights of 10, 2, 10, 2, 2 respectively. When you put a Ruby on an Enchantment Table, all the listed Enchantments have fixed and equal amount of rarity and weights and like example shown from #1, it would turn into Enchanted Ruby with whichever the three enchantment a player selected. 

 

So #1 is about Enchanting an Item Stack that turns it into an Enchanted Version of the Item with only one enchantment on it and #2 is about adjusting Enchantment weight based on item stack. My question that fits the two is: Is there a feasible way to accomplish those two objectives? Or in fact, I would like to know if the two objectives are possible to achieve with the tools given to me.

 

	   @Override
	   public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment)
	   {	 
	   	 return true;
	   }

 

Looking at this method, the only thing I have done so far is to restrict enchantments which is not what I'm trying to achieve. My question is how do I change the enchantment rarity and weight based on the item, transform an item stack to the enchanted version of it and only apply ONE selected enchantment regardless of the enchantment level?

 

... 

Link to comment
Share on other sites

41 minutes ago, Cryotron said:

Currently, I'm struggling to understand how can an item stack such as a book turning into enchantment book

NBT data

 

41 minutes ago, Cryotron said:

So how do I transform an item stack on an enchantment table much like the book? Is there a way to limit the number of enchantments applied on that item?

I believe EnchantmentHelper is what you're looking for.

That or ItemStack#addEnchantment. Been a while since I messed with it.

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.

Link to comment
Share on other sites

6 minutes ago, Draco18s said:

NBT data

 

I believe EnchantmentHelper is what you're looking for.

That or ItemStack#addEnchantment. Been a while since I messed with it.

NBT data seems new, I'll look more into it.

 

Seems like it is possible to do the two objectives. :D

Link to comment
Share on other sites

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



×
×
  • Create New...

Important Information

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