2018-08-28 02:26:34 +00:00
|
|
|
package com.seodisparate.TurnBasedMinecraft;
|
|
|
|
|
2018-08-29 06:09:44 +00:00
|
|
|
import java.time.Duration;
|
|
|
|
|
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.Battle;
|
2018-08-28 06:13:14 +00:00
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.BattleManager;
|
2018-09-03 06:19:33 +00:00
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.Config;
|
2018-08-29 06:09:44 +00:00
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleDecision;
|
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleEntered;
|
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleExited;
|
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleInfo;
|
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleRequestInfo;
|
|
|
|
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketHandler;
|
2018-08-28 06:13:14 +00:00
|
|
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
2018-08-28 02:26:34 +00:00
|
|
|
import net.minecraftforge.fml.common.Mod;
|
|
|
|
import net.minecraftforge.fml.common.Mod.EventHandler;
|
|
|
|
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-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";
|
|
|
|
public static final String VERSION = "1.0";
|
2018-08-29 06:09:44 +00:00
|
|
|
public static final Duration BattleDecisionTime = Duration.ofSeconds(15);
|
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;
|
|
|
|
public static final int CONFIG_FILE_VERSION = 1; // TODO derive this from internal config
|
2018-08-28 02:26:34 +00:00
|
|
|
|
|
|
|
private static Logger logger;
|
2018-08-30 07:15:20 +00:00
|
|
|
private static BattleManager battleManager;
|
2018-08-29 06:09:44 +00:00
|
|
|
private static int packetHandlerID = 0;
|
2018-08-28 06:13:14 +00:00
|
|
|
public static Entity attackingEntity;
|
2018-09-03 06:19:33 +00:00
|
|
|
private static Config config;
|
2018-08-29 06:09:44 +00:00
|
|
|
|
|
|
|
public static Battle currentBattle;
|
2018-08-28 02:26:34 +00:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void preInit(FMLPreInitializationEvent event)
|
|
|
|
{
|
|
|
|
logger = event.getModLog();
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void init(FMLInitializationEvent event)
|
|
|
|
{
|
2018-08-29 06:09:44 +00:00
|
|
|
currentBattle = null;
|
|
|
|
if(event.getSide() == Side.SERVER)
|
|
|
|
{
|
|
|
|
battleManager = new BattleManager();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
battleManager = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// register packets
|
|
|
|
PacketHandler.INSTANCE.registerMessage(
|
|
|
|
PacketBattleEntered.HandlerBattleEntered.class,
|
|
|
|
PacketBattleEntered.class,
|
|
|
|
packetHandlerID++,
|
|
|
|
Side.CLIENT);
|
|
|
|
PacketHandler.INSTANCE.registerMessage(
|
|
|
|
PacketBattleExited.HandlerBattleExited.class,
|
|
|
|
PacketBattleExited.class,
|
|
|
|
packetHandlerID++,
|
|
|
|
Side.CLIENT);
|
|
|
|
PacketHandler.INSTANCE.registerMessage(
|
|
|
|
PacketBattleInfo.HandlerBattleInfo.class,
|
|
|
|
PacketBattleInfo.class,
|
|
|
|
packetHandlerID++,
|
|
|
|
Side.CLIENT);
|
|
|
|
PacketHandler.INSTANCE.registerMessage(
|
|
|
|
PacketBattleRequestInfo.HandlerBattleRequestInfo.class,
|
|
|
|
PacketBattleRequestInfo.class,
|
|
|
|
packetHandlerID++,
|
|
|
|
Side.SERVER);
|
|
|
|
PacketHandler.INSTANCE.registerMessage(
|
|
|
|
PacketBattleDecision.HandleBattleDecision.class,
|
|
|
|
PacketBattleDecision.class,
|
|
|
|
packetHandlerID++,
|
|
|
|
Side.SERVER);
|
2018-08-28 06:13:14 +00:00
|
|
|
}
|
2018-08-29 06:09:44 +00:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void postInit(FMLPostInitializationEvent event)
|
|
|
|
{
|
2018-09-03 06:19:33 +00:00
|
|
|
if(battleManager != null)
|
|
|
|
{
|
|
|
|
config = new Config(logger);
|
|
|
|
}
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
2018-08-28 06:13:14 +00:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void entityAttacked(LivingAttackEvent event)
|
|
|
|
{
|
2018-08-29 06:09:44 +00:00
|
|
|
if(battleManager == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(!event.getSource().getTrueSource().equals(attackingEntity) && battleManager.checkAttack(event))
|
2018-08-28 06:13:14 +00:00
|
|
|
{
|
|
|
|
logger.debug("Canceled LivingAttackEvent between " + attackingEntity + " and " + event.getEntity());
|
|
|
|
event.setCanceled(true);
|
|
|
|
}
|
2018-08-28 02:26:34 +00:00
|
|
|
}
|
2018-08-30 07:15:20 +00:00
|
|
|
|
|
|
|
public static BattleManager getBattleManager()
|
|
|
|
{
|
|
|
|
return battleManager;
|
|
|
|
}
|
2018-08-28 02:26:34 +00:00
|
|
|
}
|