Fix for server/client setups

This commit is contained in:
Stephen Seo 2018-09-12 16:00:55 +09:00
parent 5eba2dd41b
commit 2872543c93
3 changed files with 19 additions and 18 deletions

View file

@ -9,7 +9,6 @@ import com.seodisparate.TurnBasedMinecraft.common.Battle;
import com.seodisparate.TurnBasedMinecraft.common.Combatant; import com.seodisparate.TurnBasedMinecraft.common.Combatant;
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleDecision; import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleDecision;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketHandler;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
@ -271,20 +270,20 @@ public class BattleGui extends GuiScreen
setState(MenuState.ATTACK_TARGET); setState(MenuState.ATTACK_TARGET);
break; break;
case DEFEND: case DEFEND:
PacketHandler.INSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.currentBattle.getId(), Battle.Decision.DEFEND, 0)); TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.currentBattle.getId(), Battle.Decision.DEFEND, 0));
setState(MenuState.WAITING); setState(MenuState.WAITING);
break; break;
case ITEM: case ITEM:
setState(MenuState.ITEM_ACTION); setState(MenuState.ITEM_ACTION);
break; break;
case FLEE: case FLEE:
PacketHandler.INSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.currentBattle.getId(), Battle.Decision.FLEE, 0)); TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.currentBattle.getId(), Battle.Decision.FLEE, 0));
setState(MenuState.WAITING); setState(MenuState.WAITING);
break; break;
case ATTACK_TARGET: case ATTACK_TARGET:
if(button instanceof EntitySelectionButton) if(button instanceof EntitySelectionButton)
{ {
PacketHandler.INSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.currentBattle.getId(), Battle.Decision.ATTACK, ((EntitySelectionButton)button).entityID)); TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.currentBattle.getId(), Battle.Decision.ATTACK, ((EntitySelectionButton)button).entityID));
setState(MenuState.WAITING); setState(MenuState.WAITING);
} }
else else
@ -304,7 +303,7 @@ public class BattleGui extends GuiScreen
case DO_ITEM_SWITCH: case DO_ITEM_SWITCH:
if(button instanceof ItemSelectionButton) if(button instanceof ItemSelectionButton)
{ {
PacketHandler.INSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.currentBattle.getId(), Battle.Decision.SWITCH_ITEM, ((ItemSelectionButton)button).itemStackID)); TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.currentBattle.getId(), Battle.Decision.SWITCH_ITEM, ((ItemSelectionButton)button).itemStackID));
if(((ItemSelectionButton)button).itemStackID >= 0 && ((ItemSelectionButton)button).itemStackID < 9) if(((ItemSelectionButton)button).itemStackID >= 0 && ((ItemSelectionButton)button).itemStackID < 9)
{ {
Minecraft.getMinecraft().player.inventory.currentItem = ((ItemSelectionButton)button).itemStackID; Minecraft.getMinecraft().player.inventory.currentItem = ((ItemSelectionButton)button).itemStackID;
@ -319,7 +318,7 @@ public class BattleGui extends GuiScreen
case DO_USE_ITEM: case DO_USE_ITEM:
if(button instanceof ItemSelectionButton) if(button instanceof ItemSelectionButton)
{ {
PacketHandler.INSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.currentBattle.getId(), Battle.Decision.USE_ITEM, ((ItemSelectionButton)button).itemStackID)); TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.currentBattle.getId(), Battle.Decision.USE_ITEM, ((ItemSelectionButton)button).itemStackID));
setState(MenuState.WAITING); setState(MenuState.WAITING);
} }
else else

View file

