Skip to content

Commit

Permalink
fix skill tree unlock check in FactionPlayerHandler construction
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed Mar 17, 2024
1 parent 65a6083 commit 9ab8835
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,12 @@ public interface IFactionPlayerHandler extends ILordPlayer, IPlayer {
* @param die Whether to attack the player with deadly damage
*/
void leaveFaction(boolean die);

/**
* Checks which skill trees are unlocked.
* It locks and unlocks the skill trees accordingly.
* <p>
* It is called when the player level or lord level changes as well as when the player respawns. But it can be called at any time.
*/
void checkSkillTreeLocks();
}
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ private void loadBoundActions(@NotNull CompoundTag nbt) {
}
}

private void checkSkillTreeLocks() {
@Override
public void checkSkillTreeLocks() {
if (this.player.level() instanceof ServerLevel level) {
Registry<ISkillTree> registryAccess = this.player.level().registryAccess().registryOrThrow(VampirismRegistries.Keys.SKILL_TREE);
getCurrentFactionPlayer().ifPresent(factionPlayer -> {
Expand Down Expand Up @@ -509,8 +510,6 @@ public void deserializeNBT(@NotNull CompoundTag nbt) {
} else {
currentLevel = Math.min(nbt.getInt("level"), this.currentFaction.getHighestReachableLevel());
currentLordLevel = Math.min(nbt.getInt("lord_level"), this.currentFaction.getHighestLordLevel());
this.checkSkillTreeLocks();
updateCache();
notifyFaction(null, 0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,4 +512,9 @@ public void onPlayerGameMode(PlayerEvent.PlayerChangeGameModeEvent event) {
FactionPlayerHandler.getCurrentFactionPlayer(event.getEntity()).ifPresent(factionPlayer -> factionPlayer.getActionHandler().deactivateAllActions());
}
}

@SubscribeEvent
public void onRespawn(PlayerEvent.PlayerRespawnEvent event) {
FactionPlayerHandler.get(event.getEntity()).checkSkillTreeLocks();
}
}

0 comments on commit 9ab8835

Please sign in to comment.