-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix max health not being restored in some scenarios.
This is a backport of the fixes from 1.20.4 for #7 and #5. It also contains the fix for some modded attribute sources being applied too late in the load cycle.
- Loading branch information
Showing
4 changed files
with
54 additions
and
18 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
Common/src/main/java/net/darkhax/maxhealthfix/IHealthFixable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package net.darkhax.maxhealthfix; | ||
|
||
public interface IHealthFixable { | ||
|
||
void maxhealthfix$setRestorePoint(float restorePoint); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
Common/src/main/java/net/darkhax/maxhealthfix/mixin/MixinPlayerList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package net.darkhax.maxhealthfix.mixin; | ||
|
||
import net.darkhax.maxhealthfix.IHealthFixable; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.server.players.PlayerList; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
import java.util.Optional; | ||
|
||
@Mixin(PlayerList.class) | ||
public class MixinPlayerList { | ||
|
||
@Inject(method = "respawn(Lnet/minecraft/server/level/ServerPlayer;Z)Lnet/minecraft/server/level/ServerPlayer;", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;setHealth(F)V"), locals = LocalCapture.CAPTURE_FAILSOFT) | ||
private void onPlayerRespawn(ServerPlayer oldPlayer, boolean fromEnd, CallbackInfoReturnable<ServerPlayer> cbi, BlockPos respawnPos, float respawnAngle, boolean wasForced, ServerLevel oldDimension, Optional<Vec3> calculatedPos, ServerLevel overworld, ServerPlayer newPlayer) { | ||
|
||
if (newPlayer instanceof IHealthFixable fixable) { | ||
|
||
fixable.maxhealthfix$setRestorePoint(oldPlayer.getMaxHealth()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters