Implement Vent mechanic, small adjustments to everything and dependencies

This commit is contained in:
2025-11-16 22:19:45 +01:00
parent 0bfe52a3ee
commit 0f79150c19
20 changed files with 325 additions and 49 deletions
+36 -17
View File
@@ -120,30 +120,49 @@ repositories {
// flatDir {
// dir 'libs'
// }
maven {
name = "Iron's Maven - Release"
url = "https://code.redspace.io/releases"
content {
includeGroup "io.redspace.ironsspellbooks"
}
}
maven {
name = "Iron's Maven - Snapshots"
url = "https://code.redspace.io/snapshots"
content {
includeGroup "io.redspace.ironsspellbooks"
}
}
maven { url = "https://maven.enginehub.org/repo/" }
maven { url = "https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/" }
maven { url = "https://maven.theillusivec4.top" }
maven { url = "https://cursemaven.com" }
maven { url = "https://maven.blamejared.com" }
maven { url = "https://maven.kosmx.dev/" }
}
dependencies {
// Specify the version of Minecraft to use.
// Any artifact can be supplied so long as it has a "userdev" classifier artifact and is a compatible patcher artifact.
// The "userdev" classifier will be requested and setup by ForgeGradle.
// If the group id is "net.minecraft" and the artifact id is one of ["client", "server", "joined"],
// then special handling is done to allow a setup of a vanilla dependency without the use of an external repository.
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
// Example mod dependency with JEI - using fg.deobf() ensures the dependency is remapped to your development mappings
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}-common-api:${jei_version}")
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}-forge-api:${jei_version}")
// runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}-forge:${jei_version}")
// Iron's Spellbooks API only
compileOnly fg.deobf("io.redspace.ironsspellbooks:irons_spellbooks:${irons_spells_version}:api")
implementation fg.deobf("io.redspace.ironsspellbooks:irons_spellbooks:${irons_spells_version}")
// Example mod dependency using a mod jar from ./libs with a flat dir repository
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
// The group id is ignored when searching -- in this case, it is "blank"
// implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}")
// GECKOLIB — deobfuscated, full mod
implementation fg.deobf("software.bernie.geckolib:geckolib-forge-${geckolib_version}")
// For more info:
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
// PLAYER ANIMATOR — deobf
implementation fg.deobf("dev.kosmx.player-anim:player-animation-lib-forge:${player_animator_version}")
// CAELUS — API only
compileOnly fg.deobf("top.theillusivec4.caelus:caelus-forge:${caelus_version}:api")
implementation fg.deobf("top.theillusivec4.caelus:caelus-forge:${caelus_version}")
// CURIOS — API only
compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:${curios_version}:api")
implementation fg.deobf("top.theillusivec4.curios:curios-forge:${curios_version}")
}
// This block of code expands all declared replace properties in the specified resource targets.
+5 -1
View File
@@ -37,7 +37,11 @@ mapping_channel=official
# This must match the format required by the mapping channel.
mapping_version=1.20.1
irons_spells_version=1.20.1-3.4.0.11
caelus_version=3.1.0+1.20
curios_version=5.4.7+1.20.1
geckolib_version=1.20.1:4.7.1.1
player_animator_version=1.0.2-rc1+1.20
## Mod Properties
# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
@@ -1,10 +1,12 @@
package net.fretux.mindmotion;
import com.mojang.logging.LogUtils;
import net.fretux.mindmotion.client.Keybinds;
import net.fretux.mindmotion.command.SanityCommand;
import net.fretux.mindmotion.event.CombatEvents;
import net.fretux.mindmotion.event.PlayerTickHandler;
import net.fretux.mindmotion.network.ModMessages;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.IEventBus;
@@ -22,6 +24,7 @@ public class AscendMindMotion {
public AscendMindMotion() {
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
modEventBus.addListener(this::commonSetup);
modEventBus.addListener(Keybinds::register);
MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(PlayerTickHandler.class);
MinecraftForge.EVENT_BUS.register(CombatEvents.class);
@@ -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));
}
}
@@ -11,7 +11,7 @@ public class SanityCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(Commands.literal("sanity")
.requires(source -> source.hasPermission(2)) // OP only
.requires(source -> source.hasPermission(2))
.then(Commands.literal("set")
.then(Commands.argument("sanity", FloatArgumentType.floatArg(0, 80))
.then(Commands.argument("insanity", FloatArgumentType.floatArg(0, 80))
@@ -34,19 +34,18 @@ public class PlayerTickHandler {
if (player.level().isClientSide) return;
int tick = player.tickCount;
boolean sanityTick = tick % SANITY_TICK_INTERVAL == 0;
boolean tempoTick = tick % TEMPO_TICK_INTERVAL == 0;
boolean tempoSyncTick = tick % TEMPO_TICK_INTERVAL == 0;
if (sanityTick) handleSanityAndInsanity(player);
if (tempoTick) handleTempoTick(player, tick);
if (player instanceof ServerPlayer serverPlayer && (sanityTick || tempoTick)) {
handleTempoTick(player, tick);
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.getTempo(),
tempo.getVentCooldown()
),
serverPlayer.connection.connection,
net.minecraftforge.network.NetworkDirection.PLAY_TO_CLIENT
@@ -185,12 +184,17 @@ public class PlayerTickHandler {
private static void handleTempoTick(Player player, int currentTick) {
player.getCapability(PlayerCapabilityProvider.TEMPO).ifPresent(tempo -> {
int value = tempo.getTempo();
int lastCombat = lastCombatTick.getOrDefault(player.getUUID(), -10000);
int ticksSinceCombat = currentTick - lastCombat;
if (ticksSinceCombat > COMBAT_DECAY_DELAY && value > 0) {
tempo.setTempo(value - 1);
int cd = tempo.getVentCooldown();
if (cd > 0) {
tempo.setVentCooldown(cd - 1);
}
if (currentTick % TEMPO_TICK_INTERVAL == 0) {
int value = tempo.getTempo();
int lastCombat = lastCombatTick.getOrDefault(player.getUUID(), -10000);
int ticksSinceCombat = currentTick - lastCombat;
if (ticksSinceCombat > COMBAT_DECAY_DELAY && value > 0) {
tempo.setTempo(value - 1);
}
}
});
}
@@ -0,0 +1,42 @@
package net.fretux.mindmotion.event;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.AABB;
public class VentHandler {
public static void performVent(ServerPlayer player) {
ServerLevel level = player.serverLevel();
double radius = 6.0D;
AABB area = new AABB(
player.getX() - radius, player.getY() - 2, player.getZ() - radius,
player.getX() + radius, player.getY() + 2, player.getZ() + radius
);
for (Entity e : level.getEntities(player, area, e -> e != player)) {
double dx = e.getX() - player.getX();
double dz = e.getZ() - player.getZ();
double dist = Math.sqrt(dx * dx + dz * dz) + 0.01;
double strength = 1.6 / dist;
e.push(dx * strength, 0.3, dz * strength);
e.hurtMarked = true;
}
for (int i = 0; i < 40; i++) {
double angle = level.random.nextDouble() * Math.PI * 2;
double speed = 0.3 + level.random.nextDouble() * 0.3;
double vx = Math.cos(angle) * speed;
double vz = Math.sin(angle) * speed;
level.sendParticles(
ParticleTypes.SOUL,
player.getX(),
player.getY() + 1.0,
player.getZ(),
1,
vx, 0.02, vz,
0.1
);
}
}
}
@@ -26,5 +26,15 @@ public class ModMessages {
.decoder(SyncStatsS2CPacket::decode)
.consumerMainThread(SyncStatsS2CPacket::handle)
.add();
CHANNEL.messageBuilder(VentPacket.class, id++, NetworkDirection.PLAY_TO_SERVER)
.decoder(VentPacket::new)
.encoder(VentPacket::toBytes)
.consumerMainThread(VentPacket::handle)
.add();
CHANNEL.messageBuilder(VentClientEffectPacket.class, nextId(), NetworkDirection.PLAY_TO_CLIENT)
.decoder(VentClientEffectPacket::new)
.encoder(VentClientEffectPacket::toBytes)
.consumerMainThread(VentClientEffectPacket::handle)
.add();
}
}
@@ -10,21 +10,24 @@ public class SyncStatsS2CPacket {
private final float sanity;
private final float insanity;
private final int tempo;
private final int ventCooldown;
public SyncStatsS2CPacket(float sanity, float insanity, int tempo) {
public SyncStatsS2CPacket(float sanity, float insanity, int tempo, int ventCooldown) {
this.sanity = sanity;
this.insanity = insanity;
this.tempo = tempo;
this.ventCooldown = ventCooldown;
}
public static void encode(SyncStatsS2CPacket msg, FriendlyByteBuf buf) {
buf.writeFloat(msg.sanity);
buf.writeFloat(msg.insanity);
buf.writeInt(msg.tempo);
buf.writeInt(msg.ventCooldown);
}
public static SyncStatsS2CPacket decode(FriendlyByteBuf buf) {
return new SyncStatsS2CPacket(buf.readFloat(), buf.readFloat(), buf.readInt());
return new SyncStatsS2CPacket(buf.readFloat(), buf.readFloat(), buf.readInt(), buf.readInt());
}
public static void handle(SyncStatsS2CPacket msg, Supplier<NetworkEvent.Context> ctx) {
@@ -32,6 +35,7 @@ public class SyncStatsS2CPacket {
ClientData.SANITY = msg.sanity;
ClientData.INSANITY = msg.insanity;
ClientData.TEMPO = msg.tempo;
ClientData.VENT_COOLDOWN = msg.ventCooldown;
});
ctx.get().setPacketHandled(true);
System.out.println("[Client] Sanity: " + msg.sanity + ", Insanity: " + msg.insanity + ", Tempo: " + msg.tempo);
@@ -0,0 +1,26 @@
package net.fretux.mindmotion.network;
import net.fretux.mindmotion.client.shader.VentShaderHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.network.NetworkEvent;
import java.util.function.Supplier;
public class VentClientEffectPacket {
public VentClientEffectPacket() {}
public VentClientEffectPacket(FriendlyByteBuf buf) {}
public void toBytes(FriendlyByteBuf buf) {}
public boolean handle(Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
Minecraft mc = Minecraft.getInstance();
if (mc.player == null) return;
mc.player.swingTime = 10;
VentShaderHandler.triggerVentShockwave();
});
return true;
}
}
@@ -0,0 +1,49 @@
package net.fretux.mindmotion.network;
import net.fretux.mindmotion.event.VentHandler;
import net.fretux.mindmotion.player.PlayerCapabilityProvider;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraftforge.network.NetworkEvent;
import net.minecraftforge.network.PacketDistributor;
import java.util.function.Supplier;
public class VentPacket {
public VentPacket() {}
public VentPacket(FriendlyByteBuf buf) {}
public void toBytes(FriendlyByteBuf buf) {}
public boolean handle(Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
ServerPlayer player = ctx.get().getSender();
if (player == null) return;
player.getCapability(PlayerCapabilityProvider.TEMPO).ifPresent(tempo -> {
if (tempo.getTempo() < 40) return;
if (tempo.getVentCooldown() > 0) return;
tempo.setTempo(tempo.getTempo() - 40);
tempo.setVentCooldown(20 * 15);
VentHandler.performVent(player);
player.level().playSound(
null,
player.getX(), player.getY(), player.getZ(),
SoundEvents.FIREWORK_ROCKET_BLAST,
net.minecraft.sounds.SoundSource.PLAYERS,
1.2f,
0.8f + player.getRandom().nextFloat() * 0.4f
);
player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 20 * 5, 1));
ModMessages.CHANNEL.send(
PacketDistributor.PLAYER.with(() -> player),
new VentClientEffectPacket()
);
});
});
ctx.get().setPacketHandled(true);
return true;
}
}
@@ -2,8 +2,16 @@ package net.fretux.mindmotion.player;
public interface ITempo {
int getTempo();
void setTempo(int tempo);
int getMaxTempo();
void addTempo(int amount);
void reduceTempo(int amount);
int getVentCooldown();
void setVentCooldown(int ticks);
}
@@ -14,8 +14,10 @@ import javax.annotation.Nullable;
@Mod.EventBusSubscriber(modid = "mindmotion")
public class PlayerCapabilityProvider {
public static final Capability<ISanity> SANITY = CapabilityManager.get(new CapabilityToken<>(){});
public static final Capability<ITempo> TEMPO = CapabilityManager.get(new CapabilityToken<>(){});
public static final Capability<ISanity> SANITY = CapabilityManager.get(new CapabilityToken<>() {
});
public static final Capability<ITempo> TEMPO = CapabilityManager.get(new CapabilityToken<>() {
});
@SubscribeEvent
public static void attachCapabilities(AttachCapabilitiesEvent<?> event) {
@@ -64,12 +66,14 @@ public class PlayerCapabilityProvider {
public CompoundTag serializeNBT() {
CompoundTag tag = new CompoundTag();
tag.putInt("Tempo", instance.getTempo());
tag.putInt("VentCooldown", instance.getVentCooldown());
return tag;
}
@Override
public void deserializeNBT(CompoundTag nbt) {
instance.setTempo(nbt.getInt("Tempo"));
instance.setVentCooldown(nbt.getInt("VentCooldown"));
}
}
}
@@ -5,13 +5,39 @@ public class TempoCapability implements ITempo {
private final int maxTempo = 120;
@Override
public int getTempo() { return tempo; }
public int getTempo() {
return tempo;
}
@Override
public void setTempo(int tempo) { this.tempo = Math.max(0, Math.min(maxTempo, tempo)); }
public void setTempo(int tempo) {
this.tempo = Math.max(0, Math.min(maxTempo, tempo));
}
@Override
public int getMaxTempo() { return maxTempo; }
public int getMaxTempo() {
return maxTempo;
}
@Override
public void addTempo(int amount) { setTempo(this.tempo + amount); }
public void addTempo(int amount) {
setTempo(this.tempo + amount);
}
@Override
public void reduceTempo(int amount) { setTempo(this.tempo - amount); }
public void reduceTempo(int amount) {
setTempo(this.tempo - amount);
}
private int ventCooldown = 0;
@Override
public int getVentCooldown() {
return ventCooldown;
}
@Override
public void setVentCooldown(int ticks) {
ventCooldown = ticks;
}
}
@@ -8,6 +8,7 @@ uniform float FogStrength;
uniform float PulseStrength;
uniform float Time;
uniform float FlashStrength;
uniform float ShockwaveStrength;
in vec2 texCoord;
in vec2 oneTexel;