Project MMO

Project MMO

11M Downloads

1.21.1 - pmmo:attribute perks not responding to changes or being removed.

Silvertide7 opened this issue ยท 1 comments

commented

Describe the bug
When gaining an attribute, like max_health from constitution:

set().event(SKILL_UP)
        .perk("pmmo:attribute")
        .skill(constitution)
        .attribute("minecraft:generic.max_health")
        .per_level(1.0)
        .max_boost(8.0);

I successfully gain the 1 max health. If I change the perks.pmmo per_level to 4.0 my max health doesn't update when I open the game back up, it's still the 1 extra max_health. Then if I remove constitution with /pmmo admin Silvertide clear it clears the skill but my max_health attribute doesn't change. If I gain another level in constitution it does seem to update it to the new values.

Expected behavior
When changing the perks.pmmo script my attribute would be updated with the new values when loading back in.
When clearing my skills the attributes would be updated / removed immediately

Versions:

  • Minecraft: 1.21.1
  • Loader: Neoforge 21.1.169
  • PMMO: 1.21.1-2.6.30
commented

SKILL_UP perks cannot be executed on load as they could include commands that give rewards.

Though, SKILL_UP perks could be filtered for attribute perks, clear the attributes, and rebuild...

I made the following for a PR to clear attributes from perks when using /pmmo admin <name> clear, but it could be adapted to clear the attributes and then run those perks again after they're clear.

	public static void clearAttributes(Player player) {
		for (CompoundTag nbt : Config.perks().perks().getOrDefault(EventType.SKILL_UP, new ArrayList<>()).stream()
				.filter(tag -> tag.getString("perk").equals("pmmo:attribute")).toList()) {
			Holder<Attribute> attribute = getAttribute(nbt);
			AttributeInstance instance = player.getAttributes().getInstance(attribute);
			if (instance != null)
				instance.removeModifier(attributeID(nbt.getString(APIUtils.ATTRIBUTE), nbt.getString(APIUtils.SKILLNAME)));
		}
	}

Could add a command for it to be run. Maybe something like /pmmo admin <name> resetAttributes or such.

The PR over here would do this on a skill-by-skill basis if you did a /pmmo admin <name> add <skill> level 0 but maybe an all-in-one would be better.