Exemplo n.º 1
0
        public override byte[] Load( Stream stream, Game game, out int width, out int height, out int length )
        {
            using( GZipStream wrapper = new GZipStream( stream, CompressionMode.Decompress ) ) {
                reader = new BinaryReader( wrapper );
                if( reader.ReadByte() != (byte)NbtTagType.Compound )
                    throw new InvalidDataException( "Nbt file must start with Tag_Compound" );
                this.game = game;
                map = game.Map;

                invalid.TagId = NbtTagType.Invalid;
                NbtTag root = ReadTag( (byte)NbtTagType.Compound, true );
                Dictionary<string, NbtTag> children = (Dictionary<string, NbtTag>)root.Value;
                if( children.ContainsKey( "Metadata" ) )
                    ParseMetadata( children );

                Dictionary<string, NbtTag> spawn = (Dictionary<string, NbtTag>)children["Spawn"].Value;
                LocalPlayer p = game.LocalPlayer;
                p.SpawnPoint.X = (short)spawn["X"].Value / 32f;
                p.SpawnPoint.Y = (short)spawn["Y"].Value / 32f;
                p.SpawnPoint.Z = (short)spawn["Z"].Value / 32f;

                map.Uuid = new Guid( (byte[])children["UUID"].Value );
                width = (short)children["X"].Value;
                height = (short)children["Y"].Value;
                length = (short)children["Z"].Value;
                return (byte[])children["BlockArray"].Value;
            }
        }
Exemplo n.º 2
0
 public NetPlayer( string displayName, string skinName, Game game )
     : base(game)
 {
     DisplayName = displayName;
     SkinName = Utils.StripColours( skinName );
     InitRenderingData();
 }
Exemplo n.º 3
0
        static void Main( string[] args )
        {
            ErrorHandler.InstallHandler( "client.log" );

            Utils.LogDebug( "Starting " + AppName + ".." );
            if( !File.Exists( "default.zip" ) ) {
                Utils.LogDebug( "default.zip not found. Cannot start." );
                return;
            }
            bool nullContext = true;
            #if !USE_DX
            nullContext = false;
            #endif
            int width, height;
            SelectResolution( out width, out height );

            if( args.Length == 0 || args.Length == 1 ) {
                const string skinServer = "http://s3.amazonaws.com/MinecraftSkins/";
                string pack = args.Length >= 1 ? args[0] : "default.zip";

                using( Game game = new Game( "LocalPlayer", null, skinServer,
                                            pack, nullContext, width, height ) )
                    game.Run();
            } else if( args.Length < 4 ) {
                Utils.LogDebug( "ClassicalSharp.exe is only the raw client. You must either use the launcher or"
                     + " provide command line arguments to start the client." );
            } else {
                RunMultiplayer( args, nullContext, width, height );
            }
        }
Exemplo n.º 4
0
 public Map( Game game )
 {
     this.game = game;
     info = game.BlockInfo;
     SetSunlight( DefaultSunlight );
     SetShadowlight( DefaultShadowlight );
 }
Exemplo n.º 5
0
 public FpsScreen( Game game )
     : base(game)
 {
     font = new Font( "Arial", 13 );
     posFont = new Font( "Arial", 12, FontStyle.Italic );
     text = new StringBuffer( 96 );
 }
        public static void Draw( Game game, byte block, float size, float x, float y )
        {
            info = game.BlockInfo;
            cache = game.ModelCache;
            atlas = game.TerrainAtlas;
            minBB = info.MinBB[block];
            maxBB = info.MaxBB[block];
            fullBright = info.FullBright[block];
            if( info.IsSprite[block] ) {
                minBB = Vector3.Zero; maxBB = Vector3.One;
            }
            if( info.IsAir[block] ) return;
            index = 0;

            // isometric coords size: cosY * -scale - sinY * scale
            // we need to divide by (2 * cosY), as the calling function expects size to be in pixels.
            scale = size / (2 * cosY);
            // screen to isometric coords (cos(-x) = cos(x), sin(-x) = -sin(x))
            pos.X = x; pos.Y = y; pos.Z = 0;
            pos = Utils.RotateY( Utils.RotateX( pos, cosX, -sinX ), cosY, -sinY );

            if( info.IsSprite[block] ) {
                XQuad( block, 0f, TileSide.Right );
                ZQuad( block, 0f, TileSide.Back );
            } else {
                XQuad( block, Make( maxBB.X ), TileSide.Left );
                ZQuad( block, Make( minBB.Z ), TileSide.Back );
                YQuad( block, Make( maxBB.Y ), TileSide.Top );
            }

            for( int i = 0; i < index; i++ )
                TransformVertex( ref cache.vertices[i] );
            game.Graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, cache.vb,
                                               cache.vertices, index, index * 6 / 4 );
        }
