Esempio n. 1
0
        void HandleDefineBlockCommonEnd(NetReader reader, byte shape, byte id)
        {
            BlockInfo info      = game.BlockInfo;
            byte      blockDraw = reader.ReadUInt8();

            if (shape == 0)
            {
                blockDraw = DrawType.Sprite;
            }
            info.LightOffset[id] = info.CalcLightOffset(id);

            byte fogDensity = reader.ReadUInt8();

            info.FogDensity[id] = fogDensity == 0 ? 0 : (fogDensity + 1) / 128f;
            info.FogColour[id]  = new FastColour(
                reader.ReadUInt8(), reader.ReadUInt8(), reader.ReadUInt8());
            info.Tinted[id] = info.FogColour[id] != FastColour.Black && info.Name[id].IndexOf('#') >= 0;

            info.SetBlockDraw(id, blockDraw);
            info.CalcRenderBounds(id);
            info.UpdateCulling(id);

            game.Events.RaiseBlockDefinitionChanged();
            info.DefinedCustomBlocks[id >> 5] |= (1u << (id & 0x1F));
        }
Esempio n. 2
0
        void HandleDefineBlockCommonEnd(NetReader reader, byte shape, BlockID block)
        {
            byte blockDraw = reader.ReadUInt8();

            if (shape == 0)
            {
                BlockInfo.SpriteOffset[block] = blockDraw;
                blockDraw = DrawType.Sprite;
            }
            BlockInfo.LightOffset[block] = BlockInfo.CalcLightOffset(block);

            byte fogDensity = reader.ReadUInt8();

            BlockInfo.FogDensity[block] = fogDensity == 0 ? 0 : (fogDensity + 1) / 128f;
            BlockInfo.FogColour[block]  = new FastColour(
                reader.ReadUInt8(), reader.ReadUInt8(), reader.ReadUInt8());
            BlockInfo.Tinted[block] = BlockInfo.FogColour[block] != FastColour.Black && BlockInfo.Name[block].IndexOf('#') >= 0;

            BlockInfo.SetBlockDraw(block, blockDraw);
            BlockInfo.CalcRenderBounds(block);
            BlockInfo.UpdateCulling(block);

            game.Inventory.AddDefault(block);
            BlockInfo.SetCustomDefined(block, true);
            game.Events.RaiseBlockDefinitionChanged();
        }
Esempio n. 3
0
        void ParseBlockDefinition(NbtCompound compound)
        {
            byte id = (byte)compound["ID"].Value;

            BlockInfo.Name[id] = (string)compound["Name"].Value;
            BlockInfo.SetCollide(id, (byte)compound["CollideType"].Value);
            BlockInfo.SpeedMultiplier[id] = (float)compound["Speed"].Value;

            byte[] data = (byte[])compound["Textures"].Value;
            BlockInfo.SetTex(data[0], Side.Top, id);
            BlockInfo.SetTex(data[1], Side.Bottom, id);
            BlockInfo.SetTex(data[2], Side.Left, id);
            BlockInfo.SetTex(data[3], Side.Right, id);
            BlockInfo.SetTex(data[4], Side.Front, id);
            BlockInfo.SetTex(data[5], Side.Back, id);

            BlockInfo.BlocksLight[id] = (byte)compound["TransmitsLight"].Value == 0;
            byte soundId = (byte)compound["WalkSound"].Value;

            BlockInfo.DigSounds[id]  = CPEProtocolBlockDefs.breakSnds[soundId];
            BlockInfo.StepSounds[id] = CPEProtocolBlockDefs.stepSnds[soundId];
            BlockInfo.FullBright[id] = (byte)compound["FullBright"].Value != 0;

            byte blockDraw = (byte)compound["BlockDraw"].Value;

            if ((byte)compound["Shape"].Value == 0)
            {
                BlockInfo.SpriteOffset[id] = blockDraw;
                blockDraw = DrawType.Sprite;
            }

            data = (byte[])compound["Fog"].Value;
            BlockInfo.FogDensity[id] = (data[0] + 1) / 128f;
            // Fix for older ClassicalSharp versions which saved wrong fog density value
            if (data[0] == 0xFF)
            {
                BlockInfo.FogDensity[id] = 0;
            }
            BlockInfo.FogColour[id] = new FastColour(data[1], data[2], data[3]);
            BlockInfo.Tinted[id]    = BlockInfo.FogColour[id] != FastColour.Black && BlockInfo.Name[id].IndexOf('#') >= 0;          // TODO: nasty copy paste

            data = (byte[])compound["Coords"].Value;
            BlockInfo.MinBB[id] = new Vector3(data[0] / 16f, data[1] / 16f, data[2] / 16f);
            BlockInfo.MaxBB[id] = new Vector3(data[3] / 16f, data[4] / 16f, data[5] / 16f);

            BlockInfo.SetBlockDraw(id, blockDraw);
            BlockInfo.CalcRenderBounds(id);
            BlockInfo.UpdateCulling(id);

            BlockInfo.LightOffset[id] = BlockInfo.CalcLightOffset(id);
            game.Events.RaiseBlockDefinitionChanged();
            game.Inventory.AddDefault(id);
            BlockInfo.SetCustomDefined(id, true);

            BlockInfo.CanPlace[id]  = true;
            BlockInfo.CanDelete[id] = true;
            game.Events.RaiseBlockPermissionsChanged();
        }
