add an option to disable tempo/sanity
This commit is contained in:
+1
-1
@@ -52,7 +52,7 @@ mod_name=Mind & Motion
|
||||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||
mod_license=All Rights Reserved
|
||||
# The mod version. See https://semver.org/
|
||||
mod_version=1.4.0
|
||||
mod_version=1.4.2
|
||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||
# This should match the base package used for the mod sources.
|
||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
|
||||
@@ -80,12 +80,14 @@ public final class ConfigMM {
|
||||
}
|
||||
|
||||
public static class Common {
|
||||
public final ForgeConfigSpec.BooleanValue ENABLE_SANITY;
|
||||
public final ForgeConfigSpec.DoubleValue BASE_SANITY_REGEN_LIGHT;
|
||||
public final ForgeConfigSpec.DoubleValue BASE_SANITY_DECAY_DARK;
|
||||
public final ForgeConfigSpec.BooleanValue ENABLE_LOW_SANITY_SOUNDS;
|
||||
public final ForgeConfigSpec.BooleanValue ENABLE_SANITY_GAMEPLAY_EFFECTS;
|
||||
public final ForgeConfigSpec.DoubleValue SCRATCHING_CHANCE;
|
||||
public final ForgeConfigSpec.DoubleValue PANIC_CHANCE;
|
||||
public final ForgeConfigSpec.BooleanValue ENABLE_TEMPO;
|
||||
public final ForgeConfigSpec.IntValue TEMPO_DECAY_DELAY;
|
||||
public final ForgeConfigSpec.IntValue VENT_COST;
|
||||
public final ForgeConfigSpec.IntValue TEMPO_PER_MANA_REGEN_PERCENT;
|
||||
@@ -93,6 +95,10 @@ public final class ConfigMM {
|
||||
Common(ForgeConfigSpec.Builder b) {
|
||||
b.push("sanity");
|
||||
|
||||
ENABLE_SANITY = b
|
||||
.comment("Enable the sanity and insanity systems, including HUD, shaders, sounds, commands, and gameplay effects.")
|
||||
.define("enableSanity", true);
|
||||
|
||||
BASE_SANITY_REGEN_LIGHT = b
|
||||
.comment("Sanity gained per tick in bright light.")
|
||||
.defineInRange("sanityRegenLight", 0.03, 0.0, 1.0);
|
||||
@@ -121,6 +127,10 @@ public final class ConfigMM {
|
||||
|
||||
b.pop().push("tempo");
|
||||
|
||||
ENABLE_TEMPO = b
|
||||
.comment("Enable the tempo system, including HUD, combat gain, decay, Vent, and compatibility bonuses.")
|
||||
.define("enableTempo", true);
|
||||
|
||||
TEMPO_DECAY_DELAY = b
|
||||
.comment("Ticks without combat before tempo begins to decay.")
|
||||
.defineInRange("tempoDecayDelay", 100, 0, 20000);
|
||||
|
||||
@@ -9,4 +9,6 @@ public class ClientData {
|
||||
// NEW: synced from server
|
||||
public static float MAX_SANITY = 80f;
|
||||
public static int MAX_TEMPO = 120;
|
||||
public static boolean SANITY_ENABLED = true;
|
||||
public static boolean TEMPO_ENABLED = true;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.fretux.mindmotion.client;
|
||||
|
||||
import net.fretux.mindmotion.ConfigMM;
|
||||
import net.fretux.mindmotion.network.ModMessages;
|
||||
import net.fretux.mindmotion.network.VentPacket;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -13,12 +14,14 @@ public class ClientEvents {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onKeyInput(InputEvent.Key event) {
|
||||
if (Keybinds.VENT_KEY.isDown()) {
|
||||
boolean tempoEnabled = ConfigMM.COMMON.ENABLE_TEMPO.get() && ClientData.TEMPO_ENABLED;
|
||||
boolean sanityEnabled = ConfigMM.COMMON.ENABLE_SANITY.get() && ClientData.SANITY_ENABLED;
|
||||
if (tempoEnabled && Keybinds.VENT_KEY.isDown()) {
|
||||
ModMessages.CHANNEL.sendToServer(new VentPacket());
|
||||
}
|
||||
if (Keybinds.HUD_EDITOR_KEY.consumeClick()) {
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
if (minecraft.screen == null) {
|
||||
if (minecraft.screen == null && (tempoEnabled || sanityEnabled)) {
|
||||
minecraft.setScreen(new HudEditorScreen(null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.fretux.mindmotion.client;
|
||||
|
||||
import net.fretux.mindmotion.ConfigMM;
|
||||
import net.fretux.mindmotion.client.shader.VentShaderHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
@@ -8,6 +9,9 @@ public final class ClientPacketHandlers {
|
||||
}
|
||||
|
||||
public static void handleVentEffect() {
|
||||
if (!ConfigMM.COMMON.ENABLE_TEMPO.get() || !ClientData.TEMPO_ENABLED) {
|
||||
return;
|
||||
}
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.player == null) {
|
||||
return;
|
||||
|
||||
@@ -65,6 +65,8 @@ public class HudEditorScreen extends Screen {
|
||||
int sliderWidth = 150;
|
||||
int y = 36;
|
||||
int step = 24;
|
||||
boolean tempoEnabled = ConfigMM.COMMON.ENABLE_TEMPO.get() && ClientData.TEMPO_ENABLED;
|
||||
boolean sanityEnabled = ConfigMM.COMMON.ENABLE_SANITY.get() && ClientData.SANITY_ENABLED;
|
||||
|
||||
barWidthSlider = addRenderableWidget(new IntSlider(
|
||||
leftX,
|
||||
@@ -90,6 +92,7 @@ public class HudEditorScreen extends Screen {
|
||||
));
|
||||
|
||||
y += step;
|
||||
if (tempoEnabled) {
|
||||
tempoXSlider = addRenderableWidget(new IntSlider(
|
||||
leftX,
|
||||
y,
|
||||
@@ -112,8 +115,10 @@ public class HudEditorScreen extends Screen {
|
||||
tempoOffsetY,
|
||||
value -> setTempoOffsetY(value, false)
|
||||
));
|
||||
|
||||
y += step;
|
||||
}
|
||||
|
||||
if (sanityEnabled) {
|
||||
sanityXSlider = addRenderableWidget(new IntSlider(
|
||||
leftX,
|
||||
y,
|
||||
@@ -136,6 +141,7 @@ public class HudEditorScreen extends Screen {
|
||||
sanityOffsetY,
|
||||
value -> setSanityOffsetY(value, false)
|
||||
));
|
||||
}
|
||||
|
||||
int buttonY = this.height - 28;
|
||||
addRenderableWidget(Button.builder(
|
||||
@@ -170,7 +176,7 @@ public class HudEditorScreen extends Screen {
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (button == 0) {
|
||||
BarPosition tempoBar = getTempoBarPosition();
|
||||
if (isMouseOver(mouseX, mouseY, tempoBar)) {
|
||||
if (isTempoEnabled() && isMouseOver(mouseX, mouseY, tempoBar)) {
|
||||
draggingTempo = true;
|
||||
dragStartX = mouseX;
|
||||
dragStartY = mouseY;
|
||||
@@ -179,7 +185,7 @@ public class HudEditorScreen extends Screen {
|
||||
return true;
|
||||
}
|
||||
BarPosition sanityBar = getSanityBarPosition();
|
||||
if (isMouseOver(mouseX, mouseY, sanityBar)) {
|
||||
if (isSanityEnabled() && isMouseOver(mouseX, mouseY, sanityBar)) {
|
||||
draggingSanity = true;
|
||||
dragStartX = mouseX;
|
||||
dragStartY = mouseY;
|
||||
@@ -231,8 +237,11 @@ public class HudEditorScreen extends Screen {
|
||||
private void renderPreview(GuiGraphics gui) {
|
||||
BarPosition tempoBar = getTempoBarPosition();
|
||||
BarPosition sanityBar = getSanityBarPosition();
|
||||
if (isTempoEnabled()) {
|
||||
drawRoundedBar(gui, tempoBar, 0xFF33AFFF, (int) (barWidth * 0.75f));
|
||||
gui.drawString(this.font, Component.literal("Tempo"), tempoBar.x, tempoBar.y - 12, 0x66CCFF, false);
|
||||
}
|
||||
if (isSanityEnabled()) {
|
||||
drawRoundedBar(gui, sanityBar, 0xFFFFFFFF, (int) (barWidth * 0.6f));
|
||||
int sanityLabelWidth = this.font.width("Sanity");
|
||||
gui.drawString(
|
||||
@@ -244,6 +253,7 @@ public class HudEditorScreen extends Screen {
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private BarPosition getTempoBarPosition() {
|
||||
int baseY = this.height - BASE_Y_OFFSET;
|
||||
@@ -327,6 +337,14 @@ public class HudEditorScreen extends Screen {
|
||||
ConfigMM.CLIENT_SPEC.save();
|
||||
}
|
||||
|
||||
private static boolean isTempoEnabled() {
|
||||
return ConfigMM.COMMON.ENABLE_TEMPO.get() && ClientData.TEMPO_ENABLED;
|
||||
}
|
||||
|
||||
private static boolean isSanityEnabled() {
|
||||
return ConfigMM.COMMON.ENABLE_SANITY.get() && ClientData.SANITY_ENABLED;
|
||||
}
|
||||
|
||||
private static int clamp(int value, int min, int max) {
|
||||
return Math.min(Math.max(value, min), max);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ public class SanityTempoOverlay {
|
||||
public static void onRenderOverlay(RenderGuiOverlayEvent.Post event) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.player == null || mc.options.hideGui) return;
|
||||
boolean tempoEnabled = ConfigMM.COMMON.ENABLE_TEMPO.get() && ClientData.TEMPO_ENABLED;
|
||||
boolean sanityEnabled = ConfigMM.COMMON.ENABLE_SANITY.get() && ClientData.SANITY_ENABLED;
|
||||
if (!tempoEnabled && !sanityEnabled) return;
|
||||
GuiGraphics gui = event.getGuiGraphics();
|
||||
int width = event.getWindow().getGuiScaledWidth();
|
||||
int height = event.getWindow().getGuiScaledHeight();
|
||||
@@ -44,9 +47,11 @@ public class SanityTempoOverlay {
|
||||
int tempoFill = (int) (barWidth * tempoPercent);
|
||||
int insanityFill = (int) (barWidth * insanityPercent);
|
||||
RenderSystem.enableBlend();
|
||||
if (tempoEnabled) {
|
||||
drawRoundedBar(gui, xTempo, yTempo, barWidth, barHeight, 0xFF33AFFF, tempoFill);
|
||||
gui.drawString(mc.font, Component.literal("Tempo"), xTempo, yTempo - labelOffset, 0x66CCFF, false);
|
||||
if (ClientData.VENT_COOLDOWN > 0) {
|
||||
}
|
||||
if (tempoEnabled && ClientData.VENT_COOLDOWN > 0) {
|
||||
int seconds = ClientData.VENT_COOLDOWN / 20;
|
||||
String ventText = "Vent: " + seconds + "s";
|
||||
gui.drawString(
|
||||
@@ -59,6 +64,7 @@ public class SanityTempoOverlay {
|
||||
);
|
||||
}
|
||||
boolean insaneMode = sanity <= 0;
|
||||
if (sanityEnabled) {
|
||||
if (!insaneMode) {
|
||||
drawRoundedBar(gui, xSanity, ySanity, barWidth, barHeight, 0xFFFFFFFF, sanityFill);
|
||||
int sanityLabelWidth = mc.font.width("Sanity");
|
||||
@@ -73,13 +79,14 @@ public class SanityTempoOverlay {
|
||||
int insanityLabelX = xSanity + barWidth - insanityLabelWidth;
|
||||
gui.drawString(mc.font, Component.literal("Insanity"), insanityLabelX, ySanity - labelOffset, 0xCC66FF, false);
|
||||
}
|
||||
}
|
||||
double mouseX = mc.mouseHandler.xpos() * width / (double) event.getWindow().getScreenWidth();
|
||||
double mouseY = mc.mouseHandler.ypos() * height / (double) event.getWindow().getScreenHeight();
|
||||
if (isMouseOver(mouseX, mouseY, xTempo, yTempo, barWidth, barHeight)) {
|
||||
if (tempoEnabled && isMouseOver(mouseX, mouseY, xTempo, yTempo, barWidth, barHeight)) {
|
||||
String text = String.format("%.0f%%", tempoPercent * 100f);
|
||||
gui.drawCenteredString(mc.font, text, xTempo + barWidth / 2, yTempo - (labelOffset + 2), 0x66CCFF);
|
||||
}
|
||||
if (isMouseOver(mouseX, mouseY, xSanity, ySanity, barWidth, barHeight)) {
|
||||
if (sanityEnabled && isMouseOver(mouseX, mouseY, xSanity, ySanity, barWidth, barHeight)) {
|
||||
if (!insaneMode) {
|
||||
String text = String.format("%.0f%%", sanityPercent * 100f);
|
||||
gui.drawCenteredString(mc.font, text, xSanity + barWidth / 2, ySanity - (labelOffset + 2), 0xFFFFFF);
|
||||
|
||||
@@ -69,7 +69,7 @@ public final class FakeChatMessageHandler {
|
||||
if (event.phase != TickEvent.Phase.END) return;
|
||||
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
if (minecraft.level == null || minecraft.player == null || ConfigMM.CLIENT.DISABLE_SHADERS.get()) {
|
||||
if (minecraft.level == null || minecraft.player == null || ConfigMM.CLIENT.DISABLE_SHADERS.get() || !ConfigMM.COMMON.ENABLE_SANITY.get() || !ClientData.SANITY_ENABLED) {
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class SanityShaderHandler {
|
||||
@SubscribeEvent
|
||||
public static void onRenderWorld(RenderLevelStageEvent event) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (ConfigMM.CLIENT.DISABLE_SHADERS.get()) {
|
||||
if (ConfigMM.CLIENT.DISABLE_SHADERS.get() || !ConfigMM.COMMON.ENABLE_SANITY.get() || !ClientData.SANITY_ENABLED) {
|
||||
if (mc.gameRenderer.currentEffect() != null)
|
||||
mc.gameRenderer.shutdownEffect();
|
||||
return;
|
||||
|
||||
@@ -49,7 +49,7 @@ public final class ShadowFigureHandler {
|
||||
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
LocalPlayer player = minecraft.player;
|
||||
if (minecraft.level == null || player == null || ConfigMM.CLIENT.DISABLE_SHADERS.get()) {
|
||||
if (minecraft.level == null || player == null || ConfigMM.CLIENT.DISABLE_SHADERS.get() || !ConfigMM.COMMON.ENABLE_SANITY.get() || !ClientData.SANITY_ENABLED) {
|
||||
FIGURES.clear();
|
||||
spawnCooldown = MIN_SPAWN_DELAY;
|
||||
return;
|
||||
@@ -77,7 +77,7 @@ public final class ShadowFigureHandler {
|
||||
if (event.getStage() != RenderLevelStageEvent.Stage.AFTER_PARTICLES || FIGURES.isEmpty()) return;
|
||||
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
if (minecraft.level == null || minecraft.player == null || ConfigMM.CLIENT.DISABLE_SHADERS.get()) return;
|
||||
if (minecraft.level == null || minecraft.player == null || ConfigMM.CLIENT.DISABLE_SHADERS.get() || !ConfigMM.COMMON.ENABLE_SANITY.get() || !ClientData.SANITY_ENABLED) return;
|
||||
|
||||
Camera camera = event.getCamera();
|
||||
Vec3 cameraPos = camera.getPosition();
|
||||
|
||||
@@ -2,9 +2,11 @@ package net.fretux.mindmotion.command;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.FloatArgumentType;
|
||||
import net.fretux.mindmotion.ConfigMM;
|
||||
import net.fretux.mindmotion.player.PlayerCapabilityProvider;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
@@ -17,6 +19,10 @@ public class SanityCommand {
|
||||
.then(Commands.literal("set")
|
||||
.then(Commands.argument("sanity", FloatArgumentType.floatArg(0))
|
||||
.executes(ctx -> {
|
||||
if (!ConfigMM.COMMON.ENABLE_SANITY.get()) {
|
||||
ctx.getSource().sendFailure(Component.literal("Sanity system is disabled."));
|
||||
return 0;
|
||||
}
|
||||
ServerPlayer player = ctx.getSource().getPlayerOrException();
|
||||
float requestedSanity = FloatArgumentType.getFloat(ctx, "sanity");
|
||||
final float[] appliedSanity = new float[] {0f};
|
||||
@@ -30,7 +36,7 @@ public class SanityCommand {
|
||||
});
|
||||
|
||||
ctx.getSource().sendSuccess(() ->
|
||||
net.minecraft.network.chat.Component.literal("Set sanity = " + appliedSanity[0]),
|
||||
Component.literal("Set sanity = " + appliedSanity[0]),
|
||||
true
|
||||
);
|
||||
|
||||
@@ -44,6 +50,10 @@ public class SanityCommand {
|
||||
.then(Commands.literal("set")
|
||||
.then(Commands.argument("insanity", FloatArgumentType.floatArg(0))
|
||||
.executes(ctx -> {
|
||||
if (!ConfigMM.COMMON.ENABLE_SANITY.get()) {
|
||||
ctx.getSource().sendFailure(Component.literal("Sanity system is disabled."));
|
||||
return 0;
|
||||
}
|
||||
ServerPlayer player = ctx.getSource().getPlayerOrException();
|
||||
float requestedInsanity = FloatArgumentType.getFloat(ctx, "insanity");
|
||||
final float[] appliedInsanity = new float[] {0f};
|
||||
@@ -57,7 +67,7 @@ public class SanityCommand {
|
||||
});
|
||||
|
||||
ctx.getSource().sendSuccess(() ->
|
||||
net.minecraft.network.chat.Component.literal("Set insanity = " + appliedInsanity[0]),
|
||||
Component.literal("Set insanity = " + appliedInsanity[0]),
|
||||
true
|
||||
);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.fretux.mindmotion.compat;
|
||||
|
||||
|
||||
import net.fretux.ascend.player.PlayerStatsProvider;
|
||||
import net.fretux.mindmotion.ConfigMM;
|
||||
import net.fretux.mindmotion.player.PlayerCapabilityProvider;
|
||||
import net.fretux.mindmotion.player.SanityCapability;
|
||||
import net.fretux.mindmotion.player.TempoCapability;
|
||||
@@ -16,16 +17,20 @@ public final class AscendCompat {
|
||||
int willpower = stats.getAttributeLevel("willpower");
|
||||
float sanityBonus = willpower * 3.0f;
|
||||
float tempoBonus = willpower * 0.5f;
|
||||
if (ConfigMM.COMMON.ENABLE_SANITY.get()) {
|
||||
player.getCapability(PlayerCapabilityProvider.SANITY).ifPresent(cap -> {
|
||||
if (cap instanceof SanityCapability impl) {
|
||||
impl.setBonusMaxSanity(sanityBonus);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (ConfigMM.COMMON.ENABLE_TEMPO.get()) {
|
||||
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.ConfigMM;
|
||||
import net.fretux.mindmotion.player.PlayerCapabilityProvider;
|
||||
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
@@ -11,13 +12,21 @@ public class CombatEvents {
|
||||
@SubscribeEvent
|
||||
public static void onEntityHurt(LivingHurtEvent event) {
|
||||
if (event.getEntity() instanceof net.minecraft.world.entity.player.Player player) {
|
||||
if (ConfigMM.COMMON.ENABLE_TEMPO.get()) {
|
||||
player.getCapability(PlayerCapabilityProvider.TEMPO).ifPresent(tempo -> tempo.addTempo(3));
|
||||
}
|
||||
if (ConfigMM.COMMON.ENABLE_SANITY.get() || ConfigMM.COMMON.ENABLE_TEMPO.get()) {
|
||||
PlayerTickHandler.markCombat(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (event.getSource().getEntity() instanceof net.minecraft.world.entity.player.Player attacker) {
|
||||
if (ConfigMM.COMMON.ENABLE_TEMPO.get()) {
|
||||
attacker.getCapability(PlayerCapabilityProvider.TEMPO).ifPresent(tempo -> tempo.addTempo(4));
|
||||
}
|
||||
if (ConfigMM.COMMON.ENABLE_SANITY.get() || ConfigMM.COMMON.ENABLE_TEMPO.get()) {
|
||||
PlayerTickHandler.markCombat(attacker);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.fretux.mindmotion.event;
|
||||
|
||||
import net.fretux.mindmotion.ConfigMM;
|
||||
import net.fretux.mindmotion.player.PlayerCapabilityProvider;
|
||||
import net.fretux.mindmotion.player.SanityCapability;
|
||||
import net.minecraft.world.entity.monster.Monster;
|
||||
@@ -15,6 +16,7 @@ public class CommonEvents {
|
||||
public void onPlayerHurt(LivingHurtEvent event) {
|
||||
if (!(event.getEntity() instanceof net.minecraft.world.entity.player.Player player)) return;
|
||||
if (player.level().isClientSide) return;
|
||||
if (!ConfigMM.COMMON.ENABLE_SANITY.get()) return;
|
||||
|
||||
float loss = Math.min(5f, 0.5f + event.getAmount() * 0.25f);
|
||||
player.getCapability(PlayerCapabilityProvider.SANITY).ifPresent(sanity -> sanity.reduceSanity(loss));
|
||||
@@ -24,6 +26,7 @@ public class CommonEvents {
|
||||
public void onLivingDeath(LivingDeathEvent event) {
|
||||
if (!(event.getSource().getEntity() instanceof net.minecraft.world.entity.player.Player player)) return;
|
||||
if (player.level().isClientSide) return;
|
||||
if (!ConfigMM.COMMON.ENABLE_SANITY.get()) return;
|
||||
|
||||
player.getCapability(PlayerCapabilityProvider.SANITY).ifPresent(sanity -> {
|
||||
if (event.getEntity() instanceof Monster) {
|
||||
|
||||
@@ -78,21 +78,29 @@ public class PlayerTickHandler {
|
||||
int tick = player.tickCount;
|
||||
boolean sanityTick = tick % SANITY_TICK_INTERVAL == 0;
|
||||
boolean tempoSyncTick = tick % TEMPO_TICK_INTERVAL == 0;
|
||||
boolean sanityEnabled = ConfigMM.COMMON.ENABLE_SANITY.get();
|
||||
boolean tempoEnabled = ConfigMM.COMMON.ENABLE_TEMPO.get();
|
||||
|
||||
if (sanityTick) handleSanityAndInsanity(player);
|
||||
if (sanityEnabled && sanityTick) handleSanityAndInsanity(player);
|
||||
if (tempoEnabled) {
|
||||
handleTempoTick(player, tick);
|
||||
} else if (tick % TEMPO_TICK_INTERVAL == 0) {
|
||||
applyTempoToManaRegen(player, 0);
|
||||
}
|
||||
|
||||
if (player instanceof ServerPlayer serverPlayer && (sanityTick || tempoSyncTick)) {
|
||||
player.getCapability(PlayerCapabilityProvider.SANITY).ifPresent(sanity ->
|
||||
player.getCapability(PlayerCapabilityProvider.TEMPO).ifPresent(tempo ->
|
||||
ModMessages.CHANNEL.sendTo(
|
||||
new SyncStatsS2CPacket(
|
||||
sanity.getSanity(),
|
||||
sanity.getInsanity(),
|
||||
tempo.getTempo(),
|
||||
tempo.getVentCooldown(),
|
||||
sanityEnabled ? sanity.getSanity() : sanity.getMaxSanity(),
|
||||
sanityEnabled ? sanity.getInsanity() : 0f,
|
||||
tempoEnabled ? tempo.getTempo() : 0,
|
||||
tempoEnabled ? tempo.getVentCooldown() : 0,
|
||||
sanity.getMaxSanity(),
|
||||
tempo.getMaxTempo()
|
||||
tempo.getMaxTempo(),
|
||||
sanityEnabled,
|
||||
tempoEnabled
|
||||
),
|
||||
serverPlayer.connection.connection,
|
||||
net.minecraftforge.network.NetworkDirection.PLAY_TO_CLIENT
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.fretux.mindmotion.AscendMindMotion;
|
||||
|
||||
public class ModMessages {
|
||||
|
||||
private static final String PROTOCOL_VERSION = "1";
|
||||
private static final String PROTOCOL_VERSION = "2";
|
||||
public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel(
|
||||
ResourceLocation.fromNamespaceAndPath(AscendMindMotion.MODID, "main"),
|
||||
() -> PROTOCOL_VERSION,
|
||||
|
||||
@@ -13,19 +13,25 @@ public class SyncStatsS2CPacket {
|
||||
private final int ventCooldown;
|
||||
private final float maxSanity;
|
||||
private final int maxTempo;
|
||||
private final boolean sanityEnabled;
|
||||
private final boolean tempoEnabled;
|
||||
|
||||
public SyncStatsS2CPacket(float sanity,
|
||||
float insanity,
|
||||
int tempo,
|
||||
int ventCooldown,
|
||||
float maxSanity,
|
||||
int maxTempo) {
|
||||
int maxTempo,
|
||||
boolean sanityEnabled,
|
||||
boolean tempoEnabled) {
|
||||
this.sanity = sanity;
|
||||
this.insanity = insanity;
|
||||
this.tempo = tempo;
|
||||
this.ventCooldown = ventCooldown;
|
||||
this.maxSanity = maxSanity;
|
||||
this.maxTempo = maxTempo;
|
||||
this.sanityEnabled = sanityEnabled;
|
||||
this.tempoEnabled = tempoEnabled;
|
||||
}
|
||||
|
||||
public static void encode(SyncStatsS2CPacket msg, FriendlyByteBuf buf) {
|
||||
@@ -35,6 +41,8 @@ public class SyncStatsS2CPacket {
|
||||
buf.writeInt(msg.ventCooldown);
|
||||
buf.writeFloat(msg.maxSanity);
|
||||
buf.writeInt(msg.maxTempo);
|
||||
buf.writeBoolean(msg.sanityEnabled);
|
||||
buf.writeBoolean(msg.tempoEnabled);
|
||||
}
|
||||
|
||||
public static SyncStatsS2CPacket decode(FriendlyByteBuf buf) {
|
||||
@@ -44,7 +52,9 @@ public class SyncStatsS2CPacket {
|
||||
int ventCooldown = buf.readInt();
|
||||
float maxSanity = buf.readFloat();
|
||||
int maxTempo = buf.readInt();
|
||||
return new SyncStatsS2CPacket(sanity, insanity, tempo, ventCooldown, maxSanity, maxTempo);
|
||||
boolean sanityEnabled = buf.readBoolean();
|
||||
boolean tempoEnabled = buf.readBoolean();
|
||||
return new SyncStatsS2CPacket(sanity, insanity, tempo, ventCooldown, maxSanity, maxTempo, sanityEnabled, tempoEnabled);
|
||||
}
|
||||
|
||||
public static void handle(SyncStatsS2CPacket msg, Supplier<NetworkEvent.Context> ctx) {
|
||||
@@ -55,6 +65,8 @@ public class SyncStatsS2CPacket {
|
||||
ClientData.VENT_COOLDOWN = msg.ventCooldown;
|
||||
ClientData.MAX_SANITY = msg.maxSanity;
|
||||
ClientData.MAX_TEMPO = msg.maxTempo;
|
||||
ClientData.SANITY_ENABLED = msg.sanityEnabled;
|
||||
ClientData.TEMPO_ENABLED = msg.tempoEnabled;
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
|
||||
@@ -64,7 +76,9 @@ public class SyncStatsS2CPacket {
|
||||
", Tempo: " + msg.tempo +
|
||||
", VentCD: " + msg.ventCooldown +
|
||||
", MaxSanity: " + msg.maxSanity +
|
||||
", MaxTempo: " + msg.maxTempo
|
||||
", MaxTempo: " + msg.maxTempo +
|
||||
", SanityEnabled: " + msg.sanityEnabled +
|
||||
", TempoEnabled: " + msg.tempoEnabled
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ public class VentPacket {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
ServerPlayer player = ctx.get().getSender();
|
||||
if (player == null) return;
|
||||
if (!ConfigMM.COMMON.ENABLE_TEMPO.get()) return;
|
||||
int ventCost = ConfigMM.COMMON.VENT_COST.get();
|
||||
player.getCapability(PlayerCapabilityProvider.TEMPO).ifPresent(tempo -> {
|
||||
if (tempo.getTempo() < ventCost) return;
|
||||
|
||||
Reference in New Issue
Block a user