public virtual void Init( Game game )
 {
     this.game = game;
     map = game.World;
     graphics = game.Graphics;
     game.WorldEvents.EnvVariableChanged += EnvVariableChanged;
 }
Exemple #2
0
 public Physics( Game game )
 {
     this.game = game;
     map = game.World;
     info = game.BlockInfo;
     game.WorldEvents.OnNewMapLoaded += ResetMap;
     enabled = Options.GetBool( OptionsKey.SingleplayerPhysics, true );
 }
 public void Init( Game game )
 {
     this.game = game;
     map = game.World;
     graphics = game.Graphics;
     info = game.BlockInfo;
     weatherVb = graphics.CreateDynamicVb( VertexFormat.P3fT2fC4b, vertices.Length );
 }
        public void Init( Game game )
        {
            this.game = game;
            map = game.World;
            graphics = game.Graphics;

            game.WorldEvents.EnvVariableChanged += EnvVariableChanged;
            game.Events.ViewDistanceChanged += ResetSidesAndEdges;
            game.Events.TerrainAtlasChanged += ResetTextures;
        }
        public void Init( Game game )
        {
            this.game = game;
            map = game.World;
            graphics = game.Graphics;

            game.WorldEvents.EnvVariableChanged += EnvVariableChanged;
            game.Events.ViewDistanceChanged += ResetSidesAndEdges;
            game.Events.TerrainAtlasChanged += ResetTextures;

            MakeTexture( ref edgeTexId, ref lastEdgeTexLoc, map.EdgeBlock );
            MakeTexture( ref sideTexId, ref lastSideTexLoc, map.SidesBlock );
            ResetSidesAndEdges( null, null );
        }
        public byte[] Load( Stream stream, Game game, out int width, out int height, out int length )
        {
            GZipHeaderReader gsHeader = new GZipHeaderReader();
            while( !gsHeader.ReadHeader( stream ) ) { }

            using( DeflateStream gs = new DeflateStream( stream, CompressionMode.Decompress ) ) {
                reader = new BinaryReader( gs );
                if( reader.ReadByte() != (byte)NbtTagType.Compound )
                    throw new InvalidDataException( "Nbt file must start with Tag_Compound" );
                this.game = game;
                map = game.World;
                file = new NbtFile( reader );

                NbtTag root = file.ReadTag( (byte)NbtTagType.Compound, true );
                NbtCompound children = (NbtCompound)root.Value;
                if( children.ContainsKey( "Metadata" ) )
                    ParseMetadata( children );

                NbtCompound spawn = (NbtCompound)children["Spawn"].Value;
                LocalPlayer p = game.LocalPlayer;
                p.Spawn.X = (short)spawn["X"].Value;
                p.Spawn.Y = (short)spawn["Y"].Value;
                p.Spawn.Z = (short)spawn["Z"].Value;
                if( spawn.ContainsKey( "H" ) )
                    p.SpawnYaw = (float)Utils.PackedToDegrees( (byte)spawn["H"].Value );
                if( spawn.ContainsKey( "P" ) )
                    p.SpawnPitch = (float)Utils.PackedToDegrees( (byte)spawn["P"].Value );

                map.Uuid = new Guid( (byte[])children["UUID"].Value );
                width = (short)children["X"].Value;
                height = (short)children["Y"].Value;
                length = (short)children["Z"].Value;

                // Older versions incorrectly multiplied spawn coords by * 32, so we check for that.
                if( p.Spawn.X < 0 || p.Spawn.X >= width || p.Spawn.Y < 0 ||
                   p.Spawn.Y >= height || p.Spawn.Z < 0 || p.Spawn.Z >= length ) {
                    p.Spawn.X /= 32; p.Spawn.Y /= 32; p.Spawn.Z /= 32;
                }
                return (byte[])children["BlockArray"].Value;
            }
        }
        public void Save( Stream stream, Game game )
        {
            using( GZipStream wrapper = new GZipStream( stream, CompressionMode.Compress ) ) {
                writer = new BinaryWriter( wrapper );
                nbt = new NbtFile( writer );
                this.game = game;
                map = game.World;

                nbt.Write( NbtTagType.Compound ); nbt.Write( "ClassicWorld" );

                nbt.Write( NbtTagType.Int8 );
                nbt.Write( "FormatVersion" ); nbt.WriteInt8( 1 );

                nbt.Write( NbtTagType.Int8Array );
                nbt.Write( "UUID" ); nbt.WriteInt32( 16 );
                nbt.WriteBytes( map.Uuid.ToByteArray() );

                nbt.Write( NbtTagType.Int16 );
                nbt.Write( "X" ); nbt.WriteInt16( (short)map.Width );

                nbt.Write( NbtTagType.Int16 );
                nbt.Write( "Y" ); nbt.WriteInt16( (short)map.Height );

                nbt.Write( NbtTagType.Int16 );
                nbt.Write( "Z" ); nbt.WriteInt16( (short)map.Length );

                WriteSpawnCompoundTag();

                nbt.Write( NbtTagType.Int8Array );
                nbt.Write( "BlockArray" ); nbt.WriteInt32( map.blocks.Length );
                nbt.WriteBytes( map.blocks );

                WriteMetadata();

                nbt.Write( NbtTagType.End );
            }
        }
Exemple #8
0
        static byte GetBlock( World map, int x, int y, int z, Vector3I origin )
        {
            bool sides = map.Env.SidesBlock != Block.Air;
            int height = Math.Max( 1, map.Env.SidesHeight );
            bool insideMap = map.IsValidPos( origin );

            // handling of blocks inside the map, above, and on borders
            if( x >= 0 && z >= 0 && x < map.Width && z < map.Length ) {
                if( y >= map.Height ) return 0;
                if( sides && y == -1 && insideMap ) return border;
                if( sides && y == 0 && origin.Y < 0 ) return border;

                if( sides && x == 0 && y >= 0 && y < height && origin.X < 0 ) return border;
                if( sides && z == 0 && y >= 0 && y < height && origin.Z < 0 ) return border;
                if( sides && x == (map.Width - 1) && y >= 0 && y < height && origin.X >= map.Width )
                    return border;
                if( sides && z == (map.Length - 1) && y >= 0 && y < height && origin.Z >= map.Length )
                    return border;
                if( y >= 0 ) return map.GetBlock( x, y, z );
            }

            // pick blocks on the map boundaries (when inside the map)
            if( !sides || !insideMap ) return 0;
            if( y == 0 && origin.Y < 0 ) return border;
            bool validX = (x == -1 || x == map.Width) && (z >= 0 && z < map.Length);
            bool validZ = (z == -1 || z == map.Length) && (x >= 0 && x < map.Width);
            if( y >= 0 && y < height && (validX || validZ) ) return border;
            return 0;
        }
 public void OnNewMapLoaded()
 {
     map = game.World;
     env = game.World.Env;
     width = map.Width;
     height = map.Height;
     length = map.Length;
     clipLevel = Math.Max( 0, game.World.Env.SidesHeight );
     maxX = width - 1;
     maxY = height - 1;
     maxZ = length - 1;
 }