#How to get sound to work with Valkyrien skies Objects

1 messages · Page 1 of 1 (latest)

fresh otter
#

Does anyone know what settings I need to change to get sound to work with these?

more specifically how to get it to work with
sound physics remastered
presence footsteps

strange walrus
#

I don’t think there’s much you can do

#

Unless you know Java

fresh otter
strange walrus
#

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

  1. Find the distance check / position the sound uses, and change it to one that VS will transform automatically
  2. Write some code that runs optionally if VS is installed, that uses the vs api to manually move the position out of the shipyard
fresh otter
strange walrus
#

They are physically really far away

fresh otter
#

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.

strange walrus
#

Then rendered to up close where the ship “is”

fresh otter
#

Ahhhhhh

strange walrus
#

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

fresh otter
#

that makes a lot of sense

strange walrus
#

But it’s hard for VS to improve that compat overall for all the mods, because each mod is different and requires different context

fresh otter
#

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?

strange walrus
#

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

fresh otter
#

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

strange walrus
#

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)

fresh otter
#

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

strange walrus
#

Have you written Java before?

fresh otter
#

yes

strange walrus
#

That’s good then

fresh otter
#

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.

fresh otter
#

@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);
strange walrus
#

and I can provide those functions for you

#

however, this would cause sound physics to crash if Valkyrien Skies isn't installed

fresh otter
#

so it just needs a compatability check

#

er. "check for if mod installed"

strange walrus
#

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

fresh otter
#

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

strange walrus
#

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

fresh otter
#

yeah. i wouldnt want to do that....

strange walrus
#

and having a third mod would involve a mixin, which you probably don't want to get into yet

fresh otter
#

seems like asking and waiting may take a bit

strange walrus
#

just PR sound physics remastered

#

then you could PR the originals later if needed

neat dawn
#

if i can help...

#

watever

#

probably not needed

fresh otter
strange walrus
#

alright I can walk you through that then

#

lemme get you the VS functions first

fresh otter
#

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

strange walrus
#
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

fresh otter
#

It would be better to just assume that it will be. yeah exactly

fresh otter
#

OHH cool!!

neat dawn
#

visual and audible are similar

fresh otter
#

very simmilar!

fresh otter
brisk arrow
#

I'm pretty sure 2.5 has sound physics remastered compat

fresh otter
brisk arrow
#

Wait a second

#

The published vs version should have compatibility

fresh otter
#

pepeOOP 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

brisk arrow
#

That one should have it

fresh otter
#

check this out
video inbound

#

@brisk arrow Thoughts?

brisk arrow
#

Weird

fresh otter
brisk arrow
#

What if you remove presence footsteps

fresh otter
#
  • removed. testing again. sending video.
#

@brisk arrow same result

brisk arrow
#

What I don't understand is what version of sound physics it's using

#

Weird

fresh otter
brisk arrow
#

Actually

fresh otter
#

could this be something?

fresh otter
brisk arrow
#

Nah, it's k

brisk arrow
fresh otter
#

probably right

brisk arrow
#

Ok, I understand what's going on

fresh otter
#

ah i was looking at the wrong version before.

#

lmfao i was also reading it

#

my idea was this. what was yours?

brisk arrow
#

But vs mixins that

#

You'd just need to mixin processSound instead

fresh otter
brisk arrow
#

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

fresh otter
brisk arrow
#

Welp, I gtg for today, it's night over here

fresh otter
fresh otter
#

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?

brisk arrow
#

I think that would work yeah

#

(I really gotta sleep now tho)

#

Test it out ig

#

Runclient gradle task

strange walrus
#

you can make processSound an abstract function

fresh otter
#

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

strange walrus
#

then you dont need the dummy assert

fresh otter
#

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.

brisk arrow
fresh otter
#

so i'm definately not doing things 100% right here

fresh otter
#

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

fresh otter
brisk arrow
#

Nice

fresh otter
#

@brisk arrow It built but i'm unsure on how to test it with the other mod at the same time

strange walrus
#

But you should add it to the dev environment

#

Did you put it in common, forge, or fabric?

strange walrus
#

although I did tamper a bit with the mixins

brisk arrow
#
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

strange walrus
#

anyway I debugged

#

and beforeProcessSound isn't being called for the sounds on the ship at all

brisk arrow
#

Huh

strange walrus
#

possibly because the sounds aren't getting to the client

#

so its not "beforeProcessing" them

brisk arrow
#

Cuz iirc it checks level anyway

brisk arrow
fresh otter
#

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

strange walrus
#
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)

fresh otter
#

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.

fresh otter
# strange walrus specifically you would add

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?

strange walrus
#

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

strange walrus
#

and set the mixin to

@Mixin(value=SoundPhysics.class, remap=false)

instead of a string target

fresh otter
strange walrus
#

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

fresh otter
#

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

fresh otter
#

its saying processSound cant have an abstract for some reason

strange walrus
#

oh its beecause its static

#

which I didn't notice

#

you can turn it back into an empty function

fresh otter
#

yeah that made it happy

strange walrus
#

what

#

no it should be static

#

just remove the abstract part and add a {} on the end of the line

fresh otter
#

still not entirely happy with that eyther

strange walrus
#

before the ;

fresh otter
#

OHH

#

right

strange walrus
fresh otter
#

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

strange walrus
#
@Shadow(remap = false)
public static Vec3 processSound(int sourceId, double posX, double posY, double posZ, SoundSource category, String sound, boolean auxOnly) {};
fresh otter
#

so you dropped the abstract?

strange walrus
#

yea

fresh otter
#

thats fair enough.

brisk arrow
#

Getting the ship needs level

strange walrus
#

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

fresh otter
#

@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.
fierce tide
fresh otter
fierce tide
#

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!

fresh otter
fierce tide
#

I totally agree lol

fresh otter
#

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.
strange walrus
#

But you’ll need to import it

#

Which means it needs to be in the common gradle

fresh otter
# strange walrus ^

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?\

strange walrus
#

That’s uh

#

Tricky

#

I would recommend IntelliJ (community edition)

strange walrus
fresh otter
#

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?

brisk arrow
#

Not really

#

I've been busy too

fresh otter
#

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.

brisk arrow
#

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

#

¯_(ツ)_/¯

fresh otter
# brisk arrow so uh

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

brisk arrow
#

Dang