Exemplo n.º 7
0
        public override byte[] Load( Stream stream, Game game, out int width, out int height, out int length )
        {
            byte[] map = null;
            width = 0;
            height = 0;
            length = 0;
            LocalPlayer p = game.LocalPlayer;
            p.SpawnPoint = Vector3.Zero;

            using( GZipStream gs = new GZipStream( stream, CompressionMode.Decompress ) ) {
                reader = new BinaryReader( gs );
                ClassDescription obj = ReadData();
                for( int i = 0; i < obj.Fields.Length; i++ ) {
                    FieldDescription field = obj.Fields[i];
                    if( field.FieldName == "width" )
                        width = (int)field.Value;
                    else if( field.FieldName == "height" )
                        length = (int)field.Value;
                    else if( field.FieldName == "depth" )
                        height = (int)field.Value;
                    else if( field.FieldName == "blocks" )
                        map = (byte[])field.Value;
                    else if( field.FieldName == "xSpawn" )
                        p.SpawnPoint.X = (int)field.Value;
                    else if( field.FieldName == "ySpawn" )
                        p.SpawnPoint.Y = (int)field.Value;
                    else if( field.FieldName == "zSpawn" )
                        p.SpawnPoint.Z = (int)field.Value;
                }
            }
            return map;
        }
Exemplo n.º 8
0
        static void Main( string[] args )
        {
            AppDirectory = AppDomain.CurrentDomain.BaseDirectory;
            string logPath = Path.Combine( AppDirectory, "client.log" );
            ErrorHandler.InstallHandler( logPath );
            CleanupMainDirectory();

            Utils.LogDebug( "Starting " + AppName + ".." );
            string path = Path.Combine( Program.AppDirectory, TexturePackExtractor.Dir );
            if( !File.Exists( Path.Combine( path, "default.zip" ) ) ) {
                Utils.LogDebug( "default.zip not found. Cannot start." );
                return;
            }

            bool nullContext = true;
            #if !USE_DX
            nullContext = false;
            #endif
            int width, height;
            SelectResolution( out width, out height );

            if( args.Length == 0 || args.Length == 1 ) {
                const string skinServer = "http://static.classicube.net/skins/";
                string user = args.Length > 0 ? args[0] : "Singleplayer";
                using( Game game = new Game( user, null, skinServer, nullContext, width, height ) )
                    game.Run();
            } else if( args.Length < 4 ) {
                Utils.LogDebug( "ClassicalSharp.exe is only the raw client. You must either use the launcher or"
                     + " provide command line arguments to start the client." );
            } else {
                RunMultiplayer( args, nullContext, width, height );
            }
        }
Exemplo n.º 9
0
 public ChunkMeshBuilder( Game game )
 {
     this.game = game;
     graphics = game.Graphics;
     info = game.BlockInfo;
     game.Events.TerrainAtlasChanged += TerrainAtlasChanged;
 }
Exemplo n.º 10
0
 public BlockHotbarWidget( Game game )
     : base(game)
 {
     HorizontalDocking = Docking.Centre;
     VerticalDocking = Docking.BottomOrRight;
     game.Events.HeldBlockChanged += HeldBlockChanged;
 }
Exemplo n.º 11
0
 public LoadingMapScreen( Game game, string name, string motd )
     : base(game)
 {
     serverName = name;
     serverMotd = motd;
     font = new Font( "Arial", 14 );
 }
