'SoundInstance' is abstract; cannot be instantiated

Hi, I've been trying to make a minecraft mod that plays an audio file when I'm idle, and since I don't know anything about coding, and don't enough braincells to learn (trust me, I've tried a couple times), I've had to use AI. 14 hours later, and 100 something errors fixed, I'm left with a single one neither the AI or I can figure out. 'SoundInstance' is abstract; cannot be instantiated
package com.idlereminder;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.sound.SoundManager;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.sound.SoundEvent;

public class AlertSound {

private final SoundEvent soundEvent;
private SoundInstance soundInstance;

public AlertSound(SoundEvent soundEvent) {
this.soundEvent = soundEvent;
this.soundInstance = new SoundInstance(soundEvent, 1.0f); // This is the line the error points to
}

public void playSound() {
if (soundInstance != null) {
SoundManager soundManager = MinecraftClient.getInstance().getSoundManager();
soundManager.play(soundInstance);
}
}

public void stopSound() {
if (soundInstance != null) {
SoundManager soundManager = MinecraftClient.getInstance().getSoundManager();
soundManager.stop(soundInstance);
}
}
}
package com.idlereminder;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.sound.SoundManager;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.sound.SoundEvent;

public class AlertSound {

private final SoundEvent soundEvent;
private SoundInstance soundInstance;

public AlertSound(SoundEvent soundEvent) {
this.soundEvent = soundEvent;
this.soundInstance = new SoundInstance(soundEvent, 1.0f); // This is the line the error points to
}

public void playSound() {
if (soundInstance != null) {
SoundManager soundManager = MinecraftClient.getInstance().getSoundManager();
soundManager.play(soundInstance);
}
}

public void stopSound() {
if (soundInstance != null) {
SoundManager soundManager = MinecraftClient.getInstance().getSoundManager();
soundManager.stop(soundInstance);
}
}
}
Have tried using SimpleSoundInstance, but
import net.minecraft.client.sound.SimpleSoundInstance;
import net.minecraft.client.sound.SimpleSoundInstance;
didn't work. If anyone could help me figure out how to make it not abstract, it would be very appreciated.
44 Replies
JavaBot
JavaBot3d ago
This post has been reserved for your question.
Hey @Vemo! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Harry
Harry3d ago
You can’t get instance of an abstract class. From that error the SoundInstance class is an abstract class. You can only make subclasses of abstract classes I believe so extends SoundInstance
JavaBot
JavaBot3d ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
¡ᴉoɯᴉʞɐ!
what if
lucia
lucia3d ago
Hi, I can do this.
Vemo
VemoOP3d ago
If you're willing to help, I can send ya $20 as thanks.
JavaBot
JavaBot3d ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
ayylmao123xdd
ayylmao123xdd3d ago
at which line do you get that error
Vemo
VemoOP3d ago
No description
ayylmao123xdd
ayylmao123xdd3d ago
my bad didnt see it lol
Vemo
VemoOP3d ago
You're good
ayylmao123xdd
ayylmao123xdd3d ago
check if
public AlertSound(SoundEvent soundEvent) {
this.soundEvent = soundEvent;
this.soundInstance = new SimpleSoundInstance(soundEvent, 1.0f); // This is the line the error points to
}
public AlertSound(SoundEvent soundEvent) {
this.soundEvent = soundEvent;
this.soundInstance = new SimpleSoundInstance(soundEvent, 1.0f); // This is the line the error points to
}
works any better or did you try that already you showed that theres an import for it
Vemo
VemoOP3d ago
No description
ayylmao123xdd
ayylmao123xdd3d ago
and so what was the error when you used that same thing again or was it some different error
Vemo
VemoOP3d ago
The import isn't being recognized, so I get these errors on the lines SimpleSoundInstance is mentioned
Cannot resolve symbol 'SimpleSoundInstance'
Cannot resolve symbol 'SimpleSoundInstance'
No description
ayylmao123xdd
ayylmao123xdd3d ago
whats your minecraft version
Vemo
VemoOP3d ago
1.21.4
ayylmao123xdd
ayylmao123xdd3d ago
hmmm can you show which classes you get when you click this ctrl + click
import net.minecraft.client.**sound** click sound
import net.minecraft.client.**sound** click sound
duh dumb formatting
Vemo
VemoOP3d ago
No description
ayylmao123xdd
ayylmao123xdd3d ago
no no i didnt mean to paste that line lol just wanted to show which part to click if you got import net.minecraft.client.sound.SoundInstance; click sound
Vemo
VemoOP3d ago
Bear with me lol, I'm way out of my depth here
ayylmao123xdd
ayylmao123xdd3d ago
absolutely no worries also what loader do you use or whatever thats called for minecraft
Vemo
VemoOP3d ago
Fabric, when I ctrl click sound this opens up on the side
No description
ayylmao123xdd
ayylmao123xdd3d ago
and is SimpleSoundInstance inside the sound folder or no
Vemo
VemoOP3d ago
It's not
ayylmao123xdd
ayylmao123xdd3d ago
can you send a screenshot of whats there cuz i only see 3 classes rn
Vemo
VemoOP3d ago
Sure, 1 min. Might have to be more than 1 screenshot tho
ayylmao123xdd
ayylmao123xdd3d ago
ok
Vemo
VemoOP3d ago
No description
No description
ayylmao123xdd
ayylmao123xdd3d ago
ok you dont have to send more 1 sec let me check the docs
public AlertSound(SoundEvent soundEvent) {
this.soundEvent = soundEvent;
this.soundInstance = PositionedSoundInstance.master(
soundEvent,
1.0f,
1.0f
}
public AlertSound(SoundEvent soundEvent) {
this.soundEvent = soundEvent;
this.soundInstance = PositionedSoundInstance.master(
soundEvent,
1.0f,
1.0f
}
try this
Vemo
VemoOP3d ago
No description
No description
ayylmao123xdd
ayylmao123xdd3d ago
add this next to other imports
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.sound.PositionedSoundInstance;
Vemo
VemoOP3d ago
I think that did it. Build was successful atleast
ayylmao123xdd
ayylmao123xdd3d ago
🙀 shocking right also make sure this is for client side because it wont work for server side
Vemo
VemoOP3d ago
Yeah ofc. This is meant for just me You have no idea how long I sat with chatgpt going in circles lmao. Thank you. What's your paypal?
JavaBot
JavaBot3d ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
ayylmao123xdd
ayylmao123xdd3d ago
why would you need my paypal
Vemo
VemoOP3d ago
No description
ayylmao123xdd
ayylmao123xdd3d ago
well im not lucia thus i dont want money ez
Vemo
VemoOP3d ago
Ye but still yk. But alright, well, thank you so much
ayylmao123xdd
ayylmao123xdd3d ago
heres a crazy gif
Vemo
VemoOP3d ago
That's the extent of my coding knowledge lmao
JavaBot
JavaBot3d ago
Post Closed
This post has been closed by <@168008947880558593>.

Did you find this page helpful?