/// <summary> /// Gets the block at pos /// </summary> /// <param name="pos">Global position of the block</param> /// <returns>The block at the given global coordinates</returns> public Block GetBlock(BlockPos pos) { Chunk containerChunk = GetChunk(pos); if (containerChunk != null) { BlockPos localPos = pos - containerChunk.Position; if (!Chunk.InRange(localPos)) { Debug.LogError("Error while setting block"); return(Block.Void); } return(containerChunk.GetBlock(localPos)); } else { return("solid"); } }
public Rect GetTexture(Chunk chunk, BlockPos pos, Direction direction) { if (UsesConnectedTextures) { string blockName = chunk.GetBlock(pos).Controller.Name(); bool wn = ConnectedTextures.IsSame(chunk, pos, -1, 1, direction, blockName); bool n = ConnectedTextures.IsSame(chunk, pos, 0, 1, direction, blockName); bool ne = ConnectedTextures.IsSame(chunk, pos, 1, 1, direction, blockName); bool w = ConnectedTextures.IsSame(chunk, pos, -1, 0, direction, blockName); bool e = ConnectedTextures.IsSame(chunk, pos, 1, 0, direction, blockName); bool es = ConnectedTextures.IsSame(chunk, pos, 1, -1, direction, blockName); bool s = ConnectedTextures.IsSame(chunk, pos, 0, -1, direction, blockName); bool sw = ConnectedTextures.IsSame(chunk, pos, -1, -1, direction, blockName); return(m_ConnectedTextures[ConnectedTextures.GetTexture(n, e, s, w, wn, ne, es, sw)]); } if (m_Textures.Count == 1) { return(m_Textures[0]); } if (m_Textures.Count > 1) { float randomNumber = m_NoiseGen.Generate(pos.x, pos.y, pos.z); randomNumber += 1; randomNumber /= 2; randomNumber *= m_Textures.Count; return(m_Textures[(int)randomNumber]); } Debug.LogError("There were no textures for " + TextureName); return(new Rect()); }
public static bool IsSame(Chunk chunk, BlockPos pos, int h, int v, Direction forwards, string name) { return(chunk.GetBlock(RelativePos(pos, h, v, forwards)).Controller.Name() == name); }
public static Block GetBlock(Chunk chunk, BlockPos pos) { return(chunk.GetBlock(pos)); }