2018-09-13 12:03:28 -04:00
package noppes.npcs ;
2022-02-27 06:58:53 -03:00
import com.google.common.util.concurrent.ThreadFactoryBuilder ;
2018-09-13 12:03:28 -04:00
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 ;
2022-02-27 06:58:53 -03:00
import me.luizotavio.compressor.executor.IOExecutor ;
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.* ;
2018-09-13 12:03:28 -04:00
import noppes.npcs.config.ConfigLoader ;
import noppes.npcs.config.ConfigProp ;
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.* ;
2021-10-11 06:49:30 -05:00
import noppes.npcs.scripted.wrapper.WrapperNpcAPI ;
2022-02-27 06:58:53 -03:00
import java.io.File ;
import java.util.Set ;
import java.util.concurrent.Executors ;
2018-09-13 12:03:28 -04:00
2022-02-02 19:25:17 -05:00
@Mod ( modid = "customnpcs" , name = "CustomNpcs" , version = "1.5.1-beta" )
2018-09-13 12:03:28 -04:00
public class CustomNpcs {
2022-02-27 06:58:53 -03:00
@ConfigProp ( info = "Disable Chat Bubbles" )
2018-09-13 12:03:28 -04:00
public static boolean EnableChatBubbles = true ;
2022-02-27 06:58:53 -03:00
2018-09-13 12:03:28 -04:00
private static int NewEntityStartId = 0 ;
2022-02-27 06:58:53 -03:00
2022-03-03 15:58:21 -05:00
@ConfigProp ( info = "*BACKUP BEFORE CHANGING* File Type used with PlayerData. Converting files may reduce lag. To convert existing files: /noppes compressor update [<filename>|all] [json|zstd]" )
2022-02-27 06:58:53 -03:00
public static String CompressorType = "json" ;
@ConfigProp ( info = "The size of IO executors used for compression and decompression. This is the number of threads used for compression and decompression. If you are experiencing issues with the server lagging/crashing, try changing this to a higher number." )
public static int CompressorThreads = 2 ;
2022-01-14 17:37:09 -06:00
@ConfigProp ( info = "Navigation search range for NPCs. Not recommended to increase if you have a slow pc or on a server. Minimum of 16, maximum of 96." )
2018-09-13 12:03:28 -04:00
public static int NpcNavRange = 32 ;
2022-01-25 14:54:15 -06:00
@ConfigProp ( info = "Size limit for NPCs. Default 100, larger sizes may cause lag on clients and servers that can't take it!" )
public static int NpcSizeLimit = 100 ;
2018-09-13 12:03:28 -04:00
@ConfigProp ( info = "Set to true if you want the dialog command option to be able to use op commands like tp etc" )
public static boolean NpcUseOpCommands = false ;
2022-02-02 07:53:42 -06:00
@ConfigProp ( info = "The amount of time that passes before a player's quests are checked for completion in seconds." )
public static int PlayerQuestCheck = 300 ;
2018-09-13 12:03:28 -04:00
@ConfigProp
public static boolean InventoryGuiEnabled = true ;
@ConfigProp
public static boolean DisableExtraItems = false ;
@ConfigProp
public static boolean DisableExtraBlock = false ;
public static long ticks ;
@SidedProxy ( clientSide = "noppes.npcs.client.ClientProxy" , serverSide = "noppes.npcs.CommonProxy" )
public static CommonProxy proxy ;
@ConfigProp ( info = "Enables CustomNpcs startup update message" )
public static boolean EnableUpdateChecker = true ;
public static CustomNpcs instance ;
public static boolean FreezeNPCs = false ;
@ConfigProp ( info = "Only ops can create and edit npcs" )
public static boolean OpsOnly = false ;
@ConfigProp ( info = "Default interact line. Leave empty to not have one" )
public static String DefaultInteractLine = "Hello @p" ;
@ConfigProp
public static boolean DisableEnchants = false ;
@ConfigProp ( info = "Start Id for enchants. IDs can only range from 0-256" )
public static int EnchantStartId = 100 ;
@ConfigProp ( info = "Number of chunk loading npcs that can be active at the same time" )
public static int ChuckLoaders = 20 ;
public static File Dir ;
@ConfigProp ( info = "Set to false if you want to disable guns" )
public static boolean GunsEnabled = true ;
@ConfigProp ( info = "Enables leaves decay" )
public static boolean LeavesDecayEnabled = true ;
@ConfigProp ( info = "Enables Vine Growth" )
public static boolean VineGrowthEnabled = true ;
@ConfigProp ( info = "Enables Ice Melting" )
public static boolean IceMeltsEnabled = true ;
@ConfigProp ( info = "Normal players can use soulstone on animals" )
public static boolean SoulStoneAnimals = true ;
@ConfigProp ( info = "Normal players can use soulstone on all npcs" )
public static boolean SoulStoneNPCs = false ;
@ConfigProp ( info = "When set to Minecraft it will use minecrafts font, when Default it will use OpenSans. Can only use fonts installed on your PC" )
public static String FontType = "Default" ;
@ConfigProp ( info = "Font size for custom fonts (doesn't work with minecrafts font)" )
public static int FontSize = 18 ;
public static FMLEventChannel Channel ;
public static FMLEventChannel ChannelPlayer ;
public static ConfigLoader Config ;
2021-06-13 19:26:00 -04:00
public static final MarkovGenerator [] MARKOV_GENERATOR = new MarkovGenerator [ 10 ] ;
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 ();
Config = new ConfigLoader ( this . getClass (), new File ( dir , "config" ), "CustomNpcs" );
Config . loadConfig ();
if ( NpcNavRange < 16 ) {
NpcNavRange = 16 ;
}
2022-01-14 17:37:09 -06:00
if ( NpcNavRange > 96 ) {
NpcNavRange = 96 ;
}
2022-01-25 14:54:15 -06:00
if ( NpcSizeLimit < 1 )
NpcSizeLimit = 1 ;
2022-02-02 07:53:42 -06:00
if ( PlayerQuestCheck < 1 )
PlayerQuestCheck = 1 ;
2018-09-13 12:03:28 -04:00
EnchantInterface . load ();
CustomItems . load ();
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
2021-12-16 04:05:05 -06: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" );
2022-02-27 06:58:53 -03:00
IOExecutor . IO_EXECUTOR = Executors . newFixedThreadPool (
CompressorThreads ,
new ThreadFactoryBuilder ()
. setNameFormat ( "CustomNpcs-IO-%d" )
. build ()
);
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 ();
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 ) {
ChunkController . instance . clear ();
new QuestController ();
new PlayerDataController ();
new FactionController ();
new TransportController ();
new GlobalDataController ();
new SpawnController ();
new LinkedNpcController ();
ScriptController . Instance . loadStoredData ();
2021-10-11 06:49:30 -05:00
ScriptController . Instance . loadForgeScripts ();
2022-03-23 03:54:06 -05:00
ScriptController . Instance . loadNPCScripts ();
2021-10-11 06:49:30 -05:00
ScriptController . Instance . loadPlayerScripts ();
2018-09-13 12:03:28 -04:00
ScriptController . HasStart = false ;
2021-10-11 06:49:30 -05:00
WrapperNpcAPI . clearCache ();
2018-09-13 12:03:28 -04:00
Set < String > names = Block . blockRegistry . getKeys ();
for ( String name : names ){
Block block = ( Block ) Block . blockRegistry . getObject ( name );
if ( block instanceof BlockLeavesBase ){
block . setTickRandomly ( LeavesDecayEnabled );
}
if ( block instanceof BlockVine ){
block . setTickRandomly ( VineGrowthEnabled );
}
if ( block instanceof BlockIce ){
block . setTickRandomly ( IceMeltsEnabled );
}
}
}
//Loading items in the about to start event was corrupting items with a damage value
@EventHandler
public void started ( FMLServerStartedEvent event ) {
RecipeController . instance . load ();
new DialogController ();
new BankController ();
QuestController . instance . load ();
ScriptController . HasStart = true ;
ServerCloneController . Instance = new ServerCloneController ();
}
@EventHandler
public void stopped ( FMLServerStoppedEvent event ){
ServerCloneController . Instance = null ;
}
@EventHandler
public void serverstart ( FMLServerStartingEvent event ) {
event . registerServerCommand ( new CommandNoppes ());
}
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 ();
}
2018-09-13 12:03:28 -04:00
}