From 5eba2dd41bc1a0ecd552af49e25b67703aa6fa65 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Wed, 12 Sep 2018 15:39:55 +0900 Subject: [PATCH] Fix to allow mod to work on server --- .../TurnBasedMinecraft/client/BattleGui.java | 2 + .../client/ClientProxy.java | 52 +++++++++++++++++++ .../common/CommonProxy.java | 14 +++++ .../TurnBasedMinecraft/common/EntityInfo.java | 1 - .../common/TurnBasedMinecraftMod.java | 8 +-- .../common/networking/PacketBattleInfo.java | 7 +-- .../networking/PacketBattleMessage.java | 21 ++------ 7 files changed, 77 insertions(+), 28 deletions(-) create mode 100644 src/main/java/com/seodisparate/TurnBasedMinecraft/client/ClientProxy.java create mode 100644 src/main/java/com/seodisparate/TurnBasedMinecraft/common/CommonProxy.java diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/client/BattleGui.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/client/BattleGui.java index 3e69db7..d2f1584 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/client/BattleGui.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/client/BattleGui.java @@ -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); } diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/client/ClientProxy.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/client/ClientProxy.java new file mode 100644 index 0000000..baed4f4 --- /dev/null +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/client/ClientProxy.java @@ -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(); + } +} diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/CommonProxy.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/CommonProxy.java new file mode 100644 index 0000000..6cd8421 --- /dev/null +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/CommonProxy.java @@ -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() {} +} diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/EntityInfo.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/EntityInfo.java index 1f7aebe..bd63532 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/EntityInfo.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/EntityInfo.java @@ -1,7 +1,6 @@ package com.seodisparate.TurnBasedMinecraft.common; import java.util.ArrayList; -import java.util.Comparator; import java.util.List; public class EntityInfo diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java index b493f98..577fcca 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java @@ -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) diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketBattleInfo.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketBattleInfo.java index a9e5b46..e979aff 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketBattleInfo.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketBattleInfo.java @@ -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; } } diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketBattleMessage.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketBattleMessage.java index 833bb14..83e8bfd 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketBattleMessage.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketBattleMessage.java @@ -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)