package JAKJ . RedstoneInMotion ;

public class Configuration
{
	public final net . minecraftforge . common . Configuration Configuration ;

	public Configuration ( java . io . File File )
	{
		Configuration = new net . minecraftforge . common . Configuration ( File , true ) ;
	}

	public String String ( String Category , String Name , String Default )
	{
		return ( Configuration . get ( Category , Name , Default ) . getString ( ) ) ;
	}

	public boolean Boolean ( String Category , String Name , boolean Default )
	{
		return ( Configuration . get ( Category , Name , Default ) . getBoolean ( Default ) ) ;
	}

	public int Integer ( String Category , String Name , int Default )
	{
		return ( Configuration . get ( Category , Name , Default ) . getInt ( Default ) ) ;
	}

	public int BoundedInteger ( String Category , String Name , int Min , int Default , int Max )
	{
		int Value = Integer ( Category , Name , Default ) ;

		if ( Value < Min )
		{
			throw ( new RuntimeException ( Name + " must be at least " + Min ) ) ;
		}

		if ( Value > Max )
		{
			throw ( new RuntimeException ( Name + " must be at most " + Max ) ) ;
		}

		return ( Value ) ;
	}

	public int BlockId ( String Name , int Default )
	{
		return ( Configuration . getBlock ( "Block IDs" , Name , Default ) . getInt ( Default ) ) ;
	}

	public int ItemId ( String Name , int Default )
	{
		return ( Configuration . getItem ( "Item IDs" , Name , Default ) . getInt ( Default ) ) ;
	}

	public void Process ( )
	{
		{
			Carriage . Id = BlockId ( "Carriages" , 1123 ) ;

			CarriageDrive . Id = BlockId ( "Carriage Drives" , 1124 ) ;

			MotiveSpectre . Id = BlockId ( "Motive Spectre" , 1125 ) ;
		}

		{
			ToolItemSet . Id = ItemId ( "Tools" , 11235 ) ;

			SimpleItemSet . Id = ItemId ( "Simple Items" , 11236 ) ;
		}

		{
			String Category = "Carriage" ;

			{
				String Blacklist = String ( Category , "Blacklist" , "" ) ;

				if ( ! Blacklist . equals ( "" ) )
				{
					for ( String BlacklistItem : Blacklist . split ( "," ) )
					{
						String [ ] BlacklistItemElements = BlacklistItem . split ( ":" ) ;

						try
						{
							if ( BlacklistItemElements . length == 1 )
							{
								CarriagePackageBlacklist . Add ( Integer . parseInt ( BlacklistItemElements [ 0 ] ) ) ;

								continue ;
							}

							if ( BlacklistItemElements . length == 2 )
							{
								CarriagePackageBlacklist . Add ( Integer . parseInt ( BlacklistItemElements [ 0 ] ) , Integer . parseInt ( BlacklistItemElements [ 1 ] ) ) ;

								continue ;
							}
						}
						catch ( Throwable Throwable )
						{
							Throwable . printStackTrace ( ) ;
						}

						throw ( new RuntimeException ( "Invalid blacklist item: " + BlacklistItem ) ) ;
					}
				}
			}

			CarriagePackage . MaxBlockCount = BoundedInteger ( Category , "Maximum size of any carriage (0 = no limit)" , 0 , CarriagePackage . MaxBlockCount , Integer . MAX_VALUE ) ;

			PlatformCarriageEntity . MaxBlocksCarried = BoundedInteger ( Category , "Maximum blocks carried by platform carriage" , 1 , PlatformCarriageEntity . MaxBlocksCarried , Integer . MAX_VALUE ) ;

			SupportCarriageEntity . MaxBlocksCarried = BoundedInteger ( Category , "Maximum blocks carried by a support carriage" , 1 , SupportCarriageEntity . MaxBlocksCarried , Integer . MAX_VALUE ) ;
		}

		{
			String Category = "Carriage Drive" ;

			CarriageDriveEntity . ContinuousCooldown = BoundedInteger ( Category , "Cooldown (in ticks) between motions in continuous mode" , 0 , CarriageDriveEntity . ContinuousCooldown , Integer . MAX_VALUE ) ;
		}

		{
			String Category = "Carriage Motion" ;

			MotiveSpectreEntity . CapturePlayerEntities = Boolean ( Category , "Should grab players during motion" , MotiveSpectreEntity . CapturePlayerEntities ) ;

			MotiveSpectreEntity . CaptureOtherLivingEntities = Boolean ( Category , "Should grab non-player living entities during motion" , MotiveSpectreEntity . CaptureOtherLivingEntities ) ;

			MotiveSpectreEntity . CaptureItemEntities = Boolean ( Category , "Should grab floating items during motion" , MotiveSpectreEntity . CaptureItemEntities ) ;

			MotiveSpectreEntity . CaptureOtherEntities = Boolean ( Category , "Should grab all other miscellaneous entities during motion" , MotiveSpectreEntity . CaptureOtherEntities ) ;

			CarriagePackage . ObstructedByLiquids = Boolean ( Category , "Carriage motion is obstructed by liquids" , CarriagePackage . ObstructedByLiquids ) ;

			CarriagePackage . ObstructedByFragileBlocks = Boolean ( Category , "Carriage motion is obstructed by fragile blocks like tall grass" , CarriagePackage . ObstructedByFragileBlocks ) ;
		}

		Configuration . save ( ) ;
	}
}