@ -13,7 +13,6 @@ import java.util.concurrent.atomic.AtomicInteger;
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;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketHandler;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -368,7 +367,7 @@ public class Battle
PacketBattleInfo infoPacket = new PacketBattleInfo(getSideAIDs(), getSideBIDs(), timer); PacketBattleInfo infoPacket = new PacketBattleInfo(getSideAIDs(), getSideBIDs(), timer);
for(Combatant p : players.values()) for(Combatant p : players.values())
{ {
PacketHandler.INSTANCE.sendTo(infoPacket, (EntityPlayerMP)p.entity); TurnBasedMinecraftMod.NWINSTANCE.sendTo(infoPacket, (EntityPlayerMP)p.entity);
} }
} }
@ -382,7 +381,7 @@ public class Battle
{ {
if(p.entity.isEntityAlive()) if(p.entity.isEntityAlive())
{ {
PacketHandler.INSTANCE.sendTo(new PacketBattleMessage(type, from, to, amount), (EntityPlayerMP)p.entity); TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketBattleMessage(type, from, to, amount), (EntityPlayerMP)p.entity);
} }
} }
} }
@ -397,7 +396,7 @@ public class Battle
{ {
if(p.entity.isEntityAlive()) if(p.entity.isEntityAlive())
{ {
PacketHandler.INSTANCE.sendTo(new PacketBattleMessage(type, from, to, amount, custom), (EntityPlayerMP)p.entity); TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketBattleMessage(type, from, to, amount, custom), (EntityPlayerMP)p.entity);
} }
} }
} }
@ -415,7 +414,7 @@ public class Battle
removeQueue.add(c.entity.getEntityId()); removeQueue.add(c.entity.getEntityId());
if(c.entity instanceof EntityPlayer) if(c.entity instanceof EntityPlayer)
{ {
PacketHandler.INSTANCE.sendTo(new PacketBattleMessage(PacketBattleMessage.MessageType.ENDED, c.entity.getEntityId(), 0, 0), (EntityPlayerMP)c.entity); TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketBattleMessage(PacketBattleMessage.MessageType.ENDED, c.entity.getEntityId(), 0, 0), (EntityPlayerMP)c.entity);
} }
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DIED, c.entity.getEntityId(), 0, 0); sendMessageToAllPlayers(PacketBattleMessage.MessageType.DIED, c.entity.getEntityId(), 0, 0);
} }
@ -427,7 +426,7 @@ public class Battle
removeQueue.add(c.entity.getEntityId()); removeQueue.add(c.entity.getEntityId());
if(c.entity instanceof EntityPlayer) if(c.entity instanceof EntityPlayer)
{ {
PacketHandler.INSTANCE.sendTo(new PacketBattleMessage(PacketBattleMessage.MessageType.ENDED, c.entity.getEntityId(), 0, 0), (EntityPlayerMP)c.entity); TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketBattleMessage(PacketBattleMessage.MessageType.ENDED, c.entity.getEntityId(), 0, 0), (EntityPlayerMP)c.entity);
} }
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DIED, c.entity.getEntityId(), 0, 0); sendMessageToAllPlayers(PacketBattleMessage.MessageType.DIED, c.entity.getEntityId(), 0, 0);
} }
@ -792,7 +791,7 @@ public class Battle
{ {
players.remove(next.entity.getEntityId()); players.remove(next.entity.getEntityId());
playerCount.decrementAndGet(); playerCount.decrementAndGet();
PacketHandler.INSTANCE.sendTo(new PacketBattleMessage(PacketBattleMessage.MessageType.ENDED, 0, 0, 0), (EntityPlayerMP)next.entity); TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketBattleMessage(PacketBattleMessage.MessageType.ENDED, 0, 0, 0), (EntityPlayerMP)next.entity);
} }
} }
else else

View file

@ -8,7 +8,6 @@ import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleDecisio
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;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleRequestInfo; import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleRequestInfo;
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;
@ -18,6 +17,8 @@ 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.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
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)
@ -33,6 +34,8 @@ public class TurnBasedMinecraftMod
public static final String CONFIG_INTERNAL_PATH = "/assets/TurnBasedMinecraft/" + CONFIG_FILENAME; public static final String CONFIG_INTERNAL_PATH = "/assets/TurnBasedMinecraft/" + CONFIG_FILENAME;
private static int CONFIG_FILE_VERSION = 0; private static int CONFIG_FILE_VERSION = 0;
public static final SimpleNetworkWrapper NWINSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("seodisparate.tbmc");
protected static Logger logger; protected static Logger logger;
protected static BattleManager battleManager; protected static BattleManager battleManager;
@ -61,22 +64,22 @@ public class TurnBasedMinecraftMod
config = new Config(logger); config = new Config(logger);
// register packets // register packets
PacketHandler.INSTANCE.registerMessage( NWINSTANCE.registerMessage(
PacketBattleInfo.HandlerBattleInfo.class, PacketBattleInfo.HandlerBattleInfo.class,
PacketBattleInfo.class, PacketBattleInfo.class,
packetHandlerID++, packetHandlerID++,
Side.CLIENT); Side.CLIENT);
PacketHandler.INSTANCE.registerMessage( NWINSTANCE.registerMessage(
PacketBattleRequestInfo.HandlerBattleRequestInfo.class, PacketBattleRequestInfo.HandlerBattleRequestInfo.class,
PacketBattleRequestInfo.class, PacketBattleRequestInfo.class,
packetHandlerID++, packetHandlerID++,
Side.SERVER); Side.SERVER);
PacketHandler.INSTANCE.registerMessage( NWINSTANCE.registerMessage(
PacketBattleDecision.HandleBattleDecision.class, PacketBattleDecision.HandleBattleDecision.class,
PacketBattleDecision.class, PacketBattleDecision.class,
packetHandlerID++, packetHandlerID++,
Side.SERVER); Side.SERVER);
PacketHandler.INSTANCE.registerMessage( NWINSTANCE.registerMessage(
PacketBattleMessage.HandlerBattleMessage.class, PacketBattleMessage.HandlerBattleMessage.class,
PacketBattleMessage.class, PacketBattleMessage.class,
packetHandlerID++, packetHandlerID++,