// 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; }
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); }
// 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); }
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); }
static void setBlock(ChunkRef chunk, int x, int y, int z, int color, string text) { if (color < 16) { chunk.Blocks.SetBlock(x, y, z, new AlphaBlock((int)BlockType.WOOL, color)); } else if (color == 16) { chunk.Blocks.SetBlock(x, y, z, new AlphaBlock((int)BlockType.GRASS)); } else if (color == 17) { chunk.Blocks.SetBlock(x, y, z, new AlphaBlock((int)BlockType.WOOD)); } else if (color == 18) { chunk.Blocks.SetBlock(x, y, z, new AlphaBlock((int)BlockType.LEAVES)); } else if (color == 19) { AlphaBlock block = new AlphaBlock(63); TileEntitySign tile = new TileEntitySign(block.GetTileEntity()); tile.Text1 = text; block.SetTileEntity(tile); chunk.Blocks.SetBlock(x, y, z + 1, block); block = new AlphaBlock(63, 8); tile = new TileEntitySign(block.GetTileEntity()); tile.Text1 = text; block.SetTileEntity(tile); chunk.Blocks.SetBlock(x, y, z - 1, block); block = new AlphaBlock(63, 4); tile = new TileEntitySign(block.GetTileEntity()); tile.Text1 = text; block.SetTileEntity(tile); chunk.Blocks.SetBlock(x - 1, y, z, block); block = new AlphaBlock(63, 12); tile = new TileEntitySign(block.GetTileEntity()); tile.Text1 = text; block.SetTileEntity(tile); chunk.Blocks.SetBlock(x + 1, y, z, block); } else if (color == 20) { chunk.Blocks.SetBlock(x, y, z, new AlphaBlock((int)BlockType.GLASS)); } }
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]; }
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); }
/// <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()); } }
/// <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 (EntityTyped 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); Stream nbtStream = schematicFile.GetDataOutputStream(); if (nbtStream == null) { return; } NbtTree tree = new NbtTree(schematic, "Schematic"); tree.WriteTo(nbtStream); nbtStream.Close(); }
/// <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()); }