Files
CustomNPC-Plus/src/main/java/noppes/npcs/CustomNpcs.java
T

306 lines
11 KiB
Java
Raw Normal View History

2018-09-13 12:03:28 -04:00
package noppes.npcs;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.*;
2018-09-13 12:03:28 -04:00
import cpw.mods.fml.common.network.FMLEventChannel;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;
import foxz.command.CommandNoppes;
2023-02-28 04:26:16 -05:00
import kamkeel.CommandKamkeel;
2018-09-13 12:03:28 -04:00
import net.minecraft.block.Block;
import net.minecraft.block.BlockIce;
import net.minecraft.block.BlockLeavesBase;
import net.minecraft.block.BlockVine;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.common.ForgeChunkManager;
import net.minecraftforge.common.MinecraftForge;
import nikedemos.markovnames.generators.*;
2023-01-07 00:21:08 -05:00
import noppes.npcs.config.ConfigMain;
2023-01-12 21:33:06 -05:00
import noppes.npcs.config.LoadConfiguration;
2023-01-07 18:07:23 -05:00
import noppes.npcs.config.legacy.LegacyConfig;
import noppes.npcs.controllers.*;
2018-09-13 12:03:28 -04:00
import noppes.npcs.enchants.EnchantInterface;
2021-04-27 11:56:36 -04:00
import noppes.npcs.entity.*;
import noppes.npcs.entity.old.*;
import noppes.npcs.scripted.NpcAPI;
import java.io.File;
2022-07-07 16:22:50 -05:00
import java.util.ArrayList;
import java.util.Set;
2022-07-07 16:22:50 -05:00
import java.util.UUID;
2018-09-13 12:03:28 -04:00
2022-11-15 00:25:14 -05:00
@Mod(modid = "customnpcs", name = "CustomNpcs", version = "1.7")
2018-09-13 12:03:28 -04:00
public class CustomNpcs {
@SidedProxy(clientSide = "noppes.npcs.client.ClientProxy", serverSide = "noppes.npcs.CommonProxy")
public static CommonProxy proxy;
2023-01-07 00:21:08 -05:00
public static File Dir;
2018-09-13 12:03:28 -04:00
2023-01-07 00:21:08 -05:00
private static int NewEntityStartId = 0;
public static long ticks;
2018-09-13 12:03:28 -04:00
public static CustomNpcs instance;
public static boolean FreezeNPCs = false;
public static FMLEventChannel Channel;
public static FMLEventChannel ChannelPlayer;
2022-11-07 01:49:54 -05:00
2022-07-07 16:22:50 -05:00
public static ArrayList<UUID> ScriptDevs = new ArrayList<>();
public static final MarkovGenerator[] MARKOV_GENERATOR = new MarkovGenerator[10];
2022-11-07 01:49:54 -05:00
public static boolean InitIgnore = false;
public static boolean TickIgnore = false;
public static boolean InteractIgnore = false;
public static boolean DialogIgnore = false;
public static boolean DamagedIgnore = false;
public static boolean KilledIgnore = false;
public static boolean AttackIgnore = false;
public static boolean TargetIgnore = false;
public static boolean CollideIgnore = false;
public static boolean KillsIgnore = false;
public static boolean DialogCloseIgnore = false;
public static boolean TimerIgnore = false;
2023-01-07 00:21:08 -05:00
public static String configPath;
2023-01-07 18:07:23 -05:00
public static String legacyPath;
public static boolean legacyExist;
public static LegacyConfig legacyConfig;
2023-01-07 00:21:08 -05:00
2018-09-13 12:03:28 -04:00
public CustomNpcs() {
instance = this;
}
@EventHandler
public void load(FMLPreInitializationEvent ev) {
Channel = NetworkRegistry.INSTANCE.newEventDrivenChannel("CustomNPCs");
ChannelPlayer = NetworkRegistry.INSTANCE.newEventDrivenChannel("CustomNPCsPlayer");
MinecraftServer server = MinecraftServer.getServer();
String dir = "";
if (server != null) {
dir = new File(".").getAbsolutePath();
} else {
dir = Minecraft.getMinecraft().mcDataDir.getAbsolutePath();
}
Dir = new File(dir, "customnpcs");
Dir.mkdir();
2023-01-07 18:07:23 -05:00
configPath = ev.getModConfigurationDirectory() + File.separator + "CustomNpcPlus";
legacyPath = ev.getModConfigurationDirectory() + "/CustomNpcs.cfg";
File configDir = new File(configPath);
if(!configDir.exists()){
// Convert Legacy Config to New Config if NO Config Folder Exists
File legacyFile = new File(legacyPath);
if(legacyFile.exists()){
2023-02-28 03:32:35 -05:00
System.out.println("Loading Legacy Config");
2023-01-07 18:07:23 -05:00
legacyExist = true;
legacyConfig = new LegacyConfig();
legacyConfig.init();
}
}
configPath += File.separator;
2023-01-07 00:21:08 -05:00
LoadConfiguration.init(configPath);
2022-11-07 01:49:54 -05:00
2018-09-13 12:03:28 -04:00
EnchantInterface.load();
CustomItems.load();
2022-11-07 01:49:54 -05:00
2018-09-13 12:03:28 -04:00
proxy.load();
NetworkRegistry.INSTANCE.registerGuiHandler(this, proxy);
MinecraftForge.EVENT_BUS.register(new ServerEventsHandler());
2018-09-13 12:03:28 -04:00
MinecraftForge.EVENT_BUS.register(new ScriptController());
ScriptPlayerEventHandler scriptPlayerEventHandler = new ScriptPlayerEventHandler();
MinecraftForge.EVENT_BUS.register(scriptPlayerEventHandler);
FMLCommonHandler.instance().bus().register(scriptPlayerEventHandler);
2022-01-10 12:37:26 -06:00
ScriptForgeEventHandler forgeEventHandler = (new ScriptForgeEventHandler()).registerForgeEvents();
MinecraftForge.EVENT_BUS.register(forgeEventHandler);
FMLCommonHandler.instance().bus().register(forgeEventHandler);
ScriptItemEventHandler scriptItemEventHandler = new ScriptItemEventHandler();
MinecraftForge.EVENT_BUS.register(scriptItemEventHandler);
FMLCommonHandler.instance().bus().register(scriptItemEventHandler);
2022-11-07 01:49:54 -05:00
FMLCommonHandler.instance().bus().register(new ServerTickHandler());
2018-09-13 12:03:28 -04:00
registerNpc(EntityNPCHumanMale.class, "npchumanmale");
registerNpc(EntityNPCVillager.class, "npcvillager");
registerNpc(EntityNpcPony.class, "npcpony");
registerNpc(EntityNPCHumanFemale.class, "npchumanfemale");
registerNpc(EntityNPCDwarfMale.class, "npcdwarfmale");
registerNpc(EntityNPCFurryMale.class, "npcfurrymale");
registerNpc(EntityNpcMonsterMale.class, "npczombiemale");
registerNpc(EntityNpcMonsterFemale.class, "npczombiefemale");
registerNpc(EntityNpcSkeleton.class, "npcskeleton");
registerNpc(EntityNPCDwarfFemale.class, "npcdwarffemale");
registerNpc(EntityNPCFurryFemale.class, "npcfurryfemale");
registerNpc(EntityNPCOrcMale.class, "npcorcfmale");
registerNpc(EntityNPCOrcFemale.class, "npcorcfemale");
registerNpc(EntityNPCElfMale.class, "npcelfmale");
registerNpc(EntityNPCElfFemale.class, "npcelffemale");
registerNpc(EntityNpcCrystal.class, "npccrystal");
registerNpc(EntityNpcEnderchibi.class, "npcenderchibi");
registerNpc(EntityNpcNagaMale.class, "npcnagamale");
registerNpc(EntityNpcNagaFemale.class, "npcnagafemale");
registerNpc(EntityNpcSlime.class, "NpcSlime");
registerNpc(EntityNpcDragon.class, "NpcDragon");
registerNpc(EntityNPCEnderman.class, "npcEnderman");
registerNpc(EntityNPCGolem.class, "npcGolem");
2021-04-29 01:10:15 -04:00
registerNpc(EntityCustomNpc.class, "CustomNpc");
2018-09-13 12:03:28 -04:00
registerNewEntity(EntityChairMount.class, "CustomNpcChairMount", 64, 10, false);
registerNewEntity(EntityProjectile.class, "throwableitem", 64, 3, true);
registerNewEntity(EntityMagicProjectile.class, "magicprojectile", 64, 3, true);
new RecipeController();
2018-09-13 12:03:28 -04:00
ForgeChunkManager.setForcedChunkLoadingCallback(this, new ChunkController());
new CustomNpcsPermissions();
2022-11-07 01:49:54 -05:00
2018-09-13 12:03:28 -04:00
PixelmonHelper.load();
}
@EventHandler
public void load(FMLInitializationEvent ev) {
MARKOV_GENERATOR[0] = new MarkovRoman(3);
MARKOV_GENERATOR[1] = new MarkovJapanese(4);
MARKOV_GENERATOR[2] = new MarkovSlavic(3);
MARKOV_GENERATOR[3] = new MarkovWelsh(3);
MARKOV_GENERATOR[4] = new MarkovSaami(3);
MARKOV_GENERATOR[5] = new MarkovOldNorse(4);
MARKOV_GENERATOR[6] = new MarkovAncientGreek(3);
MARKOV_GENERATOR[7] = new MarkovAztec(3);
MARKOV_GENERATOR[8] = new MarkovCustomNPCsClassic(3);
MARKOV_GENERATOR[9] = new MarkovSpanish(3);
}
2018-09-13 12:03:28 -04:00
@EventHandler
public void setAboutToStart(FMLServerAboutToStartEvent event) {
2022-11-07 01:49:54 -05:00
ChunkController.instance.clear();
2018-09-13 12:03:28 -04:00
new QuestController();
new PlayerDataController();
new FactionController();
new TagController();
2018-09-13 12:03:28 -04:00
new TransportController();
new GlobalDataController();
new SpawnController();
new LinkedNpcController();
new AnimationController();
2018-09-13 12:03:28 -04:00
ScriptController.Instance.loadStoredData();
ScriptController.Instance.loadForgeScripts();
2022-03-23 03:54:06 -05:00
ScriptController.Instance.loadNPCScripts();
ScriptController.Instance.loadPlayerScripts();
2018-09-13 12:03:28 -04:00
ScriptController.HasStart = false;
NpcAPI.clearCache();
2018-09-13 12:03:28 -04:00
Set<String> names = Block.blockRegistry.getKeys();
for(String name : names){
2022-11-07 01:49:54 -05:00
Block block = (Block) Block.blockRegistry.getObject(name);
if(block instanceof BlockLeavesBase){
2023-01-07 00:21:08 -05:00
block.setTickRandomly(ConfigMain.LeavesDecayEnabled);
2022-11-07 01:49:54 -05:00
}
if(block instanceof BlockVine){
2023-01-07 00:21:08 -05:00
block.setTickRandomly(ConfigMain.VineGrowthEnabled);
2022-11-07 01:49:54 -05:00
}
if(block instanceof BlockIce){
2023-01-07 00:21:08 -05:00
block.setTickRandomly(ConfigMain.IceMeltsEnabled);
2022-11-07 01:49:54 -05:00
}
2018-09-13 12:03:28 -04:00
}
}
2022-11-07 01:49:54 -05:00
2018-09-13 12:03:28 -04:00
//Loading items in the about to start event was corrupting items with a damage value
@EventHandler
public void started(FMLServerStartedEvent event) {
2022-11-07 01:49:54 -05:00
RecipeController.instance.load();
2018-09-13 12:03:28 -04:00
new DialogController();
new BankController();
QuestController.instance.load();
ScriptController.HasStart = true;
ServerCloneController.Instance = new ServerCloneController();
}
2022-11-07 01:49:54 -05:00
2018-09-13 12:03:28 -04:00
@EventHandler
public void stopped(FMLServerStoppedEvent event){
ServerCloneController.Instance = null;
2022-06-12 01:26:23 -05:00
GlobalDataController.instance.saveData();
ScriptController.Instance.saveForgeScripts();
ScriptController.Instance.savePlayerScripts();
ScriptController.Instance.saveNpcScripts();
2018-09-13 12:03:28 -04:00
}
@EventHandler
public void serverstart(FMLServerStartingEvent event) {
event.registerServerCommand(new CommandNoppes());
2023-02-28 04:26:16 -05:00
event.registerServerCommand(new CommandKamkeel());
2018-09-13 12:03:28 -04:00
}
private void registerNpc(Class<? extends Entity> cl, String name) {
EntityRegistry.registerModEntity(cl, name, NewEntityStartId++, this, 64, 3, true);
EntityList.stringToClassMapping.put(name, cl);
}
private void registerNewEntity(Class<? extends Entity> cl, String name, int range, int update, boolean velocity) {
EntityRegistry.registerModEntity(cl, name, NewEntityStartId++, this, range, update, velocity);
}
public static File getWorldSaveDirectory() {
MinecraftServer server = MinecraftServer.getServer();
File saves = new File(".");
if (server != null && !server.isDedicatedServer()) {
saves = new File(Minecraft.getMinecraft().mcDataDir, "saves");
}
if (server != null) {
File savedir = new File(new File(saves, server.getFolderName()), "customnpcs");
if (!savedir.exists()) {
savedir.mkdir();
}
return savedir;
}
return null;
}
public static File getWorldSaveDirectory(String s) {
try {
File dir = new File(".");
if (getServer() != null) {
if (!getServer().isDedicatedServer()) {
dir = new File(Minecraft.getMinecraft().mcDataDir, "saves");
}
dir = new File(new File(dir, getServer().getFolderName()), "customnpcs");
}
if (s != null) {
dir = new File(dir, s);
}
if (!dir.exists()) {
dir.mkdirs();
}
return dir;
} catch (Exception var2) {
LogWriter.error("Error getting worldsave", var2);
return null;
}
}
public static MinecraftServer getServer(){
return MinecraftServer.getServer();
}
2022-11-07 01:49:54 -05:00
}