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;
|
2021-06-13 19:26:00 -04:00
|
|
|
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-05-12 20:32:55 -04:00
|
|
|
import kamkeel.command.CommandKamkeel;
|
2023-05-16 12:39:55 -04:00
|
|
|
import kamkeel.developer.Developer;
|
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;
|
2021-06-13 19:26:00 -04:00
|
|
|
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;
|
2022-02-27 06:58:53 -03:00
|
|
|
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.*;
|
2022-02-27 06:58:53 -03:00
|
|
|
import noppes.npcs.entity.old.*;
|
2022-05-11 22:08:31 -05:00
|
|
|
import noppes.npcs.scripted.NpcAPI;
|
2022-05-11 17:12:48 -05:00
|
|
|
|
2022-02-27 06:58:53 -03:00
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.Set;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2023-06-03 17:50:06 -04:00
|
|
|
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.8.5")
|
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
|
|
|
|
2021-06-13 19:26:00 -04:00
|
|
|
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);
|
|
|
|
|
|
2021-12-16 04:05:05 -06:00
|
|
|
MinecraftForge.EVENT_BUS.register(new ServerEventsHandler());
|
2018-09-13 12:03:28 -04:00
|
|
|
MinecraftForge.EVENT_BUS.register(new ScriptController());
|
|
|
|
|
|
2021-12-16 04:05:05 -06:00
|
|
|
ScriptPlayerEventHandler scriptPlayerEventHandler = new ScriptPlayerEventHandler();
|
|
|
|
|
MinecraftForge.EVENT_BUS.register(scriptPlayerEventHandler);
|
2021-12-17 15:14:52 -06:00
|
|
|
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);
|
2021-12-23 10:26:46 -06:00
|
|
|
|
2022-05-11 13:30:13 -05:00
|
|
|
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();
|
2022-02-27 06:58:53 -03:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
ForgeChunkManager.setForcedChunkLoadingCallback(this, new ChunkController());
|
|
|
|
|
|
|
|
|
|
new CustomNpcsPermissions();
|
2023-05-16 12:39:55 -04:00
|
|
|
new Developer();
|
2022-11-07 01:49:54 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
PixelmonHelper.load();
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-13 19:26:00 -04:00
|
|
|
@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) {
|
2023-06-05 22:12:48 -04:00
|
|
|
ChunkController.Instance.clear();
|
2018-09-13 12:03:28 -04:00
|
|
|
new QuestController();
|
|
|
|
|
new PlayerDataController();
|
|
|
|
|
new FactionController();
|
2023-01-10 16:48:14 -05:00
|
|
|
new TagController();
|
2018-09-13 12:03:28 -04:00
|
|
|
new TransportController();
|
|
|
|
|
new GlobalDataController();
|
|
|
|
|
new SpawnController();
|
|
|
|
|
new LinkedNpcController();
|
2023-01-26 14:14:13 -06:00
|
|
|
new AnimationController();
|
2018-09-13 12:03:28 -04:00
|
|
|
ScriptController.Instance.loadStoredData();
|
2021-10-11 06:49:30 -05:00
|
|
|
ScriptController.Instance.loadForgeScripts();
|
2023-03-16 04:27:19 -05:00
|
|
|
ScriptController.Instance.loadGlobalNPCScripts();
|
2021-10-11 06:49:30 -05:00
|
|
|
ScriptController.Instance.loadPlayerScripts();
|
2018-09-13 12:03:28 -04:00
|
|
|
ScriptController.HasStart = false;
|
2022-05-11 17:12:48 -05:00
|
|
|
NpcAPI.clearCache();
|
2023-06-05 19:35:27 -04:00
|
|
|
PlayerDataController.Instance.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) {
|
2023-06-05 22:12:48 -04:00
|
|
|
RecipeController.Instance.load();
|
2018-09-13 12:03:28 -04:00
|
|
|
new DialogController();
|
|
|
|
|
new BankController();
|
2023-06-05 22:12:48 -04:00
|
|
|
QuestController.Instance.load();
|
2018-09-13 12:03:28 -04:00
|
|
|
ScriptController.HasStart = true;
|
|
|
|
|
ServerCloneController.Instance = new ServerCloneController();
|
2023-03-22 16:06:22 -04:00
|
|
|
ServerTagMapController.Instance = new ServerTagMapController();
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
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;
|
2023-06-05 19:35:27 -04:00
|
|
|
GlobalDataController.Instance.saveData();
|
2023-02-19 13:38:43 -06:00
|
|
|
ScriptController.Instance.saveForgeScripts();
|
|
|
|
|
ScriptController.Instance.savePlayerScripts();
|
2023-03-16 04:27:19 -05:00
|
|
|
ScriptController.Instance.saveGlobalNpcScripts();
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-20 23:04:52 -05:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-30 21:44:30 -05:00
|
|
|
public static MinecraftServer getServer(){
|
|
|
|
|
return MinecraftServer.getServer();
|
|
|
|
|
}
|
2022-11-07 01:49:54 -05:00
|
|
|
}
|