diff --git a/gradle.properties b/gradle.properties index 8de2252..680b52f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ yarn_mappings=1.16.4+build.7 loader_version=0.10.8 # Mod Properties -mod_version=0.2.7 +mod_version=0.2.8 maven_group=xyz.nucleoid archives_base_name=fantasy diff --git a/src/main/java/xyz/nucleoid/fantasy/player/PlayerResetter.java b/src/main/java/xyz/nucleoid/fantasy/player/PlayerResetter.java index 3219ca2..78c1399 100644 --- a/src/main/java/xyz/nucleoid/fantasy/player/PlayerResetter.java +++ b/src/main/java/xyz/nucleoid/fantasy/player/PlayerResetter.java @@ -1,7 +1,12 @@ package xyz.nucleoid.fantasy.player; +import net.minecraft.entity.attribute.AttributeContainer; +import net.minecraft.entity.attribute.EntityAttribute; +import net.minecraft.entity.attribute.EntityAttributeInstance; +import net.minecraft.entity.attribute.EntityAttributeModifier; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.registry.Registry; public final class PlayerResetter { private final CompoundTag resetTag; @@ -11,8 +16,28 @@ public PlayerResetter(CompoundTag resetTag) { } public void apply(ServerPlayerEntity player) { - player.fromTag(this.resetTag); + this.clearAttributeModifiers(player); player.clearStatusEffects(); player.getScoreboardTags().clear(); + + player.fromTag(this.resetTag); + } + + private void clearAttributeModifiers(ServerPlayerEntity player) { + AttributeContainer attributes = player.getAttributes(); + for (EntityAttribute attribute : Registry.ATTRIBUTE) { + if (attributes.hasAttribute(attribute)) { + EntityAttributeInstance instance = attributes.getCustomInstance(attribute); + if (instance != null) { + this.clearModifiers(instance); + } + } + } + } + + private void clearModifiers(EntityAttributeInstance instance) { + for (EntityAttributeModifier modifier : instance.getModifiers()) { + instance.removeModifier(modifier); + } } }