Exemplo n.º 12
0
        public static void ClipCameraPos( Game game, Vector3 origin, Vector3 dir, float reach, PickedPos pickedPos )
        {
            if( !game.CameraClipping ) {
                pickedPos.SetAsInvalid();
                pickedPos.IntersectPoint = origin + dir * reach;
                return;
            }
            tracer.SetRayData( origin, dir );
            World map = game.World;
            BlockInfo info = game.BlockInfo;
            float reachSquared = reach * reach;
            int iterations = 0;
            Vector3I pOrigin = Vector3I.Floor( origin );

            while( iterations < 10000 ) {
                int x = tracer.X, y = tracer.Y, z = tracer.Z;
                byte block = GetBlock( map, x, y, z, pOrigin );
                Vector3 min = new Vector3( x, y, z ) + info.MinBB[block];
                Vector3 max = new Vector3( x, y, z ) + info.MaxBB[block];

                float dx = Math.Min( Math.Abs( origin.X - min.X ), Math.Abs( origin.X - max.X ) );
                float dy = Math.Min( Math.Abs( origin.Y - min.Y ), Math.Abs( origin.Y - max.Y ) );
                float dz = Math.Min( Math.Abs( origin.Z - min.Z ), Math.Abs( origin.Z - max.Z ) );

                if( dx * dx + dy * dy + dz * dz > reachSquared ) {
                    pickedPos.SetAsInvalid();
                    pickedPos.IntersectPoint = origin + dir * reach;
                    return;
                }

                if( info.Collide[block] == CollideType.Solid && !info.IsAir[block] ) {
                    float t0, t1;
                    const float adjust = 0.1f;
                    if( Intersection.RayIntersectsBox( origin, dir, min, max, out t0, out t1 ) ) {
                        Vector3 intersect = origin + dir * t0;
                        pickedPos.SetAsValid( x, y, z, min, max, block, intersect );

                        switch( pickedPos.BlockFace) {
                            case CpeBlockFace.XMin:
                                pickedPos.IntersectPoint.X -= adjust; break;
                            case CpeBlockFace.XMax:
                                pickedPos.IntersectPoint.X += adjust; break;
                            case CpeBlockFace.YMin:
                                pickedPos.IntersectPoint.Y -= adjust; break;
                            case CpeBlockFace.YMax:
                                pickedPos.IntersectPoint.Y += adjust; break;
                            case CpeBlockFace.ZMin:
                                pickedPos.IntersectPoint.Z -= adjust; break;
                            case CpeBlockFace.ZMax:
                                pickedPos.IntersectPoint.Z += adjust; break;
                        }
                        return;
                    }
                }
                tracer.Step();
                iterations++;
            }
            throw new InvalidOperationException( "did over 10000 iterations in ClipCameraPos(). " +
                                                "Something has gone wrong. (dir: " + dir + ")" );
        }
Exemplo n.º 13
0
        public static void Draw( Game game, byte block, float size, float x, float y )
        {
            info = game.BlockInfo;
            cache = game.ModelCache;
            atlas = game.TerrainAtlas;
            blockHeight = info.Height[block];
            index = 0;
            scale = size;

            // screen to isometric coords (cos(-x) = cos(x), sin(-x) = -sin(x))
            pos.X = x; pos.Y = y; pos.Z = 0;
            pos = Utils.RotateY( Utils.RotateX( pos, cosX, -sinX ), cosY, -sinY );

            if( info.IsSprite[block] ) {
                DrawXFace( block, 0f, TileSide.Right );
                DrawZFace( block, 0f, TileSide.Back );
            } else {
                DrawXFace( block, scale, TileSide.Left );
                DrawZFace( block, -scale, TileSide.Back );
                DrawYFace( block, scale * blockHeight, TileSide.Top );
            }

            for( int i = 0; i < index; i++ )
                TransformVertex( ref cache.vertices[i] );
            game.Graphics.DrawDynamicIndexedVb( DrawMode.Triangles, cache.vb,
                                               cache.vertices, index, index * 6 / 4 );
        }
Exemplo n.º 14
0
 public BlockHotbarWidget( Game game )
     : base(game)
 {
     HorizontalAnchor = Anchor.Centre;
     VerticalAnchor = Anchor.BottomOrRight;
     hotbarCount = game.Inventory.Hotbar.Length;
 }
Exemplo n.º 15
0
 public virtual byte[] Load( Stream stream, Game game, out int width, out int height, out int length )
 {
     width = 0;
     height = 0;
     length = 0;
     return null;
 }
Exemplo n.º 16
0
        public static void Main( string[] args )
        {
            if( !Debugger.IsAttached ) {
                AppDomain.CurrentDomain.UnhandledException += UnhandledException;
            }

            Utils.Log( "Starting " + Utils.AppName + ".." );
            if( !File.Exists( "default.zip" ) ) {
                Fail( "default.zip not found. Cannot start." );
                return;
            }

            if( args.Length == 0 || args.Length == 1 ) {
                Utils.Log( "Starting singleplayer mode." );
                const string skinServer = "http://s3.amazonaws.com/MinecraftSkins/";
                using( Game game = new Game( "LocalPlayer", null, skinServer, "default.zip" ) ) {
                    game.Run();
                }
            } else if( args.Length < 4 ) {
                Fail( "ClassicalSharp.exe is only the raw client. You must either use the launcher or"
                     + " provide command line arguments to start the client." );
            } else {
                RunMultiplayer( args );
            }
        }
