Example #1
0
        /// <summary>
        /// Sets a new Tile Entity record for the block.
        /// </summary>
        /// <param name="te">A Tile Entity record compatible with the block's type.</param>
        /// <exception cref="ArgumentException">Thrown when an incompatible <see cref="TileEntity"/> is added to a block.</exception>
        /// <exception cref="InvalidOperationException">Thrown when a <see cref="TileEntity"/> is added to a block that does not use tile entities.</exception>
        public void SetTileEntity(TileEntity te)
        {
            BlockInfoEx info = BlockInfo.BlockTable[_id] as BlockInfoEx;

            if (info == null)
            {
                throw new InvalidOperationException("The current block type does not accept a Tile Entity");
            }

            if (te.GetType() != TileEntityFactory.Lookup(info.TileEntityName))
            {
                throw new ArgumentException("The current block type is not compatible with the given Tile Entity", "te");
            }

            _tileEntity = te;
        }
Example #2
0
        private void UpdateTileEntity(int old, int value)
        {
            BlockInfoEx info1 = BlockInfo.BlockTable[old] as BlockInfoEx;
            BlockInfoEx info2 = BlockInfo.BlockTable[value] as BlockInfoEx;

            if (info1 != info2)
            {
                if (info1 != null)
                {
                    _tileEntity = null;
                }

                if (info2 != null)
                {
                    _tileEntity = TileEntityFactory.Create(info2.TileEntityName);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Creates a default Tile Entity record appropriate for the block.
        /// </summary>
        public void CreateTileEntity()
        {
            BlockInfoEx info = BlockInfo.BlockTable[_id] as BlockInfoEx;

            if (info == null)
            {
                throw new InvalidOperationException("The given block is of a type that does not support TileEntities.");
            }

            TileEntity te = TileEntityFactory.Create(info.TileEntityName);

            if (te == null)
            {
                throw new UnknownTileEntityException("The TileEntity type '" + info.TileEntityName + "' has not been registered with the TileEntityFactory.");
            }

            _tileEntity = te;
        }
Example #4
0
        static BlockInfo()
        {
            _blockTable     = new BlockInfo[MAX_BLOCKS];
            _opacityTable   = new int[MAX_BLOCKS];
            _luminanceTable = new int[MAX_BLOCKS];

            _blockTableCache     = new CacheTableArray <BlockInfo>(_blockTable);
            _opacityTableCache   = new CacheTableArray <int>(_opacityTable);
            _luminanceTableCache = new CacheTableArray <int>(_luminanceTable);

            Air                = new BlockInfo(0, "Air").SetOpacity(0).SetState(BlockState.NONSOLID);
            Stone              = new BlockInfo(1, "Stone");
            Grass              = new BlockInfo(2, "Grass");
            Dirt               = new BlockInfo(3, "Dirt");
            Cobblestone        = new BlockInfo(4, "Cobblestone");
            WoodPlank          = new BlockInfo(5, "Wooden Plank");
            Sapling            = new BlockInfo(6, "Sapling").SetOpacity(0).SetState(BlockState.NONSOLID);
            Bedrock            = new BlockInfo(7, "Bedrock");
            Water              = new BlockInfo(8, "Water").SetOpacity(3).SetState(BlockState.FLUID);
            StationaryWater    = new BlockInfo(9, "Stationary Water").SetOpacity(3).SetState(BlockState.FLUID);
            Lava               = new BlockInfo(10, "Lava").SetOpacity(0).SetLuminance(MAX_LUMINANCE).SetState(BlockState.FLUID);
            StationaryLava     = new BlockInfo(11, "Stationary Lava").SetOpacity(0).SetLuminance(MAX_LUMINANCE).SetState(BlockState.FLUID);
            Sand               = new BlockInfo(12, "Sand");
            Gravel             = new BlockInfo(13, "Gravel");
            GoldOre            = new BlockInfo(14, "Gold Ore");
            IronOre            = new BlockInfo(15, "Iron Ore");
            CoalOre            = new BlockInfo(16, "Coal Ore");
            Wood               = new BlockInfo(17, "Wood");
            Leaves             = new BlockInfo(18, "Leaves").SetOpacity(1);
            Sponge             = new BlockInfo(19, "Sponge");
            Glass              = new BlockInfo(20, "Glass").SetOpacity(0);
            LapisOre           = new BlockInfo(21, "Lapis Lazuli Ore");
            LapisBlock         = new BlockInfo(22, "Lapis Lazuli Block");
            Dispenser          = new BlockInfoEx(23, "Dispenser");
            Sandstone          = new BlockInfo(24, "Sandstone");
            NoteBlock          = new BlockInfoEx(25, "Note Block");
            Bed                = new BlockInfo(26, "Bed").SetOpacity(0);
            PoweredRail        = new BlockInfo(27, "Powered Rail").SetOpacity(0).SetState(BlockState.NONSOLID);
            DetectorRail       = new BlockInfo(28, "Detector Rail").SetOpacity(0).SetState(BlockState.NONSOLID);
            StickyPiston       = new BlockInfo(29, "Sticky Piston").SetOpacity(0);
            Cobweb             = new BlockInfo(30, "Cobweb").SetOpacity(0).SetState(BlockState.NONSOLID);
            TallGrass          = new BlockInfo(31, "Tall Grass").SetOpacity(0).SetState(BlockState.NONSOLID);
            DeadShrub          = new BlockInfo(32, "Dead Shrub").SetOpacity(0).SetState(BlockState.NONSOLID);
            Piston             = new BlockInfo(33, "Piston").SetOpacity(0);
            PistonHead         = new BlockInfo(34, "Piston Head").SetOpacity(0);
            Wool               = new BlockInfo(35, "Wool");
            PistonMoving       = (BlockInfoEx) new BlockInfoEx(36, "Piston Moving").SetOpacity(0);
            YellowFlower       = new BlockInfo(37, "Yellow Flower").SetOpacity(0).SetState(BlockState.NONSOLID);
            RedRose            = new BlockInfo(38, "Red Rose").SetOpacity(0).SetState(BlockState.NONSOLID);
            BrownMushroom      = new BlockInfo(39, "Brown Mushroom").SetOpacity(0).SetLuminance(1).SetState(BlockState.NONSOLID);
            RedMushroom        = new BlockInfo(40, "Red Mushroom").SetOpacity(0).SetState(BlockState.NONSOLID);
            GoldBlock          = new BlockInfo(41, "Gold Block");
            IronBlock          = new BlockInfo(42, "Iron Block");
            DoubleSlab         = new BlockInfo(43, "Double Slab");
            Slab               = new BlockInfo(44, "Slab").SetOpacity(0);
            BrickBlock         = new BlockInfo(45, "Brick Block");
            TNT                = new BlockInfo(46, "TNT");
            Bookshelf          = new BlockInfo(47, "Bookshelf");
            MossStone          = new BlockInfo(48, "Moss Stone");
            Obsidian           = new BlockInfo(49, "Obsidian");
            Torch              = new BlockInfo(50, "Torch").SetOpacity(0).SetLuminance(MAX_LUMINANCE - 1).SetState(BlockState.NONSOLID);
            Fire               = new BlockInfo(51, "Fire").SetOpacity(0).SetLuminance(MAX_LUMINANCE).SetState(BlockState.NONSOLID);
            MonsterSpawner     = (BlockInfoEx) new BlockInfoEx(52, "Monster Spawner").SetOpacity(0);
            WoodStairs         = new BlockInfo(53, "Wooden Stairs").SetOpacity(0);
            Chest              = (BlockInfoEx) new BlockInfoEx(54, "Chest").SetOpacity(0);
            RedstoneWire       = new BlockInfo(55, "Redstone Wire").SetOpacity(0).SetState(BlockState.NONSOLID);
            DiamondOre         = new BlockInfo(56, "Diamond Ore");
            DiamondBlock       = new BlockInfo(57, "Diamond Block");
            CraftTable         = new BlockInfo(58, "Crafting Table");
            Crops              = new BlockInfo(59, "Crops").SetOpacity(0).SetState(BlockState.NONSOLID);
            Farmland           = new BlockInfo(60, "Farmland").SetOpacity(0);
            Furnace            = new BlockInfoEx(61, "Furnace");
            BurningFurnace     = (BlockInfoEx) new BlockInfoEx(62, "Burning Furnace").SetLuminance(MAX_LUMINANCE - 1);
            SignPost           = (BlockInfoEx) new BlockInfoEx(63, "Sign Post").SetOpacity(0).SetState(BlockState.NONSOLID);
            WoodDoor           = new BlockInfo(64, "Wooden Door").SetOpacity(0);
            Ladder             = new BlockInfo(65, "Ladder").SetOpacity(0);
            Rails              = new BlockInfo(66, "Rails").SetOpacity(0).SetState(BlockState.NONSOLID);
            CobbleStairs       = new BlockInfo(67, "Cobblestone Stairs").SetOpacity(0);
            WallSign           = (BlockInfoEx) new BlockInfoEx(68, "Wall Sign").SetOpacity(0).SetState(BlockState.NONSOLID);
            Lever              = new BlockInfo(69, "Lever").SetOpacity(0).SetState(BlockState.NONSOLID);
            StonePlate         = new BlockInfo(70, "Stone Pressure Plate").SetOpacity(0).SetState(BlockState.NONSOLID);
            IronDoor           = new BlockInfo(71, "Iron Door").SetOpacity(0);
            WoodPlate          = new BlockInfo(72, "Wooden Pressure Plate").SetOpacity(0).SetState(BlockState.NONSOLID);
            RedstoneOre        = new BlockInfo(73, "Redstone Ore");
            GlowRedstoneOre    = new BlockInfo(74, "Glowing Redstone Ore").SetLuminance(9);
            RedstoneTorch      = new BlockInfo(75, "Redstone Torch (Off)").SetOpacity(0).SetState(BlockState.NONSOLID);
            RedstoneTorchOn    = new BlockInfo(76, "Redstone Torch (On)").SetOpacity(0).SetLuminance(7).SetState(BlockState.NONSOLID);
            StoneButton        = new BlockInfo(77, "Stone Button").SetOpacity(0).SetState(BlockState.NONSOLID);
            Snow               = new BlockInfo(78, "Snow").SetOpacity(0).SetState(BlockState.NONSOLID);
            Ice                = new BlockInfo(79, "Ice").SetOpacity(3);
            SnowBlock          = new BlockInfo(80, "Snow Block");
            Cactus             = new BlockInfo(81, "Cactus").SetOpacity(0);
            ClayBlock          = new BlockInfo(82, "Clay Block");
            SugarCane          = new BlockInfo(83, "Sugar Cane").SetOpacity(0).SetState(BlockState.NONSOLID);
            Jukebox            = new BlockInfo(84, "Jukebox");
            Fence              = new BlockInfo(85, "Fence").SetOpacity(0);
            Pumpkin            = new BlockInfo(86, "Pumpkin");
            Netherrack         = new BlockInfo(87, "Netherrack");
            SoulSand           = new BlockInfo(88, "Soul Sand");
            Glowstone          = new BlockInfo(89, "Glowstone Block").SetLuminance(MAX_LUMINANCE);
            Portal             = new BlockInfo(90, "Portal").SetOpacity(0).SetLuminance(11).SetState(BlockState.NONSOLID);
            JackOLantern       = new BlockInfo(91, "Jack-O-Lantern").SetLuminance(MAX_LUMINANCE);
            CakeBlock          = new BlockInfo(92, "Cake Block").SetOpacity(0);
            RedstoneRepeater   = new BlockInfo(93, "Redstone Repeater (Off)").SetOpacity(0);
            RedstoneRepeaterOn = new BlockInfo(94, "Redstone Repeater (On)").SetOpacity(0).SetLuminance(7);
            LockedChest        = (BlockInfoEx) new BlockInfoEx(95, "Locked Chest").SetLuminance(MAX_LUMINANCE);
            Trapdoor           = new BlockInfo(96, "Trapdoor").SetOpacity(0);
            SilverfishStone    = new BlockInfo(97, "Stone with Silverfish");
            StoneBrick         = new BlockInfo(98, "Stone Brick");
            HugeRedMushroom    = new BlockInfo(99, "Huge Red Mushroom");
            HugeBrownMushroom  = new BlockInfo(100, "Huge Brown Mushroom");
            IronBars           = new BlockInfo(101, "Iron Bars").SetOpacity(0);
            GlassPane          = new BlockInfo(102, "Glass Pane").SetOpacity(0);
            Melon              = new BlockInfo(103, "Melon");
            PumpkinStem        = new BlockInfo(104, "Pumpkin Stem").SetOpacity(0).SetState(BlockState.NONSOLID);
            MelonStem          = new BlockInfo(105, "Melon Stem").SetOpacity(0).SetState(BlockState.NONSOLID);
            Vines              = new BlockInfo(106, "Vines").SetOpacity(0).SetState(BlockState.NONSOLID);
            FenceGate          = new BlockInfo(107, "Fence Gate").SetOpacity(0);
            BrickStairs        = new BlockInfo(108, "Brick Stairs").SetOpacity(0);
            StoneBrickStairs   = new BlockInfo(109, "Stone Brick Stairs").SetOpacity(0);
            Mycelium           = new BlockInfo(110, "Mycelium");
            LillyPad           = new BlockInfo(111, "Lilly Pad").SetOpacity(0).SetState(BlockState.NONSOLID);
            NetherBrick        = new BlockInfo(112, "Nether Brick");
            NetherBrickFence   = new BlockInfo(113, "Nether Brick Fence").SetOpacity(0);
            NetherBrickStairs  = new BlockInfo(114, "Nether Brick Stairs").SetOpacity(0);
            NetherWart         = new BlockInfo(115, "Nether Wart").SetOpacity(0).SetState(BlockState.NONSOLID);
            EnchantmentTable   = (BlockInfoEx) new BlockInfoEx(116, "Enchantment Table").SetOpacity(0);
            BrewingStand       = (BlockInfoEx) new BlockInfoEx(117, "Brewing Stand").SetOpacity(0);
            Cauldron           = new BlockInfo(118, "Cauldron").SetOpacity(0);
            EndPortal          = (BlockInfoEx) new BlockInfoEx(119, "End Portal").SetOpacity(0).SetLuminance(MAX_LUMINANCE).SetState(BlockState.NONSOLID);
            EndPortalFrame     = new BlockInfo(120, "End Portal Frame").SetLuminance(MAX_LUMINANCE);
            EndStone           = new BlockInfo(121, "End Stone");
            DragonEgg          = new BlockInfo(122, "Dragon Egg").SetOpacity(0).SetLuminance(1);

            for (int i = 0; i < MAX_BLOCKS; i++)
            {
                if (_blockTable[i] == null)
                {
                    _blockTable[i] = new BlockInfo(i);
                }
            }

            // Override default light transmission rules

            Lava.SetLightTransmission(false);
            StationaryLava.SetLightTransmission(false);
            Slab.SetLightTransmission(false);
            WoodStairs.SetLightTransmission(false);
            Farmland.SetLightTransmission(false);
            CobbleStairs.SetLightTransmission(false);
            BrickStairs.SetLightTransmission(false);
            StoneBrickStairs.SetLightTransmission(false);
            NetherBrickStairs.SetLightTransmission(false);

            // Override default fluid blocking rules

            SignPost.SetBlocksFluid(true);
            WallSign.SetBlocksFluid(true);
            Cactus.SetBlocksFluid(false);

            // Set Tile Entity Data

            Dispenser.SetTileEntity("Trap");
            NoteBlock.SetTileEntity("Music");
            PistonMoving.SetTileEntity("Piston");
            MonsterSpawner.SetTileEntity("MobSpawner");
            Chest.SetTileEntity("Chest");
            Furnace.SetTileEntity("Furnace");
            BurningFurnace.SetTileEntity("Furnace");
            SignPost.SetTileEntity("Sign");
            WallSign.SetTileEntity("Sign");
            EnchantmentTable.SetTileEntity("EnchantTable");
            BrewingStand.SetTileEntity("Cauldron");
            EndPortal.SetTileEntity("Airportal");

            // Set Data Limits

            Wood.SetDataLimits(0, 2, 0);
            Leaves.SetDataLimits(0, 2, 0);
            Jukebox.SetDataLimits(0, 2, 0);
            Sapling.SetDataLimits(0, 15, 0);
            Cactus.SetDataLimits(0, 15, 0);
            SugarCane.SetDataLimits(0, 15, 0);
            Water.SetDataLimits(0, 7, 0x8);
            Lava.SetDataLimits(0, 7, 0x8);
            TallGrass.SetDataLimits(0, 2, 0);
            Crops.SetDataLimits(0, 7, 0);
            PoweredRail.SetDataLimits(0, 5, 0x8);
            DetectorRail.SetDataLimits(0, 5, 0x8);
            StickyPiston.SetDataLimits(1, 5, 0x8);
            Piston.SetDataLimits(1, 5, 0x8);
            PistonHead.SetDataLimits(1, 5, 0x8);
            Wool.SetDataLimits(0, 15, 0);
            Torch.SetDataLimits(1, 5, 0);
            RedstoneTorch.SetDataLimits(0, 5, 0);
            RedstoneTorchOn.SetDataLimits(0, 5, 0);
            Rails.SetDataLimits(0, 9, 0);
            Ladder.SetDataLimits(2, 5, 0);
            WoodStairs.SetDataLimits(0, 3, 0);
            CobbleStairs.SetDataLimits(0, 3, 0);
            Lever.SetDataLimits(0, 6, 0x8);
            WoodDoor.SetDataLimits(0, 3, 0xC);
            IronDoor.SetDataLimits(0, 3, 0xC);
            StoneButton.SetDataLimits(1, 4, 0x8);
            Snow.SetDataLimits(0, 7, 0);
            SignPost.SetDataLimits(0, 15, 0);
            WallSign.SetDataLimits(2, 5, 0);
            Furnace.SetDataLimits(2, 5, 0);
            BurningFurnace.SetDataLimits(2, 5, 0);
            Dispenser.SetDataLimits(2, 5, 0);
            Pumpkin.SetDataLimits(0, 3, 0);
            JackOLantern.SetDataLimits(0, 3, 0);
            StonePlate.SetDataLimits(0, 0, 0x1);
            WoodPlate.SetDataLimits(0, 0, 0x1);
            Slab.SetDataLimits(0, 6, 0);
            DoubleSlab.SetDataLimits(0, 3, 0);
            Cactus.SetDataLimits(0, 5, 0);
            Bed.SetDataLimits(0, 3, 0x8);
            RedstoneRepeater.SetDataLimits(0, 0, 0xF);
            RedstoneRepeaterOn.SetDataLimits(0, 0, 0xF);
            Trapdoor.SetDataLimits(0, 3, 0x4);
            StoneBrick.SetDataLimits(0, 2, 0);
            HugeRedMushroom.SetDataLimits(0, 10, 0);
            HugeBrownMushroom.SetDataLimits(0, 10, 0);
            Vines.SetDataLimits(0, 0, 0xF);
            FenceGate.SetDataLimits(0, 3, 0x4);
            SilverfishStone.SetDataLimits(0, 2, 0);
            BrewingStand.SetDataLimits(0, 0, 0x7);
            Cauldron.SetDataLimits(0, 3, 0);
            EndPortalFrame.SetDataLimits(0, 0, 0x7);
        }
        /// <inheritdoc/>
        /// <remarks>Depending on the options set for this <see cref="AlphaBlockCollection"/>, this method can be very
        /// heavy-handed in the amount of work it does to maintain consistency of tile entities, lighting, fluid, etc.
        /// for the affected block and possibly many other indirectly-affected blocks in the collection or neighboring
        /// collections.  If many SetID calls are expected to be made, some of this auto-reconciliation behavior should
        /// be disabled, and the data should be rebuilt at the <see cref="AlphaBlockCollection"/>-level at the end.</remarks>
        public void SetID(int x, int y, int z, int id)
        {
            int oldid = _blocks[x, y, z];

            if (oldid == id)
            {
                return;
            }

            // Update value

            _blocks[x, y, z] = (byte)id;

            // Update tile entities

            BlockInfo info1 = BlockInfo.BlockTable[oldid];
            BlockInfo info2 = BlockInfo.BlockTable[id];

            BlockInfoEx einfo1 = info1 as BlockInfoEx;
            BlockInfoEx einfo2 = info2 as BlockInfoEx;

            if (einfo1 != einfo2)
            {
                if (einfo1 != null || !info1.Registered)
                {
                    ClearTileEntity(x, y, z);
                }

                if (einfo2 != null)
                {
                    CreateTileEntity(x, y, z);
                }
            }

            // Light consistency

            if (_autoLight)
            {
                if (info1.ObscuresLight != info2.ObscuresLight)
                {
                    _lightManager.UpdateHeightMap(x, y, z);
                }

                if (info1.Luminance != info2.Luminance || info1.Opacity != info2.Opacity || info1.TransmitsLight != info2.TransmitsLight)
                {
                    UpdateBlockLight(x, y, z);
                }

                if (info1.Opacity != info2.Opacity || info1.TransmitsLight != info2.TransmitsLight)
                {
                    UpdateSkyLight(x, y, z);
                }
            }

            // Fluid consistency

            if (_autoFluid)
            {
                if (info1.State == BlockState.FLUID || info2.State == BlockState.FLUID)
                {
                    UpdateFluid(x, y, z);
                }
            }

            _dirty = true;
        }