Implement Ascend Compat, Irons spellbooks compat, And rehauled most things.
This commit is contained in:
@@ -5,4 +5,8 @@ public class ClientData {
|
||||
public static float INSANITY = 0f;
|
||||
public static int TEMPO = 0;
|
||||
public static int VENT_COOLDOWN = 0;
|
||||
}
|
||||
|
||||
// NEW: synced from server
|
||||
public static float MAX_SANITY = 80f;
|
||||
public static int MAX_TEMPO = 120;
|
||||
}
|
||||
@@ -19,27 +19,21 @@ public class SanityTempoOverlay {
|
||||
public static void onRenderOverlay(RenderGuiOverlayEvent.Post event) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.player == null || mc.options.hideGui) return;
|
||||
|
||||
GuiGraphics gui = event.getGuiGraphics();
|
||||
int width = event.getWindow().getGuiScaledWidth();
|
||||
int height = event.getWindow().getGuiScaledHeight();
|
||||
|
||||
int y = height - 48;
|
||||
int xTempo = 8;
|
||||
int xSanity = width - BAR_WIDTH - 8;
|
||||
|
||||
float sanity = ClientData.SANITY;
|
||||
float insanity = ClientData.INSANITY;
|
||||
float tempo = ClientData.TEMPO;
|
||||
|
||||
float sanityPercent = sanity / 80f;
|
||||
float insanityPercent = insanity / 80f; // same max as sanity (80)
|
||||
float tempoPercent = tempo / 120f;
|
||||
|
||||
float sanityPercent = sanity / ClientData.MAX_SANITY;
|
||||
float insanityPercent = insanity / ClientData.MAX_SANITY;
|
||||
float tempoPercent = (float) tempo / (float) ClientData.MAX_TEMPO;
|
||||
int sanityFill = (int) (BAR_WIDTH * sanityPercent);
|
||||
int tempoFill = (int) (BAR_WIDTH * tempoPercent);
|
||||
int insanityFill = (int) (BAR_WIDTH * insanityPercent);
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
drawRoundedBar(gui, xTempo, y, BAR_WIDTH, BAR_HEIGHT, 0xFF33AFFF, tempoFill);
|
||||
gui.drawString(mc.font, Component.literal("Tempo"), xTempo, y - 10, 0x66CCFF, false);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package net.fretux.mindmotion.client.effects;
|
||||
|
||||
import io.redspace.ironsspellbooks.api.registry.AttributeRegistry;
|
||||
import net.fretux.mindmotion.player.PlayerCapabilityProvider;
|
||||
import net.minecraft.world.entity.ai.attributes.Attribute;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public final class IronsSpellbooksCompatMM {
|
||||
public static final double TEMPO_PER_PERCENT = 3;
|
||||
private static final UUID TEMPO_MANA_REGEN_UUID =
|
||||
UUID.fromString("de4f16ad-73b3-4b99-bf77-44c9878222aa");
|
||||
|
||||
private IronsSpellbooksCompatMM() {}
|
||||
|
||||
public static boolean isLoaded() {
|
||||
return ModList.get().isLoaded("irons_spellbooks");
|
||||
}
|
||||
public static void applyTempo(Player player) {
|
||||
if (!isLoaded()) return;
|
||||
player.getCapability(PlayerCapabilityProvider.TEMPO).ifPresent(tempoCap -> {
|
||||
int tempo = tempoCap.getTempo();
|
||||
applyTempoToManaRegen(player, tempo);
|
||||
});
|
||||
}
|
||||
|
||||
public static void applyTempoToManaRegen(Player player, int tempo) {
|
||||
Attribute manaRegenAttr = (Attribute) AttributeRegistry.MANA_REGEN.get();
|
||||
if (manaRegenAttr == null) return;
|
||||
AttributeInstance inst = player.getAttribute(manaRegenAttr);
|
||||
if (inst == null) return;
|
||||
inst.removeModifier(TEMPO_MANA_REGEN_UUID);
|
||||
if (tempo <= 0) {
|
||||
return;
|
||||
}
|
||||
double bonusPercent = (double) tempo / TEMPO_PER_PERCENT;
|
||||
double multiplier = bonusPercent / 100.0;
|
||||
inst.addTransientModifier(new AttributeModifier(
|
||||
TEMPO_MANA_REGEN_UUID,
|
||||
"MindMotion Tempo mana regen",
|
||||
multiplier,
|
||||
AttributeModifier.Operation.MULTIPLY_BASE
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -38,22 +38,17 @@ public class SanityShaderHandler {
|
||||
@SubscribeEvent
|
||||
public static void onRenderWorld(RenderLevelStageEvent event) {
|
||||
if (event.getStage() != RenderLevelStageEvent.Stage.AFTER_LEVEL) return;
|
||||
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.player == null || mc.level == null) return;
|
||||
|
||||
float sanity = ClientData.SANITY;
|
||||
float insanity = ClientData.INSANITY;
|
||||
float maxSanity = 80f;
|
||||
|
||||
float maxSanity = ClientData.MAX_SANITY;
|
||||
float sanityPct = sanity / maxSanity;
|
||||
float insanityPct = insanity / maxSanity;
|
||||
|
||||
float baseDesat = 0f;
|
||||
if (sanityPct < 0.70f) {
|
||||
baseDesat = 1f - (sanityPct / 0.70f);
|
||||
}
|
||||
|
||||
float insanityBoost = 0.75f * insanityPct;
|
||||
float target = Math.max(baseDesat, insanityBoost);
|
||||
if (sanity <= 0f) target = 1f;
|
||||
@@ -73,7 +68,6 @@ public class SanityShaderHandler {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
PostChain chain = mc.gameRenderer.currentEffect();
|
||||
if (chain == null) return;
|
||||
try {
|
||||
@@ -107,13 +101,10 @@ public class SanityShaderHandler {
|
||||
blur = Math.min(blur, 1f);
|
||||
vig = Math.min(vig, 1f);
|
||||
fog = Math.min(fog, 1f);
|
||||
|
||||
var uBlur = effect.getUniform("BlurAmount");
|
||||
if (uBlur != null) uBlur.set(blur);
|
||||
|
||||
var uVig = effect.getUniform("Vignette");
|
||||
if (uVig != null) uVig.set(vig);
|
||||
|
||||
var uFog = effect.getUniform("FogStrength");
|
||||
if (uFog != null) uFog.set(fog);
|
||||
float shake = 0f;
|
||||
@@ -151,10 +142,8 @@ public class SanityShaderHandler {
|
||||
@SubscribeEvent
|
||||
public static void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) {
|
||||
if (!event.getEntity().level().isClientSide()) return;
|
||||
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
currentStrength = 0f;
|
||||
|
||||
mc.execute(() -> {
|
||||
if (mc.gameRenderer.currentEffect() != null) {
|
||||
mc.gameRenderer.shutdownEffect();
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.fretux.mindmotion.compat;
|
||||
|
||||
|
||||
import net.fretux.ascend.player.PlayerStatsProvider;
|
||||
import net.fretux.mindmotion.player.PlayerCapabilityProvider;
|
||||
import net.fretux.mindmotion.player.SanityCapability;
|
||||
import net.fretux.mindmotion.player.TempoCapability;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
public final class AscendCompat {
|
||||
|
||||
private AscendCompat() {}
|
||||
|
||||
public static void applyWillpowerBonuses(Player player) {
|
||||
player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
|
||||
int willpower = stats.getAttributeLevel("willpower");
|
||||
float sanityBonus = willpower * 3.0f;
|
||||
float tempoBonus = willpower * 0.5f;
|
||||
player.getCapability(PlayerCapabilityProvider.SANITY).ifPresent(cap -> {
|
||||
if (cap instanceof SanityCapability impl) {
|
||||
impl.setBonusMaxSanity(sanityBonus);
|
||||
}
|
||||
});
|
||||
player.getCapability(PlayerCapabilityProvider.TEMPO).ifPresent(cap -> {
|
||||
if (cap instanceof TempoCapability impl) {
|
||||
impl.setBonusMaxTempo(tempoBonus);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.fretux.mindmotion.event;
|
||||
|
||||
import net.fretux.mindmotion.compat.AscendCompat;
|
||||
import net.fretux.mindmotion.network.ModMessages;
|
||||
import net.fretux.mindmotion.network.SyncStatsS2CPacket;
|
||||
import net.fretux.mindmotion.player.PlayerCapabilityProvider;
|
||||
@@ -17,6 +18,8 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static net.fretux.mindmotion.client.effects.IronsSpellbooksCompatMM.applyTempoToManaRegen;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = "mindmotion")
|
||||
public class PlayerTickHandler {
|
||||
|
||||
@@ -32,11 +35,14 @@ public class PlayerTickHandler {
|
||||
if (event.phase != TickEvent.Phase.END) return;
|
||||
Player player = event.player;
|
||||
if (player.level().isClientSide) return;
|
||||
AscendCompat.applyWillpowerBonuses(player);
|
||||
int tick = player.tickCount;
|
||||
boolean sanityTick = tick % SANITY_TICK_INTERVAL == 0;
|
||||
boolean tempoSyncTick = tick % TEMPO_TICK_INTERVAL == 0;
|
||||
|
||||
if (sanityTick) handleSanityAndInsanity(player);
|
||||
handleTempoTick(player, tick);
|
||||
|
||||
if (player instanceof ServerPlayer serverPlayer && (sanityTick || tempoSyncTick)) {
|
||||
player.getCapability(PlayerCapabilityProvider.SANITY).ifPresent(sanity ->
|
||||
player.getCapability(PlayerCapabilityProvider.TEMPO).ifPresent(tempo ->
|
||||
@@ -45,7 +51,9 @@ public class PlayerTickHandler {
|
||||
sanity.getSanity(),
|
||||
sanity.getInsanity(),
|
||||
tempo.getTempo(),
|
||||
tempo.getVentCooldown()
|
||||
tempo.getVentCooldown(),
|
||||
sanity.getMaxSanity(),
|
||||
tempo.getMaxTempo()
|
||||
),
|
||||
serverPlayer.connection.connection,
|
||||
net.minecraftforge.network.NetworkDirection.PLAY_TO_CLIENT
|
||||
@@ -195,6 +203,7 @@ public class PlayerTickHandler {
|
||||
if (ticksSinceCombat > COMBAT_DECAY_DELAY && value > 0) {
|
||||
tempo.setTempo(value - 1);
|
||||
}
|
||||
applyTempoToManaRegen(player, tempo.getTempo());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -11,12 +11,21 @@ public class SyncStatsS2CPacket {
|
||||
private final float insanity;
|
||||
private final int tempo;
|
||||
private final int ventCooldown;
|
||||
private final float maxSanity;
|
||||
private final int maxTempo;
|
||||
|
||||
public SyncStatsS2CPacket(float sanity, float insanity, int tempo, int ventCooldown) {
|
||||
public SyncStatsS2CPacket(float sanity,
|
||||
float insanity,
|
||||
int tempo,
|
||||
int ventCooldown,
|
||||
float maxSanity,
|
||||
int maxTempo) {
|
||||
this.sanity = sanity;
|
||||
this.insanity = insanity;
|
||||
this.tempo = tempo;
|
||||
this.ventCooldown = ventCooldown;
|
||||
this.maxSanity = maxSanity;
|
||||
this.maxTempo = maxTempo;
|
||||
}
|
||||
|
||||
public static void encode(SyncStatsS2CPacket msg, FriendlyByteBuf buf) {
|
||||
@@ -24,10 +33,18 @@ public class SyncStatsS2CPacket {
|
||||
buf.writeFloat(msg.insanity);
|
||||
buf.writeInt(msg.tempo);
|
||||
buf.writeInt(msg.ventCooldown);
|
||||
buf.writeFloat(msg.maxSanity);
|
||||
buf.writeInt(msg.maxTempo);
|
||||
}
|
||||
|
||||
public static SyncStatsS2CPacket decode(FriendlyByteBuf buf) {
|
||||
return new SyncStatsS2CPacket(buf.readFloat(), buf.readFloat(), buf.readInt(), buf.readInt());
|
||||
float sanity = buf.readFloat();
|
||||
float insanity = buf.readFloat();
|
||||
int tempo = buf.readInt();
|
||||
int ventCooldown = buf.readInt();
|
||||
float maxSanity = buf.readFloat();
|
||||
int maxTempo = buf.readInt();
|
||||
return new SyncStatsS2CPacket(sanity, insanity, tempo, ventCooldown, maxSanity, maxTempo);
|
||||
}
|
||||
|
||||
public static void handle(SyncStatsS2CPacket msg, Supplier<NetworkEvent.Context> ctx) {
|
||||
@@ -36,8 +53,18 @@ public class SyncStatsS2CPacket {
|
||||
ClientData.INSANITY = msg.insanity;
|
||||
ClientData.TEMPO = msg.tempo;
|
||||
ClientData.VENT_COOLDOWN = msg.ventCooldown;
|
||||
ClientData.MAX_SANITY = msg.maxSanity;
|
||||
ClientData.MAX_TEMPO = msg.maxTempo;
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
System.out.println("[Client] Sanity: " + msg.sanity + ", Insanity: " + msg.insanity + ", Tempo: " + msg.tempo);
|
||||
|
||||
System.out.println(
|
||||
"[Client] Sanity: " + msg.sanity +
|
||||
", Insanity: " + msg.insanity +
|
||||
", Tempo: " + msg.tempo +
|
||||
", VentCD: " + msg.ventCooldown +
|
||||
", MaxSanity: " + msg.maxSanity +
|
||||
", MaxTempo: " + msg.maxTempo
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,23 +3,61 @@ package net.fretux.mindmotion.player;
|
||||
public class SanityCapability implements ISanity {
|
||||
private float sanity = 80f;
|
||||
private float insanity = 0f;
|
||||
private final float maxSanity = 80f;
|
||||
|
||||
// Base + bonus so Ascend can modify max
|
||||
private float baseMaxSanity = 80f;
|
||||
private float bonusMaxSanity = 0f; // from Ascend willpower etc.
|
||||
|
||||
@Override
|
||||
public float getSanity() { return sanity; }
|
||||
@Override
|
||||
public void setSanity(float sanity) { this.sanity = Math.max(0, Math.min(maxSanity, sanity)); }
|
||||
public float getSanity() {
|
||||
return sanity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getInsanity() { return insanity; }
|
||||
@Override
|
||||
public void setInsanity(float insanity) { this.insanity = Math.max(0, Math.min(maxSanity, insanity)); }
|
||||
public void setSanity(float sanity) {
|
||||
float max = getMaxSanity();
|
||||
this.sanity = Math.max(0, Math.min(max, sanity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxSanity() { return maxSanity; }
|
||||
public float getInsanity() {
|
||||
return insanity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSanity(float amount) { setSanity(this.sanity + amount); }
|
||||
public void setInsanity(float insanity) {
|
||||
float max = getMaxSanity();
|
||||
this.insanity = Math.max(0, Math.min(max, insanity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reduceSanity(float amount) { setSanity(this.sanity - amount); }
|
||||
}
|
||||
public float getMaxSanity() {
|
||||
return baseMaxSanity + bonusMaxSanity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSanity(float amount) {
|
||||
setSanity(this.sanity + amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reduceSanity(float amount) {
|
||||
setSanity(this.sanity - amount);
|
||||
}
|
||||
|
||||
public void setBaseMaxSanity(float baseMaxSanity) {
|
||||
this.baseMaxSanity = baseMaxSanity;
|
||||
setSanity(this.sanity);
|
||||
setInsanity(this.insanity);
|
||||
}
|
||||
|
||||
public void setBonusMaxSanity(float bonusMaxSanity) {
|
||||
this.bonusMaxSanity = Math.max(0f, bonusMaxSanity);
|
||||
setSanity(this.sanity);
|
||||
setInsanity(this.insanity);
|
||||
}
|
||||
|
||||
public float getBonusMaxSanity() {
|
||||
return bonusMaxSanity;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,11 @@ package net.fretux.mindmotion.player;
|
||||
|
||||
public class TempoCapability implements ITempo {
|
||||
private int tempo = 0;
|
||||
private final int maxTempo = 120;
|
||||
|
||||
private int baseMaxTempo = 120;
|
||||
private float bonusMaxTempo = 0f; // from Ascend willpower
|
||||
|
||||
private int ventCooldown = 0;
|
||||
|
||||
@Override
|
||||
public int getTempo() {
|
||||
@@ -11,12 +15,12 @@ public class TempoCapability implements ITempo {
|
||||
|
||||
@Override
|
||||
public void setTempo(int tempo) {
|
||||
this.tempo = Math.max(0, Math.min(maxTempo, tempo));
|
||||
this.tempo = Math.max(0, Math.min(getMaxTempo(), tempo));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxTempo() {
|
||||
return maxTempo;
|
||||
return Math.max(0, Math.round(baseMaxTempo + bonusMaxTempo));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -29,8 +33,6 @@ public class TempoCapability implements ITempo {
|
||||
setTempo(this.tempo - amount);
|
||||
}
|
||||
|
||||
private int ventCooldown = 0;
|
||||
|
||||
@Override
|
||||
public int getVentCooldown() {
|
||||
return ventCooldown;
|
||||
@@ -38,6 +40,20 @@ public class TempoCapability implements ITempo {
|
||||
|
||||
@Override
|
||||
public void setVentCooldown(int ticks) {
|
||||
ventCooldown = ticks;
|
||||
ventCooldown = Math.max(0, ticks);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBaseMaxTempo(int baseMaxTempo) {
|
||||
this.baseMaxTempo = baseMaxTempo;
|
||||
setTempo(this.tempo);
|
||||
}
|
||||
|
||||
public void setBonusMaxTempo(float bonusMaxTempo) {
|
||||
this.bonusMaxTempo = Math.max(0f, bonusMaxTempo);
|
||||
setTempo(this.tempo);
|
||||
}
|
||||
|
||||
public float getBonusMaxTempo() {
|
||||
return bonusMaxTempo;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user