Exemplo n.º 17
0
 public InputHandler( Game game )
 {
     this.game = game;
     RegisterInputHandlers();
     LoadMouseToKeyMappings();
     Keys = new KeyMap();
 }
Exemplo n.º 18
0
        public TextGroupWidget( Game game, int elementsCount, 
		                       Font font, Font underlineFont )
            : base(game)
        {
            ElementsCount = elementsCount;
            this.font = font;
            this.underlineFont = underlineFont;
        }
Exemplo n.º 19
0
 public ErrorScreen( Game game, string title, string message )
     : base(game)
 {
     this.title = title;
     this.message = message;
     titleFont = new Font( "Arial", 16, FontStyle.Bold );
     messageFont = new Font( "Arial", 14, FontStyle.Regular );
 }
Exemplo n.º 20
0
 public WeatherRenderer( Game game )
 {
     this.game = game;
     map = game.Map;
     graphics = game.Graphics;
     info = game.BlockInfo;
     weatherVb = graphics.CreateDynamicVb( VertexFormat.Pos3fTex2fCol4b, 12 * 9 * 9 );
 }
Exemplo n.º 21
0
 public void Init( Game game )
 {
     this.game = game;
     // We can't use enum array initaliser because this causes problems when building with mono
     // and running on default .NET (https://bugzilla.xamarin.com/show_bug.cgi?id=572)
     Hotbar = new Block[9];
     SetDefaultHotbar();
 }
Exemplo n.º 22
0
        bool useLiquidGravity = false; // used by BlockDefinitions.

        #endregion Fields

        #region Constructors

        public LocalPlayer( Game window )
            : base(window)
        {
            DisplayName = window.Username;
            SkinName = window.Username;
            SkinIdentifier = "skin_" + SkinName;
            InitRenderingData();
        }
Exemplo n.º 23
0
 public Player( Game game )
     : base(game)
 {
     this.game = game;
     StepSize = 0.5f;
     SkinType = game.DefaultPlayerSkinType;
     SetModel( "humanoid" );
 }
Exemplo n.º 24
0
 public void BeginBatch( Game game, VertexP3fT2fC4b[] vertices, int vb )
 {
     this.game = game;
     lastIndex = -1;
     index = 0;
     this.vertices = vertices;
     this.vb = vb;
 }
Exemplo n.º 25
0
 protected override void TextButtonClick( Game game, Widget widget )
 {
     string path = ((ButtonWidget)widget).Text;
     if( File.Exists( path ) ) {
         TexturePackExtractor extractor = new TexturePackExtractor();
         extractor.Extract( path, game );
     }
 }
Exemplo n.º 26
0
 public InputHandler( Game game )
 {
     this.game = game;
     RegisterInputHandlers();
     LoadMouseToKeyMappings();
     Keys = new KeyMap();
     Hotkeys = new HotkeyList();
     Hotkeys.LoadSavedHotkeys();
 }
Exemplo n.º 27
0
 public InputHandler( Game game )
 {
     this.game = game;
     RegisterInputHandlers();
     Keys = new KeyMap();
     Hotkeys = new HotkeyList();
     Hotkeys.LoadSavedHotkeys();
     picking = new PickingHandler( game, this );
 }
Exemplo n.º 28
0
 public static ChatTextWidget Create( Game game, int x, int y, string text, Anchor horizontal, Anchor vertical, Font font )
 {
     ChatTextWidget widget = new ChatTextWidget( game, font );
     widget.Init();
     widget.HorizontalAnchor = horizontal; widget.VerticalAnchor = vertical;
     widget.XOffset = x; widget.YOffset = y;
     widget.SetText( text );
     return widget;
 }
Exemplo n.º 29
0
 public MenuInputWidget( Game game, Font font, Font boldFont, Font hintFont )
     : base(game)
 {
     HorizontalAnchor = Anchor.LeftOrTop;
     VerticalAnchor = Anchor.BottomOrRight;
     this.font = font;
     this.boldFont = boldFont;
     this.hintFont = hintFont;
     chatInputText = new StringBuffer( 64 );
 }
Exemplo n.º 30
0
 public TextInputWidget( Game game, Font font, Font boldFont )
     : base(game)
 {
     HorizontalDocking = Docking.LeftOrTop;
     VerticalDocking = Docking.BottomOrRight;
     typingLogPos = game.Chat.InputLog.Count; // Index of newest entry + 1.
     this.font = font;
     this.boldFont = boldFont;
     chatInputText = new StringBuffer( 64 );
 }