Stephen Seo
676f71e313
Battle music volume is set based on the music volume slider in the Minecraft settings. The default Midi device provided in Java does not appear to support changing the volume of playing midi file after some testing. For now, only ".wav" files obey the Music volume slider settings.
166 lines
3.8 KiB
Java
166 lines
3.8 KiB
Java
package com.seodisparate.TurnBasedMinecraft.client;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.CommonProxy;
|
|
import com.seodisparate.TurnBasedMinecraft.common.Config;
|
|
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.util.SoundCategory;
|
|
import net.minecraft.util.text.TextComponentString;
|
|
|
|
public class ClientProxy extends CommonProxy
|
|
{
|
|
private BattleGui battleGui;
|
|
private BattleMusic battleMusic;
|
|
private Logger logger;
|
|
private Config config;
|
|
|
|
@Override
|
|
public void initialize()
|
|
{
|
|
battleGui = new BattleGui();
|
|
battleMusic = null; // will be initialized in postInit()
|
|
}
|
|
|
|
@Override
|
|
public void setBattleGuiTime(int timeRemaining)
|
|
{
|
|
battleGui.timeRemaining.set(timeRemaining);
|
|
}
|
|
|
|
@Override
|
|
public void setBattleGuiBattleChanged()
|
|
{
|
|
battleGui.battleChanged();
|
|
}
|
|
|
|
@Override
|
|
public void setBattleGuiAsGui()
|
|
{
|
|
Minecraft.getMinecraft().addScheduledTask(() -> {
|
|
if(Minecraft.getMinecraft().currentScreen != battleGui)
|
|
{
|
|
battleGui.turnEnd();
|
|
Minecraft.getMinecraft().displayGuiScreen(battleGui);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public void battleGuiTurnBegin()
|
|
{
|
|
battleGui.turnBegin();
|
|
}
|
|
|
|
@Override
|
|
public void battleGuiTurnEnd()
|
|
{
|
|
battleGui.turnEnd();
|
|
}
|
|
|
|
@Override
|
|
public void battleStarted()
|
|
{
|
|
setBattleGuiAsGui();
|
|
}
|
|
|
|
@Override
|
|
public void battleEnded()
|
|
{
|
|
TurnBasedMinecraftMod.currentBattle = null;
|
|
Minecraft.getMinecraft().addScheduledTask(() -> {
|
|
Minecraft.getMinecraft().displayGuiScreen(null);
|
|
Minecraft.getMinecraft().setIngameFocus();
|
|
});
|
|
stopMusic();
|
|
}
|
|
|
|
@Override
|
|
public void postInit()
|
|
{
|
|
battleMusic = new BattleMusic(logger);
|
|
}
|
|
|
|
@Override
|
|
public void setLogger(Logger logger)
|
|
{
|
|
this.logger = logger;
|
|
}
|
|
|
|
@Override
|
|
public void playBattleMusic()
|
|
{
|
|
battleMusic.playBattle(Minecraft.getMinecraft().gameSettings.getSoundLevel(SoundCategory.MUSIC));
|
|
}
|
|
|
|
@Override
|
|
public void playSillyMusic()
|
|
{
|
|
battleMusic.playSilly(Minecraft.getMinecraft().gameSettings.getSoundLevel(SoundCategory.MUSIC));
|
|
}
|
|
|
|
@Override
|
|
public void stopMusic()
|
|
{
|
|
battleMusic.stopMusic();
|
|
}
|
|
|
|
/**
|
|
* Sets what music to play based on type and loaded Config
|
|
*/
|
|
@Override
|
|
public void typeEnteredBattle(String type)
|
|
{
|
|
if(type == null || type.isEmpty() || config.isBattleMusicType(type))
|
|
{
|
|
if(battleMusic.isPlaying())
|
|
{
|
|
if(battleMusic.isPlayingSilly())
|
|
{
|
|
stopMusic();
|
|
playBattleMusic();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
playBattleMusic();
|
|
}
|
|
}
|
|
else if(config.isSillyMusicType(type))
|
|
{
|
|
if(battleMusic.isPlaying())
|
|
{
|
|
if(!battleMusic.isPlayingSilly())
|
|
{
|
|
stopMusic();
|
|
playSillyMusic();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
playSillyMusic();
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void setConfig(Config config)
|
|
{
|
|
this.config = config;
|
|
}
|
|
|
|
@Override
|
|
public void displayString(String message)
|
|
{
|
|
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(message));
|
|
}
|
|
|
|
@Override
|
|
public Entity getEntityByID(int id)
|
|
{
|
|
return Minecraft.getMinecraft().world.getEntityByID(id);
|
|
}
|
|
}
|