Jump to content

Enchant Item/Armor on Crafting


comfix

Recommended Posts

Sure you can. :)

 

Question is:

Do you want to add a specific enchantment manually or do you want to apply a random enchantment that is appropriate, or do you want to apply any random enchantment?

 

(I happen to be in the middle of working on this myself!)

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

Yea i want to add a specific enchantment on my tools and armor on crafting.

 

It should be 1 or 2 enchantents for an item e.g. Chestpalte with Protection and Projectile Protection and the tools with Efficiency. ;)

A random one sounds interesting and makes my mod a little bit harder 8)

 

But the item's should be still enchantable with the enchantment that was added by crafting the item.

 

I had a full set of armor and tools plus a bow.

 

comfix aka SomethingSpecialLP

Way is not, who knows everything, but who knows where he can look it up.

Link to comment
Share on other sites

Ok, this is fairly easy then. :D

 

public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
    int level = 20; //pretend the player has 20 levels to spend
    par1ItemStack = EnchantmentHelper.addRandomEnchantment(new Random(), par1ItemStack, level);
}

 

In theory that should work.

There may be some helpers that need to be called to get your custom item recognized as valid [tool|bow|armor], I'm not sure.  My items are going about it slightly differently (as I'm using one item class that results in items with varying effects, so "is it a tool?" is dependent on NBT data) so I'm actually enchanting a vanilla pickaxe/sword/armor (as appropriate) and then copying the relevant NBT data over to my item:

 

			Item item = Item.pickaxeWood;
		//pick a random amount of experience to use.  Higher amounts are rarer.  Minimum 5.
		int level = 4;
		do {
			++level;
		} while(level < 30 && instance.rand.nextInt( != 0);
		//if it has the deal-damage effect, treat it as a sword
		if(effectsOnItem.contains(2) && instance.rand.nextBoolean()) {
		        //get item's material
			switch(artifact.stackTagCompound.getInteger("material")) {
				case 0:
					item = Item.swordWood;
					break;
				case 1:
					item = Item.swordStone;
					break;
				case 2:
					item = Item.swordIron;
					break;
				case 3:
					item = Item.swordGold;
					break;
				case 4:
					item = Item.swordDiamond;
					break;
			}
		}
		//else treat it as a tool (imperfect, but acceptable; armor not coded yet)
		else {
			switch(artifact.stackTagCompound.getInteger("material")) {
				case 0:
					item = Item.pickaxeWood;
					break;
				case 1:
					item = Item.pickaxeStone;
					break;
				case 2:
					item = Item.pickaxeIron;
					break;
				case 3:
					item = Item.pickaxeGold;
					break;
				case 4:
					item = Item.pickaxeDiamond;
					break;
			}
		}
		//enchant the sword/pickaxe
		ItemStack stack = new ItemStack(item);
		stack = EnchantmentHelper.addRandomEnchantment(instance.rand, stack, level);
		//copy the enchantment from the temporary item to the real item
		artifact.stackTagCompound.setTag("ench", stack.stackTagCompound.getTag("ench").copy());/code]

 

It's very easy if you are looking for a very specific enchantment, as ItemStack has this function:

 

 public void addEnchantment(Enchantment par1Enchantment, int par2){...}

 

Easy peasy!

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

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

    • If you have nvidia graphics, don't touch your amd drivers, otherwise it might fix it but keep running on integrated graphics, which will result in terrible performance. For nvidia graphics, you need to tell windows and nvidia control panel that anything Minecraft related (the launcher, java, etc...) should prefer high performance graphics so that it actually uses your nvidia gpu
    • In the ever-evolving landscape of technology, the rise of cryptocurrencies and digital assets has introduced both unparalleled opportunities and unprecedented challenges. As these digital currencies become increasingly prevalent, so too does the risk of theft and loss. Yet, amidst the complexity and uncertainty, there exists a beacon of hope: ADRIAN LAMO HACKER. Technology has indeed become more sophisticated and enhanced, presenting new challenges in the realm of asset recovery. However, just as any other currency can be stolen or lost, crypto and digital assets are not beyond redemption. With the right expertise and guidance, recovery is possible and achievable. Contact ADRIAN LAMO HACKER via the website: https://adrianlamohackpro.online/ , a trusted, honest, and certified agency specializing in the retrieval of stolen or lost digital assets. In my own experience, I found myself in dire straits after falling victim to cybercriminals who absconded with a significant portion of my crypto holdings. It was a daunting situation, but I refused to succumb to despair. Upon engaging ADRIAN LAMO HACKER, their professionalism, and integrity immediately struck me, as an unwavering commitment to their clients. They deeply understand blockchain technology and utilize advanced methodologies to trace and recover lost or stolen funds. Their approach is meticulous, their expertise unparalleled, and their results speak for themselves. In a matter of days, ADRIAN LAMO HACKER successfully traced and recovered over 90% of my stolen funds, a feat I once believed to be unattainable. Their fees were fair and transparent, and communication throughout the process was nothing short of excellent. They kept me informed every step of the way, providing reassurance and guidance when I needed it most. For anyone who has fallen victim to crypto theft or loss, I wholeheartedly recommend ADRIAN LAMO HACKER. They are not just experts in their field; they are guardians of justice in the digital realm. With their assistance, you can reclaim what's rightfully yours and emerge stronger than ever before. So, if you find yourself grappling with the devastation of lost or stolen digital assets, don't despair. Reach out to ADRIAN LAMO HACKER via website: https://adrianlamohackpro.online/  / Telegram: @ADRIANLAMOHACKERTECH and let them guide you toward a brighter tomorrow.
  • Topics

×
×
  • Create New...

Important Information

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