Advanced-Tools

Advanced-Tools

58.5k Downloads

How to correctly decrease damage so your tools don't break

ricksouth opened this issue ยท 2 comments

commented

Hi henkelmax,

I'm working on my mod Tree Harvester, and I want to decrease the tool's damage per harvested log. I'm currently using this code, which works with vanilla tools. How can I alter this so it works with your advanced tools?

Thanks,
Rick

int durabilitycount = Util.breakTreeAndGetDurability(world, bpos, logcount);
if (ConfigHandler.GENERAL.loseDurabilityPerHarvestedLog.get() && hand != null && player instanceof ServerPlayerEntity) {
	boolean broken = hand.attemptDamageItem(durabilitycount, GlobalVariables.random, (ServerPlayerEntity)player);
	if (broken) {
		hand.shrink(1);
	}
}

When I tried to add compatibility before I used this code:

int durabilitycount = Util.breakTreeAndGetDurability(world, bpos, logcount);
if (ConfigHandler.GENERAL.loseDurabilityPerHarvestedLog.get() && hand != null && player instanceof ServerPlayerEntity) {
	hand.attemptDamageItem(durabilitycount, GlobalVariables.random, (ServerPlayerEntity)player);
	if (hand.getDamage() >= hand.getMaxDamage()) {
		hand.setDamage(hand.getMaxDamage());
	}
}

But that caused other issues unfortunately. Which is why I thought I'll just ask :)

commented

https://github.com/henkelmax/reap/blob/8b6b86da91abbc3303f42b248e1512b89106d8ed/src/main/java/de/maxhenkel/reap/TreeEvents.java#L133
This is how I did it in the reap mod, that also has a tree harvester. Should work with every tool from every mod.

commented

Thank you! I managed to get it to work with your help. Closing the issue.