Implement Vent mechanic, small adjustments to everything and dependencies
This commit is contained in:
@@ -4,4 +4,5 @@ public class ClientData {
|
||||
public static float SANITY = 80f;
|
||||
public static float INSANITY = 0f;
|
||||
public static int TEMPO = 0;
|
||||
public static int VENT_COOLDOWN = 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.fretux.mindmotion.client;
|
||||
|
||||
import net.fretux.mindmotion.network.ModMessages;
|
||||
import net.fretux.mindmotion.network.VentPacket;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.InputEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = "mindmotion", value = Dist.CLIENT)
|
||||
public class ClientEvents {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onKeyInput(InputEvent.Key event) {
|
||||
if (Keybinds.VENT_KEY.isDown()) {
|
||||
ModMessages.CHANNEL.sendToServer(new VentPacket());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package net.fretux.mindmotion.client;
|
||||
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
|
||||
import net.minecraftforge.client.settings.KeyConflictContext;
|
||||
import net.minecraftforge.client.settings.KeyModifier;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
|
||||
public class Keybinds {
|
||||
|
||||
public static KeyMapping VENT_KEY;
|
||||
|
||||
public static void register(RegisterKeyMappingsEvent event) {
|
||||
VENT_KEY = new KeyMapping(
|
||||
"key.mindmotion.vent",
|
||||
KeyConflictContext.IN_GAME,
|
||||
KeyModifier.NONE,
|
||||
InputConstants.Type.KEYSYM,
|
||||
InputConstants.KEY_G,
|
||||
"key.categories.mindmotion"
|
||||
);
|
||||
|
||||
event.register(VENT_KEY);
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,18 @@ public class SanityTempoOverlay {
|
||||
RenderSystem.enableBlend();
|
||||
drawRoundedBar(gui, xTempo, y, BAR_WIDTH, BAR_HEIGHT, 0xFF33AFFF, tempoFill);
|
||||
gui.drawString(mc.font, Component.literal("Tempo"), xTempo, y - 10, 0x66CCFF, false);
|
||||
if (ClientData.VENT_COOLDOWN > 0) {
|
||||
int seconds = ClientData.VENT_COOLDOWN / 20;
|
||||
String ventText = "Vent: " + seconds + "s";
|
||||
gui.drawString(
|
||||
mc.font,
|
||||
Component.literal(ventText),
|
||||
xTempo,
|
||||
y - 22,
|
||||
0x33AFFF,
|
||||
false
|
||||
);
|
||||
}
|
||||
boolean insaneMode = sanity <= 0;
|
||||
if (!insaneMode) {
|
||||
drawRoundedBar(gui, xSanity, y, BAR_WIDTH, BAR_HEIGHT, 0xFFFFFFFF, sanityFill);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.fretux.mindmotion.client.effects;
|
||||
|
||||
import net.fretux.mindmotion.client.ClientData;
|
||||
import net.fretux.mindmotion.client.shader.VentShaderHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.PostChain;
|
||||
import net.minecraft.client.renderer.PostPass;
|
||||
@@ -22,8 +23,6 @@ public class SanityShaderHandler {
|
||||
new ResourceLocation("mindmotion", "shaders/post/desaturate.json");
|
||||
|
||||
private static float currentStrength = 0f;
|
||||
|
||||
// cache reflection so we don't look it up every frame
|
||||
private static Field passesField;
|
||||
|
||||
private static List<PostPass> getPasses(PostChain chain) throws IllegalAccessException, NoSuchFieldException {
|
||||
@@ -38,7 +37,6 @@ public class SanityShaderHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRenderWorld(RenderLevelStageEvent event) {
|
||||
// AFTER_LEVEL is the point where the full world image is ready
|
||||
if (event.getStage() != RenderLevelStageEvent.Stage.AFTER_LEVEL) return;
|
||||
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
@@ -59,11 +57,7 @@ public class SanityShaderHandler {
|
||||
float insanityBoost = 0.75f * insanityPct;
|
||||
float target = Math.max(baseDesat, insanityBoost);
|
||||
if (sanity <= 0f) target = 1f;
|
||||
|
||||
// smooth to avoid popping
|
||||
currentStrength += (target - currentStrength) * 0.08f;
|
||||
|
||||
// if essentially zero, shut the effect off completely
|
||||
if (currentStrength < 0.005f) {
|
||||
if (mc.gameRenderer.currentEffect() != null) {
|
||||
mc.gameRenderer.shutdownEffect();
|
||||
@@ -71,8 +65,6 @@ public class SanityShaderHandler {
|
||||
currentStrength = 0f;
|
||||
return;
|
||||
}
|
||||
|
||||
// ensure our effect is loaded
|
||||
if (mc.gameRenderer.currentEffect() == null) {
|
||||
try {
|
||||
mc.gameRenderer.loadEffect(DESAT_EFFECT);
|
||||
@@ -142,6 +134,14 @@ public class SanityShaderHandler {
|
||||
float time = (mc.level.getGameTime() % 200000) / 20f;
|
||||
var uTime = effect.getUniform("Time");
|
||||
if (uTime != null) uTime.set(time);
|
||||
if (VentShaderHandler.isActive()) {
|
||||
float strength = VentShaderHandler.getStrength();
|
||||
var uShock = effect.getUniform("ShockwaveStrength");
|
||||
if (uShock != null) uShock.set(strength);
|
||||
} else {
|
||||
var uShock = effect.getUniform("ShockwaveStrength");
|
||||
if (uShock != null) uShock.set(0f);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.fretux.mindmotion.client.shader;
|
||||
|
||||
public class VentShaderHandler {
|
||||
|
||||
private static long shockwaveEnd = 0;
|
||||
|
||||
public static void triggerVentShockwave() {
|
||||
shockwaveEnd = System.currentTimeMillis() + 400; // 0.4 seconds
|
||||
}
|
||||
|
||||
public static boolean isActive() {
|
||||
return System.currentTimeMillis() < shockwaveEnd;
|
||||
}
|
||||
|
||||
public static float getStrength() {
|
||||
float remain = (shockwaveEnd - System.currentTimeMillis()) / 400f;
|
||||
return Math.max(0f, Math.min(1f, 1f - remain));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user