Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unbreaking Enchantment Support #4

Closed
cjstas opened this issue May 20, 2021 · 4 comments
Closed

Unbreaking Enchantment Support #4

cjstas opened this issue May 20, 2021 · 4 comments

Comments

@cjstas
Copy link

cjstas commented May 20, 2021

It would be nice to have support for the unbreaking enchantment. It seems like it would be simple enough to implement when the use tool durability modifier is on, just check if the unbreaking enchantment is there and then apply a durability change according to the level of unbreaking and then make a percentage chance to use durability according to the value. Code could look something like this.
if (useDurabilityPerBlock|| !player.hasPermission("powermining.highdurability")) {
if (curDur++ < maxDur){
int useChance = 0;
if (enchants.get(Enchantment.DURABILITY) !=null) {
useChance += enchants.get(Enchantment.DURABILITY)
}
if (100/(Math.pow(2, useChance))>=(int)Math.floor(Math.random()*(101))) {
handItem.setDurability(curDur);
}
} else {
break;
}
}

Code may not be perfect as it is untested. I plan to fork this repo to try to implement this myself.

@cjstas
Copy link
Author

cjstas commented May 20, 2021

I have forked and successfully used this code to implement the Unbreaking Enchantment. I am not submitting a pull request because when I pushed my changes it removed the iml file for some reason. The plugin works with this feature though, so feel free and use that code if you would like

Here is the fork https://github.com/cjstas/JodellePowerMining

@alexfilipemb98
Copy link
Collaborator

I have forked and successfully used this code to implement the Unbreaking Enchantment. I am not submitting a pull request because when I pushed my changes it removed the iml file for some reason. The plugin works with this feature though, so feel free and use that code if you would like

Here is the fork https://github.com/cjstas/JodellePowerMining

hello there thank you much for helping us <3

@mgl23606
Copy link
Owner

Thank you very much for reminding of the unbreaking enchantment. I may or may not have forgotten about it 😆

According to the wiki page the durability enchant has a probability of 100/level+1.

I tried a very basic implementation of this logic. When I have time I'll take a closer look at it.

@mgl23606
Copy link
Owner

I finished implementing the unbreaking enchantment.
Everything should work properly now, if not please open another issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants