Skip to content

Commit 13ee7bd

Browse files
committed
finish update
1 parent 606bee0 commit 13ee7bd

8 files changed

+86
-53
lines changed

Diff for: README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ is to simply nerf the everliving heck out of it.
1919

2020
# Configuration
2121

22-
All configuration is done through the file `config/armor-nerf.json` in your `.minecraft` directory or through
22+
All configuration is done through the file `config/armor-nerf.json5` in your `.minecraft` directory or through
2323
[Mod Menu](https://modrinth.com/mod/modmenu). Vanilla values are shown here:
2424

2525
```json
2626
{
2727
"armorPercentage": 0.8,
2828
"protectionPerPoint": 0.04,
29-
"armorFormula": "VANILLA"
29+
"removeArmorLimit": false,
30+
"armorFormula": "vanilla"
3031
}
3132
```
3233

@@ -35,6 +36,8 @@ All configuration is done through the file `config/armor-nerf.json` in your `.mi
3536
`protectionPerPoint` is the percentage of damage reduction granted by each protection point. You can read up on what a
3637
protection point is [here](https://minecraft.wiki/w/Protection#Usage).
3738

39+
`removeArmorLimit`: removes the cap of 20 armor points.
40+
3841
`armorFormula` is the formula used to determine how armor and toughness affect damage taken. It can be one of these
3942
options:
4043

@@ -43,6 +46,7 @@ options:
4346
- `toughness_disabled`: Ignores the toughness system entirely.
4447
- `flat_toughness`: Toughness reduces the incoming damage by a flat amount.
4548
- `large_toughness`: Toughness makes armor more effective against larger attacks.
49+
- `crumbling_armor`: Rebel's insane formula that makes toughness add to the armor value based on durability.
4650

4751
# Extending
4852

Diff for: gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ org.gradle.parallel=true
99
loader_version=0.16.5
1010

1111
# Mod Properties
12-
mod_version = 2.1.1
12+
mod_version = 2.2.0
1313
maven_group = me.ryleu
1414
archives_base_name = armor-nerf
1515

Diff for: src/main/java/me/ryleu/armornerf/ArmorNerf.java

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public void onInitialize() {
4444
registerFormula("toughness_disabled", new ToughnessDisabledFormula());
4545
registerFormula("flat_toughness", new FlatToughnessFormula());
4646
registerFormula("large_toughness", new LargeToughnessFormula());
47+
registerFormula("crumbling_armor", new CrumblingArmorFormula());
4748
registerFormula("debug", new DebugFormula());
4849

4950
setArmorFormula(CONFIG.armorFormula());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package me.ryleu.armornerf.formula;
2+
3+
import me.ryleu.armornerf.ArmorFormula;
4+
import net.minecraft.component.DataComponentTypes;
5+
import net.minecraft.entity.LivingEntity;
6+
import net.minecraft.entity.damage.DamageSource;
7+
import net.minecraft.item.ItemStack;
8+
9+
public class CrumblingArmorFormula extends ArmorFormula {
10+
private final ArmorFormula baseFormula = new ToughnessDisabledFormula();
11+
12+
@Override
13+
public float calculate(
14+
LivingEntity armorWearer,
15+
float damageAmount,
16+
DamageSource damageSource,
17+
float armor,
18+
float armorToughness
19+
) {
20+
float totalMaxDamage = 0;
21+
float totalDamage = 0;
22+
23+
for (ItemStack itemStack : armorWearer.getAllArmorItems()) {
24+
25+
int maxDamage = itemStack.getOrDefault(DataComponentTypes.MAX_DAMAGE, 0);
26+
if (maxDamage == 0) {
27+
continue;
28+
}
29+
30+
totalMaxDamage += maxDamage;
31+
totalDamage += itemStack.getDamage();
32+
}
33+
34+
float toughnessAdder = (armorToughness / 4F) * (1F - totalDamage / totalMaxDamage);
35+
36+
return baseFormula.calculate(
37+
armorWearer,
38+
damageAmount,
39+
damageSource,
40+
armor + toughnessAdder,
41+
armorToughness
42+
);
43+
}
44+
}

Diff for: src/main/java/me/ryleu/armornerf/formula/DebugFormula.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,27 @@ public class DebugFormula extends ArmorFormula {
1313
private final FlatToughnessFormula flatToughnessFormula = new FlatToughnessFormula();
1414
private final LargeToughnessFormula largeToughnessFormula = new LargeToughnessFormula();
1515
private final ToughnessDisabledFormula toughnessDisabledFormula = new ToughnessDisabledFormula();
16+
private final CrumblingArmorFormula crumblingArmorFormula = new CrumblingArmorFormula();
1617
private final VanillaFormula vanillaFormula = new VanillaFormula();
1718

1819
@Override
1920
public float calculate(LivingEntity armorWearer, float damageAmount, DamageSource damageSource, float armor, float armorToughness) {
2021
Text name = armorWearer.getCustomName();
2122
LOGGER.debug(
22-
"!![{},{},{},{},{},{}]",
23+
"!![{},{},{},{},{},{},{}]",
2324
name,
2425
damageAmount,
2526
flatToughnessFormula.calculate(armorWearer, damageAmount, damageSource, armor, armorToughness),
2627
largeToughnessFormula.calculate(armorWearer, damageAmount, damageSource, armor, armorToughness),
2728
toughnessDisabledFormula.calculate(armorWearer, damageAmount, damageSource, armor, armorToughness),
29+
crumblingArmorFormula.calculate(armorWearer, damageAmount, damageSource, armor, armorToughness),
2830
vanillaFormula.calculate(armorWearer, damageAmount, damageSource, armor, armorToughness)
2931
);
3032

3133
return 0;
3234
}
3335

3436
public DebugFormula() {
35-
LOGGER.debug("!![name,none,flat,large,disabled,vanilla]");
37+
LOGGER.debug("!![name,none,flat,large,disabled,crumbling,vanilla]");
3638
}
3739
}
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
package me.ryleu.armornerf.formula;
22

33
import me.ryleu.armornerf.ArmorFormula;
4-
import me.ryleu.armornerf.ArmorNerf;
54
import net.minecraft.entity.LivingEntity;
65
import net.minecraft.entity.damage.DamageSource;
76

87
/**
98
* Toughness will reduce damage by a flat amount with this formula
109
*/
1110
public class FlatToughnessFormula extends ArmorFormula {
11+
private final ArmorFormula baseFormula = new ToughnessDisabledFormula();
12+
1213
@Override
1314
public float calculate(LivingEntity armorWearer, float damageAmount, DamageSource damageSource, float armor, float armorToughness) {
14-
float finalArmorFraction;
15-
float adjustedDamage = damageAmount - armorToughness / 4F;
16-
float armorValue = armor;
17-
18-
// whether to cap armor at a full bar -- will make many modded armors far more effective
19-
if (!ArmorNerf.CONFIG.removeArmorLimit()) {
20-
armorValue = Math.min(armorValue, 20.0F);
21-
}
22-
23-
// apply the config numbers
24-
float adjustedArmorFraction = (armorValue / 20.0F) * ArmorNerf.CONFIG.armorPercentage();
25-
26-
finalArmorFraction = applyEnchantments(damageSource, armorWearer, adjustedArmorFraction);
15+
float damageReduction = -armorToughness / 4F;
2716

28-
return adjustedDamage * (1.0F - finalArmorFraction);
17+
return baseFormula.calculate(
18+
armorWearer,
19+
// reduce the incoming damage by the toughness
20+
Math.max(0F, damageAmount + damageReduction),
21+
damageSource,
22+
armor,
23+
armorToughness
24+
);
2925
}
3026
}
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
11
package me.ryleu.armornerf.formula;
22

33
import me.ryleu.armornerf.ArmorFormula;
4-
import me.ryleu.armornerf.ArmorNerf;
54
import net.minecraft.entity.LivingEntity;
65
import net.minecraft.entity.damage.DamageSource;
76

87
/**
98
* Toughness will protect more against larger damage values with this formula
109
*/
1110
public class LargeToughnessFormula extends ArmorFormula {
11+
private final ArmorFormula baseFormula = new ToughnessDisabledFormula();
12+
1213
@Override
1314
public float calculate(LivingEntity armorWearer, float damageAmount, DamageSource damageSource, float armor, float armorToughness) {
14-
float finalArmorFraction;
15-
16-
// Increase armor at higher damage amounts
1715
float armorIncrease = Math.min(damageAmount, 20F) * armorToughness / 100F;
18-
float armorValue = armor + armorIncrease;
19-
20-
// whether to cap armor at a full bar -- will make many modded armors far more effective
21-
if (!ArmorNerf.CONFIG.removeArmorLimit()) {
22-
armorValue = Math.min(armorValue, 20.0F);
23-
}
24-
25-
// apply the config numbers
26-
float adjustedArmorFraction = (armorValue / 20.0F) * ArmorNerf.CONFIG.armorPercentage();
27-
28-
finalArmorFraction = applyEnchantments(damageSource, armorWearer, adjustedArmorFraction);
2916

30-
return damageAmount * (1.0F - finalArmorFraction);
17+
return baseFormula.calculate(
18+
armorWearer,
19+
damageAmount,
20+
damageSource,
21+
armor + armorIncrease,
22+
armorToughness
23+
);
3124
}
3225
}
+10-17
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
11
package me.ryleu.armornerf.formula;
22

33
import me.ryleu.armornerf.ArmorFormula;
4-
import me.ryleu.armornerf.ArmorNerf;
54
import net.minecraft.entity.LivingEntity;
65
import net.minecraft.entity.damage.DamageSource;
76

87
public class VanillaFormula extends ArmorFormula {
8+
private final ArmorFormula baseFormula = new ToughnessDisabledFormula();
9+
910
@Override
1011
public float calculate(LivingEntity armorWearer, float damageAmount, DamageSource damageSource, float armor, float armorToughness) {
11-
float finalArmorFraction;
12-
1312
float adjustedToughness = 2.0F + armorToughness / 4.0F;
1413

15-
// calculate armor toughness effectiveness reduction
16-
float armorValue = Math.max(armor - damageAmount / adjustedToughness, armor * 0.2F);
17-
18-
// whether to cap armor at a full bar -- will make many modded armors far more effective
19-
if (!ArmorNerf.CONFIG.removeArmorLimit()) {
20-
armorValue = Math.min(armorValue, 20.0F);
21-
}
22-
23-
// apply the config numbers
24-
float adjustedArmorFraction = (armorValue / 20.0F) * ArmorNerf.CONFIG.armorPercentage();
25-
26-
finalArmorFraction = applyEnchantments(damageSource, armorWearer, adjustedArmorFraction);
27-
28-
return damageAmount * (1.0F - finalArmorFraction);
14+
return baseFormula.calculate(
15+
armorWearer,
16+
damageAmount,
17+
damageSource,
18+
// calculate armor toughness effectiveness reduction
19+
Math.max(armor - damageAmount / adjustedToughness, armor * 0.2F),
20+
armorToughness
21+
);
2922
}
3023
}

0 commit comments

Comments
 (0)