Skip to content

Commit

Permalink
clear player attribute modifiers when resetting
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed May 7, 2021
1 parent cd042ea commit 36e8533
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 26 additions & 1 deletion src/main/java/xyz/nucleoid/fantasy/player/PlayerResetter.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}
}

0 comments on commit 36e8533

Please sign in to comment.