コード例 #1
0
ファイル: JsApi.cs プロジェクト: pabranch/CommandBlocksJS
 public void placeCommandBlock(string command, int x, int y, int z)
 {
     AlphaBlock cblock = new AlphaBlock(BlockType.COMMAND_BLOCK);
     TileEntityControl te = cblock.GetTileEntity() as TileEntityControl; //unsafe
     te.Command = command;
     blockManager.SetBlock(x, y, z, cblock);
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: tofurama3000/Substrate
        // This function will create a new Block object of type 'Chest', fills it
        // with random items, and returns it
        static AlphaBlock BuildChest ()
        {
            // A default, appropriate TileEntity entry is created
            AlphaBlock block = new AlphaBlock(BlockType.CHEST);
            TileEntityChest ent = block.GetTileEntity() as TileEntityChest;

            // Unless Substrate has a bug, the TileEntity was definitely a TileEntityChest
            if (ent == null) {
                Console.WriteLine("Catastrophic");
                return null;
            }

            // Loop through each slot in the chest, assign an item
            // with a probability
            for (int i = 0; i < ent.Items.Capacity; i++) {
                if (rand.NextDouble() < 0.3) {
                    // Ask the ItemTable for a random Item type registered with Substrate
                    ItemInfo itype = ItemInfo.GetRandomItem();

                    // Create the item object, give it an appropriate, random count (items in stack)
                    Item item = new Item(itype.ID);
                    item.Count = 1 + rand.Next(itype.StackSize);

                    // Assign the item to the chest at slot i
                    ent.Items[i] = item;
                }
            }

            // That's all, we've got a loaded chest block ready to be
            // inserted into a chunk
            return block;
        }
コード例 #3
0
 public void placeCommandBlock(string command, int x, int y, int z)
 {
     AlphaBlock cblock = new AlphaBlock(BlockType.COMMAND_BLOCK);
     TileEntityControl te = cblock.GetTileEntity() as TileEntityControl; //unsafe
     te.Command = command;
     if (blocks.ContainsKey(new IntVector3(x, y, z)))
     {
         blocks.Remove(new IntVector3(x, y, z));
     }
     blocks.Add(new IntVector3(x, y, z), cblock);
 }
コード例 #4
0
ファイル: JsApi.cs プロジェクト: pabranch/CommandBlocksJS
        public void placeSign(string[] text, int direction, int x, int y, int z)
        {
            AlphaBlock sign = new AlphaBlock(BlockType.SIGN_POST);
            TileEntitySign te = sign.GetTileEntity() as TileEntitySign;
            sign.Data = direction;

            if (text.Length > 0)
                te.Text1 = text[0];
            if (text.Length > 1)
                te.Text2 = text[1];
            if (text.Length > 2)
                te.Text3 = text[2];
            if (text.Length > 3)
                te.Text4 = text[3];
        }
コード例 #5
0
        public void placeSign(string[] text, int direction, int x, int y, int z)
        {
            AlphaBlock sign = new AlphaBlock(BlockType.SIGN_POST);
            TileEntitySign te = sign.GetTileEntity() as TileEntitySign;
            sign.Data = direction;

            if (text.Length > 0)
                te.Text1 = text[0];
            if (text.Length > 1)
                te.Text2 = text[1];
            if (text.Length > 2)
                te.Text3 = text[2];
            if (text.Length > 3)
                te.Text4 = text[3];

            if (blocks.ContainsKey(new IntVector3(x, y, z)))
            {
                blocks.Remove(new IntVector3(x, y, z));
            }
            blocks.Add(new IntVector3(x, y, z), sign);
        }
コード例 #6
0
ファイル: BlockManager.cs プロジェクト: omglolbah/Blightfall
        /// <summary>
        /// Updates a block with values from a <see cref="AlphaBlock"/> object.
        /// </summary>
        /// <param name="x">Global X-coordinate of a block.</param>
        /// <param name="y">Global Y-coordinate of a block.</param>
        /// <param name="z">Global Z-coordinate of a block.</param>
        /// <param name="block">A <see cref="AlphaBlock"/> object to copy block data from.</param>
        public void SetBlock(int x, int y, int z, AlphaBlock block)
        {
            cache = GetChunk(x, y, z);
            if (cache == null || !Check(x, y, z)) {
                return;
            }

            cache.Blocks.SetBlock(x & chunkXMask, y & chunkYMask, z & chunkZMask, block);
        }
コード例 #7
0
        /// <summary>
        /// Updates a block in this collection with values from a <see cref="AlphaBlock"/> object.
        /// </summary>
        /// <param name="x">Local X-coordinate of a block.</param>
        /// <param name="y">Local Y-coordinate of a block.</param>
        /// <param name="z">Local Z-coordinate of a block.</param>
        /// <param name="block">A <see cref="AlphaBlock"/> object to copy block data from.</param>
        public void SetBlock(int x, int y, int z, AlphaBlock block)
        {
            SetID(x, y, z, block.ID);
            SetData(x, y, z, block.Data);

            TileEntity te = block.GetTileEntity();
            if (te != null) {
                SetTileEntity(x, y, z, te.Copy());
            }

            TileTick tt = block.GetTileTick();
            if (tt != null) {
                SetTileTick(x, y, z, tt.Copy());
            }
        }
コード例 #8
0
        public World ConvertWorld(String mcDirectory)
        {
            String segmentDirectory = Path.Combine(FCEDirectory, "Segments");

            if (!Directory.Exists(FCEDirectory))
            {
                Directory.CreateDirectory(FCEDirectory);
            }
            if (!Directory.Exists(Path.Combine(FCEDirectory, segmentDirectory)))
            {
                Directory.CreateDirectory(segmentDirectory);
            }

            Boolean anvil = true;

            NbtWorld      nbtWorld     = AnvilWorld.Open(mcDirectory);
            String        worldName    = nbtWorld.Level.LevelName;
            IChunkManager chunkManager = nbtWorld.GetChunkManager();

            try
            {
                // Try to test for mc world type
                // Don't know how this is supposed to work, but it presumably throws an exception
                // on a non-Anvil world.
                chunkManager.Count();
            }
            catch
            {
                anvil        = false;
                nbtWorld     = BetaWorld.Open(mcDirectory);
                worldName    = nbtWorld.Level.LevelName;
                chunkManager = nbtWorld.GetChunkManager();
            }
            Int32 spawnChunkX = nbtWorld.Level.Spawn.X >> 4;
            Int32 spawnChunkZ = nbtWorld.Level.Spawn.Z >> 4;

            WorldSettings settings = new WorldSettings();

            settings.Name = worldName;
            var fceWorld       = World.Create(FCEDirectory, settings);
            var segmentManager = fceWorld.SegmentManager;

            _totalSegments = chunkManager.LongCount() * (anvil ? 16 : 8);
            _segmentsLeft  = _totalSegments;
            StartSaveThread(fceWorld);
            foreach (ChunkRef chunk in chunkManager)
            {
                // If the save thread is too slow, wait until it has caught up before adding to it to prevent high ram usage
                while (_saveQueue.Count > 5000)
                {
                    Thread.Sleep(500);
                }

                if (chunk.Blocks == null)
                {
                    _segmentsLeft -= (anvil ? 16 : 8);
                    continue;
                }

                Int32 spawnOffsetX = UseSpawnAsOrigin ? spawnChunkX - chunk.X : -chunk.X;
                Int32 spawnOffsetZ = UseSpawnAsOrigin ? spawnChunkZ - chunk.Z : -chunk.Z;

                // Minecraft has different x/y directions so we must reverse z so the world isn't mirrored
                var chunkCoords = new SegmentCoords(spawnOffsetX, 0, -spawnOffsetZ) + SegmentCoords.WorldCenter;
                for (Int32 i = 0; i < (anvil ? 16 : 8); i++)
                {
                    SegmentCoords segCoords = chunkCoords + SegmentCoords.Above * i;
                    var           segment   = new Segment(segmentManager, segCoords);
                    var           array     = new Cube[16, 16, 16];
                    for (Byte x = 0; x < 16; x++)
                    {
                        for (Byte y = 0; y < 16; y++)
                        {
                            for (Byte z = 0; z < 16; z++)
                            {
                                // Minecraft has different x/y directions so we must reverse z so the world isn't mirrored
                                AlphaBlock block    = chunk.Blocks.GetBlock(15 - z, y + i * 16, x);
                                UInt32     mcIdData = (UInt32)block.ID << 16 | (UInt16)block.Data;

                                Cube cube;
                                if (!_mcIdDataToFCECube.TryGetValue(mcIdData, out cube))
                                {
                                    cube = new Cube(1, 0, 0, 0);
                                    if (!UnknownBlocks.ContainsKey((UInt16)block.ID))
                                    {
                                        UnknownBlocks.Add((UInt16)block.ID, block.Info.Name);
                                    }
                                }
                                array[z, y, x] = cube;
                            }
                        }
                    }

                    segment.CubeData = array;
                    _segmentsLeft--;
                    _saveQueue.Enqueue(segment);
                }
                // Pad the area above the converted world with 11 blank segments to prevent world gen from occuring
                // Possibly replace this in the future with simply shifting the world up
                for (Int32 i = (anvil ? 16 : 8); i < 27; i++)
                {
                    var padding = new Segment(segmentManager, chunkCoords + SegmentCoords.Above * i);
                    padding.CubeData = Segment.GetBlankSegment().CubeData;
                    padding.IsEmpty  = true;
                    _saveQueue.Enqueue(padding);
                }
            }
            Task.WaitAll(_saveTask);

            return(fceWorld);
        }
コード例 #9
0
        public void Execute()
        {
            IChunkManager cm = cmPoolHolder.Target.Get(Thread.CurrentThread.ManagedThreadId);

            // Get chunks
            for (int mc_cx = 0; mc_cx < 2; mc_cx++)
            {
                for (int mc_cz = 0; mc_cz < 2; mc_cz++)
                {
                    if (cm.ChunkExists(cx * 2 + mc_cx, cz * 2 + mc_cz))
                    {
                        var mc_blocks = cm.GetChunkRef(cx * 2 + mc_cx, cz * 2 + mc_cz).Blocks;
                        if (mc_blocks == null)
                        {
                            continue;
                        }

                        for (int cy = 0; cy < cySize; cy++)
                        {
                            Chunk     chunk = chunks.Target[cy];
                            BoundsInt b     = new BoundsInt(0, 0, 0, 16, 32, 16);
                            foreach (var pos in b.allPositionsWithin)
                            {
                                //if (pos.y + cy * 32 < 5)
                                //{
                                //    chunk.chunkData[pos.x * 1024 + pos.y * 32 + pos.z] = 0xffffffff;
                                //}
                                //else
                                //{
                                //    chunk.chunkData[pos.x * 1024 + pos.y * 32 + pos.z] = 0x00000000;
                                //}

                                AlphaBlock blk = mc_blocks.GetBlock(pos.x, pos.y + cy * 32, pos.z);
                                int        ix  = (pos.x + mc_cx * 16) * 1024 + pos.y * 32 + (pos.z + mc_cz * 16);
                                uint       cbk = 0x00000000;

                                switch (blk.ID)
                                {
                                // air
                                case 0:
                                    cbk = 0;
                                    break;

                                // stone
                                case 1:
                                    cbk = 0x6b6b6bff;
                                    break;

                                // grass
                                case 2:
                                    cbk = 0x71a32aff;
                                    break;

                                // dirt
                                case 3:
                                    cbk = 0x694429ff;
                                    break;

                                // log
                                case 17:
                                    cbk = 0x96623bff;
                                    break;

                                // leaves
                                case 18:
                                    cbk = 0x147a23ff;
                                    break;

                                // water
                                case 9:
                                    cbk = 0x0000FFFF;
                                    break;

                                default:
                                    cbk = 0xFFFFFFFF;
                                    break;
                                }

                                if (cbk != 0)
                                {
                                    chunk.SetBlock(pos.x + mc_cx * 16, pos.y, pos.z + mc_cz * 16, Block.From32bitColor(cbk));
                                }
                                else
                                {
                                    chunk.SetBlock(pos.x + mc_cx * 16, pos.y, pos.z + mc_cz * 16, Block.Empty);
                                }

                                if (useID)
                                {
                                    chunk.SetBlock(pos.x + mc_cx * 16, pos.y, pos.z + mc_cz * 16, new Block()
                                    {
                                        id = (ushort)blk.ID, meta = chunk.blockData[ix].meta
                                    });
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #10
0
ファイル: WorldStamp.cs プロジェクト: heneryville/MineDefine
 public void PlaceBlock(AlphaBlock block, Location loc)
 {
     _blockManager.SetID(loc.X, loc.Y, loc.Z,block.ID);
 }
コード例 #11
0
ファイル: BlockStamp.cs プロジェクト: heneryville/MineDefine
 public void PlaceBlock(AlphaBlock block, Location loc)
 {
     _world.GetBlockManager().SetBlock(loc.X, loc.Y, loc.Z, block);
 }
コード例 #12
0
ファイル: Schematic.cs プロジェクト: IAAA-Lab/EINA-TO-NBT
        /// <summary>
        /// Exports the <see cref="Schematic"/> object to a schematic file.
        /// </summary>
        /// <param name="path">The path to write out the schematic file to.</param>
        public void Export(string path)
        {
            int xdim = _blockset.XDim;
            int ydim = _blockset.YDim;
            int zdim = _blockset.ZDim;

            byte[] blockData = new byte[xdim * ydim * zdim];
            byte[] dataData  = new byte[xdim * ydim * zdim];

            YZXByteArray schemaBlocks = new YZXByteArray(_blockset.XDim, _blockset.YDim, _blockset.ZDim, blockData);
            YZXByteArray schemaData   = new YZXByteArray(_blockset.XDim, _blockset.YDim, _blockset.ZDim, dataData);

            TagNodeList entities     = new TagNodeList(TagType.TAG_COMPOUND);
            TagNodeList tileEntities = new TagNodeList(TagType.TAG_COMPOUND);

            for (int x = 0; x < xdim; x++)
            {
                for (int z = 0; z < zdim; z++)
                {
                    for (int y = 0; y < ydim; y++)
                    {
                        AlphaBlock block = _blockset.GetBlock(x, y, z);
                        schemaBlocks[x, y, z] = (byte)block.ID;
                        schemaData[x, y, z]   = (byte)block.Data;

                        TileEntity te = block.GetTileEntity();
                        if (te != null)
                        {
                            te.X = x;
                            te.Y = y;
                            te.Z = z;

                            tileEntities.Add(te.BuildTree());
                        }
                    }
                }
            }

            foreach (TypedEntity e in _entityset)
            {
                entities.Add(e.BuildTree());
            }

            TagNodeCompound schematic = new TagNodeCompound();

            schematic["Width"]  = new TagNodeShort((short)xdim);
            schematic["Length"] = new TagNodeShort((short)zdim);
            schematic["Height"] = new TagNodeShort((short)ydim);

            schematic["Entities"]     = entities;
            schematic["TileEntities"] = tileEntities;

            schematic["Materials"] = new TagNodeString("Alpha");

            schematic["Blocks"] = new TagNodeByteArray(blockData);
            schematic["Data"]   = new TagNodeByteArray(dataData);

            NBTFile schematicFile = new NBTFile(path);

            using (Stream nbtStream = schematicFile.GetDataOutputStream())
            {
                if (nbtStream == null)
                {
                    return;
                }

                NbtTree tree = new NbtTree(schematic, "Schematic");
                tree.WriteTo(nbtStream);
            }
        }
コード例 #13
0
ファイル: Element.cs プロジェクト: heneryville/MineDefine
 public SingleBlock(AlphaBlock block)
 {
     _block = block;
 }
コード例 #14
0
ファイル: FakeStamp.cs プロジェクト: heneryville/MineDefine
 public void PlaceBlock(AlphaBlock block, Location loc)
 {
     placements[loc] = block;
 }
コード例 #15
0
        /// <summary>
        /// Updates a block in this collection with values from a <see cref="AlphaBlock"/> object.
        /// </summary>
        /// <param name="x">Local X-coordinate of a block.</param>
        /// <param name="y">Local Y-coordinate of a block.</param>
        /// <param name="z">Local Z-coordinate of a block.</param>
        /// <param name="block">A <see cref="AlphaBlock"/> object to copy block data from.</param>
        public void SetBlock(int x, int y, int z, AlphaBlock block)
        {
            SetID(x, y, z, block.ID);
            SetData(x, y, z, block.Data);

            SetTileEntity(x, y, z, block.GetTileEntity().Copy());
        }