module Network.Minecraft.GameMode (
	GameMode(..),
	fromInteger,
	isSurvival,
	isCreative,
	isAdventure,
	isHardcore
) where

import Data.Bits
import Prelude hiding (fromInteger)

data GameMode = Survival | Creative | Adventure | HardcoreSurvival | HardcoreCreative | HardcoreAdventure
	deriving (Show)

fromInteger i | testBit i 3 = case i .&. 4 of
				0 -> HardcoreSurvival
				1 -> HardcoreCreative
				2 -> HardcoreAdventure

fromInteger 0 = Survival
fromInteger 1 = Creative
fromInteger 2 = Adventure

isSurvival Survival = True
isSurvival HardcoreSurvival = True
isSurvival _ = False

isCreative Creative = True
isCreative HardcoreCreative = True
isCreative _ = False

isAdventure Adventure = True
isAdventure HardcoreAdventure = True
isAdventure _ = False

isHardcore HardcoreSurvival = True
isHardcore HardcoreCreative = True
isHardcore HardcoreAdventure = True
isHardcore _ = False
