public void SetTileEntity(Vector2 Position, TileEntity TE) { Vector2 ChunkV = WorldHelper.GetChunkPos(Position); if (Chunks.ContainsKey(ChunkV)) { Vector2 TEPos = WorldHelper.GetBlockInChunkPos(Position); Chunks[ChunkV].TileEntities[(int)TEPos.X, (int) TEPos.Y] = TE; } }
public static void RegisterBlock(TileEntity TE) { TE.TileBlock.LoadTextures(); TE.TileBlock.CreateShape(); //BlockRegistry.Add(new KeyValuePair<int, Block>(TE.TileBlock.Id, TE.TileBlock)); try { BlockRegist.Add(TE.TileBlock.Id, TE.TileBlock); } catch (ArgumentException e) { Logger.Write("Failed to add new Block key, probably it was already registered or you are calling register in wrong place"); Logger.Write(e.StackTrace.ToString()); } }
public void SetBlock(Vector2 Vect, TileEntity TE) { Vector2 ChunkV = WorldHelper.GetChunkPos(Vect); if (this.Chunks.ContainsKey(ChunkV)) { TE.Position = Vect; if (TE is IMultiBlockTE) // if TE is multiblock entity { MultiBlockDef MultiBlock = (TE as IMultiBlockTE).GetMultiBlockDef(); //Vector2 Center = (TE as IMultiBlockTE).GetCenterCoord(); if ((TE as IMultiBlockTE).CanBePlaced(Vect)) { for (int y = 0; y < MultiBlock.Size.Y; y++) { for (int x = 0; x < MultiBlock.Size.X; x++) { SetBlock(Vect + new Vector2(x, y), MultiBlock.BlockTable[x, y]); SetTileEntity(Vect + new Vector2(x, y), TE); //Chunks[ChunkV].TileEntities[(int)PosInChunk.X + x, (int)PosInChunk.Y + y] = TE; } } } } else // if TE is single block { SetBlock(Vect, TE.TileBlock); Vector2 PosInChunk = WorldHelper.GetBlockInChunkPos(Vect); Chunks[ChunkV].TileEntities[(int)PosInChunk.X, (int)PosInChunk.Y] = TE; } } }