Jump to content

Recommended Posts

Posted (edited)

Hi! I've got little problem. Each time my music is starting to playing, minecraft got one lag spike (like resource loading spike). Then the music normally plays. Is there any way to solve it?

Event class

Spoiler

import com.Krevik.Main.KCore;

import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.SoundCategory;
import net.minecraftforge.client.event.sound.PlaySoundEvent;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class KetherEventsHandler {
	

	@SubscribeEvent
	@SideOnly(Side.CLIENT)
	public static void onEvent(PlaySoundEvent event)
	{
		ISound sound = event.getSound();

		if(sound!=null&&sound.getCategory() == SoundCategory.MUSIC) {
			EntityPlayer ep = FMLClientHandler.instance().getClient().player;
			if(ep!=null) {
				if(ep.dimension==KCore.DIMENSION_ID) {

					PositionedSoundRecord  positionedDaySound;
					PositionedSoundRecord  positionedNightSound;
					positionedDaySound=PositionedSoundRecord.getMusicRecord(KCore.instance.cproxy.dayMusic);
					positionedNightSound=PositionedSoundRecord.getMusicRecord(KCore.instance.cproxy.nightMusic);
					if(sound!=positionedDaySound&&sound!=positionedNightSound) {
						if(ep.world.getWorldTime()>12000) {
							event.setResultSound(positionedNightSound);
						}else {
							event.setResultSound(positionedDaySound);

	
						}
					}
				}
			}
		}
	}
	
	
}

 

 

Client Proxy

Spoiler

public static SoundEvent nightMusic = new SoundHelper("night.music");
public static SoundEvent dayMusic = new SoundHelper("day.music");

 

Event register (in mod main class)

Spoiler

    @Mod.EventHandler
    public void postInit(FMLPostInitializationEvent e) {
        MinecraftForge.EVENT_BUS.register(KetherEventsHandler.class);
    }
	

 

 

Sounds.json

Spoiler

{
    "mob.bird.bird":
    {
        "category": "weather",
		"sounds":
        [
            "mystic:bird/bird1",
			"mystic:bird/bird2",
			"mystic:bird/bird3",
			"mystic:bird/bird4"
        ]
    },
	"mob.howler.living":
    {
        "category": "weather",
		"sounds":
        [
            "mystic:howler/living"
        ]
    },
	"mob.howler.dead":
    {
        "category": "weather",
		"sounds":
        [
            "mystic:howler/dead"
        ]
    },
	"mob.jellyfish.dead":
    {
        "category": "weather",
		"sounds":
        [
            "mystic:jellyfish/dead"
        ]
    },
	"mob.jellyfish.hurt":
    {
        "category": "weather",
		"sounds":
        [
            "mystic:jellyfish/hurt"
        ]
    },
	"mob.jellyfish.living":
    {
        "category": "weather",
		"sounds":
        [
            "mystic:jellyfish/living1",
			"mystic:jellyfish/living2",
			"mystic:jellyfish/living3"
        ]
    },
	"mob.turtle.dead":
    {
        "category": "weather",
		"sounds":
        [
            "mystic:turtle/turtle_dead"
        ]
    },
	"mob.bison.dead":
    {
        "category": "weather",
		"sounds":
        [
            "mystic:bison/dead"
        ]
    },
	"mob.bison.hurt":
    {
        "category": "weather",
		"sounds":
        [
            "mystic:bison/hurt"
        ]
    },
	"mob.bison.living":
    {
        "category": "weather",
		"sounds":
        [
            "mystic:bison/1",
			"mystic:bison/2",
			"mystic:bison/3",
			"mystic:bison/4",
			"mystic:bison/5",
			"mystic:bison/6",
			"mystic:bison/7"
        ]
    },
	"kether.night.music":
    {
		"stream": true,
        "category": "weather",
		"sounds":
        [
            "mystic:kether/kether_night"
        ]
    },
	"kether.day.music":
    {
		"stream": true,
        "category": "weather",
		"sounds":
        [
            "mystic:kether/kether_day"
        ]
    },
	"mob.ghost.living":
    {
        "category": "weather",
		"sounds":
        [
            "mystic:ghost/ghost1",
			"mystic:ghost/ghost2",
			"mystic:ghost/ghost3",
			"mystic:ghost/ghost4"
        ]
    },
	"mob.ghost.attack":
    {
        "category": "weather",
		"sounds":
        [
            "mystic:ghost/ghost_attack"
        ]
    },
	"mob.ghost.dead":
    {
        "category": "weather",
		"sounds":
        [
            "mystic:ghost/ghost_dead"
        ]
    },
	"mob.death.living":
    {
        "category": "weather",
		"sounds":
        [
            "mystic:death/death1",
			"mystic:death/death2",
			"mystic:death/death3",
			"mystic:death/death4",
			"mystic:death/death5",
			"mystic:death/death6",
			"mystic:death/death7",
			"mystic:death/death8",
			"mystic:death/death9",
			"mystic:death/death10"
        ]
    },
	"mob.scary.flower":
    {
        "category": "weather",
		"sounds":
        [
            "mystic:scary/scary1",
			"mystic:scary/scary2",
			"mystic:scary/scary3",
			"mystic:scary/scary4",
			"mystic:scary/scary5"
        ]
    }
}

 

