2018-09-12 05:43:59 +00:00
|
|
|
package com.seodisparate.TurnBasedMinecraft.common;
|
2018-08-28 02:26:34 +00:00
|
|
|
|
2018-09-17 06:49:10 +00:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
2018-08-29 06:09:44 +00:00
|
|
|
|
2018-08-28 06:13:14 +00:00
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
|
2018-08-29 06:09:44 +00:00
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleDecision;
|
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleInfo;
|
2018-09-06 08:08:36 +00:00
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleMessage;
|
2018-08-29 06:09:44 +00:00
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleRequestInfo;
|
2018-08-28 06:13:14 +00:00
|
|
|
|
|
|
|
import net.minecraft.entity.Entity;
|
2018-09-12 05:43:59 +00:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2018-08-28 02:26:34 +00:00
|
|
|
import net.minecraftforge.fml.common.Mod;
|
|
|
|
import net.minecraftforge.fml.common.Mod.EventHandler;
|
2018-09-12 06:39:55 +00:00
|
|
|
import net.minecraftforge.fml.common.SidedProxy;
|
2018-08-28 02:26:34 +00:00
|
|
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
2018-09-03 06:19:33 +00:00
|
|
|
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
2018-08-28 02:26:34 +00:00
|
|
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
2018-09-20 06:15:34 +00:00
|
|
|
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
|
|
|
|
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent;
|
2018-09-12 07:00:55 +00:00
|
|
|
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
|
|
|
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
2018-08-29 06:09:44 +00:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
2018-08-28 02:26:34 +00:00
|
|
|
|
2018-08-28 02:51:26 +00:00
|
|
|
@Mod(modid = TurnBasedMinecraftMod.MODID, name = TurnBasedMinecraftMod.NAME, version = TurnBasedMinecraftMod.VERSION)
|
2018-08-28 02:26:34 +00:00
|
|
|
public class TurnBasedMinecraftMod
|
|
|
|
{
|
2018-08-28 02:51:26 +00:00
|
|
|
public static final String MODID = "com.seodisparate.turnbasedminecraft";
|
2018-08-28 02:26:34 +00:00
|
|
|
public static final String NAME = "Turn Based Minecraft Mod";
|
2018-09-21 07:11:59 +00:00
|
|
|
public static final String VERSION = "0.3";
|
2018-09-03 06:19:33 +00:00
|
|
|
public static final String CONFIG_FILENAME = "TBM_Config.xml";
|
|
|
|
public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
|
|
|
|
public static final String CONFIG_FILE_PATH = CONFIG_DIRECTORY + CONFIG_FILENAME;
|
2018-09-07 07:41:22 +00:00
|
|
|
public static final String CONFIG_INTERNAL_PATH = "/assets/TurnBasedMinecraft/" + CONFIG_FILENAME;
|
2018-09-14 05:14:10 +00:00
|
|
|
public static final String MUSIC_ROOT = CONFIG_DIRECTORY + "Music/";
|
|
|
|
public static final String MUSIC_SILLY = MUSIC_ROOT + "silly/";
|
|
|
|
public static final String MUSIC_BATTLE = MUSIC_ROOT + "battle/";
|
2018-09-10 05:59:56 +00:00
|
|
|
|
2018-09-07 07:41:22 +00:00
|
|
|
private static int CONFIG_FILE_VERSION = 0;
|
2018-09-12 07:00:55 +00:00
|
|
|
|
|
|
|
public static final SimpleNetworkWrapper NWINSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("seodisparate.tbmc");
|
2018-08-28 02:26:34 +00:00
|
|
|
|
2018-09-12 05:43:59 +00:00
|
|
|
protected static Logger logger;
|
|
|
|
protected static BattleManager battleManager;
|
2018-08-29 06:09:44 +00:00
|
|
|
private static int packetHandlerID = 0;
|
2018-09-12 05:43:59 +00:00
|
|
|
protected static Entity attackingEntity;
|
|
|
|
protected static int attackingDamage = 0;
|
2018-09-17 06:49:10 +00:00
|
|
|
protected static Set<AttackerViaBow> attackerViaBow;
|
2018-09-12 05:43:59 +00:00
|
|
|
protected static Config config;
|
2018-09-25 05:55:24 +00:00
|
|
|
public static final long BATTLE_DECISION_DURATION_NANO_MIN = 5000000000L;
|
|
|
|
public static final long BATTLE_DECISION_DURATION_NANO_MAX = 60000000000L;
|
|
|
|
public static final long BATTLE_DECISION_DURATION_NANO_DEFAULT = 15000000000L;
|
|
|
|
private static long BATTLE_DECISION_DURATION_NANOSECONDS = BATTLE_DECISION_DURATION_NANO_DEFAULT;
|
2018-08-29 06:09:44 +00:00
|
|
|
|
2018-09-12 06:39:55 +00:00
|
|
|
@SidedProxy(modId=MODID, serverSide="com.seodisparate.TurnBasedMinecraft.common.CommonProxy", clientSide="com.seodisparate.TurnBasedMinecraft.client.ClientProxy")
|
|
|
|
public static CommonProxy commonProxy;
|
2018-08-28 02:26:34 +00:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void preInit(FMLPreInitializationEvent event)
|
|
|
|
{
|
|
|
|
logger = event.getModLog();
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void init(FMLInitializationEvent event)
|
|
|
|
{
|
2018-09-20 06:15:34 +00:00
|
|
|
commonProxy.initialize();
|
2018-09-12 05:43:59 +00:00
|
|
|
battleManager = null;
|
2018-09-17 06:49:10 +00:00
|
|
|
attackerViaBow = new HashSet<AttackerViaBow>();
|
2018-09-14 05:14:10 +00:00
|
|
|
commonProxy.setLogger(logger);
|
2018-08-29 06:09:44 +00:00
|
|
|
|
|
|
|
// register packets
|
2018-09-12 07:00:55 +00:00
|
|
|
NWINSTANCE.registerMessage(
|
2018-08-29 06:09:44 +00:00
|
|
|
PacketBattleInfo.HandlerBattleInfo.class,
|
|
|
|
PacketBattleInfo.class,
|
|
|
|
packetHandlerID++,
|
|
|
|
Side.CLIENT);
|
2018-09-12 07:00:55 +00:00
|
|
|
NWINSTANCE.registerMessage(
|
2018-08-29 06:09:44 +00:00
|
|
|
PacketBattleRequestInfo.HandlerBattleRequestInfo.class,
|
|
|
|
PacketBattleRequestInfo.class,
|
|
|
|
packetHandlerID++,
|
|
|
|
Side.SERVER);
|
2018-09-12 07:00:55 +00:00
|
|
|
NWINSTANCE.registerMessage(
|
2018-08-29 06:09:44 +00:00
|
|
|
PacketBattleDecision.HandleBattleDecision.class,
|
|
|
|
PacketBattleDecision.class,
|
|
|
|
packetHandlerID++,
|
|
|
|
Side.SERVER);
|
2018-09-12 07:00:55 +00:00
|
|
|
NWINSTANCE.registerMessage(
|
2018-09-06 08:08:36 +00:00
|
|
|
PacketBattleMessage.HandlerBattleMessage.class,
|
|
|
|
PacketBattleMessage.class,
|
|
|
|
packetHandlerID++,
|
|
|
|
Side.CLIENT);
|
2018-09-12 05:43:59 +00:00
|
|
|
|
|
|
|
// register event handler(s)
|
|
|
|
MinecraftForge.EVENT_BUS.register(new AttackEventHandler());
|
2018-08-28 06:13:14 +00:00
|
|
|
}
|
2018-08-29 06:09:44 +00:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void postInit(FMLPostInitializationEvent event)
|
|
|
|
{
|
2018-09-13 06:00:00 +00:00
|
|
|
config = new Config(logger);
|
2018-09-14 05:14:10 +00:00
|
|
|
commonProxy.setConfig(config);
|
|
|
|
commonProxy.postInit();
|
2018-09-20 06:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void serverStarting(FMLServerStartingEvent event)
|
|
|
|
{
|
|
|
|
logger.debug("About to initialize BattleManager");
|
|
|
|
if(commonProxy.initializeBattleManager())
|
|
|
|
{
|
|
|
|
logger.debug("Initialized BattleManager");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void serverStopping(FMLServerStoppingEvent event)
|
|
|
|
{
|
|
|
|
logger.debug("About to cleanup BattleManager");
|
|
|
|
if(commonProxy.cleanupBattleManager())
|
|
|
|
{
|
|
|
|
logger.debug("Cleaned up BattleManager");
|
|
|
|
}
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
2018-08-30 07:15:20 +00:00
|
|
|
|
|
|
|
public static BattleManager getBattleManager()
|
|
|
|
{
|
|
|
|
return battleManager;
|
|
|
|
}
|
2018-09-07 07:41:22 +00:00
|
|
|
|
|
|
|
public static void setConfigVersion(int version)
|
|
|
|
{
|
|
|
|
CONFIG_FILE_VERSION = version;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getConfigVersion()
|
|
|
|
{
|
|
|
|
return CONFIG_FILE_VERSION;
|
|
|
|
}
|
2018-09-25 05:55:24 +00:00
|
|
|
|
|
|
|
public static long getBattleDurationNanos()
|
|
|
|
{
|
|
|
|
return BATTLE_DECISION_DURATION_NANOSECONDS;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getBattleDurationSeconds()
|
|
|
|
{
|
|
|
|
return (int)(BATTLE_DECISION_DURATION_NANOSECONDS / 1000000000L);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static void setBattleDurationSeconds(long seconds)
|
|
|
|
{
|
|
|
|
BATTLE_DECISION_DURATION_NANOSECONDS = seconds * 1000000000L;
|
|
|
|
if(BATTLE_DECISION_DURATION_NANOSECONDS < BATTLE_DECISION_DURATION_NANO_MIN)
|
|
|
|
{
|
|
|
|
BATTLE_DECISION_DURATION_NANOSECONDS = BATTLE_DECISION_DURATION_NANO_MIN;
|
|
|
|
}
|
|
|
|
else if(BATTLE_DECISION_DURATION_NANOSECONDS > BATTLE_DECISION_DURATION_NANO_MAX)
|
|
|
|
{
|
|
|
|
BATTLE_DECISION_DURATION_NANOSECONDS = BATTLE_DECISION_DURATION_NANO_MAX;
|
|
|
|
}
|
|
|
|
}
|
2018-09-28 03:02:39 +00:00
|
|
|
|
|
|
|
public static Config getConfig()
|
|
|
|
{
|
|
|
|
return config;
|
|
|
|
}
|
2018-08-28 02:26:34 +00:00
|
|
|
}
|