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); TurnBasedMinecraftMod.currentBattle.setState(Battle.State.DECISION);
} }
timeRemaining.set((int)TurnBasedMinecraftMod.BattleDecisionTime.getSeconds()); timeRemaining.set((int)TurnBasedMinecraftMod.BattleDecisionTime.getSeconds());
elapsedTime = 0;
lastInstant = System.nanoTime();
setState(MenuState.MAIN_MENU); 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; package com.seodisparate.TurnBasedMinecraft.common;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.List; import java.util.List;
public class EntityInfo public class EntityInfo

View file

@ -4,7 +4,6 @@ import java.time.Duration;
import org.apache.logging.log4j.Logger; 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.PacketBattleDecision;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleInfo; import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleInfo;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleMessage; 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.minecraft.entity.Entity;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler; 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.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
@Mod(modid = TurnBasedMinecraftMod.MODID, name = TurnBasedMinecraftMod.NAME, version = TurnBasedMinecraftMod.VERSION) @Mod(modid = TurnBasedMinecraftMod.MODID, name = TurnBasedMinecraftMod.NAME, version = TurnBasedMinecraftMod.VERSION)
@ -44,7 +42,9 @@ public class TurnBasedMinecraftMod
protected static Config config; protected static Config config;
public static Battle currentBattle = null; 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 @EventHandler
public void preInit(FMLPreInitializationEvent event) public void preInit(FMLPreInitializationEvent event)

View file

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

View file

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