Esempio n. 4
0
        void ParseBlockDefinition(NbtCompound compound)
        {
            byte      id   = (byte)compound["ID"].Value;
            BlockInfo info = game.BlockInfo;

            info.Name[id]            = (string)compound["Name"].Value;
            info.Collide[id]         = (CollideType)compound["CollideType"].Value;
            info.SpeedMultiplier[id] = (float)compound["Speed"].Value;

            byte[] data = (byte[])compound["Textures"].Value;
            info.SetTex(data[0], Side.Top, id);
            info.SetTex(data[1], Side.Bottom, id);
            info.SetTex(data[2], Side.Left, id);
            info.SetTex(data[3], Side.Right, id);
            info.SetTex(data[4], Side.Front, id);
            info.SetTex(data[5], Side.Back, id);

            info.BlocksLight[id] = (byte)compound["TransmitsLight"].Value == 0;
            byte soundId = (byte)compound["WalkSound"].Value;

            info.DigSounds[id]  = CPEProtocolBlockDefs.breakSnds[soundId];
            info.StepSounds[id] = CPEProtocolBlockDefs.stepSnds[soundId];
            info.FullBright[id] = (byte)compound["FullBright"].Value != 0;
            info.IsSprite[id]   = (byte)compound["Shape"].Value == 0;
            byte blockDraw = (byte)compound["BlockDraw"].Value;

            info.SetBlockDraw(id, (BlockDraw)blockDraw);

            data = (byte[])compound["Fog"].Value;
            info.FogDensity[id] = (data[0] + 1) / 128f;
            // Fix for older ClassicalSharp versions which saved wrong fog density value
            if (data[0] == 0xFF)
            {
                info.FogDensity[id] = 0;
            }
            info.FogColour[id] = new FastColour(data[1], data[2], data[3]);

            data           = (byte[])compound["Coords"].Value;
            info.MinBB[id] = new Vector3(data[0] / 16f, data[1] / 16f, data[2] / 16f);
            info.MaxBB[id] = new Vector3(data[3] / 16f, data[4] / 16f, data[5] / 16f);

            if (info.Collide[id] != CollideType.Solid)
            {
                info.IsTransparent[id] = true;
                info.IsOpaque[id]      = false;
            }

            info.UpdateCulling(id);
            info.LightOffset[id] = info.CalcLightOffset(id);
            game.Events.RaiseBlockDefinitionChanged();
            info.DefinedCustomBlocks[id >> 5] |= (1u << (id & 0x1F));

            game.Inventory.CanPlace.SetNotOverridable(true, id);
            game.Inventory.CanDelete.SetNotOverridable(true, id);
            game.Events.RaiseBlockPermissionsChanged();
        }
Esempio n. 5
0
        void HandleDefineBlockCommonEnd(NetReader reader, byte shape, byte id)
        {
            BlockInfo info      = game.BlockInfo;
            byte      blockDraw = reader.ReadUInt8();

            if (shape == 0)
            {
                blockDraw = (byte)BlockDraw.Sprite;
            }
            info.SetBlockDraw(id, (BlockDraw)blockDraw);
            info.LightOffset[id] = info.CalcLightOffset(id);

            byte fogDensity = reader.ReadUInt8();

            info.FogDensity[id] = fogDensity == 0 ? 0 : (fogDensity + 1) / 128f;
            info.FogColour[id]  = new FastColour(
                reader.ReadUInt8(), reader.ReadUInt8(), reader.ReadUInt8());

            info.UpdateCulling(id);
            game.Events.RaiseBlockDefinitionChanged();
            info.DefinedCustomBlocks[id >> 5] |= (1u << (id & 0x1F));
        }