Reply To: Enchanting Improvements

Home Forums General Enchanting Improvements Reply To: Enchanting Improvements

#1500
Coder J
Member

There are client mods that do this, along with client/server combination mods.

Enchanting in SMP is handled almost exclusively by the server, however. The server does not actually assign an enchantment until after the experience cost has been paid by the player. That means until that cost is paid, it is possible with the Bukkit API to change the level costs for enchantments.

—-
Code (going to look bad because I hate code tags….)
(Keep in mind I’m tired, there’s bound to be an error in here)
—-
[sourcecode language=”java”]
public void PreppyEnchanter(PrepareItemEnchantEvent event){
int MaxLevel = event.player.getLevel();
Random r = new Random();

for(int x=0; x MaxLevel; x++){
if(event.getExpLevelCostOffered()[x] > MaxLevel){
event.getExpLevelCostsOffered()[x] = r.nextInt(MaxLevel) + 1;
}
}
}
[/sourcecode]

This code checks all 3 indexes of getExpLevelCostsOffered, and if that’s greater than MaxLevel, rolls a new number between 1 and MaxLevel (nextInt actually rolls between 0 and MaxLevel-1, hence the +1)

  • This reply was modified 12 years, 5 months ago by Coder J. Reason: somehow left out the if statement
  • This reply was modified 12 years, 5 months ago by Coder J. Reason: okay... lost the if and part of for.... strange
  • This reply was modified 12 years, 5 months ago by Coder J.
  • This reply was modified 12 years, 5 months ago by PseudoKnight. Reason: shouldn't be parsing shortcode in code tags =(