static void Dirt(Level level, int pos) { BlockPos blockPos = level.IntToPos(pos); //This code works, but in order to change dirt into grass we have to check below every block in the same way, so we wont use it for now //if (level.physics.realistic) //{ // for (int y = blockPos.y + 1; y < level.sizeY; ++y) // { // BlockPos currentBlockPos = new BlockPos(blockPos.x, (ushort)y, blockPos.z); // int currentPos = level.PosToInt(currentBlockPos); // byte type = level.blocks[currentPos]; // if (!Block.LightPass.Contains(type)) { return; } // } //} //else { BlockPos currentBlockPos = blockPos.diff(0, 1, 0); int currentPos = level.PosToInt(currentBlockPos); byte type = level.blocks[currentPos]; if (!Block.lightPass.Contains(type)) return; } if (level.blocks[pos] != (byte)Blocks.Dirt) return; level.PhysicsBlockChange(blockPos, Blocks.Grass); }
static void Water(Level level, int pos) { BlockPos blockPos = level.IntToPos(pos); BlockPos belowBlockPos = blockPos.diff(0, -1, 0); int belowPos = level.PosToInt(belowBlockPos); byte type = level.blocks[belowPos]; if (type == (byte)Blocks.WaterStill) { level.physics.OtherData.Remove(belowPos); level.physics.OtherData.Add(belowPos, level.physics.waterCurrent); } else if (Block.crushable.Contains(type)) { level.physics.OtherData.Remove(belowPos); level.physics.OtherData.Add(belowPos, level.physics.waterCurrent); level.PhysicsBlockChange(belowBlockPos, Blocks.WaterStill); } else { for (int _X = -1; _X < 2; ++_X) for (int _Z = -1; _Z < 2; ++_Z) { if (Math.Abs(_X) == 1 && Math.Abs(_Z) == 1) continue; if (blockPos.x + _X < 0 || blockPos.z + _Z < 0) continue; BlockPos aroundPos = blockPos.diff(_X, 0, _Z); if (level.NotInBounds(aroundPos)) continue; int newPos = level.PosToInt(aroundPos); if (level.blocks[newPos] == (byte)Blocks.WaterStill) { level.physics.OtherData.Remove(newPos); level.physics.OtherData.Add(newPos, level.physics.waterCurrent); } else if (Block.crushable.Contains(level.blocks[newPos])) { level.physics.OtherData.Remove(newPos); level.physics.OtherData.Add(newPos, level.physics.waterCurrent); level.PhysicsBlockChange(aroundPos, Blocks.WaterStill); //if (level.physics.PhysicsUpdates.Contains(level.PosToInt(aroundBelowPos))) return; //level.physics.PhysicsUpdates.Add(level.PosToInt(aroundBelowPos)); return; } else { continue; } } } }
static void Sponge(Level level, int pos) { BlockPos blockPos = level.IntToPos(pos); for (int _x = -1; _x < 2; ++_x) { for (int _y = -1; _y < 2; ++_y) { for (int _z = -1; _z < 2; ++_z) { BlockPos currentBlockPos = blockPos.diff(_x, _y, _z); int currentPos = level.PosToInt(currentBlockPos); if (level.NotInBounds(currentBlockPos)) continue; Blocks type = (Blocks)level.blocks[currentPos]; if (type == Blocks.Water || type == Blocks.WaterStill || type == Blocks.Lava || type == Blocks.LavaStill) { level.PhysicsBlockChange(currentBlockPos, Blocks.Air); } } } } }
static void Sand(Level level, int pos) { BlockPos blockPos = level.IntToPos(pos); BlockPos belowBlockPos = blockPos.diff(0, -1, 0); Blocks below = level.GetTile(belowBlockPos); if (below == Blocks.Zero) { return; } else if (Block.crushable.Contains((byte)below)) { level.PhysicsBlockChange(belowBlockPos, Blocks.Sand); level.PhysicsBlockChange(blockPos, Blocks.Air); //if(level.physics.PhysicsUpdates.Contains(level.PosToInt(belowPos))) return; //level.physics.PhysicsUpdates.Add(level.PosToInt(belowPos)); } else if (level.physics.realistic) { for(int _X = -1;_X<2;++_X) for (int _Z = -1; _Z < 2; ++_Z) { if (Math.Abs(_X) == 1 && Math.Abs(_Z) == 1) continue; if (belowBlockPos.x + _X < 0 || belowBlockPos.z + _Z < 0) continue; BlockPos aroundPos = blockPos.diff(_X, 0, _Z); BlockPos aroundBelowPos = belowBlockPos.diff(_X, 0, _Z); if (level.NotInBounds(aroundBelowPos)) continue; int testPos = level.PosToInt(aroundPos); int newPos = level.PosToInt(aroundBelowPos); if (Block.crushable.Contains(level.blocks[newPos]) && level.blocks[testPos] == 0) { level.PhysicsBlockChange(aroundBelowPos, Blocks.Sand); level.PhysicsBlockChange(blockPos, Blocks.Air); //if (level.physics.PhysicsUpdates.Contains(level.PosToInt(aroundBelowPos))) return; //level.physics.PhysicsUpdates.Add(level.PosToInt(aroundBelowPos)); return; } else { continue; } } } }
static void HalfStair(Level level, int pos) { BlockPos blockPos = level.IntToPos(pos); BlockPos belowBlockPos = blockPos.diff(0, -1, 0); int belowPos = level.PosToInt(belowBlockPos); if (level.blocks[belowPos] == (byte)Blocks.Staircasestep) { level.PhysicsBlockChange(belowBlockPos, Blocks.Staircasefull); level.PhysicsBlockChange(blockPos, Blocks.Air); } }
static void Grass(Level level, int pos) { BlockPos blockPos = level.IntToPos(pos); BlockPos aboveBlockPos = blockPos.diff(0, 1, 0); int abovePos = level.PosToInt(aboveBlockPos); byte type = level.blocks[abovePos]; if (Block.lightPass.Contains(type)) return; level.PhysicsBlockChange(blockPos, Blocks.Dirt); }