There is no error during loading sounds.json (in console)

 

SoundHelper

Spoiler

public class SoundHelper extends SoundEventHandlerMystic {

	public SoundHelper(String mob,String subset) {
		super("mob."+mob+"." + subset);
		register();
	}
	
	public SoundHelper(String Name) {
		super("kether."+Name);
		register();
	}

}

 

 

SoundEventHandlerMystic

Spoiler

import com.Krevik.Main.KCore;

import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

public abstract class SoundEventHandlerMystic extends SoundEvent {
	public SoundEventHandlerMystic(String name) {
		super(new ResourceLocation(KCore.MODID, name));
		this.setRegistryName(new ResourceLocation(KCore.MODID, name));
	}

	public void register() {
		GameRegistry.findRegistry(SoundEvent.class).register(this);
	}
	
}

 

 

Edited by Krevik
Code update
Posted
48 minutes ago, diesieben07 said:

Set stream to true in your sounds.json.

Didn't help. Also I noticed that after few minutes of playing this sound (maybe 1/2 minutes) the game crashes. Here's the log

Quote

[19:17:12] [Server thread/INFO]: Stopping server
[19:17:12] [Server thread/INFO]: Saving players
[19:17:12] [Server thread/INFO]: Saving worlds
[19:17:12] [Server thread/INFO]: Saving chunks for level 'New World'/overworld
[19:17:12] [Server thread/INFO]: Saving chunks for level 'New World'/the_nether
[19:17:12] [Server thread/INFO]: Saving chunks for level 'New World'/the_end
[19:17:12] [Server thread/INFO]: Saving chunks for level 'New World'/MYSTIC
[19:17:14] [main/FATAL]: Unreported exception thrown!
java.lang.IllegalArgumentException: value already present: net.minecraft.client.audio.PositionedSoundRecord@a548a06
	at com.google.common.collect.HashBiMap.put(HashBiMap.java:287) ~[guava-21.0.jar:?]
	at com.google.common.collect.HashBiMap.put(HashBiMap.java:262) ~[guava-21.0.jar:?]
	at net.minecraft.client.audio.SoundManager.playSound(SoundManager.java:453) ~[SoundManager.class:?]
	at net.minecraft.client.audio.SoundHandler.playSound(SoundHandler.java:261) ~[SoundHandler.class:?]
	at net.minecraft.client.audio.MusicTicker.playMusic(MusicTicker.java:61) ~[MusicTicker.class:?]
	at net.minecraft.client.audio.MusicTicker.update(MusicTicker.java:51) ~[MusicTicker.class:?]
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1982) ~[Minecraft.class:?]
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1186) ~[Minecraft.class:?]
	at net.minecraft.client.Minecraft.run(Minecraft.java:441) [Minecraft.class:?]
	at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_162]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_162]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_162]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_162]
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_162]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_162]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_162]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_162]
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
	at GradleStart.main(GradleStart.java:25) [start/:?]

 

 

Posted (edited)
4 minutes ago, diesieben07 said:

This will never be true.

Also, you would be better off overriding getMusicType in your WorldProvider if you want to add custom music to your dimension.

 

Your sounds.json is invalid JSON.

The music normally plays so I thought this is true. Can be json invalid, even if there's no error log in console during loading? Could you point me the place this is wrong? Yea I used this method before but after updating forge to latest version there is no such method in WorldProvider - it's just deleted. Also there is no such method in latest forge version as EnumHelperClient.addMusicType. This lag occured even with using getMusicType in WorldProvider instead of using event.

Edited by Krevik
edited
Posted
34 minutes ago, ZombieEnderman5 said:

Do you have a low RAM amount? If so, that can contribute to lag (believe me, I know. My computer has frozen completely for several minutes at a time due to Minecraft using too much memory).

Hmm low RAM amount shouldn't be problem anyway. I have 8gb DDR4. Minecraft in eclipse has it's default - 1gb. I would change it to higher, but I think that most minecraft players have default. I want these "most minecraft players" to have comfortable conditions to use my mod.

Posted (edited)
10 hours ago, diesieben07 said:

You did not specify the stream setting properly. See https://minecraft.gamepedia.com/Sounds.json for the sounds.json structure.

Searched for some example, found it and updated sounds.json. Now it works nice. Got next problem that I didn't notice last time.. After some time minecraft starts to playing two musics at the same time... But I think that I can fix that myself,  so thanks everyone for help!

Edited by Krevik
edited

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.