using System; namespace ClassicalSharp { public partial class Game { /// Raised when an entity is spawned in the current world. public event EventHandler EntityAdded; internal void RaiseEntityAdded( byte id ) { idArgs.Id = id; Raise( EntityAdded, idArgs ); } /// Raised when an entity is despawned from the current world. public event EventHandler EntityRemoved; internal void RaiseEntityRemoved( byte id ) { idArgs.Id = id; Raise( EntityRemoved, idArgs ); } /// Raised when a new CPE player list entry is created. public event EventHandler CpeListInfoAdded; internal void RaiseCpeListInfoAdded( byte id ) { idArgs.Id = id; Raise( CpeListInfoAdded, idArgs ); } /// Raised when a CPE player list entry is modified. public event EventHandler CpeListInfoChanged; internal void RaiseCpeListInfoChanged( byte id ) { idArgs.Id = id; Raise( CpeListInfoChanged, idArgs ); } /// Raised when a CPE player list entry is removed. public event EventHandler CpeListInfoRemoved; internal void RaiseCpeListInfoRemoved( byte id ) { idArgs.Id = id; Raise( CpeListInfoRemoved, idArgs ); } /// Raised when the client joins and begins loading a new map. public event EventHandler OnNewMap; internal void RaiseOnNewMap() { Raise( OnNewMap ); } /// Raised when a portion of the map is read and decompressed by the client. public event EventHandler MapLoading; internal void RaiseMapLoading( byte progress ) { loadingArgs.Progress = progress; Raise( MapLoading, loadingArgs ); } /// Raised when the client has finished loading a new map and can now interact with it. public event EventHandler OnNewMapLoaded; internal void RaiseOnNewMapLoaded() { Raise( OnNewMapLoaded ); } /// Raised when the terrain atlas ("terrain.png") is changed. public event EventHandler TerrainAtlasChanged; /// Raised when an environment variable is changed by the user, CPE, or WoM config. public event EventHandler EnvVariableChanged; internal void RaiseEnvVariableChanged( EnvVariable envVar ) { envArgs.Var = envVar; Raise( EnvVariableChanged, envArgs ); } /// Raised when the user changed their view/fog distance. public event EventHandler ViewDistanceChanged; /// Raised when the held block is changed by the user or by CPE. public event EventHandler HeldBlockChanged; internal void RaiseHeldBlockChanged() { Raise( HeldBlockChanged ); } /// Raised when the client's block permissions(can place or delete a block) change. public event EventHandler BlockPermissionsChanged; internal void RaiseBlockPermissionsChanged() { Raise( BlockPermissionsChanged ); } /// Raised when the server or a client-side command sends a message. public event EventHandler ChatReceived; // Cache event instances so we don't create needless new objects. IdEventArgs idArgs = new IdEventArgs( 0 ); MapLoadingEventArgs loadingArgs = new MapLoadingEventArgs( 0 ); EnvVariableEventArgs envArgs = new EnvVariableEventArgs( 0 ); void Raise( EventHandler handler ) { if( handler != null ) { handler( this, EventArgs.Empty ); } } void Raise( EventHandler handler, T args ) where T : EventArgs { if( handler != null ) { handler( this, args ); } } } public sealed class IdEventArgs : EventArgs { public byte Id; public IdEventArgs( byte id ) { Id = id; } } public sealed class ChatEventArgs : EventArgs { public CpeMessage Type; public string Text; } public sealed class MapLoadingEventArgs : EventArgs { public int Progress; public MapLoadingEventArgs( int progress ) { Progress = progress; } } public sealed class EnvVariableEventArgs : EventArgs { public EnvVariable Var; public EnvVariableEventArgs( EnvVariable variable ) { Var = variable; } } public enum EnvVariable { SidesBlock, EdgeBlock, WaterLevel, Weather, SkyColour, CloudsColour, FogColour, SunlightColour, ShadowlightColour, } public enum Weather { Sunny, Rainy, Snowy, } }