#How to get sound to work with Valkyrien skies Objects
1 messages · Page 1 of 1 (latest)
Im not opposed to trying. are you just saying that to say it, or do you actually have an idea on exactly how i would use java to help fix it?
You would need to fork sound physics remastered
(To make a pull request later. Pull request = GitHub for “please add my code”)
Then the issue is probably that the sounds aren’t being transformed out of the shipyard
Like they’re playing, but millions of blocks away at the ship
So you would need to either
- Find the distance check / position the sound uses, and change it to one that VS will transform automatically
- Write some code that runs optionally if VS is installed, that uses the vs api to manually move the position out of the shipyard
wait. so are the blocks being rendered for Valkyrian skies like, rendered really far away?
They are physically really far away
I think i remember something simmilar being done for sea of theves or something like that, where the actual boats were stationary somewhere. and whenever the player would stand on a ship they would be transfered to the stationary ship. and the ship you see is simply being rendered with a transform of sorts.
Then rendered to up close where the ship “is”
Ahhhhhh
Although the player stays in the real world
The shipyard is like when a ship freaks out and you see a bunch of void and the world border sometimes
anyway like 99% of VS compat issues
Is stuff either being in the real world position when it should be in the shipyard
Or vice versa
that makes a lot of sense
But it’s hard for VS to improve that compat overall for all the mods, because each mod is different and requires different context
So probably the best soulution would be a "compat" of sorts for the specific sound mods. hmm... since its raycasted sounds with sound physics mod... can you even transform a raycast like that?
Yeah you can
And Valkyrien skies tries to redirect ray casts when it makes sense too
But this kinda compat is a lot easier to fix from sound physics side
that makes sense. Thank you for the information! I'll play around with that to see. I may even try to bug some of the peeps over in that mod discord if they have one.
What information/file/place would I be looking for in VS to find the transformation stuff? so i can see how you guys have done the transforms before
I think the VS code would be more confusing
My recommendation is to look around at the sound physics (specifically stepping sounds)
And try to track down where the “location” of the sound comes from
Then add a breakpoint there so it stops in debug mode, and you can look at the variables for which are in the shipyard
(These instructions are quite generic but it really does vary per mod that needs compat)
understandable. and fantastic idea!
this will.. take a moment... I've never written a mod before but i'm not a stranger to code. so i have some learnings to do
Have you written Java before?
yes
That’s good then
I was planning on learning how to actually write mods for minecraft anyway. this just gives me another excuse to do it sooner then later.
Wouldnt we have to also take into account for other stuff. I think i remember reading somewhere that Create: Big cannons also had a hard time with sound?
@strange walrus or anybody else who is online. Is there any special blocks or tags put onto things in the "shipyard"
The idea is:
// check if block is on ship
{
private static Vec3d transformVSPosition(Vec3d originalPos){
// transform from far away to closer
}
//somewhere within the evaluateEnvironment() in soundphysics
Vec3d actualSoundPos = soundPos;
if (ValkyrienSkiesAPI.isBlockInShipyard(soundBlockPos)) {
actualSoundPos = transformVSPosition(soundPos);
//then if i'm reading this right. also do this for secondary sounds
SPHitResult rayHit = fixedRaycast(actualSoundPos, actualPlayerPos, mc.world, lastBlockPos, soundChunk);
This is to be added into this "https://github.com/vlad2305m/Sound-Physics-Fabric/blob/master/src/main/java/com/sonicether/soundphysics/SoundPhysics.java"
you're on the right track
and I can provide those functions for you
however, this would cause sound physics to crash if Valkyrien Skies isn't installed
yeah and the file that it runs
has to be a seperate class file
so that the imports are only evaluated if the mod is found
roger that
another question would be. whats the best way to package this? should i just upload it to curseforge as a seperate mod? or would there be a way to easially make this sort of a third mod that you install along side both vs and soundphysics
modrinth too plz
easiest way is to make a pull request to sound physics remastered
then while you wait for it to be released officially, you hand out builds to people who need it
reuploading is... frowned upon, even if you made changes
yeah. i wouldnt want to do that....
and having a third mod would involve a mixin, which you probably don't want to get into yet
seems like asking and waiting may take a bit
This feels like the best action.
lmfao If it gets to a point that where you feel like you can help just say something
I think the approach will be. Modify this code to see if it even works. Then move onto writing a stand-alone version as a downloadable 3rd mod with mixins for soundphysics remastered and VS
private static boolean isValkyrienSkiesBlock(Level level, BlockPos pos){
// Just use instead:
VSGameUtilsKt.isBlockInShipyard(level, pos);
}
private static Vec3d transformPositionIfVS(Level level, Vec3d originalPos){
// VS uses JOML vector types, Minecraft has its own.
// Use VectorConversionsMCKt to convert between
Vector3d vectorOgPos = VectorConversionsMCKt.toJOML(originalPos);
Ship ship = VSGameUtilsKt.getShipObjectManagingPos(level, vectorOgPos);
// Ship will be null if the position isn't in the shipyard
// So isBlockInShipyard isn't that useful
if (ship != null) {
// The magic, transform the position.
// If you need to transform a direction (e.g. for a raycast)
// use .transformDirection instead!
// There's also .getWorldToShip() if you need that direction
Vector3d newPos = ship.getTransform().getShipToWorld().transformPosition(vectorOgPos);
// Back to MC's vector format
return VectorConversionsMCKt.toMinecraft(newPos);
}
// No ship, no need to transform
return originalPos;
}
now this isn't taking into account if VS isn't installed
but if you plan to make a 3rd mod anyway you dont really have to bother with that
It would be better to just assume that it will be. yeah exactly
https://www.shadertoy.com/view/Wc3SW7 my knowledge might be relevant
OHH cool!!
visual and audible are similar
very simmilar!
Thank you for this! I'll get to work on it. i'll be back with some results
Uh
I'm pretty sure 2.5 has sound physics remastered compat
as this would save me several hours of work. could you elaborate?
Wait a second
The published vs version should have compatibility
huh
is this the most recent one on curseforge?
or am i just very very very lost on witch version to use
witch is likely
because im not seeign the huge 2
Weird
What if you remove presence footsteps
I thought about that too. and it didnt effect it but i'll do it again.
- removed. testing again. sending video.
@brisk arrow same result
Actually
could this be something?
sorry. continue. didnt mean to interupt
Nah, it's k
That wouldn't really make much of a difference I don't think
probably right
Ok, I understand what's going on
ah i was looking at the wrong version before.
lmfao i was also reading it
my idea was this. what was yours?
Mine was that onPlaySound is no longer actually used
But vs mixins that
You'd just need to mixin processSound instead
sounds like we got to the bottom of the issue. whats the move from here? is that an entirely new mixin file that needs to be written?
Nah, just editing https://github.com/ValkyrienSkies/Valkyrien-Skies-2/blob/1.20.1/2.3/common/src/main/java/org/valkyrienskies/mod/mixin/mod_compat/sound_physics_remastered/MixinSoundPhysics.java this will do
But most of it has to be rewritten
Feel free to ask any questions btw
Also
This has to be done in vs and not in sound physics
So you'll have to fork and PR to vs
rodger dodger
Welp, I gtg for today, it's night over here
have a good sleep! thank you for the help!
okay.. I think I have something...
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.phys.Vec3;
import org.joml.Vector3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.valkyrienskies.core.api.ships.ClientShip;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
@Pseudo
@Mixin(targets = "com.sonicether.soundphysics.SoundPhysics", remap = false)
public abstract class MixinSoundPhysics {
@Shadow(remap = false)
public static Vec3 processSound(int sourceID, double posX, double posY, double posZ, SoundSource category, String sound, boolean auxOnly) {
throw new AssertionError();
}
@Inject(
at = @At("HEAD"),
method = "processSound",
cancellable = true,
remap = false
)
private static void beforeProcessSound(int sourceID,double posX,double posY,double posZ,SoundSource category,String sound,boolean auxOnly,CallbackInfoReturnable<Vec3> cir)
{
final ClientLevel level = Minecraft.getInstance().level;
if (level == null) {
return;
}
if (VSGameUtilsKt.getShipManagingPos(level, posX, posY, posZ) instanceof final ClientShip ship) {
final Vector3d inWorldPos = ship.getShipToWorld().transformPosition(new Vector3d(posX, posY, posZ));
Vec3 result = processSound(sourceID, inWorldPos.x, inWorldPos.y, inWorldPos.z, category, sound, auxOnly);
cir.setReturnValue(result);
cir.cancel();
}
}
}```
@strange walrus or others. can one of you guys look at this and tell me if i understood it or not?
@fierce tide or @patent hollow?
I think that would work yeah
(I really gotta sleep now tho)
Test it out ig
Runclient gradle task
you can make processSound an abstract function
from my very quick researched panic and a little bit of Ai helping me. Its basically taking the function from physics remastered and editing it
then you dont need the dummy assert
exactly what mixins do
thats really cool! what a neat thing
I gotta go to my actual job now. I'll pick this back up later if nobody else does.
Ngl, I would probably use an @ModifyArgs for this but this will probably work
yeah. Its been a hot minute since i coded with java last. and this is my first exposure to mixins lmfao
so i'm definately not doing things 100% right here
Hello guys. I'm back. does this look better? also whats the quick n dirty way I can test this?
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.phys.Vec3;
import org.joml.Vector3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.valkyrienskies.core.api.ships.ClientShip;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
@Pseudo
@Mixin(targets = "com.sonicether.soundphysics.SoundPhysics", remap = false)
public abstract class MixinSoundPhysics {
// abstract function?
// public abstract Vec3 processSound(
// int sourceID,
// double posX, double posY, double posZ,
// SoundSource category,
// String sound,
// boolean auxOnly
// );
// @Inject(at = @At("HEAD"), method = "processSound", cancellable = true, remap = false)
// private static void beforeProcessSound(int sourceID, double posX, double posY, double posZ, SoundSource category,
// String sound, boolean auxOnly, CallbackInfoReturnable<Vec3> cir) {
// final ClientLevel level = Minecraft.getInstance().level;
@ModifyArgs(
method = "processSound",
at = @At(value = "HEAD"),
remap = false
)
private static void transformSoundPositions(Args args) {
final ClientLevel level = Minecraft.getInstance().level;
if (level == null) {
return;
}
//get arguments
double posX = args.get(1);
double posY = args.get(2);
double posZ = args.get(3);
if (VSGameUtilsKt.getShipManagingPos(level, posX, posY, posZ) instanceof final ClientShip ship) {
final Vector3d inWorldPos = ship.getShipToWorld().transformPosition(new Vector3d(posX, posY, posZ));
//Modify the arguments
args.set(1, inWorldPos.x); // posX
args.set(2, inWorldPos.y); // posY
args.set(3, inWorldPos.z); // posZ
//Return not needed with ModifyArgs
// Vec3 result = processSound(sourceID, inWorldPos.x, inWorldPos.y, inWorldPos.z, category, sound, auxOnly);
// cir.setReturnValue(result);
// cir.cancel();
}
}
}```
@strange walrus @brisk arrow thoughts if alive?
ohh its a bash thing
This version built
Nice
@brisk arrow It built but i'm unsure on how to test it with the other mod at the same time
It built because it’s pseudo
But you should add it to the dev environment
Did you put it in common, forge, or fabric?
package org.valkyrienskies.mod.mixin.mod_compat.sound_physics_remastered;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.phys.Vec3;
import org.joml.Vector3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.valkyrienskies.core.api.ships.ClientShip;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
@Pseudo
@Mixin(targets = "com.sonicether.soundphysics.SoundPhysics", remap = false)
public abstract class MixinSoundPhysics {
@Shadow(remap = false)
public static abstract Vec3 processSound(int sourceID, double posX, double posY, double posZ, SoundSource category, String sound, boolean auxOnly);
@Inject(
at = @At("HEAD"),
method = "processSound",
cancellable = true,
remap = false
)
private static void beforeProcessSound(int sourceID,double posX,double posY,double posZ,SoundSource category,String sound,boolean auxOnly,CallbackInfoReturnable<Vec3> cir)
{
if (VSGameUtilsKt.getShipManagingPos(level, posX, posY, posZ) instanceof final ClientShip ship) {
final Vector3d inWorldPos = ship.getShipToWorld().transformPosition(new Vector3d(posX, posY, posZ));
Vec3 result = processSound(sourceID, inWorldPos.x, inWorldPos.y, inWorldPos.z, category, sound, auxOnly);
return result;
}
}
}
What about this
Try it out
@fresh otter
what did you change?
anyway I debugged
and beforeProcessSound isn't being called for the sounds on the ship at all
Huh
possibly because the sounds aren't getting to the client
so its not "beforeProcessing" them
Removed the null return with the level check
Cuz iirc it checks level anyway
So it's another rabbit hole
Sweet!! Thank you guys for the effort! that helps a bunch! Great to know i can just add the other mod into things. thats easier then i thought it would be.
I'll give it another pass when i have some time
specifically you would add
modRuntimeOnly("maven.modrinth:sound-physics-remastered:fabric-1.20.1-1.4.12")
to the dependencies block in the fabric build.gradle
(to test on fabric)
im re-reading it and I think we need to modify the evaluateEnvironment too. Previously I was just focused on mimicking the same code that was already there in the previous mixin. But its entirely possible that its thinking the sound is coming from too far away and just ignoring it.
I was running it via forge. Would this same mixin work on both? this is a good point to bring up. perhaps this is a forge specific issue? Do we need seperate mixins for both?
The mixin will probably work on both
to add it to the forge runtime it would be uh
modRuntimeOnly("maven.modrinth:sound-physics-remastered:forge-1.20.1-1.4.13")
to the dependencies block in the forge build.gradle
and if you want the mixin file to be aware of the actual class to give hints and stuff
you would add the fabric dependency ^ to the common build.gradle dependencies block
and set the mixin to
@Mixin(value=SoundPhysics.class, remap=false)
instead of a string target
does this make it work for both? or just specifically fabric?
if the mixin is in the common package
it'll attempt to work on both
(it could always fail if the fabric/forge versions are different, but thats usually rare)
but we use the fabric version in common as a habit
sweet. thats really good to know. i'll also go double check on curseforge to ensure that the forge version of the mod would be the same one people would install for fabric
yeah seems like they are supporting 3 environments with the same mod. and it would be the mod people install. just a sanity check that im not making something for a specific spinoff
and its the same on modrinth
and @strange walrus
in this code im getting this error. is this safe to ignore?
its saying processSound cant have an abstract for some reason
oh its beecause its static
which I didn't notice
you can turn it back into an empty function
what
no it should be static
just remove the abstract part and add a {} on the end of the line
before the ;

well
it didnt like that eyther
and i've put back the semicolon for laughs before and after and its the static that its still complaining about
isnt it because its a vec3? and is expecting a return?
mixin stuff and re-writing function stuff is still pretty new to me
thats not it eyther
i'll come back to it
here the full code:
@Shadow(remap = false)
public static Vec3 processSound(int sourceId, double posX, double posY, double posZ, SoundSource category, String sound, boolean auxOnly) {};
so you dropped the abstract?
yea
thats fair enough.
Actually, I'm dumb
Getting the ship needs level
That may be an issue
But isn’t the issue
With a breakpoint I found the function was never called with shipyard coordinates
Or with the sounds I was trying to make at all
So a function further upstream must be the issue
@brisk arrow@strange walrus I think you guys are making progress on this way faster then I could lmfao. although. I will keep trying.
It seems to me like a lot of the meat and potatoes happens around this variable within evaluate environment
and I see what you guys are doing here. where this is where it gets called
nevermind i think im just a few steps behind
public static Vec3 evaluateEnvironment(int sourceId, double posX, double posY, double posZ, SoundSource category, String sound, boolean auxOnly) {};
@Inject(
at = @At("HEAD"),
method = "evaluateEnvironment",
cancellable = true,
remap = false
)
private static void beforeEvaluateEnvironment(int sourceID, double posX, double posY, double posZ, SoundSource category,
String sound, boolean auxOnly) {
if (VSGameUtilsKt.getShipManagingPos(level, posX, posY, posZ) instanceof final ClientShip ship) {
final ClientLevel level = Minecraft.getInstance().level;
if (level == null) {
return;
}
final Vector3d inWorldPos = ship.getShipToWorld().transformPosition(new Vector3d(posX, posY, posZ));
Vec3 result = evaluateEnvironment(sourceID, inWorldPos.x, inWorldPos.y, inWorldPos.z, category, sound, auxOnly);
return result;
}
}```
I was thinking we point this instead at the eveluate environment but I dont think that will be any different since doing it with processSound passes the altered variables to it.
Sorry I didn't see this, been out of town for a few weeks, and when I messaged you earlier, I'm coming back today
all good! I hope your away days have been nice!
They have! I was visiting Europe, it was pretty neat! This was one of the things I wanted to fix with Valkyrien skies too, so I am excited to get back and try and take a swing with you! The other thing that was pretty important to me for effect was particles and those got fixed by a mod called AsyncParticles, pretty neat!
its the little things like this that really help gameplay elements feel super right. and this is 100% spured on by the fact that I just want to stand on my train and enjoy the immersive sounds. but alas. it is dreadfully silent
I totally agree lol
im having a hard time trying to figure out how i properly reference the
public static Vec3 processSound function
This wasnt quite right I dont think
public abstract class MixinSoundPhysics {```
but also this didnt work for me eyther.
```@Mixin(value=SoundPhysics.class, remap=false)```
nor did
```@Mixin(value=com.sonicether.soundphysics.SoundPhysics.processSound, remap=false)```
I probably should try to legetimately learn how to do mixins instead of working with the equivilant of cramming 20minutes before a test.
The middle one seems correct
But you’ll need to import it
Which means it needs to be in the common gradle
^
I got that in there and the middle one still didnt build for me.
hmm just checking my sanity. is ./gradlew runClient the correct bash to run?\
Wait your doing it from the command line?
That’s uh
Tricky
I would recommend IntelliJ (community edition)
It also might be ./gradlew fabric/loom/runClient
okay. its been a hot minute. Work picked up and I just didnt have time to look at this. Have any of you guys had a chance to look at this?
Gotcha. I'll give it another try today. I'll actualy sit down and try to learn a bit more properly. As of Brickyboy's comment looks like I dont even have the full development environment set up. I was just using Visual studio with a few plugins i found from the search bar.
so uh
i actually sat down at this for a bit
there was a pr for 2.3 too but mod compat should prob go to 2.5 so
¯_(ツ)_/¯
really cool
i want
holy moly. Good job man! I ended up just not having enough time to learn all of the mixin stuff. This is amazing and excelent news
Dang