public static void FixPlayerPlacement(ref IMapHandler mh) { // Thank you #mcp. //<_303> [PlayerPos is] on the head //<_303> corner pointing toward 0,0,0 Vector3d pos = mh.PlayerPos; //<_303> height of player = [1.8] int headblock = mh.GetBlockAt((int)pos.X, (int)pos.Y, (int)pos.Z); switch (headblock) { case 0: case 8: case 9: case 10: case 11: return; } for (int y = (int)mh.ChunkScale.Y - 3; y > 1; y--) { int supportblock = mh.GetBlockAt((int)pos.X, y - 3, (int)pos.Z); if (supportblock != 0) { mh.PlayerPos.Y = y; return; } } }
public byte GetBlock(int x, int y, int z) { if (x < 0 || y < 0 || z < 0 || x >= Size.X || y >= Size.Y || z >= Size.Z) { return(Map.GetBlockAt(x + (int)(Size.X * Position.X), Utils.Clamp(y, 0, 127), z + (int)(Size.Z * Position.Z))); //return 0; } return(Blocks[x, y, z]); }
public override void DoBlockLighting(IMapHandler _mh, long X, long Y) { int csx = (int)_mh.ChunkScale.X; int csy = (int)_mh.ChunkScale.Y; for (int i = 0; i < 15; i++) { for (int _x = 0; _x < csx; _x++) { for (int _y = 0; _y < csy; _y++) { int x = (int)(X * _mh.ChunkScale.X) + _x; int y = (int)(Y * _mh.ChunkScale.Y) + _y; for (int z = 0; z < _mh.GetHeightAt(x, y); z++) { byte currentBlockLight,currentSkyLight; _mh.GetLightAt(x, y, z, out currentSkyLight, out currentBlockLight); byte currentBlock = _mh.GetBlockAt(x, y, z); Block currentBlockInfo = OpenMinecraft.Blocks.Get(currentBlock); // SUNLIGHT currentSkyLight = (byte)(currentSkyLight - currentBlockInfo.Stop - 1); if (currentBlockInfo.Emit > 0) currentBlockLight = currentBlockInfo.Emit; // Get brightest neighbor if (x < csx - 1 && currentBlockLight < _mh.GetBlockLightAt(x + 1, y, z)) currentBlockLight = _mh.GetBlockLightAt(x + 1, y, z); if (y < csy - 1 && currentBlockLight < _mh.GetBlockLightAt(x, y + 1, z)) currentBlockLight = _mh.GetBlockLightAt(x, y + 1, z); if (z < _mh.ChunkScale.Z - 1 && currentBlockLight < _mh.GetBlockLightAt(x, y, z + 1)) currentBlockLight = _mh.GetBlockLightAt(x, y, z + 1); if (x > 0 && currentBlockLight < _mh.GetBlockLightAt(x - 1, y, z)) currentBlockLight = _mh.GetBlockLightAt(x - 1, y, z); if (y > 0 && currentBlockLight < _mh.GetBlockLightAt(x, y - 1, z)) currentBlockLight = _mh.GetBlockLightAt(x, y - 1, z); if (z > 0 && currentBlockLight < _mh.GetBlockLightAt(x, y, z - 1)) currentBlockLight = _mh.GetBlockLightAt(x, y, z - 1); // Drop 1 level of light + lightstop for current block currentBlockLight = (byte)(currentBlockLight - 1 - currentBlockInfo.Stop); if (currentBlockLight < 0) currentBlockLight = 0; if (currentBlockLight > 15) currentBlockLight = 15; if (currentSkyLight < 0) currentSkyLight = 0; if (currentSkyLight > 15) currentSkyLight = 15; _mh.SetBlockLightAt(x, y, z, currentBlockLight); _mh.SetSkyLightAt(x, y, z, currentSkyLight); } } } } }
private void MakeSphere(Vector3i pos, int rad) { Profiler profRead = new Profiler("Read"); Profiler profWrite = new Profiler("Write"); int radsq = rad ^ 2; // So we don't have to do sqrt, which is slow for (int x = (int)pos.X - rad; x < pos.X + rad; x++) { for (int y = (int)pos.Y - rad; y < pos.Y + rad; y++) { for (int z = (int)pos.Z - rad; z < pos.Z + rad; z++) { if (y < 0 || y >= mMap.ChunkScale.Y - 1) { continue; } profRead.Start(); byte block = mMap.GetBlockAt(x, y, z); profRead.Stop(); //byte blockabove = mMap.GetBlockAt(x,y+1,z); // If water/sand/gravel, or the block above is, abort if (block == 0 || block == 8 || block == 9 || block == 12 || block == 13 || block == KnownBlocks.Error) { continue; } //if (blockabove == 0 || blockabove == 8 || blockabove == 9 || blockabove == 12 || blockabove == 13) // continue; int distsq = (x - (int)pos.X) ^ 2 + (y - (int)pos.Y) ^ 2 + (z - (int)pos.Z); if (distsq <= radsq) { profWrite.Start(); mMap.SetBlockAt(x, y, z, 0); profWrite.Stop(); } } } } Console.WriteLine(profRead.ToString()); Console.WriteLine(profWrite.ToString()); }
public virtual void AddTrees(ref IMapHandler mh, BiomeType[,] biomes, ref Random rand, int X, int Z, int H) { int xo = (int)(X * mh.ChunkScale.X); int zo = (int)(Z * mh.ChunkScale.Z); List <Vector2i> PlantedTrees = new List <Vector2i>(); int DistanceReqd = 3; for (int t = 0; t < (int)((HumidityNoise.Noise((double)(xo) / BIOME_SCALE, (double)(zo) / BIOME_SCALE, 0) + HumidityOffset) * 5.0); t++) { Vector2i me = new Vector2i(rand.Next(0, 15), rand.Next(0, 15)); if (!Biome.NeedsTrees(biomes[me.X, me.Y])) { continue; } bool tooclose = false; foreach (Vector2i tree in PlantedTrees) { if (Vector2i.Distance(tree, me) < DistanceReqd) { tooclose = true; break; } } if (tooclose) { continue; } bool founddert = false; for (int y = (int)H - 10; y > 0; y--) { switch (mh.GetBlockAt(me.X + xo, y, me.Y + zo)) { case 0: // Air case 78: // Snow cover continue; // case 1: // ROCK case 2: // GRASS case 3: // DIRT //Utils.GrowTree(ref blocks, rand, (int)me.X, (int)y + 1, (int)me.Y); mh.SetBlockAt(me.X + xo, y + 1, me.Y + zo, 6); // Sapling mh.SetDataAt(me.X + xo, y + 1, me.Y + zo, 15); // Growth stage 15. /* * Tree tree = new NormalTree(me.X + xo, y + 1, me.Y + zo, rand.Next(5, 8)); * tree.MakeTrunk(ref mh); * tree.MakeFoliage(ref mh); */ mh.SaveAll(); founddert = true; break; case 11: // SAND //Utils.GrowCactus(ref b, rand, me.X, y + 1, me.Y); break; default: founddert = true; break; } if (founddert) { break; } } PlantedTrees.Add(me); } }
public virtual void AddTrees(ref IMapHandler mh, BiomeType[,] biomes, ref Random rand, int X, int Z, int H) { int xo = (int)(X * mh.ChunkScale.X); int zo = (int)(Z * mh.ChunkScale.Z); List<Vector2i> PlantedTrees = new List<Vector2i>(); int DistanceReqd = 3; for (int t = 0; t < (int)((HumidityNoise.Noise((double)(xo) / BIOME_SCALE, (double)(zo) / BIOME_SCALE, 0) + HumidityOffset) * 5.0); t++) { Vector2i me = new Vector2i(rand.Next(0, 15),rand.Next(0, 15)); if (!Biome.NeedsTrees(biomes[me.X, me.Y])) continue; bool tooclose=false; foreach (Vector2i tree in PlantedTrees) { if (Vector2i.Distance(tree, me) < DistanceReqd) { tooclose = true; break; } } if (tooclose) continue; bool founddert = false; for (int y = (int)H - 10; y > 0; y--) { switch (mh.GetBlockAt(me.X+xo, y, me.Y+zo)) { case 0: // Air case 78: // Snow cover continue; // case 1: // ROCK case 2: // GRASS case 3: // DIRT //Utils.GrowTree(ref blocks, rand, (int)me.X, (int)y + 1, (int)me.Y); mh.SetBlockAt(me.X + xo, y + 1, me.Y + zo, 6); // Sapling mh.SetDataAt(me.X + xo, y + 1, me.Y + zo, 15); // Growth stage 15. /* Tree tree = new NormalTree(me.X + xo, y + 1, me.Y + zo, rand.Next(5, 8)); tree.MakeTrunk(ref mh); tree.MakeFoliage(ref mh); */ mh.SaveAll(); founddert = true; break; case 11: // SAND //Utils.GrowCactus(ref b, rand, me.X, y + 1, me.Y); break; default: founddert = true; break; } if (founddert) break; } PlantedTrees.Add(me); } }
public static void FixPlayerPlacement(ref IMapHandler mh) { // Thank you #mcp. //<_303> [PlayerPos is] on the head //<_303> corner pointing toward 0,0,0 Vector3d pos = mh.PlayerPos; //<_303> height of player = [1.8] int headblock = mh.GetBlockAt((int)pos.X,(int)pos.Y,(int)pos.Z); switch (headblock) { case 0: case 8: case 9: case 10: case 11: return; } for (int y = (int)mh.ChunkScale.Y - 3; y > 1; y--) { int supportblock = mh.GetBlockAt((int)pos.X, y-3, (int)pos.Z); if (supportblock != 0) { mh.PlayerPos.Y = y; return; } } }
public override void DoBlockLighting(IMapHandler _mh, long X, long Y) { int csx = (int)_mh.ChunkScale.X; int csy = (int)_mh.ChunkScale.Y; for (int i = 0; i < 15; i++) { for (int _x = 0; _x < csx; _x++) { for (int _y = 0; _y < csy; _y++) { int x = (int)(X * _mh.ChunkScale.X) + _x; int y = (int)(Y * _mh.ChunkScale.Y) + _y; for (int z = 0; z < _mh.GetHeightAt(x, y); z++) { byte currentBlockLight, currentSkyLight; _mh.GetLightAt(x, y, z, out currentSkyLight, out currentBlockLight); byte currentBlock = _mh.GetBlockAt(x, y, z); Block currentBlockInfo = OpenMinecraft.Blocks.Get(currentBlock); // SUNLIGHT currentSkyLight = (byte)(currentSkyLight - currentBlockInfo.Stop - 1); if (currentBlockInfo.Emit > 0) { currentBlockLight = currentBlockInfo.Emit; } // Get brightest neighbor if (x < csx - 1 && currentBlockLight < _mh.GetBlockLightAt(x + 1, y, z)) { currentBlockLight = _mh.GetBlockLightAt(x + 1, y, z); } if (y < csy - 1 && currentBlockLight < _mh.GetBlockLightAt(x, y + 1, z)) { currentBlockLight = _mh.GetBlockLightAt(x, y + 1, z); } if (z < _mh.ChunkScale.Z - 1 && currentBlockLight < _mh.GetBlockLightAt(x, y, z + 1)) { currentBlockLight = _mh.GetBlockLightAt(x, y, z + 1); } if (x > 0 && currentBlockLight < _mh.GetBlockLightAt(x - 1, y, z)) { currentBlockLight = _mh.GetBlockLightAt(x - 1, y, z); } if (y > 0 && currentBlockLight < _mh.GetBlockLightAt(x, y - 1, z)) { currentBlockLight = _mh.GetBlockLightAt(x, y - 1, z); } if (z > 0 && currentBlockLight < _mh.GetBlockLightAt(x, y, z - 1)) { currentBlockLight = _mh.GetBlockLightAt(x, y, z - 1); } // Drop 1 level of light + lightstop for current block currentBlockLight = (byte)(currentBlockLight - 1 - currentBlockInfo.Stop); if (currentBlockLight < 0) { currentBlockLight = 0; } if (currentBlockLight > 15) { currentBlockLight = 15; } if (currentSkyLight < 0) { currentSkyLight = 0; } if (currentSkyLight > 15) { currentSkyLight = 15; } _mh.SetBlockLightAt(x, y, z, currentBlockLight); _mh.SetSkyLightAt(x, y, z, currentSkyLight); } } } } }