Skip to content

Commit

Permalink
fix: 从生物切换到玩家伪装后血量不会重置
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Jul 17, 2024
1 parent a3d938d commit f0d1947
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/main/java/xiamomc/morph/misc/DisguiseState.java
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,8 @@ public void dispose()

public void reset(boolean unDisguise)
{
this.provider.resetDisguise(this);

if (unDisguise)
this.provider.unMorph(getPlayer(), this);

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/xiamomc/morph/providers/DisguiseProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ public static CompoundTag cullNBT(CompoundTag compound)
@NotNull
public abstract DisguiseBackend<?, ?> getPreferredBackend();

/**
* Resets a player's some attributes from a disguise but not un-disguising them.
* Used for keeping disguise appearance while switching (if this provider allow switching to that disguise without un-disguise)
*
* @param state The {@link DisguiseState} to reset
*/
public void resetDisguise(DisguiseState state)
{
}

/**
* 取消某个玩家的伪装
* @param player 目标玩家
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/xiamomc/morph/providers/VanillaDisguiseProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,21 @@ private void removeAllHealthModifiers(Player player)
this.executeThenScaleHealth(player, attribute, () -> attribute.removeModifier(healthModifierKey));
}

@Override
public void resetDisguise(DisguiseState state)
{
var player = state.getPlayer();

removeAllHealthModifiers(player);
resetPlayerDimensions(player);
}

@Override
public boolean unMorph(Player player, DisguiseState state)
{
if (super.unMorph(player, state))
{
removeAllHealthModifiers(player);
resetPlayerDimensions(player);
resetDisguise(state);
return true;
}
else
Expand Down

0 comments on commit f0d1947

Please sign in to comment.