diff --git a/common/src/main/java/com/cobblemon/mod/common/duck/ChannelDuck.java b/common/src/main/java/com/cobblemon/mod/common/duck/ChannelDuck.java index 4e56351e2e..04ecea8efa 100644 --- a/common/src/main/java/com/cobblemon/mod/common/duck/ChannelDuck.java +++ b/common/src/main/java/com/cobblemon/mod/common/duck/ChannelDuck.java @@ -13,5 +13,6 @@ public interface ChannelDuck { void cobblemon$inverseAttenuation(float rolloffFactor); void cobblemon$clearFilters(); -// void cobblemon$exponentialAttenuation(float rolloff, float refDistance, float maxDistance); + void cobblemon$applyReverb(float decayTime, float gain, float diffusion, float density); + void cobblemon$clearReverb(); } diff --git a/common/src/main/java/com/cobblemon/mod/common/mixin/ChannelMixin.java b/common/src/main/java/com/cobblemon/mod/common/mixin/ChannelMixin.java index f7dd0eba26..ef692c8002 100644 --- a/common/src/main/java/com/cobblemon/mod/common/mixin/ChannelMixin.java +++ b/common/src/main/java/com/cobblemon/mod/common/mixin/ChannelMixin.java @@ -11,6 +11,7 @@ package com.cobblemon.mod.common.mixin; import com.cobblemon.mod.common.duck.ChannelDuck; import com.mojang.blaze3d.audio.Channel; import org.lwjgl.openal.AL10; +import org.lwjgl.openal.AL11; import org.lwjgl.openal.EXTEfx; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -21,8 +22,10 @@ public abstract class ChannelMixin implements ChannelDuck { @Shadow private int source; - // Id of filter applied when sound is obstructed + // Ids of effects applied to the channel private int cobblemon$lowPassFilterId = 0; + private int cobblemon$reverbEffectId = 0; + private int cobblemon$reverbSlotId = 0; @Override public void cobblemon$applyLowPassFilter(float gain, float hfGain) { @@ -67,4 +70,54 @@ public abstract class ChannelMixin implements ChannelDuck { cobblemon$lowPassFilterId = 0; } } + + @Override + public void cobblemon$applyReverb(float decayTime, float gain, float diffusion, float density) { + // Clean up existing reverb first if it exists + cobblemon$clearReverb(); + + // Create the effect object + int effectId = EXTEfx.alGenEffects(); + if (!EXTEfx.alIsEffect(effectId)) { + System.err.println("Failed to create OpenAL reverb effect"); + return; + } + + EXTEfx.alEffecti(effectId, EXTEfx.AL_EFFECT_TYPE, EXTEfx.AL_EFFECT_REVERB); + EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_DECAY_TIME, decayTime); + EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_GAIN, gain); + EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_DIFFUSION, diffusion); + EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_DENSITY, density); + + // Create auxiliary effect slot and load effect into it + int slotId = EXTEfx.alGenAuxiliaryEffectSlots(); + if (!EXTEfx.alIsAuxiliaryEffectSlot(slotId)) { + System.err.println("Failed to create OpenAL auxiliary effect slot"); + EXTEfx.alDeleteEffects(effectId); + return; + } + + EXTEfx.alAuxiliaryEffectSloti(slotId, EXTEfx.AL_EFFECTSLOT_EFFECT, effectId); + + // Route source through the slot ΓÇö send 0, no direct filter + AL11.alSource3i(source, EXTEfx.AL_AUXILIARY_SEND_FILTER, slotId, 0, EXTEfx.AL_FILTER_NULL); + + cobblemon$reverbEffectId = effectId; + cobblemon$reverbSlotId = slotId; + } + + @Override + public void cobblemon$clearReverb() { + if (cobblemon$reverbSlotId != 0) { + // Detach source from slot + AL11.alSource3i(source, EXTEfx.AL_AUXILIARY_SEND_FILTER, + EXTEfx.AL_EFFECTSLOT_NULL, 0, EXTEfx.AL_FILTER_NULL); + EXTEfx.alDeleteAuxiliaryEffectSlots(cobblemon$reverbSlotId); + cobblemon$reverbSlotId = 0; + } + if (cobblemon$reverbEffectId != 0) { + EXTEfx.alDeleteEffects(cobblemon$reverbEffectId); + cobblemon$reverbEffectId = 0; + } + } } diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/client/entity/PokemonClientDelegate.kt b/common/src/main/kotlin/com/cobblemon/mod/common/client/entity/PokemonClientDelegate.kt index d9f960eedb..863fe69329 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/client/entity/PokemonClientDelegate.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/client/entity/PokemonClientDelegate.kt @@ -90,6 +90,7 @@ class PokemonClientDelegate : PosableState(), PokemonSideDelegate { var playedSendOutSound: Boolean = false var playedThrowingSound: Boolean = false private var lastAlphaEyeParticle = 0L + val eyeTrailPositions = mutableMapOf>>() // List of eye locators that are tracking their position overtime for alpha eye trail rendering val secondsSinceBeamEffectStarted: Float get() = (System.currentTimeMillis() - beamStartTime) / 1000F @@ -479,9 +480,10 @@ class PokemonClientDelegate : PosableState(), PokemonSideDelegate { } } } - spawnAlphaEyeParticles() } + + // TODO: use the aspect private fun spawnAlphaEyeParticles() { if (currentEntity.entityData.get(PokemonEntity.MARK) != ALPHA_MARK_ID) { return diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/client/render/models/blockbench/bedrock/animation/BedrockAnimation.kt b/common/src/main/kotlin/com/cobblemon/mod/common/client/render/models/blockbench/bedrock/animation/BedrockAnimation.kt index 8037e369bf..8e5b792c49 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/client/render/models/blockbench/bedrock/animation/BedrockAnimation.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/client/render/models/blockbench/bedrock/animation/BedrockAnimation.kt @@ -18,23 +18,25 @@ import com.cobblemon.mod.common.client.render.models.blockbench.PosableModel import com.cobblemon.mod.common.client.render.models.blockbench.PosableState import com.cobblemon.mod.common.client.render.models.blockbench.pose.Bone import com.cobblemon.mod.common.client.render.models.blockbench.repository.RenderContext +import com.cobblemon.mod.common.client.sound.instances.AlphaCrySoundInstance +import com.cobblemon.mod.common.entity.pokemon.PokemonEntity import com.cobblemon.mod.common.util.effectiveName import com.cobblemon.mod.common.util.genericRuntime import com.cobblemon.mod.common.util.getString import com.cobblemon.mod.common.util.math.geometry.toRadians import com.cobblemon.mod.common.util.resolveDouble -import java.util.SortedMap -import java.util.TreeMap import net.minecraft.CrashReport import net.minecraft.ReportedException import net.minecraft.client.Minecraft import net.minecraft.client.model.geom.ModelPart import net.minecraft.client.multiplayer.ClientLevel +import net.minecraft.client.resources.sounds.EntityBoundSoundInstance import net.minecraft.client.resources.sounds.SimpleSoundInstance import net.minecraft.resources.ResourceLocation import net.minecraft.sounds.SoundEvent import net.minecraft.world.entity.Entity import net.minecraft.world.phys.Vec3 +import java.util.* data class BedrockAnimationGroup( val formatVersion: String, @@ -110,7 +112,13 @@ class BedrockSoundKeyframe( if (soundEvent != null) { if (entity != null) { if (!entity.isSilent) { - entity.level().playLocalSound(entity, soundEvent, entity.soundSource, 1F, 1F) + // If this entity is an alpha then play their cry as such + if (entity is PokemonEntity && entity.pokemon.isAlpha) { + Minecraft.getInstance().soundManager.play( + AlphaCrySoundInstance(soundEvent, entity.soundSource, 1.5f, 0.7f, entity, entity.level().random.nextLong())) + } else { + entity.level().playLocalSound(entity, soundEvent, entity.soundSource, 1F, 1F) + } } } else { Minecraft.getInstance().soundManager.play(SimpleSoundInstance.forUI(soundEvent, 1F, 1F)) diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/client/render/pokemon/EyeTrailRenderer.kt b/common/src/main/kotlin/com/cobblemon/mod/common/client/render/pokemon/EyeTrailRenderer.kt new file mode 100644 index 0000000000..61ddde490f --- /dev/null +++ b/common/src/main/kotlin/com/cobblemon/mod/common/client/render/pokemon/EyeTrailRenderer.kt @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2023 Cobblemon Contributors + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package com.cobblemon.mod.common.client.render.pokemon + +import com.cobblemon.mod.common.client.render.MatrixWrapper +import net.minecraft.client.renderer.RenderType +import com.mojang.blaze3d.vertex.PoseStack +import net.minecraft.client.renderer.MultiBufferSource +import net.minecraft.world.phys.Vec3 +import org.joml.Vector3f + +/** + * + * Renders an alpha eye trail based on a list of previous eye locator positions + * + * @author Jackson + * @since March 21st, 2026 + */ +private const val TRAIL_MAX_WIDTH = 0.015f +private const val TRAIL_MAX_ALPHA = 0.8f +private val TRAIL_COLOR = Vector3f(0.7f, 0.0f, 0.0f) +private const val TRAIL_DURATION_MS = 250 // lookback distance in ms for previous eye positions for trail rendering + +private val EYE_LOCATOR_NAMES = setOf( + "eye_left", "eye_right", "eye", + "locator_eye_left", "locator_eye_right", + "eye1", "eye2" +) + +/** + * Updates the eye trail positions based on the current entity position and locator states + */ +fun updateEyeTrail( + aspects: Set, + locatorStates: Map, + entityPos: Vec3, + trailPositions: MutableMap>> +) { + if ("alpha_eyes" !in aspects) { + trailPositions.clear() + return + } + for (locatorName in EYE_LOCATOR_NAMES) { + val wrapper = locatorStates[locatorName] ?: continue + val pos = wrapper.matrix.getTranslation(Vector3f()) + val worldPos = Vec3( + entityPos.x + pos.x, + entityPos.y + pos.y, + entityPos.z + pos.z + ) + val now = System.currentTimeMillis() + val deque = trailPositions.getOrPut(locatorName) { ArrayDeque() } + deque.addLast(worldPos to now) + while (deque.isNotEmpty() && now - deque.first().second > TRAIL_DURATION_MS) { + deque.removeFirst() + } + } +} + +fun renderEyeTrail( + positions: ArrayDeque>, + entityPos: Vec3, + camPos: Vec3, + poseStack: PoseStack, + bufferSource: MultiBufferSource +) { + if (positions.size < 2) return + + val consumer = bufferSource.getBuffer(RenderType.lightning()) + val matrix = poseStack.last().pose() + val n = positions.size + + for (i in 0 until n - 1) { + val curr = positions[i].first + val next = positions[i + 1].first + + val tCurr = i.toFloat() / (n - 1) + val tNext = (i + 1).toFloat() / (n - 1) + + val wCurr = TRAIL_MAX_WIDTH * tCurr + val wNext = TRAIL_MAX_WIDTH * tNext + val aCurr = TRAIL_MAX_ALPHA * tCurr + val aNext = TRAIL_MAX_ALPHA * tNext + + val localCurr = curr.subtract(entityPos) + val localNext = next.subtract(entityPos) + + val dir = next.subtract(curr).normalize() + val toCamera = camPos.subtract(curr).normalize() + val perp = dir.cross(toCamera).normalize() + + val px = perp.x.toFloat() + val py = perp.y.toFloat() + val pz = perp.z.toFloat() + + val r = TRAIL_COLOR.x + val g = TRAIL_COLOR.y + val b = TRAIL_COLOR.z + + consumer.addVertex(matrix, + (localCurr.x - px * wCurr).toFloat(), + (localCurr.y - py * wCurr).toFloat(), + (localCurr.z - pz * wCurr).toFloat() + ).setColor(r, g, b, aCurr) + + consumer.addVertex(matrix, + (localCurr.x + px * wCurr).toFloat(), + (localCurr.y + py * wCurr).toFloat(), + (localCurr.z + pz * wCurr).toFloat() + ).setColor(r, g, b, aCurr) + + consumer.addVertex(matrix, + (localNext.x + px * wNext).toFloat(), + (localNext.y + py * wNext).toFloat(), + (localNext.z + pz * wNext).toFloat() + ).setColor(r, g, b, aNext) + + consumer.addVertex(matrix, + (localNext.x - px * wNext).toFloat(), + (localNext.y - py * wNext).toFloat(), + (localNext.z - pz * wNext).toFloat() + ).setColor(r, g, b, aNext) + } +} diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/client/render/pokemon/PokemonRenderer.kt b/common/src/main/kotlin/com/cobblemon/mod/common/client/render/pokemon/PokemonRenderer.kt index be493b0700..1aab2205a4 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/client/render/pokemon/PokemonRenderer.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/client/render/pokemon/PokemonRenderer.kt @@ -151,6 +151,26 @@ class PokemonRenderer( super.render(entity, entityYaw, partialTicks, poseMatrix, buffer, packedLight) } + // Call rendering for alpha eye trail + updateEyeTrail( + aspects = clientDelegate.currentAspects, + locatorStates = clientDelegate.locatorStates, + entityPos = entity.getPosition(partialTicks), + trailPositions = clientDelegate.eyeTrailPositions + ) + if (clientDelegate.eyeTrailPositions.isNotEmpty()) { + val camPos = Minecraft.getInstance().gameRenderer.mainCamera.position + for ((_, positions) in clientDelegate.eyeTrailPositions) { + renderEyeTrail( + positions = positions, + entityPos = entity.getPosition(partialTicks), + camPos = camPos, + poseStack = poseMatrix, + bufferSource = buffer + ) + } + } + modelNow.green = 1F modelNow.blue = 1F modelNow.resetLayerContext() diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/client/sound/instances/AlphaCrySoundInstance.kt b/common/src/main/kotlin/com/cobblemon/mod/common/client/sound/instances/AlphaCrySoundInstance.kt new file mode 100644 index 0000000000..8f3e86f81c --- /dev/null +++ b/common/src/main/kotlin/com/cobblemon/mod/common/client/sound/instances/AlphaCrySoundInstance.kt @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2023 Cobblemon Contributors + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package com.cobblemon.mod.common.client.sound.instances + +import net.minecraft.client.resources.sounds.EntityBoundSoundInstance +import net.minecraft.sounds.SoundEvent +import net.minecraft.sounds.SoundSource +import net.minecraft.world.entity.Entity + +/** + * A class that acts as a "marker" for alpha cries. This is to avoid having to pass in entity info + * to the [NeoforgeSoundEngineMixin] and [FabricSoundEngineMixin]. The play() mixin can just check for it + * being an instance of [AlphaCrySoundInstance] + */ +class AlphaCrySoundInstance( + sound: SoundEvent, + source: SoundSource, + volume: Float, + pitch: Float, + entity: Entity, + seed: Long +) : EntityBoundSoundInstance(sound, source, volume, pitch, entity, seed) \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/config/CobblemonConfig.kt b/common/src/main/kotlin/com/cobblemon/mod/common/config/CobblemonConfig.kt index 6a0e075703..167dc7dfc9 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/config/CobblemonConfig.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/config/CobblemonConfig.kt @@ -226,16 +226,16 @@ class CobblemonConfig { var pokemonIntrinsicSizeMax = 1.05F @CobblemonConfigField(Category.Pokemon, lang = "alpha_pokemon_size_small_multiplier", SERVER) - var alphaPokemonSizeSmallMultiplier = 1.4F + var alphaPokemonSizeSmallMultiplier = 1.85F @CobblemonConfigField(Category.Pokemon, lang = "alpha_pokemon_size_medium_multiplier", SERVER) - var alphaPokemonSizeMediumMultiplier = 1.3F + var alphaPokemonSizeMediumMultiplier = 1.66F @CobblemonConfigField(Category.Pokemon, lang = "alpha_pokemon_size_large_multiplier", SERVER) - var alphaPokemonSizeLargeMultiplier = 1.2F + var alphaPokemonSizeLargeMultiplier = 1.5F @CobblemonConfigField(Category.Pokemon, lang = "alpha_pokemon_size_extra_large_multiplier", SERVER) - var alphaPokemonSizeExtraLargeMultiplier = 1.1F + var alphaPokemonSizeExtraLargeMultiplier = 1.33F @CobblemonConfigField(Category.Pokemon, lang = "baby_pokemon_level_duration", SERVER) var babyPokemonLevelDuration = 9 diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/aspects/PokemonAspects.kt b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/aspects/PokemonAspects.kt index 2a18004693..68d25d3ddf 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/aspects/PokemonAspects.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/aspects/PokemonAspects.kt @@ -8,6 +8,7 @@ package com.cobblemon.mod.common.pokemon.aspects +import com.cobblemon.mod.common.Cobblemon import com.cobblemon.mod.common.CobblemonCosmeticItems import com.cobblemon.mod.common.CobblemonMemories import com.cobblemon.mod.common.api.pokemon.PokemonProperties diff --git a/common/src/main/resources/data/cobblemon/marks/mark_alpha.json b/common/src/main/resources/data/cobblemon/marks/mark_alpha.json index 2b0167efed..2abcc86603 100644 --- a/common/src/main/resources/data/cobblemon/marks/mark_alpha.json +++ b/common/src/main/resources/data/cobblemon/marks/mark_alpha.json @@ -5,5 +5,5 @@ "description": "cobblemon.mark.mark_alpha.desc", "texture": "cobblemon:textures/gui/mark/mark_alpha.png", "indexNumber": 107, - "aspect": ["alpha_eyes"] + "aspects": ["alpha_eyes"] } \ No newline at end of file diff --git a/fabric/src/main/java/com/cobblemon/mod/fabric/mixin/FabricSoundEngineMixin.java b/fabric/src/main/java/com/cobblemon/mod/fabric/mixin/FabricSoundEngineMixin.java index 46e3554673..575ee7614c 100644 --- a/fabric/src/main/java/com/cobblemon/mod/fabric/mixin/FabricSoundEngineMixin.java +++ b/fabric/src/main/java/com/cobblemon/mod/fabric/mixin/FabricSoundEngineMixin.java @@ -10,6 +10,7 @@ package com.cobblemon.mod.fabric.mixin; import com.cobblemon.mod.common.api.riding.sound.RideAttenuationModel; import com.cobblemon.mod.common.api.riding.sound.RideLoopSound; +import com.cobblemon.mod.common.client.sound.instances.AlphaCrySoundInstance; import com.cobblemon.mod.common.duck.ChannelDuck; import com.llamalad7.mixinextras.sugar.Local; import net.minecraft.client.resources.sounds.SoundInstance; @@ -44,7 +45,6 @@ public class FabricSoundEngineMixin { @Local(name = "channelHandle") ChannelAccess.ChannelHandle handle ) { if (!(sound instanceof RideLoopSound rideSound)) return; - if (handle == null) return; handle.execute((channel) -> { @@ -72,6 +72,26 @@ public class FabricSoundEngineMixin { }); } + @Inject(method = "play", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/sounds/ChannelAccess$ChannelHandle;execute(Ljava/util/function/Consumer;)V" + ) + ) + private void cobblemon$applyAlphaReverb( + SoundInstance sound, + CallbackInfo ci, + @Local(name = "channelHandle") ChannelAccess.ChannelHandle handle + ) { + if (!(sound instanceof AlphaCrySoundInstance)) return; + if (handle == null) return; + + // TODO: probably not make these values hardcoded? Maybe add to alphaCrySoundInstance? + handle.execute(channel -> + ((ChannelDuck) channel).cobblemon$applyReverb(1.0f, 1.0f, 0.90f, 0.90f) + ); + } + @Inject( method = "tickNonPaused", at = @At( diff --git a/neoforge/src/main/java/com/cobblemon/mod/neoforge/mixin/NeoforgeSoundEngineMixin.java b/neoforge/src/main/java/com/cobblemon/mod/neoforge/mixin/NeoforgeSoundEngineMixin.java index d81eb7233a..bb7362ad0d 100644 --- a/neoforge/src/main/java/com/cobblemon/mod/neoforge/mixin/NeoforgeSoundEngineMixin.java +++ b/neoforge/src/main/java/com/cobblemon/mod/neoforge/mixin/NeoforgeSoundEngineMixin.java @@ -10,6 +10,7 @@ package com.cobblemon.mod.neoforge.mixin; import com.cobblemon.mod.common.api.riding.sound.RideAttenuationModel; import com.cobblemon.mod.common.api.riding.sound.RideLoopSound; +import com.cobblemon.mod.common.client.sound.instances.AlphaCrySoundInstance; import com.cobblemon.mod.common.duck.ChannelDuck; import com.llamalad7.mixinextras.sugar.Local; import net.minecraft.client.resources.sounds.SoundInstance; @@ -72,6 +73,26 @@ public class NeoforgeSoundEngineMixin { }); } + @Inject(method = "play", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/sounds/ChannelAccess$ChannelHandle;execute(Ljava/util/function/Consumer;)V" + ) + ) + private void cobblemon$applyAlphaReverb( + SoundInstance sound, + CallbackInfo ci, + @Local(name = "channelaccess$channelhandle") ChannelAccess.ChannelHandle handle + ) { + if (!(sound instanceof AlphaCrySoundInstance)) return; + if (handle == null) return; + + // TODO: probably not make these values hardcoded? Maybe add to alphaCrySoundInstance? + handle.execute(channel -> + ((ChannelDuck) channel).cobblemon$applyReverb(1.0f, 1.0f, 0.90f, 0.90f) + ); + } + @Inject( method = "tickNonPaused", at = @At(