Skip to content

Commit b1f301b

Browse files
committed
update to 1.21
1 parent 91ee92d commit b1f301b

13 files changed

+131
-46
lines changed

Diff for: build.gradle

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
plugins {
2-
id 'fabric-loom' version '1.1-SNAPSHOT'
2+
id 'fabric-loom' version '1.7-SNAPSHOT'
33
id 'maven-publish'
44
}
55

6-
sourceCompatibility = JavaVersion.VERSION_17
7-
targetCompatibility = JavaVersion.VERSION_17
8-
96
archivesBaseName = project.archives_base_name
107
version = project.mod_version
118
group = project.maven_group
@@ -36,15 +33,17 @@ processResources {
3633
}
3734

3835
tasks.withType(JavaCompile).configureEach {
39-
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
40-
it.options.release = 17
36+
it.options.release = 21
4137
}
4238

4339
java {
4440
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
4541
// if it is present.
4642
// If you remove this line, sources will not be generated.
4743
withSourcesJar()
44+
45+
sourceCompatibility = JavaVersion.VERSION_21
46+
targetCompatibility = JavaVersion.VERSION_21
4847
}
4948

5049
jar {

Diff for: gradle.properties

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ org.gradle.parallel=true
44

55
# Fabric Properties
66
# check these on https://fabricmc.net/develop
7-
minecraft_version=1.20.1
8-
yarn_mappings=1.20.1+build.10
9-
loader_version=0.15.11
7+
minecraft_version=1.21
8+
yarn_mappings=1.21+build.9
9+
loader_version=0.16.5
1010

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

1616
# Dependencies
1717
# https://maven.wispforest.io/io/wispforest/owo-lib/
18-
owo_version=0.11.2+1.20
18+
owo_version=0.12.14+1.21
1919

20-
#fabric_version=0.92.2+1.20.1
20+
fabric_version=0.102.0+1.21

Diff for: gradle/wrapper/gradle-wrapper.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
#Mon Sep 30 01:29:59 CDT 2024
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
4-
networkTimeout=10000
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

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

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
package me.ryleu.armornerf;
22

3+
import net.minecraft.enchantment.EnchantmentHelper;
4+
import net.minecraft.entity.LivingEntity;
5+
import net.minecraft.entity.damage.DamageSource;
6+
import net.minecraft.item.ItemStack;
7+
import net.minecraft.server.world.ServerWorld;
8+
import net.minecraft.util.math.MathHelper;
9+
import net.minecraft.world.World;
10+
311
public abstract class ArmorFormula {
4-
public abstract float calculate(float damage, float armor, float armorToughness);
12+
public abstract float calculate(LivingEntity armorWearer, float damageAmount, DamageSource damageSource, float armor, float armorToughness);
13+
14+
public static float applyEnchantments(DamageSource damageSource, LivingEntity armorWearer, float armorFraction) {
15+
ItemStack itemStack = damageSource.getWeaponStack();
16+
if (itemStack != null) {
17+
World world = armorWearer.getWorld();
18+
if (world instanceof ServerWorld serverWorld) {
19+
// apply enchantment effects like breaching
20+
return MathHelper.clamp(
21+
EnchantmentHelper.getArmorEffectiveness(
22+
serverWorld,
23+
itemStack,
24+
armorWearer,
25+
damageSource,
26+
armorFraction
27+
), 0.0F, 1.0F
28+
);
29+
}
30+
}
31+
32+
return armorFraction;
33+
}
534
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class ConfigModel {
1414
@RangeConstraint(min = 0F, max = 0.0625F)
1515
public float protectionPerPoint = 0.02F;
1616

17+
public boolean removeArmorLimit = true;
18+
1719
@Hook
1820
@PredicateConstraint("armorFormulaPredicate")
1921
public String armorFormula = "toughness_disabled";

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

+18-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,29 @@
22

33
import me.ryleu.armornerf.ArmorFormula;
44
import me.ryleu.armornerf.ArmorNerf;
5-
import net.minecraft.util.math.MathHelper;
5+
import net.minecraft.entity.LivingEntity;
6+
import net.minecraft.entity.damage.DamageSource;
67

78
/**
89
* Toughness will reduce damage by a flat amount with this formula
910
*/
1011
public class FlatToughnessFormula extends ArmorFormula {
1112
@Override
12-
public float calculate(float damage, float armor, float armorToughness) {
13-
float adjustedDamage = damage - armorToughness / 4F; // divide by the number of armor pieces
14-
// divide by 20 to get a percentage of the armor bar filled
15-
float adjustedArmor = MathHelper.clamp((armor / 20F) * ArmorNerf.CONFIG.armorPercentage(), 0F, 1F);
16-
return adjustedDamage * (1F - adjustedArmor);
13+
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);
27+
28+
return adjustedDamage * (1.0F - finalArmorFraction);
1729
}
1830
}

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

+20-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,31 @@
22

33
import me.ryleu.armornerf.ArmorFormula;
44
import me.ryleu.armornerf.ArmorNerf;
5+
import net.minecraft.entity.LivingEntity;
6+
import net.minecraft.entity.damage.DamageSource;
57

68
/**
79
* Toughness will protect more against larger damage values with this formula
810
*/
911
public class LargeToughnessFormula extends ArmorFormula {
1012
@Override
11-
public float calculate(float damage, float armor, float armorToughness) {
12-
float armorIncrease = Math.min(damage, 20F) * armorToughness / 100F;
13-
float adjustedArmor = ((armor + armorIncrease) / 20F) * ArmorNerf.CONFIG.armorPercentage();
14-
return (1 - adjustedArmor) * damage;
13+
public float calculate(LivingEntity armorWearer, float damageAmount, DamageSource damageSource, float armor, float armorToughness) {
14+
float finalArmorFraction;
15+
16+
// Increase armor at higher damage amounts
17+
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);
29+
30+
return damageAmount * (1.0F - finalArmorFraction);
1531
}
1632
}

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

+18-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,26 @@
22

33
import me.ryleu.armornerf.ArmorFormula;
44
import me.ryleu.armornerf.ArmorNerf;
5-
import net.minecraft.util.math.MathHelper;
5+
import net.minecraft.entity.LivingEntity;
6+
import net.minecraft.entity.damage.DamageSource;
67

78
public class ToughnessDisabledFormula extends ArmorFormula {
89
@Override
9-
public float calculate(float damage, float armor, float armorToughness) {
10-
float adjustedArmor = MathHelper.clamp((armor / 20F) * ArmorNerf.CONFIG.armorPercentage(), 0F, 1F);
11-
return damage * (1F - adjustedArmor);
10+
public float calculate(LivingEntity armorWearer, float damageAmount, DamageSource damageSource, float armor, float armorToughness) {
11+
float finalArmorFraction;
12+
13+
float armorValue = armor;
14+
15+
// whether to cap armor at a full bar -- will make many modded armors far more effective
16+
if (!ArmorNerf.CONFIG.removeArmorLimit()) {
17+
armorValue = Math.min(armorValue, 20.0F);
18+
}
19+
20+
// apply the config numbers
21+
float adjustedArmorFraction = (armorValue / 20.0F) * ArmorNerf.CONFIG.armorPercentage();
22+
23+
finalArmorFraction = applyEnchantments(damageSource, armorWearer, adjustedArmorFraction);
24+
25+
return damageAmount * (1.0F - finalArmorFraction);
1226
}
1327
}

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

+21-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,29 @@
22

33
import me.ryleu.armornerf.ArmorFormula;
44
import me.ryleu.armornerf.ArmorNerf;
5+
import net.minecraft.entity.LivingEntity;
6+
import net.minecraft.entity.damage.DamageSource;
57

68
public class VanillaFormula extends ArmorFormula {
79
@Override
8-
public float calculate(float damage, float armor, float armorToughness) {
9-
float armorReduction = damage / (2F + armorToughness / 4F);
10-
float adjustedArmor = Math.min(Math.max(
11-
armor * 0.2F, // large damage amounts cannot lower the armor below 20% efficacy
12-
(armor - armorReduction)
13-
) * ArmorNerf.CONFIG.armorPercentage() / 20F, 1F);
14-
return damage * (1F - adjustedArmor);
10+
public float calculate(LivingEntity armorWearer, float damageAmount, DamageSource damageSource, float armor, float armorToughness) {
11+
float finalArmorFraction;
12+
13+
float adjustedToughness = 2.0F + armorToughness / 4.0F;
14+
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);
1529
}
1630
}

Diff for: src/main/java/me/ryleu/armornerf/mixin/DamageUtilMixin.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import me.ryleu.armornerf.ArmorNerf;
44
import net.minecraft.entity.DamageUtil;
5+
import net.minecraft.entity.LivingEntity;
6+
import net.minecraft.entity.damage.DamageSource;
57
import net.minecraft.util.math.MathHelper;
68
import org.spongepowered.asm.mixin.Mixin;
79
import org.spongepowered.asm.mixin.injection.At;
@@ -13,16 +15,13 @@
1315
public class DamageUtilMixin {
1416
@Inject(
1517
at = @At(value = "RETURN"),
16-
method = "getDamageLeft(FFF)F",
18+
method = "getDamageLeft(Lnet/minecraft/entity/LivingEntity;FLnet/minecraft/entity/damage/DamageSource;FF)F",
1719
cancellable = true
1820
)
1921
private static void modifyGetDamageLeft(
20-
float damage,
21-
float armor,
22-
float armorToughness,
23-
CallbackInfoReturnable<Float> cir
22+
LivingEntity armorWearer, float damageAmount, DamageSource damageSource, float armor, float armorToughness, CallbackInfoReturnable<Float> cir
2423
) {
25-
cir.setReturnValue(Math.max(0F, ArmorNerf.getToughnessFormula().calculate(damage, armor, armorToughness)));
24+
cir.setReturnValue(Math.max(0F, ArmorNerf.getToughnessFormula().calculate(armorWearer, damageAmount, damageSource, armor, armorToughness)));
2625
}
2726

2827
@Inject(

Diff for: src/main/resources/armornerf.mixins.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"required": true,
3-
"minVersion": "0.8",
43
"package": "me.ryleu.armornerf.mixin",
5-
"compatibilityLevel": "JAVA_17",
4+
"compatibilityLevel": "JAVA_21",
65
"mixins": [
76
"DamageUtilMixin"
87
],

Diff for: src/main/resources/assets/armor-nerf/lang/en_us.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"text.config.armor-nerf.title": "Armor Nerf Configuration",
33
"text.config.armor-nerf.option.armorPercentage": "Armor Percentage",
44
"text.config.armor-nerf.option.protectionPerPoint": "Protection per Point",
5+
"text.config.armor-nerf.option.removeArmorLimit": "Remove Armor Limit",
56
"text.config.armor-nerf.option.armorFormula": "Armor Formula"
67
}

Diff for: src/main/resources/fabric.mod.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
],
2828

2929
"depends": {
30-
"minecraft": "1.20.1",
31-
"java": ">=17"
30+
"minecraft": "1.21",
31+
"java": ">=21"
3232
},
3333

3434
"custom": {

0 commit comments

Comments
 (0)