Fix to allow mod to work on server

This commit is contained in:
Stephen Seo 2018-09-12 15:39:55 +09:00
parent 5999808859
commit 5eba2dd41b
7 changed files with 77 additions and 28 deletions

View file

@ -131,6 +131,8 @@ public class BattleGui extends GuiScreen
TurnBasedMinecraftMod.currentBattle.setState(Battle.State.DECISION);
}
timeRemaining.set((int)TurnBasedMinecraftMod.BattleDecisionTime.getSeconds());
elapsedTime = 0;
lastInstant = System.nanoTime();
setState(MenuState.MAIN_MENU);
}

View file

@ -0,0 +1,52 @@
package com.seodisparate.TurnBasedMinecraft.client;
import com.seodisparate.TurnBasedMinecraft.common.CommonProxy;
import net.minecraft.client.Minecraft;
public class ClientProxy extends CommonProxy
{
private BattleGui battleGui;
public ClientProxy()
{
super();
battleGui = new BattleGui();
}
@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();
}
}

View file

@ -0,0 +1,14 @@
package com.seodisparate.TurnBasedMinecraft.common;
public class CommonProxy
{
public void setBattleGuiTime(int timeRemaining) {}
public void setBattleGuiBattleChanged() {}
public void setBattleGuiAsGui() {}
public void battleGuiTurnBegin() {}
public void battleGuiTurnEnd() {}
}

View file

@ -1,7 +1,6 @@
package com.seodisparate.TurnBasedMinecraft.common;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
public class EntityInfo

View file

@ -4,7 +4,6 @@ import java.time.Duration;
import org.apache.logging.log4j.Logger;
import com.seodisparate.TurnBasedMinecraft.client.BattleGui;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleDecision;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleInfo;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleMessage;
@ -13,13 +12,12 @@ import com.seodisparate.TurnBasedMinecraft.common.networking.PacketHandler;
import net.minecraft.entity.Entity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
@Mod(modid = TurnBasedMinecraftMod.MODID, name = TurnBasedMinecraftMod.NAME, version = TurnBasedMinecraftMod.VERSION)
@ -44,7 +42,9 @@ public class TurnBasedMinecraftMod
protected static Config config;
public static Battle currentBattle = null;
public static BattleGui currentBattleGui = null;
@SidedProxy(modId=MODID, serverSide="com.seodisparate.TurnBasedMinecraft.common.CommonProxy", clientSide="com.seodisparate.TurnBasedMinecraft.client.ClientProxy")
public static CommonProxy commonProxy;
@EventHandler
public void preInit(FMLPreInitializationEvent event)

View file

@ -81,11 +81,8 @@ public class PacketBattleInfo implements IMessage
{
TurnBasedMinecraftMod.currentBattle.addCombatantToSideB(Minecraft.getMinecraft().world.getEntityByID(id));
}
if(TurnBasedMinecraftMod.currentBattleGui != null)
{
TurnBasedMinecraftMod.currentBattleGui.timeRemaining.set((int)(message.decisionNanos / 1000000000));
TurnBasedMinecraftMod.currentBattleGui.battleChanged();
}
TurnBasedMinecraftMod.commonProxy.setBattleGuiTime((int)(message.decisionNanos / 1000000000));
TurnBasedMinecraftMod.commonProxy.setBattleGuiBattleChanged();
return null;
}
}

View file

@ -3,14 +3,12 @@ package com.seodisparate.TurnBasedMinecraft.common.networking;
import java.util.HashMap;
import java.util.Map;
import com.seodisparate.TurnBasedMinecraft.client.BattleGui;
import com.seodisparate.TurnBasedMinecraft.common.Battle;
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.scoreboard.ScorePlayerTeam;
import net.minecraft.util.text.TextComponentString;
@ -232,13 +230,7 @@ public class PacketBattleMessage implements IMessage
{
TurnBasedMinecraftMod.currentBattle = new Battle(message.amount, null, null, false);
}
if(TurnBasedMinecraftMod.currentBattleGui == null)
{
Minecraft.getMinecraft().addScheduledTask(() -> {
TurnBasedMinecraftMod.currentBattleGui = new BattleGui();
Minecraft.getMinecraft().displayGuiScreen(TurnBasedMinecraftMod.currentBattleGui);
});
}
TurnBasedMinecraftMod.commonProxy.setBattleGuiAsGui();
break;
case FLEE:
if(message.amount != 0)
@ -261,7 +253,6 @@ public class PacketBattleMessage implements IMessage
"Battle has ended!"));
TurnBasedMinecraftMod.currentBattle = null;
Minecraft.getMinecraft().addScheduledTask(() -> {
TurnBasedMinecraftMod.currentBattleGui = null;
Minecraft.getMinecraft().setIngameFocus();
});
break;
@ -321,10 +312,7 @@ public class PacketBattleMessage implements IMessage
case TURN_BEGIN:
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(
"The turn begins!"));
if(TurnBasedMinecraftMod.currentBattleGui != null)
{
TurnBasedMinecraftMod.currentBattleGui.turnBegin();
}
TurnBasedMinecraftMod.commonProxy.battleGuiTurnBegin();
break;
case TURN_END:
if(TurnBasedMinecraftMod.currentBattle != null)
@ -332,10 +320,7 @@ public class PacketBattleMessage implements IMessage
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(
"The turn ended!"));
}
if(TurnBasedMinecraftMod.currentBattleGui != null)
{
TurnBasedMinecraftMod.currentBattleGui.turnEnd();
}
TurnBasedMinecraftMod.commonProxy.battleGuiTurnEnd();
break;
case SWITCHED_ITEM:
if(message.amount != 0)