Update dependencies, enhance fortitude health handling and lifecycle logic, and update changelog
This commit is contained in:
@@ -6,16 +6,22 @@ import net.fretux.ascend.player.StatEffects;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = AscendMod.MODID)
|
||||
public class PlayerEvents {
|
||||
|
||||
private static final ResourceLocation PLAYER_STATS_ID =
|
||||
ResourceLocation.fromNamespaceAndPath(AscendMod.MODID, "player_stats");
|
||||
private static final Set<UUID> PENDING_FULL_HEALTH_RESTORE = new HashSet<>();
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onAttachCapabilities(AttachCapabilitiesEvent<Entity> event) {
|
||||
@@ -37,6 +43,7 @@ public class PlayerEvents {
|
||||
StatEffects.applyAll(event.getEntity());
|
||||
if (event.isWasDeath()) {
|
||||
event.getEntity().setHealth(event.getEntity().getMaxHealth());
|
||||
PENDING_FULL_HEALTH_RESTORE.add(event.getEntity().getUUID());
|
||||
}
|
||||
PlayerStatsProvider.sync(event.getEntity());
|
||||
}
|
||||
@@ -50,8 +57,22 @@ public class PlayerEvents {
|
||||
if (Math.abs(healthBeforeFortitude - 20.0F) < 0.001F
|
||||
&& event.getEntity().getMaxHealth() > healthBeforeFortitude) {
|
||||
event.getEntity().setHealth(event.getEntity().getMaxHealth());
|
||||
PENDING_FULL_HEALTH_RESTORE.add(event.getEntity().getUUID());
|
||||
}
|
||||
PlayerStatsProvider.sync(event.getEntity());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
|
||||
Player player = event.player;
|
||||
if (player.level().isClientSide
|
||||
|| event.phase != TickEvent.Phase.END
|
||||
|| !PENDING_FULL_HEALTH_RESTORE.remove(player.getUUID())) {
|
||||
return;
|
||||
}
|
||||
StatEffects.applyAll(player);
|
||||
player.setHealth(player.getMaxHealth());
|
||||
PlayerStatsProvider.sync(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,9 @@ public final class StatEffects {
|
||||
hp.removeModifier(FORTITUDE_HEALTH_UUID);
|
||||
if (fortitudeLevel > 0) {
|
||||
double healthBonus = Math.min(fortitudeLevel * 0.18d * getScaling(), 18.0d);
|
||||
hp.addTransientModifier(new AttributeModifier(
|
||||
// Max health must be present while Minecraft loads the player's saved Health
|
||||
// value, otherwise values above the vanilla 20 HP are clamped before login.
|
||||
hp.addPermanentModifier(new AttributeModifier(
|
||||
FORTITUDE_HEALTH_UUID,
|
||||
"Ascend Fortitude health bonus",
|
||||
healthBonus,
|
||||
|
||||
Reference in New Issue
Block a user