2018-09-12 06:39:55 +00:00
|
|
|
package com.seodisparate.TurnBasedMinecraft.client;
|
|
|
|
|
2018-09-28 03:13:07 +00:00
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.Battle;
|
2018-09-12 06:39:55 +00:00
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.CommonProxy;
|
|
|
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
2018-09-28 10:28:20 +00:00
|
|
|
import net.minecraft.client.settings.GameSettings;
|
2018-09-17 04:27:13 +00:00
|
|
|
import net.minecraft.entity.Entity;
|
2018-09-21 07:10:00 +00:00
|
|
|
import net.minecraft.util.SoundCategory;
|
2018-10-20 08:54:32 +00:00
|
|
|
import net.minecraft.util.text.ITextComponent;
|
2018-09-17 04:27:13 +00:00
|
|
|
import net.minecraft.util.text.TextComponentString;
|
2018-10-20 08:54:32 +00:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2018-09-12 06:39:55 +00:00
|
|
|
|
|
|
|
public class ClientProxy extends CommonProxy
|
|
|
|
{
|
2018-09-28 08:45:32 +00:00
|
|
|
private BattleGui battleGui = null;
|
|
|
|
private BattleMusic battleMusic = null;
|
|
|
|
private int battleMusicCount = 0;
|
|
|
|
private int sillyMusicCount = 0;
|
|
|
|
private Battle localBattle = null;
|
2018-09-12 06:39:55 +00:00
|
|
|
|
2018-09-20 06:15:34 +00:00
|
|
|
@Override
|
2018-10-04 03:07:26 +00:00
|
|
|
protected void initializeClient()
|
2018-09-12 06:39:55 +00:00
|
|
|
{
|
|
|
|
battleGui = new BattleGui();
|
2018-09-14 05:14:10 +00:00
|
|
|
battleMusic = null; // will be initialized in postInit()
|
2018-09-27 09:09:40 +00:00
|
|
|
battleMusicCount = 0;
|
|
|
|
sillyMusicCount = 0;
|
2018-09-28 03:13:07 +00:00
|
|
|
localBattle = null;
|
2018-09-12 06:39:55 +00:00
|
|
|
}
|
2018-09-20 06:15:34 +00:00
|
|
|
|
2018-09-12 06:39:55 +00:00
|
|
|
@Override
|
|
|
|
public void setBattleGuiTime(int timeRemaining)
|
|
|
|
{
|
2018-09-28 08:45:32 +00:00
|
|
|
battleGui.setTimeRemaining(timeRemaining);
|
2018-09-12 06:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@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();
|
|
|
|
}
|
2018-09-14 03:44:45 +00:00
|
|
|
|
2018-09-18 07:58:01 +00:00
|
|
|
@Override
|
|
|
|
public void battleStarted()
|
|
|
|
{
|
|
|
|
setBattleGuiAsGui();
|
|
|
|
}
|
|
|
|
|
2018-09-14 03:44:45 +00:00
|
|
|
@Override
|
|
|
|
public void battleEnded()
|
|
|
|
{
|
2018-09-28 03:13:07 +00:00
|
|
|
localBattle = null;
|
2018-09-14 03:44:45 +00:00
|
|
|
Minecraft.getMinecraft().addScheduledTask(() -> {
|
|
|
|
Minecraft.getMinecraft().displayGuiScreen(null);
|
|
|
|
Minecraft.getMinecraft().setIngameFocus();
|
|
|
|
});
|
2018-09-27 07:44:28 +00:00
|
|
|
stopMusic(true);
|
2018-09-27 09:09:40 +00:00
|
|
|
battleMusicCount = 0;
|
|
|
|
sillyMusicCount = 0;
|
2018-09-14 03:44:45 +00:00
|
|
|
}
|
2018-09-14 05:14:10 +00:00
|
|
|
|
|
|
|
@Override
|
2018-10-04 03:07:26 +00:00
|
|
|
protected void postInitClient()
|
2018-09-14 05:14:10 +00:00
|
|
|
{
|
2018-09-28 08:45:32 +00:00
|
|
|
battleMusic = new BattleMusic(getLogger());
|
2018-09-14 05:14:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void playBattleMusic()
|
|
|
|
{
|
2018-09-28 10:28:20 +00:00
|
|
|
GameSettings gs = Minecraft.getMinecraft().gameSettings;
|
|
|
|
battleMusic.playBattle(gs.getSoundLevel(SoundCategory.MUSIC) * gs.getSoundLevel(SoundCategory.MASTER));
|
2018-09-14 05:14:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void playSillyMusic()
|
|
|
|
{
|
2018-09-28 10:28:20 +00:00
|
|
|
GameSettings gs = Minecraft.getMinecraft().gameSettings;
|
|
|
|
battleMusic.playSilly(gs.getSoundLevel(SoundCategory.MUSIC) * gs.getSoundLevel(SoundCategory.MASTER));
|
2018-09-14 05:14:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-09-27 07:44:28 +00:00
|
|
|
public void stopMusic(boolean resumeMCSounds)
|
2018-09-14 05:14:10 +00:00
|
|
|
{
|
2018-09-27 07:44:28 +00:00
|
|
|
battleMusic.stopMusic(resumeMCSounds);
|
2018-09-14 05:14:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets what music to play based on type and loaded Config
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void typeEnteredBattle(String type)
|
|
|
|
{
|
2018-09-28 03:13:07 +00:00
|
|
|
if(localBattle == null)
|
2018-09-27 09:09:40 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-09-28 08:45:32 +00:00
|
|
|
if(type == null || type.isEmpty() || getConfig().isBattleMusicType(type))
|
2018-09-14 05:14:10 +00:00
|
|
|
{
|
2018-09-27 09:09:40 +00:00
|
|
|
++battleMusicCount;
|
2018-09-14 05:14:10 +00:00
|
|
|
}
|
2018-09-28 08:45:32 +00:00
|
|
|
else if(getConfig().isSillyMusicType(type))
|
2018-09-14 05:14:10 +00:00
|
|
|
{
|
2018-09-27 09:09:40 +00:00
|
|
|
++sillyMusicCount;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++battleMusicCount;
|
2018-09-14 05:14:10 +00:00
|
|
|
}
|
2018-09-27 09:09:40 +00:00
|
|
|
checkBattleTypes();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void typeLeftBattle(String type)
|
|
|
|
{
|
2018-09-28 03:13:07 +00:00
|
|
|
if(localBattle == null)
|
2018-09-27 09:09:40 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-09-28 08:45:32 +00:00
|
|
|
if(type == null || type.isEmpty() || getConfig().isBattleMusicType(type))
|
2018-09-27 09:09:40 +00:00
|
|
|
{
|
|
|
|
--battleMusicCount;
|
|
|
|
}
|
2018-09-28 08:45:32 +00:00
|
|
|
else if(getConfig().isSillyMusicType(type))
|
2018-09-27 09:09:40 +00:00
|
|
|
{
|
|
|
|
--sillyMusicCount;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
--battleMusicCount;
|
|
|
|
}
|
|
|
|
checkBattleTypes();
|
2018-09-14 05:14:10 +00:00
|
|
|
}
|
|
|
|
|
2018-09-17 04:27:13 +00:00
|
|
|
@Override
|
|
|
|
public void displayString(String message)
|
|
|
|
{
|
2018-10-20 08:54:32 +00:00
|
|
|
ITextComponent prefix = new TextComponentString("TBM: ");
|
|
|
|
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
|
|
|
|
ITextComponent text = new TextComponentString(message);
|
|
|
|
prefix.appendSibling(text);
|
|
|
|
text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
|
|
|
|
Minecraft.getMinecraft().player.sendMessage(prefix);
|
2018-09-17 04:27:13 +00:00
|
|
|
}
|
|
|
|
|
2018-10-24 08:20:04 +00:00
|
|
|
@Override
|
|
|
|
public void displayTextComponent(ITextComponent text)
|
|
|
|
{
|
|
|
|
Minecraft.getMinecraft().player.sendMessage(text);
|
|
|
|
}
|
|
|
|
|
2018-09-17 04:27:13 +00:00
|
|
|
@Override
|
|
|
|
public Entity getEntityByID(int id)
|
|
|
|
{
|
|
|
|
return Minecraft.getMinecraft().world.getEntityByID(id);
|
|
|
|
}
|
2018-09-27 09:09:40 +00:00
|
|
|
|
|
|
|
private void checkBattleTypes()
|
|
|
|
{
|
2018-09-28 03:02:39 +00:00
|
|
|
float percentage = 0.0f;
|
|
|
|
if(sillyMusicCount == 0 && battleMusicCount == 0)
|
|
|
|
{
|
|
|
|
percentage = 0.0f;
|
|
|
|
}
|
|
|
|
else if(battleMusicCount == 0)
|
|
|
|
{
|
|
|
|
percentage = 100.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
percentage = 100.0f * (float)sillyMusicCount / (float)(sillyMusicCount + battleMusicCount);
|
|
|
|
}
|
|
|
|
|
2018-09-28 08:45:32 +00:00
|
|
|
if(percentage >= (float)getConfig().getSillyMusicThreshold())
|
2018-09-27 09:09:40 +00:00
|
|
|
{
|
|
|
|
if(battleMusic.isPlaying())
|
|
|
|
{
|
|
|
|
if(!battleMusic.isPlayingSilly() && battleMusic.hasSillyMusic())
|
|
|
|
{
|
|
|
|
stopMusic(false);
|
|
|
|
playSillyMusic();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(battleMusic.hasSillyMusic())
|
|
|
|
{
|
|
|
|
playSillyMusic();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(battleMusic.isPlaying())
|
|
|
|
{
|
|
|
|
if(battleMusic.isPlayingSilly() && battleMusic.hasBattleMusic())
|
|
|
|
{
|
|
|
|
stopMusic(false);
|
|
|
|
playBattleMusic();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(battleMusic.hasBattleMusic())
|
|
|
|
{
|
|
|
|
playBattleMusic();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-28 03:13:07 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Battle getLocalBattle()
|
|
|
|
{
|
|
|
|
return localBattle;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void createLocalBattle(int id)
|
|
|
|
{
|
2018-10-17 09:28:47 +00:00
|
|
|
localBattle = new Battle(null, id, null, null, false);
|
2018-09-28 03:13:07 +00:00
|
|
|
}
|
2018-09-12 06:39:55 +00:00
|
|
|
}
|